#Render object only through stain

1 messages · Page 1 of 1 (latest)

zenith needle
#

I have made an interactive Unlit shader with shader graph where you can drag stains of liquid to the center of the screen (att.1). I apply its material to 3D planes that I position in front of the camera.

I want to be able to render a specific object in the scene only when viewing it through one of the liquids. I have seen tutorials on clipping masks and stencil buffers but I'm unsure how can I output the mask for the liquid from inside the shader graph (att.2) and use this information for the stencil buffer / clipping mask.

If you know how I could achieve this effect or have another suggestion, please shoot me a message or respond to the thread. I feel pretty lost on how to proceed and it would help a ton. Thank you!

zenith needle
#

Render object only through stain

spice kettle
zenith needle
#

many thanks for the response!! How could I research more on the matter? I'm very new to this

#

where would be a good place to start?

spice kettle
zenith needle
#

oooo thank you!!! :D

spice kettle
#

Might need to google around for stencil tutorials. I mostly only know older tutorials for shader code like https://www.ronja-tutorials.com/post/022-stencil-buffers/
Same idea, just implemented in code instead. The stencil params are the same

zenith needle
#

I have checked out some stencil tutorials but I was unsure if this was the solution to my problem since the edges of my liquid stains are a smooth transition to transparent and I've only seen stencils either render what's behind them or not. So you're saying there's a way to alpha mask the stencil?

spice kettle
#

Stencils can't do a smooth transition / partial transparency, but the fully transparent areas can be alpha clipped which means those pixels don't render to the stencil buffer

#

Another option could be to render your objects with a custom renderer feature to an offscreen texture, then sample that texture (using screen position as UV input) in the liquid shader. That would allow for the partial transparency / fade out at edges

zenith needle
#

I'll have to reread this thread several time over the course of today to fully understand what you mean but I think I know what you're suggesting and it just might work. I was blindsided trying to use the node from the shader and get it into some other shader/procedure to do the clipping when I can just sample the clipping into this shader where I have the mask and apply it right there. I've never considered this approach before and I'm starting to feel it's the best suited