I am just starting with shader programming and after reading a bit, I tried creating a shader that is simulating the flow of lava on rocks. Got a placeholder rock texture from internet and everything, however the end result is obviously bad. How can I simulate a flow that moves in the cracks between the rocks? My first idea was to somehow get the color of the cracks and change it to red. Then to animate it by just moving the texture with the Panner node.

Right now it just drags the bubbles texture and returns it.

Here is my shader code (generated by Shader Forge) :

 // Shader created with Shader Forge v1.38 
// Shader Forge (c) Neat Corporation / Joachim Holmer - http://www.acegikmo.com/shaderforge/
// Note: Manually altering this data may prevent you from opening it in Shader Forge

Shader "Shader Forge/lavaFlow" {
    Properties {
        _Bubbles ("Bubbles", 2D) = "white" {}
        _node_4099 ("node_4099", Color) = (1,0.2279412,0.2279412,0.5)
        _MainTex ("MainTex", 2D) = "white" {}
        _Alpha ("Alpha", Float ) = 0
    SubShader {
        Tags {
        Pass {
            Name "FORWARD"
            Tags {

            #pragma vertex vert
            #pragma fragment frag
            #define UNITY_PASS_FORWARDBASE
            #include "UnityCG.cginc"
            #pragma multi_compile_fwdbase_fullshadows
            #pragma only_renderers d3d9 d3d11 glcore gles 
            #pragma target 3.0
            uniform sampler2D _Bubbles; uniform float4 _Bubbles_ST;
            uniform fixed4 _node_4099;
            uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
            uniform float _Alpha;
            struct VertexInput {
                float4 vertex : POSITION;
                float2 texcoord0 : TEXCOORD0;
            struct VertexOutput {
                float4 pos : SV_POSITION;
                float2 uv0 : TEXCOORD0;
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.uv0 = v.texcoord0;
                o.pos = UnityObjectToClipPos( v.vertex );
                return o;
            float4 frag(VertexOutput i) : COLOR {
////// Lighting:
////// Emissive:
                fixed4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex));
                fixed4 node_156 = _Time;
                fixed4 node_9149 = _Time;
                float2 vvvvvvvvvvvvvvvvvvvvvv = (i.uv0+(sin(node_9149.g)*0.1+0.2)*float2(0,1));
                float4 _Bubbles_var = tex2D(_Bubbles,TRANSFORM_TEX(vvvvvvvvvvvvvvvvvvvvvv, _Bubbles));
                float3 emissive = ((((1.0 - _MainTex_var.rgb)*_node_4099.rgb*_node_4099.a)*(sin(node_156.g)*0.2+0.4))+(_Bubbles_var.rgb*_Alpha));
                float3 finalColor = emissive;
                return fixed4(finalColor,1);
    FallBack "Diffuse"
    CustomEditor "ShaderForgeMaterialInspector"

P.S. I decided to add the Bubbles texture, so I can at least try to animate the move of the flow.


GIF Link to imgur

The colors are broken after the upload, however the gif shows the movement. The circle things are the "bubbles" texture that I animated with the shader. The red rocks behind is the rock texture.

  • \$\begingroup\$ It's hard to imagine how your shader looks just from looking at your sourcecode. Could you post a screenshot or video and then describe which aspects of it you like and which you dislike? \$\endgroup\$
    – Philipp
    Commented Jun 1, 2018 at 8:47
  • \$\begingroup\$ @Philipp I added a gif. Hopefully it will clear things out. I wanted to make the lava flow between the cracks of the rocks. :) \$\endgroup\$ Commented Jun 1, 2018 at 9:03

1 Answer 1


I don't use Shaderforge, so i cannot help in telling you how to set it up. However, i can show you in code and explain what you could do.

You should be able to use another texture exactly the same as the rock texture except its black and white (so obviously not exactly the same...), where you want the bubbles to be is white and black wont show any bubbles. This texture can then be used as a mask in the shader above by doing the following:

return fixed4(finalColor,1) * MaskTexture.r;

If MaskTexture contains the black and white texture it works because in a texture black = 0,0,0, white is 1,1,1 and obivously multiplying the bubbles by 0 = no bubbles, and multiplying it by 1 = bubbles!. You could even use the rocks texture itself by using its alpha channel. This means the area where the bubbles are supposed to show is transparent in the texture itself, and then you do this:

return fixed4(finalColor,1) * RockTexture.a;

This does mean you cannot use the alpha channel for anything else but, this is better optimized because it doesnt require a third texture.

Alternatively you could create 2 meshes, 1 for the rock, and 1 for the lava flow. The upside of this is that you could make the lava seemingly change direction and follow the cracks direction when moving trough the cracks (like real lava would) if the uv of the mesh for the lava is setup correctly. The texture moves along the uv axis, so any change in the direction of the line in the mesh will determine the direction of the flow as long as the uv's don't follow the same line, as displayed below. The left side of the image below shows the uv layout, the right the actual line. As you can see the bubble image could simply move up on the UV layout, and on the mesh it would appear to change direction.

A single line for a Lava flow mesh (example): enter image description here

  • \$\begingroup\$ It works far better now! Thanks! I created a B&W texture of the rocks and painted white a part of it. Then added that B&W texture to the red glowing lava I had already done with the multiply node and then added that to the normal texture. Looks great now. imgur.com/a/QN98T71 \$\endgroup\$ Commented Jun 1, 2018 at 10:26
  • \$\begingroup\$ @KristianKostov result is good but anyway If you need realistic lava you can use flow map \$\endgroup\$ Commented Jun 1, 2018 at 10:44
  • \$\begingroup\$ @SeyedMortezaKamali I will look into that. As you can see I am pretty new to both shaders and Shader Forge :) \$\endgroup\$ Commented Jun 1, 2018 at 10:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .