Skip to content

Instantly share code, notes, and snippets.

@baobao
Created May 28, 2017 04:05
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 baobao/7d68b1a2a9b273203b1af49b7adc4123 to your computer and use it in GitHub Desktop.
Save baobao/7d68b1a2a9b273203b1af49b7adc4123 to your computer and use it in GitHub Desktop.
半透明シェーダにおけるステンシルテスト
// 半透明シェーダ
// マスクする側
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