- Home /
HDRP - Get/Set Reflection probe texture
Hello,
I have HDRP project. It contains reflection probe dynamically created in script.
I need to make reflection probe texture Grayscale.
So, I want to read texture, make it grayscale and write it back to Reflection probe. I found this post: https://answers.unity.com/questions/1467926/realtime-reflection-probe-cubemap.html
But it doesn't work for me. reflectionProbe.IsFinishedRendering() always returns false. In Editor I see reflection probe mode == ReflectionProbeRefreshMode.EveryFrame But in my script I set it = ReflectionProbeRefreshMode.ViaScripting. So, it seems refreshMode not applied to probe.
Why is it? When I set refreshMode = ReflectionProbeRefreshMode.OnAwake it works as expected. And ViaScripting not applied.
OK, lets get texture from Camera.RenderToCubemap() and then set custom texture to Reflection Probe. But when I set Reflection Probe to Custom mode I get exception in HDRP class:
// Crate Reflection Probe
GameObject reflectionProbeGameObject = new GameObject("The Reflection Probe");
ReflectionProbe reflectionProbe = reflectionProbeGameObject.AddComponent<ReflectionProbe>();
reflectionProbe.mode = UnityEngine.Rendering.ReflectionProbeMode.Custom;
reflectionProbe.refreshMode = UnityEngine.Rendering.ReflectionProbeRefreshMode.ViaScripting;
reflectionProbe.timeSlicingMode = UnityEngine.Rendering.ReflectionProbeTimeSlicingMode.IndividualFaces;
// Test custom texture - all pixels white
var testTexture = new Texture2D(128, 128);
var colors = new List<Color>();
for (int i = 0; i < 128 * 128; i++)
{
colors.Add(new Color(1.0f, 1.0f, 1.0f, 1.0f));
}
testTexture.SetPixels(colors.ToArray());
testTexture.Apply();
// Set texture
var texture = new RenderTexture(128, 128, 24);
reflectionProbe.customBakedTexture = testTexture;
reflectionProbe.RenderProbe(texture);
It throws Exception in UnityRngine.Experimental.Rendering.HDPipeline.ReflectionProbeCache.ConvolveProbeTexture()
line 175: renderTexture == null.
I think this problem appears because of HDRP project. Please tell me how I can get / set Reflection Probe texture in HDRP?
May be there is another way to make reflection probe grayscale?