Shadows not rendering like its suppose to

Im porting an old project made in Unity 2019 and for some reason a shader is not rendering well. The shadows are not projected directly on the object. They are projected like “behind”? I’ll show you some images to understand what I mean:

Imgur
Imgur

Also if I put a plane under this object the shadow is projected on this plane but you can see the shadow on the object.

Imgur

In case you are wandering what shader am I using is this one:

Shader "VacuumShaders/Terrain To Mesh/Legacy Shaders/Diffuse/8 Textures"
{
    Properties
    {
        _Color("Color", color) = (1, 1, 1, 1)
        [NoScaleOffset]_V_T2M_Control ("Control Map (RGBA)", 2D) = "black" {}

        //TTM
        [V_T2M_Layer] _V_T2M_Splat1 ("Layer 1 (R)", 2D) = "white" {}
        [HideInInspector] _V_T2M_Splat1_uvScale("", float) = 1

        [V_T2M_Layer] _V_T2M_Splat2 ("Layer 2 (G)", 2D) = "white" {}
        [HideInInspector] _V_T2M_Splat2_uvScale("", float) = 1

        [V_T2M_Layer] _V_T2M_Splat3 ("Layer 3 (B)", 2D) = "white" {}
        [HideInInspector] _V_T2M_Splat3_uvScale("", float) = 1

        [V_T2M_Layer] _V_T2M_Splat4 ("Layer 4 (A)", 2D) = "white" {}
        [HideInInspector] _V_T2M_Splat4_uvScale("", float) = 1


     
        [NoScaleOffset]_V_T2M_Control2 ("Control Map 2 (RGBA)", 2D) = "black" {}

        //TTM            
        [V_T2M_Layer] _V_T2M_Splat5 ("Layer 1 (R)", 2D) = "white" {}
        [HideInInspector] _V_T2M_Splat5_uvScale("", float) = 1

        [V_T2M_Layer] _V_T2M_Splat6 ("Layer 2 (G)", 2D) = "white" {}
        [HideInInspector] _V_T2M_Splat6_uvScale("", float) = 1

        [V_T2M_Layer] _V_T2M_Splat7 ("Layer 3 (B)", 2D) = "white" {}
        [HideInInspector] _V_T2M_Splat7_uvScale("", float) = 1

        [V_T2M_Layer] _V_T2M_Splat8 ("Layer 4 (A)", 2D) = "white" {}
        [HideInInspector] _V_T2M_Splat8_uvScale("", float) = 1



        //Fallback use only
        [NoScaleOffset]_MainTex ("BaseMap (Fallback use only!)", 2D) = "white" {}
    }

    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200
    
        CGPROGRAM
        #pragma surface surf Lambert vertex:vert
        #pragma target 2.0
        //#pragma exclude_renderers gles
     

        #define V_T2M_2_CONTROL_MAPS
        #define V_T2M_3_TEX
        #define V_T2M_4_TEX
        #define V_T2M_5_TEX
        #define V_T2M_6_TEX
        #define V_T2M_7_TEX
        #define V_T2M_8_TEX

        #include "../cginc/T2M_Deferred.cginc"    

        ENDCG
    }

    FallBack "Hidden/VacuumShaders/Fallback/VertexLit"
}

It includes the T2M_Deferred.cging:

#ifndef VACUUM_SHADERS_T2M_DEFERRED_CGINC
#define VACUUM_SHADERS_T2M_DEFERRED_CGINC

#include "../cginc/T2M_Variables.cginc"
#include "../cginc/CurvedWorld.cginc"


struct Input
{
    float2 uv_V_T2M_Control;

    #ifdef V_T2M_2_CONTROL_MAPS
        float2 uv_V_T2M_Control2;
    #endif
};


void vert (inout appdata_full v, out Input o)
{
    UNITY_INITIALIZE_OUTPUT(Input,o);

    //CurvedWorld vertex transform
    CURVED_WORLD_TRANSFORM_POINT_AND_NORMAL(v.vertex, v.normal, v.tangent);
}


