Created
May 28, 2017 04:05
-
-
Save baobao/7d68b1a2a9b273203b1af49b7adc4123 to your computer and use it in GitHub Desktop.
半透明シェーダにおけるステンシルテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 半透明シェーダ | |
// マスクする側 | |
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 | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 半透明シェーダ | |
// マスクされる側 | |
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