Custom Shader no shadows/bad clipping

I was fortunate someone making me custom shaders that really work well but they have some flaws… i was hoping to get some help on these?


There are 2 problems…

  • They do not receive shadows…
  • By input of position and distance they have the mesh go transparent… but as you can clearly see in the image they affect non custom shaders…

Could anyone help me out please?

Thanks!

Shader "Fader/Diffuse" {
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
    Tags { "RenderType"="Transparent" "Queue"="Transparent" }
    LOD 200

    // extra pass that renders to depth buffer only
    Pass {
        ZWrite On
        ColorMask 0
    }

CGPROGRAM
#pragma surface surf Lambert alpha

sampler2D _MainTex;
fixed4 _Color;
uniform float _MaxDist = 0.0f;
uniform float _MinDist = 0.0f;
uniform float _CamXPos = 0.0f;
uniform float _CamZPos = 0.0f;

struct Input {
    float2 uv_MainTex;
    float3 worldPos;
};

void surf (Input IN, inout SurfaceOutput o) {
    fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    float f = min(max(0,_MaxDist-((_CamXPos - IN.worldPos.x) * (_CamXPos - IN.worldPos.x) + (_CamZPos - IN.worldPos.z) * (_CamZPos - IN.worldPos.z))),_MinDist)/_MinDist;
    o.Albedo = c.rgb;
    o.Alpha = f;
}
ENDCG
}

Fallback "VertexLit"
}
Shader "Fader/Bumped Diffuse" {
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Base (RGB)", 2D) = "white" {}
    _BumpMap ("Normalmap", 2D) = "bump" {}
}

SubShader {
    Tags { "RenderType"="Transparent" "Queue"="Transparent" }
    LOD 300

    // extra pass that renders to depth buffer only
    Pass {
        ZWrite On
        ColorMask 0
    }

CGPROGRAM
#pragma surface surf Lambert alpha

sampler2D _MainTex;
sampler2D _BumpMap;
fixed4 _Color;
uniform float _MaxDist = 0.0f;
uniform float _MinDist = 0.0f;
uniform float _CamXPos = 0.0f;
uniform float _CamZPos = 0.0f;

struct Input {
    float2 uv_MainTex;
    float2 uv_BumpMap;
    float3 worldPos;
};

void surf (Input IN, inout SurfaceOutput o) {
    fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    float f = min(max(0,_MaxDist-((_CamXPos - IN.worldPos.x) * (_CamXPos - IN.worldPos.x) + (_CamZPos - IN.worldPos.z) * (_CamZPos - IN.worldPos.z))),_MinDist)/_MinDist;
    o.Albedo = c.rgb;
    o.Alpha = f;
    o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
}
ENDCG
}

FallBack "Diffuse"
}

Transparent surfaces don’t receive shadows, because they are rendered after the shadow pass.

Transparency is not order independent, so you have to manage the order in which transparent items are rendered. (Normally back to front.)