#ifdef V_T2M_STANDARD
void surf (Input IN, inout SurfaceOutputStandard o)
#else
void surf (Input IN, inout SurfaceOutput o)
#endif
{
    half4 splat_control = tex2D (_V_T2M_Control, IN.uv_V_T2M_Control);

    fixed4 mainTex  = splat_control.r * tex2D (_V_T2M_Splat1, IN.uv_V_T2M_Control * _V_T2M_Splat1_uvScale);
           mainTex += splat_control.g * tex2D (_V_T2M_Splat2, IN.uv_V_T2M_Control * _V_T2M_Splat2_uvScale);
 
    #ifdef V_T2M_3_TEX
        mainTex += splat_control.b * tex2D (_V_T2M_Splat3, IN.uv_V_T2M_Control * _V_T2M_Splat3_uvScale);
    #endif
    #ifdef V_T2M_4_TEX
        mainTex += splat_control.a * tex2D (_V_T2M_Splat4, IN.uv_V_T2M_Control * _V_T2M_Splat4_uvScale);
    #endif


    #ifdef V_T2M_2_CONTROL_MAPS
         half4 splat_control2 = tex2D (_V_T2M_Control2, IN.uv_V_T2M_Control2);

         mainTex.rgb += tex2D (_V_T2M_Splat5, IN.uv_V_T2M_Control2 * _V_T2M_Splat5_uvScale) * splat_control2.r;

         #ifdef V_T2M_6_TEX
            mainTex.rgb += tex2D (_V_T2M_Splat6, IN.uv_V_T2M_Control2 * _V_T2M_Splat6_uvScale) * splat_control2.g;
         #endif

         #ifdef V_T2M_7_TEX
            mainTex.rgb += tex2D (_V_T2M_Splat7, IN.uv_V_T2M_Control2 * _V_T2M_Splat7_uvScale) * splat_control2.b;
         #endif

         #ifdef V_T2M_8_TEX
            mainTex.rgb += tex2D (_V_T2M_Splat8, IN.uv_V_T2M_Control2 * _V_T2M_Splat8_uvScale) * splat_control2.a;
         #endif
    #endif



    mainTex.rgb *= _Color.rgb;

 
    #ifdef V_T2M_BUMP
        fixed4 nrm = 0.0f;
        nrm += splat_control.r * tex2D(_V_T2M_Splat1_bumpMap, IN.uv_V_T2M_Control * _V_T2M_Splat1_uvScale);
        nrm += splat_control.g * tex2D(_V_T2M_Splat2_bumpMap, IN.uv_V_T2M_Control * _V_T2M_Splat2_uvScale);

        #ifdef V_T2M_3_TEX
            nrm += splat_control.b * tex2D (_V_T2M_Splat3_bumpMap, IN.uv_V_T2M_Control * _V_T2M_Splat3_uvScale);
        #endif

        #ifdef V_T2M_4_TEX
            nrm += splat_control.a * tex2D (_V_T2M_Splat4_bumpMap, IN.uv_V_T2M_Control * _V_T2M_Splat4_uvScale);
        #endif
     
     
        o.Normal = UnpackNormal(nrm);
    #endif


 

    #ifdef V_T2M_STANDARD
        half metallic = 0;
        metallic += splat_control.r * _V_T2M_Splat1_Metallic;
        metallic += splat_control.g * _V_T2M_Splat2_Metallic;
        #ifdef V_T2M_3_TEX
            metallic += splat_control.b * _V_T2M_Splat3_Metallic;
        #endif
        #ifdef V_T2M_4_TEX
            metallic += splat_control.a * _V_T2M_Splat4_Metallic;
        #endif
        #ifdef V_T2M_2_CONTROL_MAPS
            #ifdef V_T2M_5_TEX
                metallic += splat_control2.r * _V_T2M_Splat5_Metallic;
            #endif
            #ifdef V_T2M_6_TEX
                metallic += splat_control2.g * _V_T2M_Splat6_Metallic;
            #endif
            #ifdef V_T2M_7_TEX
                metallic += splat_control2.b * _V_T2M_Splat7_Metallic;
            #endif
            #ifdef V_T2M_8_TEX
                metallic += splat_control2.a * _V_T2M_Splat8_Metallic;
            #endif
        #endif


        half glossiness = 0;
        glossiness += splat_control.r * _V_T2M_Splat1_Glossiness;
        glossiness += splat_control.g * _V_T2M_Splat2_Glossiness;
        #ifdef V_T2M_3_TEX
            glossiness += splat_control.b * _V_T2M_Splat3_Glossiness;
        #endif
        #ifdef V_T2M_4_TEX
            glossiness += splat_control.a * _V_T2M_Splat4_Glossiness;
        #endif
        #ifdef V_T2M_2_CONTROL_MAPS
            #ifdef V_T2M_5_TEX
                glossiness += splat_control2.r * _V_T2M_Splat5_Glossiness;
            #endif
            #ifdef V_T2M_6_TEX
                glossiness += splat_control2.g * _V_T2M_Splat6_Glossiness;
            #endif
            #ifdef V_T2M_7_TEX
                glossiness += splat_control2.b * _V_T2M_Splat7_Glossiness;
            #endif
            #ifdef V_T2M_8_TEX
                glossiness += splat_control2.a * _V_T2M_Splat8_Glossiness;
            #endif
        #endif

        o.Metallic = metallic;
        o.Smoothness = glossiness;
    #else
        #ifdef V_T2M_SPECULAR
            o.Gloss = mainTex.a;

            half shininess = 0;
            shininess += splat_control.r * _V_T2M_Splat1_Shininess;
            shininess += splat_control.g * _V_T2M_Splat2_Shininess;
            #ifdef V_T2M_3_TEX
                shininess += splat_control.b * _V_T2M_Splat3_Shininess;
            #endif
            #ifdef V_T2M_4_TEX
                shininess += splat_control.a * _V_T2M_Splat4_Shininess;
            #endif

            o.Specular = shininess;
        #endif
    #endif
 
    o.Albedo = mainTex.rgb;
    o.Alpha = 1.0;
}

