I'm trying to create a shader that, utimately, I can use to mask off the depth rendering of my scene below a certain y-height. I have this working exactly as expected in dx9 mode by using a horizontal plane with the following shader... Code (CSharp): Tags {"RenderType"="Opaque" "Queue"= "Geometry"} Fog { Mode Off } Cull Back ColorMask 0 ZWrite On CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct v2f { float4 pos : SV_POSITION; float2 depth : TEXCOORD0; }; v2f vert (appdata_base v) { v2f o; o.pos = mul (UNITY_MATRIX_MVP, v.vertex); UNITY_TRANSFER_DEPTH(o.depth); return o; } half4 frag(v2f i) : COLOR { return fixed4(0,0,0,1); } ENDCG However when I use the same shader in the same scene after enabling dx11 rendering, absolutley nothing happens. dx11 isn't picking up any depth-write info from this object/shader. Does anyone here have any wisdom they can share as to why this would be the case?
Are you sure the depth parameter is even doing anything? in your vertex function Code (csharp): UNITY_TRANSFER_DEPTH(o.depth); should be used in conjunction with Code (csharp): UNITY_OUTPUT_DEPTH(i.depth); in the fragment function to write something to the depth buffer with colormask 0 you are writing nothing to the color channels which means that in order for that shader to even do something you must write to the depth buffer, which you aren't because you frag function does nothing, to be honest, i'm not sure how it's working in dx9 also, shouldn't this be enough for you? http://wiki.unity3d.com/index.php/DepthMask
Thanks for the response @kebrus I originally tried the UNITY_OUTPUT_DEPTH function, to no avail (again works fine in dx9, not in dx11). Then though perhaps returning a set value might help which is the result of the code in my first post, which also does nothing in dx11. The example depthmap shader is the first I tried, and it doesn't work properly in dx11 either. I only want to write to the scene depth, thus the Colormask 0 setting. It's just bizarre.
You can always try to reconstruct what those two macros do by looking at their implementation, at least in the end you should be more aware of what it's doing and come up with a solution, you should find that information in the include files
Would you be able to send me a renderdoc capture (DX11 version) to let me debug what is happening. RenderDoc is very easy to use. Just need to install it from here: https://renderdoc.org/builds and this page explains how to make a capture in the Unity editor: http://docs.unity3d.com/Manual/RenderDocIntegration.html
Yeah from what I can tell, this should be working. You should not need that UNITY_TRANSFER_DEPTH macro at all. Either by looking at the Unity's frame debugger, or capturing a RenderDoc frame might reveal some things.