2021. 1. 20. 09:17
Unity/shader
지우개
Shader "ahzkwid/Stencil/Invisible" {
Properties {
_MainTex ("MainTex", 2D) = "white" {}
_Color ("Main Color", Color) = (1,1,1,1)
_Stencil_Ref ("Stencil ID", int) = 3
//_Cutoff("Cutout offset", Range(0, 1)) = 0.001
}
SubShader {
Tags {
"RenderType"="Opaque"
"Queue"="Transparent"
}
//ColorMask RGB
//Cull back
//ZWrite off
//ZTest Always
Cull back
ZWrite off
//AlphaTest Greater [_Cutoff]
//ZTest Always
Stencil {
//Ref 3
Ref [_Stencil_Ref]
Comp Always
Pass Replace
}
Pass{
blend srcalpha oneminussrcalpha
SetTexture [_MainTex]
{
//Combine texture
//Combine texture lerp(texture) constant
//Combine texture* primary DOUBLE, texture* constant
Combine texture* primary
}
SetTexture [_MainTex]
{
ConstantColor [_Color]
Combine previous* constant
}
}
}
}
지워질 대상
Shader "ahzkwid/Stencil/InvisibleTarget" {
Properties {
_MainTex ("MainTex", 2D) = "white" {}
_Color ("Main Color", Color) = (1,1,1,1)
_Stencil_Ref ("Stencil ID", int) = 3
//_Stencil_Comp ("Stencil Comp", int) = 6
//_Stencil_Pass ("Stencil OP", int) = 2
}
SubShader {
Tags {
"RenderType"="Transparent"
"Queue"="Transparent"
}
//ColorMask RGB
//Cull back
//ZWrite off
//ZTest Always
Cull back
ZWrite off
//ZTest Always
Stencil {
//Ref 3
Ref [_Stencil_Ref]
Comp NotEqual
Pass Replace
//Comp [_Stencil_Comp]
//Pass [_Stencil_Pass]
}
Pass{
blend srcalpha oneminussrcalpha
SetTexture [_MainTex]
{
//Combine texture
//Combine texture lerp(texture) constant
//Combine texture* primary DOUBLE, texture* constant
Combine texture* primary
}
SetTexture [_MainTex]
{
ConstantColor [_Color]
Combine previous* constant
}
}
}
}
컷아웃 지우개
Shader "ahzkwid/Stencil/InvisibleCutout" {
Properties {
_MainTex ("MainTex", 2D) = "white" {}
_Color ("Main Color", Color) = (1,1,1,1)
_Stencil_Ref ("Stencil ID", int) = 3
//_Cutoff("Cutout offset", Range(0, 1)) = 0.001
//_Stencil_Comp ("Stencil Comp", int) = 0
//_Stencil_Pass ("Stencil OP", int) = 2
}
SubShader {
Tags { "Queue" = "AlphaTest"
//"RenderType" = "TransparentCutout"
"RenderType" = "Transparent"
"IgnoreProjector" = "True" }
//ColorMask RGB
//Cull back
//ZWrite off
//ZTest Always
Cull back
ZWrite off
//AlphaTest Greater [_Cutoff]
AlphaTest Greater 0.001
//ZTest Always
Stencil {
//Ref 3
Ref [_Stencil_Ref]
Comp Always
Pass Replace
//Comp [_Stencil_Comp]
//Pass [_Stencil_Pass]
}
Pass{
blend srcalpha oneminussrcalpha
SetTexture [_MainTex]
{
//Combine texture
//Combine texture lerp(texture) constant
//Combine texture* primary DOUBLE, texture* constant
Combine texture* primary
}
SetTexture [_MainTex]
{
ConstantColor [_Color]
Combine previous* constant
}
}
}
}
일반적으로는 컷아웃 지우개만 만들어서 아래걸 쓰면 된다
안쪽에 있는건 안보이게 하고 싶을때
원본
결과
마스크와 마스크 타겟
마스크
Always
Less
마스크 타겟
iD만 동일하면 된다
Equal
Keep
위 지우개로 마스크도 지울수 있다
아래는 예시 사진
빨강이 마스크고
파랑이 ID 4짜리 지우개
흰색이 마스크 타겟
Comp
0-Always
1-Never
2-Less
3-Equal
4-LEqual
5-Greater
6-NotEqual
7-GEqual
OP
0-Keep
1-Zero
2-Replace
3-IncrSat
4-DecrSat
5-Invert
6-IncrWrap
7-DecrWrap
'Unity > shader' 카테고리의 다른 글
유니티 쉐이더 인스펙터 (0) | 2021.02.21 |
---|---|
자주쓰는 유니티 쉐이더 코드모음 (0) | 2020.11.04 |
Material Button GameStage Gray doesn't have _Stencil property (0) | 2020.06.29 |