#endif

And the variable Control map is this:

Shader "Custom/ControlMapShader"
{
    Properties{
        _ControlMap1("Control Map 1", 2D) = "white" {}
        _Layer1R1("Layer 1 Red", 2D) = "white" {}
        _Layer2G1("Layer 2 Green", 2D) = "white" {}
        _Layer3B1("Layer 3 Blue", 2D) = "white" {}
        _Layer4A1("Layer 4 Alpha", 2D) = "white" {}

        _ControlMap2("Control Map 2", 2D) = "white" {}
        _Layer1R2("Layer 1 Red 2", 2D) = "white" {}
        _Layer2G2("Layer 2 Green 2", 2D) = "white" {}
        _Layer3B2("Layer 3 Blue 2", 2D) = "white" {}
        _Layer4A2("Layer 4 Alpha 2", 2D) = "white" {}
    }

        SubShader{
            Tags { "RenderType" = "Opaque" }
            LOD 100

            Pass {
                CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                #pragma multi_compile_fwdbase
                #include "UnityCG.cginc"

                struct appdata_t {
                    float4 vertex : POSITION;
                    float2 uv1 : TEXCOORD0;
                    float2 uv2 : TEXCOORD1;
                };

                struct v2f {
                    float2 uv1 : TEXCOORD0;
                    float2 uv2 : TEXCOORD1;
                    float4 vertex : SV_POSITION;
                    float4 shadowCoord : TEXCOORD2;
                };

                sampler2D _ControlMap1;
                sampler2D _Layer1R1;
                sampler2D _Layer2G1;
                sampler2D _Layer3B1;
                sampler2D _Layer4A1;

                sampler2D _ControlMap2;
                sampler2D _Layer1R2;
                sampler2D _Layer2G2;
                sampler2D _Layer3B2;
                sampler2D _Layer4A2;

                v2f vert(appdata_t v) {
                    v2f o;
                    o.vertex = UnityObjectToClipPos(v.vertex);
                    o.uv1 = v.uv1;
                    o.uv2 = v.uv2;
                    o.shadowCoord = ComputeScreenPos(o.vertex);
                    return o;
                }

                fixed4 frag(v2f i) : SV_Target {
                    // Sample control maps
                    fixed4 controlMap1 = tex2D(_ControlMap1, i.uv1);
                    fixed4 controlMap2 = tex2D(_ControlMap2, i.uv2);

                    // Sample layer textures
                    fixed4 layer1 = tex2D(_Layer1R1, i.uv1) * controlMap1.r + tex2D(_Layer1R2, i.uv2) * controlMap2.r;
                    fixed4 layer2 = tex2D(_Layer2G1, i.uv1) * controlMap1.g + tex2D(_Layer2G2, i.uv2) * controlMap2.g;
                    fixed4 layer3 = tex2D(_Layer3B1, i.uv1) * controlMap1.b + tex2D(_Layer3B2, i.uv2) * controlMap2.b;
                    fixed4 layer4 = tex2D(_Layer4A1, i.uv1) * controlMap1.a + tex2D(_Layer4A2, i.uv2) * controlMap2.a;

                    // Combine the layers
                    fixed4 finalColor = layer1 + layer2 + layer3 + layer4;

                    // Apply shadows (Unity's built-in lighting)
                    #ifdef UNITY_PASS_SHADOWCASTER
                    SHADOW_CASTER_FRAGMENT(i)
                    #endif

                    return finalColor;
                }
                ENDCG
            }
    }
}

Any help with this? :frowning:

I’m somewhat concerned with that line. Using a curved world modification to the main shader, but not having a custom shadow caster pass that also does it is usually going to cause a bad time.

