Stencil properties in UI shader, using Shader Forge

Hello,

I have a custom made shader (made in Shader Forge) which I would like to use as a part of my UI for rendering some images inside a Scroll View. However, when I try to use this shader for UI rendering, then I get the following warning from Unity:

Material MyMaterialName doesn’t have stencil properties

This warning is quite expected, since this shader previously just was used for rendering meshes ingame, and not for rendering UI, so I haven’t implemented any stencil properties support in the shader. The result is that UI images using this shader are still rendered when they are outside of the visible area of the Scroll View. This is also quite expected :slight_smile:

My questions are:

  1. Is there an easy way to get a Shader Forge shader work well with Unity UI? (enabling “Stencil Buffer” under “Blending” doesn’t suffice)

  2. If the answer is “no” to question 1, then what would you recommend for Unity UI shaders - make your custom UI shaders without Shader Forge, or something else?

Thank you very much in advance for your help.

Kind regards,
Uffe Flarup

Had a similar problem, followed the answer here and worked for me:

Doesn’t seem possible via shader forge / have to do it manually, at least when I tried playing around with Shader forge stencil options.

1 Like

Thanks for your reply. I (unfortunately) also ended up concluding that UI shaders and Shader Forge dont play well together.

Hi,

Just a little visual update for 5.4.1 to get a Shaderforge-shader working with stencil UI Mask component. I hope it helps…

2 Likes