- Home /
DepthMask Shader - Receive Shadows
I have a simple DepthMask shader that masks any objects behind it. I would like the DepthMask shader to receive shadows as well. How is this possible?
Here is the shader:
Shader "Depth Mask" {
SubShader {
Tags {"Queue" = "Geometry-10" }
Lighting Off
ZTest LEqual
ZWrite On
ColorMask 0
Pass {}
}
}
Answer by absameen · Apr 22, 2012 at 07:05 PM
For anyone interested, I managed to find a solution to this by combining two shaders from the forums. Here is the working shader:
Shader "FX/Matte Shadow Mask" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
}
SubShader {
Tags {"Queue" = "Geometry-10" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
LOD 200
Blend Zero SrcColor
Lighting Off
ZTest LEqual
ZWrite On
ColorMask 0
Pass {}
CGPROGRAM
#pragma surface surf ShadowOnly alphatest:_Cutoff
fixed4 _Color;
struct Input {
float2 uv_MainTex;
};
inline fixed4 LightingShadowOnly (SurfaceOutput s, fixed3 lightDir, fixed atten)
{
fixed4 c;
c.rgb = s.Albedo*atten;
c.a = s.Alpha;
return c;
}
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = _Color;
o.Albedo = c.rgb;
o.Alpha = 1;
}
ENDCG
}
Fallback "Transparent/Cutout/VertexLit"
}
That's exactly, what I was looking for a whole day! Thanks!!!
what do i can do, if i want to change the color of the light received?, cause if i change anny color in the mask, change all the plane color. ?
Awesome! But can it be modified so that it doesn't obscure the objects behind ?
Hi.. this shader works great. But I don't want to the masking behaviour in it. I want to cast shadow on a transparent plane with shadows and with a skybox in the scene. But after putting the skybox the plane is not transparent anymore in the game mode, while it is transparent in the scene mode(screenshot attached). Which I suppose is because of the masking property. I have no knowledge about shader scripting and it is required on an urgent basis. Would really appreciate if someone could help me in this. Thanks
Answer by master_render · Aug 29, 2015 at 02:50 PM
Hello,
Thank you for the provided shader. It works fine on windows, but on Android there is bad jitters on the shadows because of the alpha test.
I've tried a similar setup like in the picture below. There is an invisible plane under the robot object which is rendered in the depth maps only with ColorMask 0. Then, under the invisible plane there is another plane with a texture. It has the ReceiveShadows bool set to true.
It works fine on Windows, you can check the picture. But on Android the invisible plane's depth is not written into the depth for some reason :(.
Does anyone have an idea why the invisible plane doesn't render on Android?