I tried to find any solution that might prevent this problem, but I couldn’t, now I have no idea. Can know how to handle this? I’m new in shader writing.
Thank’s in advance.
Unity’s masking system uses stencils. You’re writing to the stencil buffer too, so it’s interfering with the masking system.
My recommendation would be to use a hard coded stencil ref that’s unlikely to be used by Unity’s own masking system. Though this will mean you cannot use a mask to limit outlined text.
Thanks for your reply!
I remarked Unity UI uses one type of masks: 0…01 → if there’s content in first mask, 0…11 → if there’s content in second mask which nested in first one, etc. But I don’t understand how Unity UI responds to rest stencil values. I would guess rest values should using in user’s shader code to implement own logic within Unity UI system.
That third pass should decrement the stencil value back to what it was before. And because Unity’s masking system will never draw an object with a _Stencil value greater than the max value that is already in the stencil buffer from masks, there shouldn’t be any other issues. Unity’s masks do something similar after drawing all child objects under them, resetting the stencil to a lower value. The only issue I can think of is if you have 8 chained layers of masks, the _Stencil reference value will be 255, so IncrSat won’t do anything. So don’t have that many masks in a single hierarchy.
Thanks for you reply again!
But in your code snippet there shouldn’t be Less instead of Greater? As I understood comparison function works as follows: refValue compFunction bufferValue. It seems replacing Greater function to the Less works well as you explained.
Can I ask you about one moment? I have not enough understanding how shader applies to the TMP meshes: per pass for every glyph(mesh)(i.e performing 1st pass from shader for every mesh, next 2nd pass, etc.) or all glyphs batched in one mesh and then shader applies to it? Thanks in advance!
If a TMP mesh is using a single font / sprite atlas for all of the glyphs, and you’re not using rich text to change the material mid line, it’s drawn as a single mesh with multiple glyphs in it. As far as Unity’s rendering system is concerned each TMP component is a single mesh.