Hello, dear unity forum!
I have a pretty hard to solve issue - I can’t get around with rendering my custom mask into render texture with respect of scene geometry (sprites)
I would like to make a 2d water shader using hand-drawn heightmaps - I put them into the scene, set sorting layer to “water” , set appropriate order in layer,then animate verticies with shader, hide rendering from the renderer asset and draw them through scriptable renderer feature with method
So…if I render everything as is - without hiding “water” layer - the result is perfect. I would like to keep only the pixels occupied by heightmap shader after the whole scene is rendered. Is there a good approach for this?
ofc, you need to include sorting layer here if you want to draw like unity does.
Actually, here I do my own sorting, but refer to this page if you want to have exact replica
In renderer feature use the resulting collection with commandBuffer.DrawRenderers().
before that, I check if renderer I want to draw is inside layer “water” - so I draw it with assigned shader, otherwise (in any other renderer except water), I draw with shader that outputs just black color (0,0,0,0)
This solution works with 2D painter drawing algorithm. For 3D you can check something better, for example