BlackWindBooks.com | Newsletter! | risingthumb.xyz | achtung.risingthumb.xyz | github.com/RisingThumb | site map

risingthumb.xyz Warm up? We may as well sit round this cigarette.

Planar Reflections

Brief overview of reflection techniques

Planar reflections is a technique that achieves real-time reflections by rendering the scene twice by a 2nd mirror camera. Because of this, it is a fairly performance-intensive approach to rendering reflections, and it is also limited to planes(though you can use the technique for surfaces that are plane-like if you are ok with some distortion and inaccuracy, often for water with refraction and things like that).

Before we get into implementation, I will first tackle a few other ways of doing reflections to compare and contrast them. Firstly is Screen Space Reflections. This has a major limitation in that it can only reflect what is already in screen space, in other words, what is on the screen already. This means it often has harsh lines where as the camera looks down, the reflections fade out. This is a good and very cheap technique if you know the camera is either fixed perspective or for small elements that will be reflected, but in the latter case it's rare for only small elements to be reflected. Secondly, there's faking reflections by just copying and flipping the world upside down and using a translucent texture where the reflection plane is. This is effective for small scenes, gives a lot more artistic control, lets you make observable differences in the reflected scene and also lets you take advantage of occlusion culling and frustum culling. Additionally you can have reflections of reflections that get darker with each one by making the translucent texture for each reflected copy slightly darker. Then finally there is cubemapped reflections, which involve a probe taking and storing images of what the scene looks like at a particular place, and using these cubemaps as a rough estimate of what the reflection is in that area. For reflections in rivers or in lenses this is a particularly effective and cheap approach. Similar to lightmap baking, it cannot do realtime updating, and it's also a performance improvement at the cost of storage space.

If high quality accurate reflections matter, which they do for mirrors or for still ponds and lakes, planar reflections is usually the best approach.

Implementation

The approach goes roughly as follows: You have a copy of the player camera(including any additional properties attached to it, like Field of View and anything special for how the environment is rendered). You mirror this across the plane so it is embedded in the floor, and you rotate it appropriately so it is looking where the object is(in other words the rotation is also mirrored in that plane).

PlanarReflections 780 472

Doing this naively, you will observe that it mostly works, but you see weird glitches and artifacts where it's rendering geometry below this. This is because the camera embedded below the plan is still rendering below it. To fix this, the camera will have near-Z clipping(so it clips geometry near it), and use oblique camera projection so that it. What this does can be seen in comparing these 2 images below:

Standard Projection:

StandardProjection 780 272

Oblique Projection:

ObliqueProjection 780 272

This, in combination with near-Z clipping, will prevent the camera rendering anything below the plane.

What comes after, is just using the camera's texture and drawing that on the plane. You can then apply standard techniques of refraction, specular, normal mapping etc to achieve effects like water or mirrors.

As a note, this involves rendering the scene twice using the reflection camera too. To improve performance, it can be helpful to lower this mirrored camera resolution, so it is half or 1/4 the resolution of the player camera. It can also be helpful to turn off some environmental effects for this camera such as volumetric fog, screenspace reflections and screenspace ambient occlusion and so on, especially if it will be distorted like a lake would be.

Regarding using multiple reflections

To answer a basic question, yes multiple reflections can be used. As an example, you may use screenspace reflections for small reflections on say.... the metal of a gun which will always be fixed relative to the camera, then use cubemapped reflections for the lenses of its scope, and for a raging river, which then the river goes into a rather still lake using planar reflections.

The important skill is to know when to use each technique depending on the effect you are going for. Using screenspace or cubemapped reflections for everything usually isn't the answer.

What about raytraced reflections or raymarched reflections?

I don't know enough about these techniques to comment. I do know that raytraced reflections usually aren't realtime, so for prerendered cinematics they are the way to do things. As for raymarched reflections...

Is there a tool to do this in...

=> For Godot I wrote a tool for this. You can see this here.

For other tools you will have to look it up.