Hello! I was tasked with creating a blob of lava in unity.
Naturally everything I found was a premade asset you could buy or it was for UE4.
So I took the one UE4 tutorial that got close to what I wanted and tried to replicate the nodes in shaderforge.
At the same time I send a link to a premade substance lava material from textures.com to a friend of mine to ask what the best plan of action was to make a similar effect. With one look she could tell that the textures it used weren’t for colour, they were masks and had a normal map.
Knowing that makes everything easier!
So, what you need:
You’ll need a mask map (for emission and colour), normal map, ambient occlusion and roughness maps would also be useful, but you can still get a basic flowing lava shader without the last two. Look up some examples and make your own, or do what I do and download some free ones! I’m sure there are some even better ones you can buy too.
I get 90% of my textures from this site, its super useful – https://www.textures.com/
Let’s get started –
Open up Shaderforge, create a basic shader.
Create a texture2D node, load in your normal map, tick normal map on. Rename it to normal map.
Create a texture asset node, load in your mask, plug the rgb output to the tex input of 2 texture2D nodes. Rename one Diffuse and the other Emission
If the node is green, it means it becomes an editable parameter for whoever uses the materials created from this shader.
From here on I’m going to split the steps up in categories instead of the method I used, that way if you’re only interested in panning uvs you can just take that bit.
For that “flowing” effect, you move the UVs of the all the texture maps.
In this example we will be rolling the Mask (which is plugged into Emission).
Bring in a time node and a uv coordinates node. Add the t output on the time node and UV output on the coordinates node together, output goes into the UV input of your texture2D node.
Result is a moving texture!
Though it’s moving quite quickly, especially if you want slow moving lava.
To control the speed:
Bring in two value nodes
Name one something like Speed_U, the other Speed_V
(you can use spaces in these names, I just prefer not to)
Bring in an append and a multiply node.
Connect the value nodes to the Append node.
The output of the Append goes into the first input of the multiply node. Reconnect the time node from the add it is in to the multiply node.
The multiply node is then plugged in to the add node with the UV coordinates output as the second input.
The result of that add plugs into the UV input of the texture node.
Finally, change the values in the value nodes to any number and what the texture change speed. Set it to something you like.
Don’t forget to compile shader!
To tile UVs:
Place two value nodes down. Name one Tile_U and the other Tile_V
Create an append and multiply node.
Attach the values to the append, and plug in the output to the multiply node.
Plug in the result of the add from the speed set up above to the second input in the multiply node.
If you didn’t do that set up, or your setup doesn’t need panning textures, just plug in the UV coordinates.
The result of the multiply is plugged into the UV input of the texture asset.
Changing the values will now tile the texture!
Controlling strength of texture:
This one is super simple – add a multiply node with a constant/value in input B to a texture right before plugging into the shader
Now all that’s left is to set up your normal map and the other mask for colour using the above techniques and you will have completed a lava shader!
Play around with the different ways you can put a colour over your mask
For example, you could divide the colour by the mask –
Or you could subtract it, whatever works for you.
Note: The shader will not compile if you have two green nodes with the same name.