- Home /
How do I set RenderSetting.customReflection using a cubemap RenderTexture?
Hi people,
I'm trying to set RenderSettings.customReflection
with a RenderTexture
, but I'm not sure how or if this is even possible. I can create a RenderTexture
that is a cubemap, but I can't get a Cubemap
object from that to plug into RenderSettings.customReflection
.
I tried casting but it gives "error CS0039: Cannot convert type UnityEngine.RenderTexture' to
UnityEngine.Cubemap' via a built-in conversion"
I tried casting to a Texture
and then a Cubemap
, but then I just get null
. That makes sense, but it was worth a try.
Haven't been able to find any conversion methods. Seems like this should be possible. Am I missing anything? Maybe I should submit a feature request?
I would like to know that too. We get the texture from ReflectionProbe.BlendCubemap, so it's a Cubemap.
Answer by alexandre-fiset · Jul 08, 2015 at 02:12 PM
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.
You did not answered his question. The method you mentioned that still created a RenderTexture cubemap that can not apply to the RenderSetting.customRefection.
Your answer
![](https://koobas.hobune.stream/wayback/20220613194440im_/https://answers.unity.com/themes/thub/images/avi.jpg)