- Home /
Shadow Support in Custom Shader
Hello all –
I'm trying to develop a game where portals can be torn in between different layered worlds.
Currently, I'm doing the following:
I have a set of objects in Layer A, and a set of objects in Layer B.
Layer A objects have a stencil ref of 1 and Layer B objects have a stencil ref of 2.
In front of the camera is a plane that has the portal shader (seen below), and a stencil ref of the world currently being rendered.
I can't seem to see any shadows.
You can see the problem in the picture below. On the left is the game view, on the right the editor view. You can see that the plane that is in front of the camera seems to be killing the shadows, and I don't quite know why.
Anyone have any ideas?
Thank you for your help!
Every object has this shader attached:
Shader "Custom/HiddenShader" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_StencilVal ("stencilVal", Int) = 1
}
SubShader {
Lighting On
Tags { "RenderType"="Opaque" }
Stencil {
Ref [_StencilVal]
Comp Equal
Pass Replace
}
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
fixed4 _Color;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "VertexLit"
}
My portals have this shader:
Shader "Custom/PortalShader" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_StencilVal ("stencilVal", Int) = 1
}
SubShader {
ColorMask 0
Pass
{
Tags { "RenderType"="Opaque" "Queue"="Geometry" }
ZWrite Off
Stencil {
Ref [_StencilVal]
Comp always
Pass Replace
}
}
Lighting On
ColorMask A
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
fixed4 _Color;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "VertexLit"
}