#Is the stencil buffer bugged in unity 2022.1?

1 messages · Page 1 of 1 (latest)

mellow lantern
#

So, I'm trying to make a stencil mask that would allow fog to be seen only when looking through the mask, however, the stencil buffer in urp 13 seems to be bugged. Either that or I don't know how to write shaders, here is the mask shader: https://paste.myst.rs/fzrh6xs3 and here the fog shader I want to mask out : https://paste.myst.rs/u8bnxei2

#

Forgot to mention, the fog is implemented as a custom post processing effect using a blit renderer feature

rocky olive
#

blit operations discard stencil buffer information afaik
but I don't know specifics of your situation. usually I find related information to issues like those on the unity forums, often from bgolus

mellow lantern
#

Then it must be because I use blit, I'm really still a beginner in writing shaders

rocky olive
#

what's your use case?
I found an article or two about this once but I can't find it now

mellow lantern
#

This is how my scene looks like and I want to make the fog visible only by looking through a plane. The readon fot that is because I would then discard the plane's pixels if they are above 0 in world space, esentially replicating a wateine effect

rocky olive
#

and where does the blit come into play? is it maybe possible to do the fog rendering before the blit?

#

maybe that's different in newer unity versions as you can specify channels for render textures (I think i have seen that)
but when I tried it, when you do the first image effect blit, the incoming texture will have the right stencil buffer, but the target texture that is blitted to doesn't have it anymore.
and as such, only the first incoming texture for the first blit would have the stencil information

mellow lantern
#

What I think I'm gonna do, is instead of the fog being an image effect, how about I use a fog plane, this way I would be able to clip it based on height and I'd need stencils anymore

#

As you said, it's probably because the texture blitted to doesn't have stencil buffer anymore

#

I'm really interested in learning more about graphics even though I am still in high school

rocky olive
#

oh nice
there are a few resources for learning (unity) shaders pinned in #old_shaders

#

you could do the fog plane testing purely in a single shader for the water for whatever element you wanna apply it on too,
but I feel like this will be more complex and possibly more expensive than a stencil based approach

mellow lantern
#

I actually tried with the fog plane method

#

Before the blit one, but I wanted it to affect the water too which is a transparent shader, seeing it didn't I gave up and tried using blit(since I can set the render event to after transparents)

rocky olive
#

not sure, maybe that's useful ,maybe not

mellow lantern
#

Thanks