- Home /
Is it possible to rotate the environment's reflection source at runtime? (C#)
Using Unity 5.4 and C#, I'm trying to script swapping out / rotating lighting environments at runtime. It's fairly easy to swap the skybox in the render settings (and rotate it via the skybox material). However, the reflection source does not update.
I can change the reflection source via RenderSettings.customReflection, however this will replace the reflection environment with a skybox at its default rotation, which will not match the (runtime) rotation set in the skybox material. And it seems that custom reflection source can't be rotated.
From reading the docs, it seems that I might need to call DynamicGI.UpdateEnvironment() after changing the skybox, but this does not update the reflection environment. (Which makes sense, as GI is not reflection.)
DynamicGI.UpdateMaterials() might also (not) be of use, but the function requires passing it a renderer, which I'm unsure of. Would that be the renderer for each mesh in the scene?
Has anyone been able to rotate an environment lighting skybox with corresponding environment reflections at runtime?
Any hints would be great!
Thanks!
Answer by SuppleTeets · Jul 02, 2016 at 02:42 PM
In order to get the world reflection cubemap updating in realtime I ended up in C# generating a cubemap, connecting it to RenderSettings.customReflection, and then running camera.RenderToCubemap to update it when things are changing, in your case rotating, in my case it was blending/fading between two cubemaps. It's a performance hit(especially with higher res cubemaps), but it works! You can do whatever you want with the skybox and it'll update the reflections.
I tried to use a RenderTexture with .isCubeMap set, thinking that might be perform better, but I couldn't figure out how to connect it to the lighting custom reflection cubemap slot.
Your answer
Follow this Question
Related Questions
Skybox reflections stopped working. 0 Answers
Unity iOS Rendering Standard shader issue 0 Answers
Instantiated light not working properly 0 Answers
Outdoor Reflection Probes 0 Answers