- Home /
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.
So I'm using this to render a sprite but as soon as I add the _Color$$anonymous$$ask property my sprite is no longer rendered at all... Tried with and without actually using the color mask property and it just won't render at all.
Answer by tayl0r · Jun 17, 2015 at 08:59 PM
(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 ...
// these six unused properties are required when a shader
// is used in the UI system, or you get a warning.
// look to UI-Default.shader to see these.
_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
// see for example
// 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 _Color$$anonymous$$ask 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.
Answer by olonge · Nov 01, 2016 at 04:32 PM
...or as in my case, if you were only interested in the text element, just use a material based on the following shader: UI/Unlit/Test
Shader "UI/Unlit/Text"
{
Properties {
[PerRendererData] _MainTex ("Font Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_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
}
FallBack "UI/Default Font"
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613201116im_/https://answers.unity.com/themes/thub/images/avi.jpg)