In this tutorial, we will see how to use reflection probe in unity applications.
A reflection probe is like a camera that stores the spherical view of its surroundings as a Cubemap. This Cubemap is then used to provide reflection on the objects having reflective materials. A unity scene can have multiple reflection probes.
We can generate three type of reflection probes:
- Baked probe: stores baked cubemap in the editor and provide static reflection. Baked probes are good for performance.
- Custom probe: stores static cubemap, can be baked in the editor or can be set manually by the user.
- Realtime probe: stores dynamic cubemap that can be updated at the runtime. Realtime probes are not good for performance as it updates on every frame.
In this tutorial, We will see how to use a baked and realtime probe.
Set up Scene
- Let’s set up a very simple scene for this demo.
Create a reflecting object
- Add a sphere in the scene. (Create -> 3D Object -> Sphere)
- Create a material in the Assets folder (Create -> Materials) and apply it on the sphere.
- Set the metallic and smoothness property of the material to 1. This will allow material to behave as a reflecting surface.
Now, you can see the skybox reflection on the sphere. But the scene game objects (Cubes) are not showing in the reflection of the sphere. We will fix this using reflection probe.
Set up reflection Probe
- Add a reflection probe in the scene. (Create -> Light -> Reflection Probe).
- Place the reflection probe at the center of the Sphere object. (Copy transform component value from sphere object and paste it to the Reflection Probe object).
A Reflection Probe component is attached to the object. This component is like the Camera component and we can change the reflection behavior by changing the properties of this component.
Edit Bounding Volume
Edit the bounding volume of the reflection probe as per requirement. This will add scene objects from this bounding volume in the reflection.
Ignore Sphere GameObject
Since the reflection is displayed on the Sphere Game Object itself, so we need to ignore this while calculating reflection.
- Create a new layer as ReflectionIgnore. Change the layer of the Sphere game object to this new layer. Checkout my layer mask tutorial to know more about layers.
- Select Reflection Probe in scene and click on the Culling Mask dropdown property of the Reflection Probe component. By default, its value will be set to Everything. Uncheck the ReflectionIgnore layer.
- By default, the reflection type is baked. To include the objects, present in the bounding volume, we need to bake the lighting once again.
- Set environment objects as reflection static. Select the Environment object and mark it reflection static. If a pop up will ask to mark the same change for the child objects then click on Yes button.
- Open Lighting panel (Window -> Rendering -> Light Settings). In the Debug Settings section, uncheck the Auto Generate check box.
- Click on the Generate Lighting button. Reflection will be now baked again.
- The environment objects are now the included in the reflection.
Real time Reflection
- Since the above reflection is baked, if there will be any change in the environment objects at run time then it will not reflect on the reflecting surface. For example, if the cube objects will change its position at run time, it will not reflect in the reflection. We can use real time reflection in this scenario.
- Change Reflection Probe type to Realtime. It will enable two more options. Change refresh mode property to Every Frame and Time Slicing property to No time slicing.
- Check Autogenerate checkbox in Lighting panel (Window -> Rendering -> Light Settings -> Debug Settings)
- Now the reflection will update on every frame.
Try to manipulate different properties of Reflection Probe component and see the results on the reflection.
Download the example unity package here.
That’s it for the tutorial. Please post your comments for queries and feedback. Thanks for reading.
Latest posts by Gyanendu Shekhar (see all)
- Create fake shadow using blob shadow projector: Unity tutorial - October 2, 2018
- Using Reflection Probe: Unity Tutorial - October 1, 2018
- Difference Between Material and Shared Material: Unity Tutorial - September 23, 2018