I'm trying to get certain objects to alpha blend, but also include a ShadowCaster pass. So far, I've only been able to get one or the other in the same SubShader. With the tags in the snippet below, the depth texture is written to, but when it is rendered, there's no alpha blending occuring. If I change the queue to "Geometry+501" (the first value considered "transparent"), then the depth texture is not written to, but the content renders with alpha blending. Is there a way to get ShadowCaster to work for objects in the transparent queue? I can workaround this by cloning the objects and doing the depth texture writes with a separate material, but I'd love to avoid doing that. Using Unity 5.0.0f4. Thanks for any help in advance. Code (CSharp): SubShader { Tags { "RenderType" = "Transparent" "IgnoreProjector" = "True" "Queue" = "Geometry+500" } Pass { Name "ShadowCaster" Tags { "LightMode" = "ShadowCaster" } ZWrite On Cull Off CGPROGRAM // Vertex/fragment program, same as VertexLit's ShadowCaster pass, but with texture read and clipping based on low alpha ENDCG } Pass { Name "Draw" ZWrite On Blend SrcAlpha OneMinusSrcAlpha Cull Off CGPROGRAM // Vertex/fragment program, same as Unlit/Transparent, but with clipping based on low alpha ENDCG } }
Why not use a sub-shader? As the shader replacment used for rendering shadows checks the tags of subshaders. (Make sure the "normal" subshader is first, you probably want to do this anyways unless you want a pass before the normal transparent pass drawing to the z-buffer even when not doing shadows?) (Idk how good unity is at filtering out passes) Code (CSharp): SubShader { Tags { "RenderType" = "Transparent" "IgnoreProjector" = "True" "Queue" = "Geometry+500" } Pass { Name "Draw" ZWrite On Blend SrcAlpha OneMinusSrcAlpha Cull Off CGPROGRAM // Vertex/fragment program, same as Unlit/Transparent, but with clipping based on low alpha ENDCG } } SubShader { Tags { "RenderType" = "Opaque" "IgnoreProjector" = "True" "Queue" = "Geometry" } Pass { Name "ShadowCaster" Tags { "LightMode" = "ShadowCaster" } ZWrite On Cull Off CGPROGRAM // Vertex/fragment program, same as VertexLit's ShadowCaster pass, but with texture read and clipping based on low alpha ENDCG } }
Hi Zicandar, I tried your suggestion, but I couldn't get it to work (it'd only render or write to the depth texture, not both). From this doc (http://docs.unity3d.com/Manual/SL-CameraDepthTexture.html), it seems like shader replacement is used to render the depth texture (which I'm doing in a later step), but not to populate the depth texture in the first place.
Then to the first subshader leave both passes, and still leave the second subshader. (Or replace the second subshader with a fallback to something like the basic diffuse) ?
Putting both passes in the first subshader and leaving the 2nd subshader didn't seem to help, but looking closer at the frame debugger, it looks like this might be a Unity bug? As I have it now, my first subshader only includes the ShadowCaster pass, and has the following tags: Code (csharp): Tags { "RenderType" = "Opaque" "IgnoreProjector" = "True" "Queue" = "Geometry" } And the second subshader only includes the normal rendering pass, and has the following tags: Code (csharp): Tags { "RenderType" = "Transparent" "IgnoreProjector" = "True" "Queue" = "Transparent" } In the frame debugger, I see the expected objects being rendered in the UpdateDepthTexture pass. The same objects are then rendered under Render.OpaqueGeometry. If I remove the first subshader containing the ShadowCaster pass, the objects are correctly drawn during Render.TransparentGeometry. Is Unity ignoring tags for the second subshader?
http://forum.unity3d.com/threads/si...th-separate-mask-texture.321147/#post-2090829 The last 3 posts show a alpha blended shadow casting AND recieving shader, and the artifacts that come with it. If it's EITHER shadow casting OR receiving I think I was able to make it artifact free!