Jump to content
Happy Holidays! Limited Staff Responses: 1/20 - 1/31 ×

Unity stencil shaders and single-pass rendering


noony
 Share

Recommended Posts

We have a few shaders using the stencil buffer to create masks, and portal-like effects. These work fine with single-pass rendering disabled on Unity 2018.2, but with single-pass forced on, the stencil buffer seems to be ignored and the objects render as regular opaque renderers. Although experimental, we're fairly reliant on single-pass for performance reasons, so turning it off is not feasible at this stage.

 

Has anybody else managed to use a stencil buffer effect under single-pass rendering? Is this expected behaviour for the current state of single-pass  ?

Link to comment
Share on other sites

Hi  

 

The shaders are custom, written by ourselves as part of the project. The actual shaders are quite complex, but I've attached below simplified versions that demonstrate the same issue. UnlitStencil draws an object in blue with stencil set to 1; StencilMask should cause any renderer to mask the previous object when occupying the same pixels. This works fine in the editor scene view, and on device with single-pass off, but with single-pass on, no mask effect is seen, as if the stencil buffer is being ignored. Thanks for the help!

 

Shader "UnlitStencil"{    SubShader    {        Tags { "RenderType"="Opaque" }        Stencil {			Ref 1			Comp NotEqual			Pass Keep			Fail Keep		}        Pass        {            CGPROGRAM            #pragma vertex vert            #pragma fragment frag            struct appdata            {                float4 vertex : POSITION;            };            struct v2f            {                float4 vertex : SV_POSITION;            };            v2f vert (appdata v)            {                v2f o;                o.vertex = UnityObjectToClipPos(v.vertex);                return o;            }            fixed4 frag (v2f i) : SV_Target            {                return half4(0, 0, 1, 1);            }            ENDCG        }    }}
Shader "StencilMask"{	SubShader 	{		Tags { "RenderType"="Opaque" "Queue"="Geometry-100"}		ColorMask 0		ZWrite Off		Stencil 		{			Ref 1			Comp Always			Pass Replace		}				Pass		{		CGPROGRAM			#pragma vertex vert			#pragma fragment frag						struct appdata 			{				float4 vertex : POSITION;			};						struct v2f 			{				float4 vertex : SV_POSITION;			};						v2f vert(appdata v) 			{				v2f o;				o.vertex = UnityObjectToClipPos(v.vertex);				return o;			}						half4 frag(v2f i) : COLOR 			{                                return 0;			}		ENDCG		}	}}
Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...

Hi  ,

 

Is this update fixing stencil buffer support for single-pass still on course for July? Would you have a more precise release date now, and is it likely to be an SDK or ROM update to look out for?

 

Thanks!

Link to comment
Share on other sites

  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...