How do draw multiple layers of transparent surfaces that include refraction

In my unrelated thread about Transparent SSR, an issue came up about rendering multiple layers of transparent objects with some kind of refraction/distortion.

(this one: Resolved - Transparent surfaces not receiving SSR despite all settings enabled - Unity Forum )

Here’s the image from GXMark showing the problem:

One way to deal with it, is to render the first layer (for example water) during the regular transparent pass with refraction or using HD Scene Color with distorted offset in a shader graph. You then render the second layer (for example the glass through which the water should be visible) using built-in Distortion. The built-in Distortion forces a second update of the color pyramid, and so your surface will now also include the water.

A big problem with Distortion is that it is applied to your entire glass, including surface details. It it not just blurring the background for example, it is blurring entire thing after rendering it. So your specular glass details will also get distorted and blurred, rather than just what is behind the glass (background).

So I wanted to achieve both distorted layers (water and glass) without using built-in Distortion. The trick is to render your glass during the “Before Post Process” custom pass injection point, in which case you can just use HD Scene Color to distort what is behind the glass.

A big catch was, that if you do not render anything at all using build-in Distortion, then the distortion color pyramid will not be created, and your water will be missing behind the glass. I solved this by forcing the distortion color pyramid update, by drawing a dummy invisible cube that uses built-in Distortion.

The following images explain it better:

2 Likes

Thanks for clarifying that for everyone else to see.
It’s not something trivial and it is indeed how you are supposed to do it if you want to stack a fake refraction using distortion with another refractive transparent (in that case, a water surface)

1 Like