Skip to content

Instantly share code, notes, and snippets.

@partybusiness
Last active April 23, 2023 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save partybusiness/de700f80168dadc5cc814efe4a8508f1 to your computer and use it in GitHub Desktop.
Save partybusiness/de700f80168dadc5cc814efe4a8508f1 to your computer and use it in GitHub Desktop.
Testing stencil to prove the order that passes are rendered
Shader "Unlit/TwoPassStencilShader"
{
Properties
{
_Color1("Colour1", Color) = (1,0,0,1)
_Color2("Colour2", Color) = (0,0,1,1)
}
SubShader
{
Tags{
"RenderType" = "Opaque"
"DisableBatching" = "True" //make sure it isn't combining meshes
}
ZTest always //make sure overlapping mesh is drawn to test the stencil behaviour
Pass
{
Stencil {
Comp always
Pass IncrSat
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 vertex : SV_POSITION;
};
float4 _Color1;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
return _Color1;
}
ENDCG
}
Pass
{
Stencil{
Ref 2
Comp equal
Fail DecrSat
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 vertex : SV_POSITION;
};
float4 _Color2;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
return _Color2;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment