Transparency using Scene Color node not layering multiple transparent objects over each other
This transparent shader is using the Scene Color node to show opaque objects that are behind it, mimicking transparency and refraction. The problem is, because it uses the Scene Color node (which uses the Opaque Texture from the render pipeline), when one transparent object is drawn over another, it does not sample the transparent object behind, as transparent objects are not drawn to the Opaque Texture being sampled.
You can see this water cube not blending with the water plane, they instead just overwrite each other.
Gif Water Layering: https://github.com/M-O-Marmalade/Pix/blob/master/waterlayering.gif?raw=true
I attempted to sample a Render Texture from the camera, but it ended up in this buffer loop.
Gif Water Buffer Loop: https://github.com/M-O-Marmalade/Pix/blob/master/waterbufferloop.gif?raw=true
Any ideas of how I could fix the layering of these transparent objects? I'm convinced the solution lies in sampling a Render Texture rather than the Opaque Texture, but I just can't wrap my head around the fix.
[preview of external content removed for GDPR compliance as it was including 3rd party cookies]
I could imagine using a Custom Function node with GrabPass might work.. currently looking into it more.
I see now that GrabPass is no longer supported in URP (I am using URP), but I'm reading about CommandBuffer.Blit, and trying to figure out how to use it in a Custom Function node to update my Render Texture before or after each transparent object is rendered, so they all get included in the Render Texture to be sampled by each other. Still having trouble getting a working function in the Custom Function node though (maybe it only supports HLSL and not C#? If so, would CommandBuffer.Blit be impossible to use this way?) Would be nice if GrabPass still existed :\
I feel like if I can avoid the RenderTexture feedback loop from happening, then everything will work when using the RenderTexture..