Broken Mirror URP
Planar reflections for URP
Techniques / Implementation
It use a Render Texture. So the scene need to be rendered twice, performance depends on the complexity of the scene, render texture size and camera configuration (mostly post-rendering).
Near clip of the reflection camera is adjusted to the plane position (oblique projection) so anything behind the plane could be rendered.
Culling mask of the camera can be used if you need to remove something from the reflection.
Orthogonal and Perspective camera are supported.
HDRP support, but It’s not our purpose to replace unity built’n.
Auto mode, so you don’t need to worry about anything (just 3 things in the inspector) or manually, so you can tweak performance as much as you need.
Shaders / Effects / Example Scenes
Just reflection, the most basic example.
./BrokenMirror/Scenes/1 - Mirror Reflection.unity
Broken glass, Embossed Glass: Mirror with normal distortion
With this shader you can distord the reflection.
Also notice the use of two different post-processing volumes.
./BrokenMirror/Scenes/2 - Broken Mirror Reflection.unity
Blend the reflection with a texture by a factor
./BrokenMirror/Scenes/3 - Decal Reflection.unity
Texture RGB goes directly to Albedo, alpha is used to blend the reflection texture and include normal map for distortion that only affect the reflection.
./BrokenMirror/Scenes/4 - Window Reflection.unity
5 - Glass Reflection
./BrokenMirror/Scenes/5 - Glass Reflection.unity
Glass Reflection 2
Translucent glass with texture blend by a factor.
So you wil see three images, reflection, given texture, and the object behind, a bit messy :)
./BrokenMirror/Scenes/6 - Glass Reflection 2.unity
Beatiful rain shader.
it’s a migration this tutorial to unity:
./BrokenMirror/Scenes/7 - Rain shader.unity
Example to setup everything manually, so you can tweak everything!
In this scene, render texture is created prior execution and also the camera.
It run faster than
Mirror Scene because the lower render texture resolution and disabled post-processing.
./BrokenMirror/Scenes/8 - Manual.unity
Override post processing
Example of how to override post processing in created camera.
This time, the main camera don’t have post processing while reflection does.
./BrokenMirror/Scenes/9 - Override post processing.unity
Exclude From Reflection
Example of how to exclude staff from reflection.
./BrokenMirror/Scenes/10 - Exclude From Reflection.unity
There are, maybe, endless combinations you can achieve. We include some subgraphs to easy your task.
Just the reflection part.
Reflection plus distortion using a normal map as input
Reflection plus distortion using a normal map vector.
You need to calculate normal map in the shader.
Reflection with alpha.
Blend an Albedo texture and the reflection by a factor.
Blend an Albedo texture and the reflection by a factor with alpha.
Reflection with distortion using a normal map, Opaque
Reflection with distortion using a normal map with alpha.
Planar Reflection Manager (MonoBehaviour)
This is the main componet of the asset.
You just need to configure the first two things:
Main Camera and
Reflection plane, we take care of the rest.
Or could have finer grain configuring
Reflection Camera and
Select here your main camera, the one that see the mirror.
Game object with a Renderer that represents the Reflection Plane.
Transform is used to know the orientation of the plane/mirror/glass.
We can create a camera based on your main camera.
We will asssign render texture to the one given or an temporary one.
You choose all the camera options except, render texture.
Give you all the fine grain for performance. For example you can disable post-processing.
Culling mask (Automatic only)
Use it to exclude objects from reflection.
We can use your render texture or create a temporary one base on the current resolucion and color setting of the camera: HDR / Normal.
We will assign it to all materials in the
You create the render texture with the options you desire.
We wont assign it to anything this time, you have to do it yourself.
Render texture Scale based on the current screen resolution.
Half should be OK, less will need some distortion.
Name of the shader property for Texture2D reflection. By default: _ReflectionTex
Errors / Troubleshooting
Reflection plane must have a Renderer to set temporary render texture to materials that need it.
Just like the error says.
Reflection plane require a
Renderer in itself (a
Mesh Renderer for example)
Could not find any material with a property named: XXX
The parameter sent at:
Shader property is not a valid property of any material in the
debug to see all shader parameter names in the console and choose the right one.
The most common issue is that Shader graph give an auto-generated-unique-name.
I see the reflection laggin
Most likely you are updating
Main Camera after
I don’t see the reflection in Reflection Probe
Baked Reflection Probes are not supported as Reflection is a realtime effect.
Your only option is to use realtime Reflection Probes.
I can see Reflections only from one side
Edit your shader, display
Graph Inspector ->
Graph settings -> enable:
Relfection colors are wrong / darker / brighter
Most likely double post-processing (double tonemapping/vignette?)
For example: tonemapping in reflection and then again for the entire scene.
Automatic mode: Use
Reflection Camera Volume Mask to select the desired layer for reflection.
In Manual mode edit
The most important aspect to performance are:
- render texture resolution
Note that some post-processing are reduntant and you dont have to do it twice, like tonemapping.
Those tweaks are “Inspector-manual”.
Update frequency on the contrary, require knowledge of your scene. We update every frame, because we don’t know if there is something non-static in your scene. But… if you do… you should disable the camera GameObject to skip the rendering process. Also if the camera is slow you can just frameskip odd/even frames.
But the most important of all. If your reflective plane is not visible, disable the
RenderTexture is required, so your device must support them.
VR and AR working in unity but we didn’t tested in a real device.
List of all external resources used and packed.
Texel Density Texture 1
Rain textures from: * https://deepspacebanana.github.io/blog/shader/art/unreal%20engine/Rainy-Surface-Shader-Part-1 * https://deepspacebanana.github.io/blog/shader/art/unreal%20engine/Rainy-Surface-Shader-Part-2
single pass reflection URP
TODO / Future plans
There is a basic / buggy implementation already in the asset but it’s still a work in progress.
backport to Unity 2019