Yeah sorry there were more includes that I didnt post. The T2M_Deferred has 2 more includes:

T2M_Variables.cginc:

#ifndef VACUUM_SHADERS_T2M_VARIABLES_CGINC

#define VACUUM_SHADERS_T2M_VARIABLES_CGINC

fixed4 _Color;

sampler2D _V_T2M_Control;
sampler2D _V_T2M_Splat1; half _V_T2M_Splat1_uvScale;
sampler2D _V_T2M_Splat2; half _V_T2M_Splat2_uvScale;

#ifdef V_T2M_BUMP
    sampler2D _V_T2M_Splat1_bumpMap;
    sampler2D _V_T2M_Splat2_bumpMap;
#endif

#ifdef V_T2M_3_TEX
sampler2D _V_T2M_Splat3; half _V_T2M_Splat3_uvScale;

    #ifdef V_T2M_BUMP
        sampler2D _V_T2M_Splat3_bumpMap;
    #endif
#endif

#ifdef V_T2M_4_TEX
sampler2D _V_T2M_Splat4; half _V_T2M_Splat4_uvScale;

    #ifdef V_T2M_BUMP
        sampler2D _V_T2M_Splat4_bumpMap;
    #endif
#endif

#ifdef V_T2M_2_CONTROL_MAPS
    sampler2D _V_T2M_Control2;

    sampler2D _V_T2M_Splat5; half _V_T2M_Splat5_uvScale;
    #ifdef V_T2M_BUMP
        sampler2D _V_T2M_Splat5_bumpMap;
    #endif

    #ifdef V_T2M_6_TEX
        sampler2D _V_T2M_Splat6; half _V_T2M_Splat6_uvScale;
        #ifdef V_T2M_BUMP
            sampler2D _V_T2M_Splat6_bumpMap;
        #endif
    #endif

    #ifdef V_T2M_7_TEX
        sampler2D _V_T2M_Splat7; half _V_T2M_Splat7_uvScale;
    #endif

    #ifdef V_T2M_8_TEX
        sampler2D _V_T2M_Splat8; half _V_T2M_Splat8_uvScale;
    #endif
#endif

#ifdef V_T2M_SPECULAR
    half _V_T2M_Splat1_Shininess;
    half _V_T2M_Splat2_Shininess;

    #ifdef V_T2M_3_TEX
        half _V_T2M_Splat3_Shininess;
    #endif
    #ifdef V_T2M_4_TEX
        half _V_T2M_Splat4_Shininess;
    #endif
#endif

#ifdef V_T2M_STANDARD
    half _V_T2M_Splat1_Glossiness;
    half _V_T2M_Splat1_Metallic;

    half _V_T2M_Splat2_Glossiness;
    half _V_T2M_Splat2_Metallic;

    #ifdef V_T2M_3_TEX
        half _V_T2M_Splat3_Glossiness;
        half _V_T2M_Splat3_Metallic;
    #endif

    #ifdef V_T2M_4_TEX
        half _V_T2M_Splat4_Glossiness;
        half _V_T2M_Splat4_Metallic;
    #endif

    #ifdef V_T2M_5_TEX
        half _V_T2M_Splat5_Glossiness;
        half _V_T2M_Splat5_Metallic;
    #endif

    #ifdef V_T2M_6_TEX
        half _V_T2M_Splat6_Glossiness;
        half _V_T2M_Splat6_Metallic;
    #endif

    #ifdef V_T2M_7_TEX
        half _V_T2M_Splat7_Glossiness;
        half _V_T2M_Splat7_Metallic;
    #endif

    #ifdef V_T2M_8_TEX
        half _V_T2M_Splat8_Glossiness;
        half _V_T2M_Splat8_Metallic;
    #endif
#endif

#endif

And CuveWorld.cginc:

//Uncomment line below and set it to be the correct path to the 'CurvedWorld_Base.cginc' file (part of the Curved World package).
//#include "Assets/VacuumShaders/Curved World/Shaders/cginc/CurvedWorld_Base.cginc"


#ifndef CURVED_WORLD_TRANSFORM_POINT_AND_NORMAL
    #define CURVED_WORLD_TRANSFORM_POINT_AND_NORMAL(vertex,normal,tangent)
#endif

#ifndef CURVED_WORLD_TRANSFORM_POINT
    #define CURVED_WORLD_TRANSFORM_POINT(vertex)
#endif

Also this shader was on a plugin (Terrain to mesh) and is responsible to bake the terrain textures into one using the RGBA channels and painting each texture in each channel.