Shader error: Material doesn't have stencil properties ??

This is a new shader error for us with Unity 5:

Material doesn't have stencil properties

What is causing this? We are using a stencil buffer in the shader but AFAIK there is nothing else in the Unity docs that talk about a stencil property.



저런 에러(워닝)가 뜨면 아래 코드를 붙여넣으면 된다



(answering my own question)

There seems to be a magic property called _Stencil, which is supposed to be used for the unique stencil buffer id.

_Stencil ("Stencil Ref", Float) = 0

in full ...

  1. // these six unused properties are required when a shader
  2. // is used in the UI system, or you get a warning.
  3. // look to UI-Default.shader to see these.
  4. _StencilComp ("Stencil Comparison", Float) = 8
  5. _Stencil ("Stencil ID", Float) = 0
  6. _StencilOp ("Stencil Operation", Float) = 0
  7. _StencilWriteMask ("Stencil Write Mask", Float) = 255
  8. _StencilReadMask ("Stencil Read Mask", Float) = 255
  9. _ColorMask ("Color Mask", Float) = 15
  10. // see for example
  11. // http://answers.unity3d.com/questions/980924/ui-mask-with-shader.html

So I'm using the UI-default shader as a starting point for my sprite shader, and if I have the _ColorMask property my sprite doesn't render at all. Removing the property allows the sprite to render but then it doesn't clip properly. Even if I remove the code where the color mask is being used, just having the property still breaks the shader.

I would recommend using the Sprites-Default or Sprites-Diffuse shader as a basis - why use UI-default? Without seeing your code, can't really suggest anything else

Small note: If you have spaces in your shader name, this does not seem, to work.


반응형

+ Recent posts