Update global reflections from procedural skybox


I’m using the built-in procedural sky in Unity 5. When I set “Reflection Source” under the Lighting tab to “Skybox”, this updates the reflections based on the sky color. But when I run the game, it doesn’t refresh the reflections automatically when I change the sun position/sky color.

Is it possible to call a method from a script to refresh the reflection map? If not, how would I render a reflection probe into a cubemap, and use this as the reflection source instead?

Hey there!

To achieve what you want, I would suggest creating a giant Reflection Probe around your environment and add a script that uses the ReflectionProbe.BlendCubeMap function.

This will return a RenderTexture that you can assign by script in the probe. The function is quite efficient (~0.3 ms). Here’s a simple proof-of-concept script:

using UnityEngine;
using System.Collections;

[RequireComponent (typeof (ReflectionProbe))]
public class BlendReflection : MonoBehaviour {

	[SerializeField] Cubemap cubemap1;
	[SerializeField] Cubemap cubemap2;
	[Range(0.0F, 1F)] [SerializeField] float blendFactor;
	RenderTexture renderTexture;
	ReflectionProbe probe;

	public void Start () 
		probe = this.GetComponent<ReflectionProbe> ();
		probe.mode = UnityEngine.Rendering.ReflectionProbeMode.Custom;
		renderTexture = new RenderTexture (cubemap1.height, cubemap1.height, 0, RenderTextureFormat.ARGBHalf);
		renderTexture.useMipMap = true;
		renderTexture.isCubemap = true;
		probe.customBakedTexture = renderTexture;

	public void Update () 
		if (probe != null && cubemap1 != null && cubemap2 !=null) 
			ReflectionProbe.BlendCubemap (cubemap1, cubemap2, blendFactor, renderTexture);

Simply add this script to a probe, set the two cubemap, press play and use the slider to see it blend between the two maps. This will work on all objects affected by the probe.