Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
半透明シェーダにおけるステンシルテスト
// 半透明シェーダ
// マスクする側
Shader "TransparentStencilMask"
{
Properties
{
_MainTex("-", 2D) = "white"{}
}
SubShader
{
Tags {"Queue"="Transparent"}
Pass
{
Stencil {
Ref 2
Comp always
Pass replace
}
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
sampler2D _MainTex;
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
fixed4 frag (v2f_img i) : SV_Target
{
fixed4 c = tex2D(_MainTex, i.uv);
return c;
}
ENDCG
}
}
}
// 半透明シェーダ
// マスクされる側
Shader "TransparentStencilMasked"
{
Properties
{
_MainTex("-",2D)="white"{}
}
SubShader
{
Tags {"Queue"="Transparent+1"}
Pass
{
Stencil {
Ref 2
Comp equal
}
ZTest Always
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
sampler2D _MainTex;
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
fixed4 frag (v2f_img i) : SV_Target
{
return tex2D(_MainTex, i.uv);
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment