No Shadows on Colour by Height Shader

Hello,

to preface this, I’m rather new to Unity and have no experience with shaders so far.

So far I’ve got a game that basically generates a 100x100 world with random heights.

It looks like this:


As you can see, there are shadows under every tree.

Now I’ve got a shader by Jason Beetham that colors the ground based on height. Sadly this shader outputs only flat colors:

Now I wanted to “combine” my ground grass texture with this shader so it looks something like this:


What I did was just fade the Standard shader with the grass texture on the Height Shader. But as you can see there are no shadows.

Is there a simple way to get shadows to work? Is there maybe another way of doing this?

Here’s the shader code:

Shader "Lit/Smooth Shaded Colour By Height"
{
    //Created By Jason Beetham
    Properties
    {
        _First("Highest Point",float) = 1
        _Second("Second Heighest",float) = 1
        _Third("Third Heighest",float) = 1
        _Fourth("Fourth Heighest",float) = 1
        _FirstC("Highest Point Colour", Color) = (0,0,0,1)
        _SecondC("Second Heighest Colour",Color) = (0,0,0,1)
        _ThirdC("Third Colour",Color) = (0,0,0,1)
        _FourthC("Fourth Colour",Color) = (0,0,0,1)
        _FifthC("Fifth Colour",Color) = (0,0,0,1)
    }
        SubShader
        {
        Lighting on
        Pass
            {
            Cull Back
                CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                #include "UnityCG.cginc"
                #include "Lighting.cginc"
                #include "AutoLight.cginc"
                #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight
               struct appdata
            {
                float2 uv : TEXCOORD0;
                fixed4 diff : COLOR;
                float3 normal : NORMAL;
                float4 vertex : POSITION;
            }




;
            struct v2f
            {
                float2 uv : TEXCOORD0;
                fixed4 diff : COLOR;
                float3 normal : NORMAL;
                float4 vertex : POSITION;
            }




;
            float4 _FirstC;
            float4 _SecondC;
            float4 _ThirdC;
            float4 _FourthC;
            float4 _FifthC;
            float _Scale;
            float _First;
            float _Second;
            float _Third;
            float _Fourth;
            float _Fifth;
            float4 _Position;
            v2f vert(appdata v)
            {
                float4 tempPos = mul(unity_ObjectToWorld, float4(0,0,0,1));
                _Position = mul( unity_WorldToObject,tempPos);
                v2f OUT;
                OUT.normal = v.normal;
                OUT.vertex = UnityObjectToClipPos(v.vertex);
                if (v.vertex.y >= _First) {
                    OUT.diff = lerp(_FirstC,_SecondC,(_First /v.vertex.y) +.1f);
                }


                else if (v.vertex.y >= _Second && v.vertex.y < _First) {
                    OUT.diff = lerp(_ThirdC,_SecondC, (v.vertex.y / _First));

                }


                else if (v.vertex.y >= _Third && v.vertex.y < _Second) {
                   OUT.diff = lerp(_FourthC,_ThirdC, (v.vertex.y / _Second));
                }


                else if (v.vertex.y <= _Third && v.vertex.y > _Fourth){
                     OUT.diff = lerp(_ThirdC,_FourthC, (v.vertex.y / _Third));
                }

                else {
                    OUT.diff = _FifthC;
                }

                return OUT;
            }





                fixed4 frag(v2f i) : SV_Target
                {
                float4 col = i.diff;
                half3 lightColor = ShadeVertexLights(i.vertex, i.normal);
                col.rgb *= lightColor;
                return col;
            }

ENDCG
}
}
}

Any help is appreciated. Thanks!

Okay, maybe I need to ask a different question.

Is there a way to add the option for a texture to that shader code? Basically all I want is to use this shader on a grass texture. That way I wouldn’t have to use two materials and combine them by making the grass texture transparent or fade, which makes shadows disappear.

Or is there another way of doing this?

You might look at using a surface shader.

Otherwise start going through these: