透明阴影着色器Unity5

时间:2015-04-21 14:49:02

标签: unity3d shader vuforia

我在Unity 4.6.2中使用了以下着色器,但遗憾的是它并没有在unity5中工作。我在AR场景(vuforia 4)中有一个对象,我想在对象下面的平面上显示阴影。那个平面应该是透明的,只显示阴影,如图中所示。

Like in this picture here

这是在统一工作中使用的着色器4.6.2

Shader "TransparentShadowShader" {

Properties
{
    _ShadowColor ("Shadow Color", Color) = (0,0,0,1)
}

Category {

Blend  SrcAlpha OneMinusSrcAlpha

Lighting Off
Zwrite Off
LOD 200


SubShader
{
    Tags { "RenderType"="Transparent" }

    CGPROGRAM
    #pragma surface surf Custom

    struct Input {
        float2 pos : POSITION;
    };

    uniform float4 _ShadowColor;

    void surf(Input IN, inout SurfaceOutput o)
    {
        //Pass through shadow colour to lighting model
        o.Albedo = _ShadowColor.rgb;
        o.Alpha  = _ShadowColor.a;
    }

    half4 LightingCustom(SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
    {
        half4 c;

        //Inverse illumination - atten accounts for shadowing
        c.rgb = s.Albedo.rgb * 1.0f-atten;
        c.a   = s.Alpha * 1.0f-atten;

        return c;
    }
    ENDCG
}
}

Fallback "VertexLit", 2

}

这是我在unity5中使用此着色器

获得的内容

enter image description here

1 个答案:

答案 0 :(得分:-1)

好的,已经在这个问题上寻找答案了,一切都比预期的要简单

Shader "Invisible/InvisibleShadowCaster" {
 SubShader {
     Tags { 
         "Queue"="Transparent"
         "RenderType"="Transparent" 
     }
     CGPROGRAM
     #pragma surface surf Lambert alpha addshadow

     struct Input {
         float nothing; // Just a dummy because surf expects something
     };

     void surf (Input IN, inout SurfaceOutput o) {
         o.Alpha = 0;
     }
     ENDCG
 } 
 FallBack "Diffuse"}

这对我来说很完美,试试吧