Hey!
I am working on a project with a dynamic skybox (day/night cycle) and I came up with the solution of using one single huge (1000x1000x1000) realtime reflection probe so that sky color changes are rendered on all objects that are close to the player. To follow the player, the reflection probe is a child of the player game object.
So far I do not see any issue while profiling (even when not optimizing the settings like cubemap resolution, culling mask, time slicing, etc.), but I am wondering if this is an acceptable thing to do and if there are other solutions. Any thoughts?
Notes:
- I use URP;
- I use realtime instead of baked because the skybox changes dynamically;
- The dimensions of the probe (1000x1000x1000) are set regarding how far objects can be seen in the scene.
Many thanks!
You are essentially emulating the default sky reflection probe, which is the fallback used when a renderer is not within the bounds of any reflection probe. You can set the value for this probe directly with RenderSettings.customReflectionTexture.
It’s worth noting that environment lighting in Unity consists of 2 components - 1 is the default sky reflection, the other is the “ambient probe”. The ambient probe is a fallback for when a renderer is not near any light probes, and provides the diffuse component of the environment lighting. Concretely, it’s a SphericalHarmonicsL2 object, accessible via RenderSettings.ambientProbe.
Unfortunately it isn’t very straight forward to rebake these on the fly at runtime, but it is possible. You’ll end up having to use a reflection probe to bake the cubemap anyways, but you can have it not affecting anything. I posted a snippet of how to do it here [Solved] SceneManager.LoadScene() make the scene darker... a bug?
That said, if your setup works for you, I don’t really see any issue with it. Hope this helps.
Thank you for your help!
After 2 years developing this project I finally have performance issues using a realtime reflection probe for the reflection of a dynamic skybox.
So I switched to using a custom cubemap texture but I cannot manage to apply it to the environment. Following your exemple (thanks for the details btw, I found it very helpful), I update the custom reflection texture but nothing changes at runtime:
private void Update()
{
// A method for getting the new texture
// (I am not baking it as in your example, I do something using colors that change over time)
Cubemap cubemap = GetCubeMap();
// Set the cubemap
RenderSettings.customReflectionTexture = cubemap;
{
I can however do this using a reference to a reflexion probe and update its ReflectionProbe.customBakedTexture, but I thought it would be better to use the native environment reflections.
[SerializeField] private ReflectionProbe probe;
private void Update()
{
// A method for getting the new texture
Cubemap cubemap = GetCubeMap();
// Set the cubemap (this works)
probe.customBakedTexture = cubemap;
{
My settings for the environment are as follows. Note that I am not using any Skybox (I use a custom sphere game object that is rendered at the back using no depth write).
I don’t immediately see an issue with your setup. It looks like a bug. If you are unhappy with the workaround, submit a bug report.