ShaderGraph로 제작된 쉐이더 마스크 문제 Sprite Mask

 

유니티 내장 쉐이더 그래프로 제작된 쉐이더를 적용해보면

UI에서 마스크가 작동하지 않는다.

 

정식 지원이 아니라서 그런듯.

한 TA분이 해당 오류를 해결하는 방법을 올려주셔서 해결했다. 

 

쉐이더 그래프로 제작 -> 코드로 변환 -> 코드 수정

하는 귀찮은 과정을 거쳐야하고, 쉐이더를 수정하게되면 그때마다 다시 만들어줘야된다 ㅠㅠ

 

https://www.youtube.com/watch?v=RxW7_qgkXPo 

 

 

1. 쉐이더 그래프로 쉐이더를 제작

2. View Generated Code로 내용을 복사

3. 새로 일반 코드 Unlit Shader 생성

4. 내용 붙여넣음

5. 최상단

_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0
_StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255
_ColorMask ("Color Mask", Float) = 15

 

6. z 뎁스 부분 수정

 

    ZTest [unity_GUIZTestMode]

 

7. 스탠실 추가


   Stencil
   {
    Ref [_Stencil]
    Comp [_StencilComp]
    Pass [_StencilOp]
    ReadMask [_StencilReadMask]
    WriteMask [_StencilWriteMask]
   }
   ColorMask [_ColorMask]

 

 

 

 

https://forum.unity.com/threads/shader-graph-and-ui-mask.746927/

 

Help Wanted - Shader Graph and UI Mask

Is it currently so that for the UI Shaders to "respect" UI Masks, use of stencil buffers is needed? In other words this is currently not supported in...

forum.unity.com

맨마지막.

 

So I found the actual cause & the solution, it was rather silly. The problem was actually Unity for some reason decides not to include my custom shaders into the build. The solution is of course adding all of the corresponding shaders to the project setting menu > always included shader list

 

For anyone coming to this in the future. You may need to add the ztest line and stencil info to anywhere there is the ztest line. For me there were 3 places. Works great though and easily fixed my issue!

 

모든 ztest 가 있는곳에 stencil 이랑 Ztest 넣어줌

댓글

Designed by JB FACTORY