- Home /
Override the reflection probe's texture in shader graph
Hi,
I've implemented a 2 faced (top, bottom) reflection which I stretch by a matrix and use it as my realtime reflection,
I want to access the reflection probe input inside the shader graph's PBR Master node and override the reflection map it has with my custom reflection map,
I know that I can disable reflection probe detection in mesh renderer and just use my reflection map, but
I want to take advantage of the builtin PBR calculations for the reflections (metallic, smoothness, ...).
so, is there any way to override the reflection prob's map in my shader and pass my custom texture as the reflection?
Aside from reflection strength, those parameters wouldn't do much to a regular cubemap. Unity pre-processes their reflection probes outside of the material to get glossy reflections, if that is what you are after. To replace reflection probes in a shader, you would need to either override the HLSL include files in the SRP package (which would apply to every material), or hand write a shader that uses the Lit shader as reference. In theory, you could just manually override the reflection probe property through script, i.e.
material.SetTexture ("unity_SpecCube0", customReflection);
material.SetVector ("unity_SpecCube0_HDR", Vector4.zero);
But even then, I'm not sure it would take precedence over the internal renderer.
hey buddy, thanks a lot
tried what you said but it spams me with this warning:
Trying to set builtin parameter "unity_SpecCube0_HDR". Will be ignored.
and this didn't work.
I can't even use GetTexture on the material, it gives the following error:
$$anonymous$$aterial doesn't have a texture property 'unity_SpecCube0'
Even, if everything was ok, I still had to inject the reflection texture as a cube map.
is there any way to inject it through the shader itself? so I can process my reflections with the matrix beforehand.
I have no problem trying to handwrite the shader if the shader graph doesn't support such functionality.
This is the code I used : using System.Collections; using System.Collections.Generic; using UnityEngine;
public class ReflProbeReplacer : $$anonymous$$onoBehaviour
{
public $$anonymous$$aterial material;
public Texture customReflection;
public Vector4 vector4;
public bool useDefault;
private Texture defaultReflection;
private Vector4 defaultVector;
private void Awake()
{
defaultReflection = material.GetTexture("unity_SpecCube0");
defaultVector = material.GetVector("unity_SpecCube0_HDR");
}
private void LateUpdate()
{
if(useDefault)
{
material.SetTexture("unity_SpecCube0", defaultReflection);
material.SetVector("unity_SpecCube0_HDR", defaultVector);
}
else
{
material.SetTexture("unity_SpecCube0", customReflection);
material.SetVector("unity_SpecCube0_HDR", vector4);
}
}
}
once again, thanks for caring
I don't understand, why can't you just override the reflection probe in the mesh renderer? how does that not use the builtin pbr calculations? Also keep in $$anonymous$$d that in deferred renderer, reflection probes are rendered separately, not in the surface shader.
sorry I can't understand what you mean by "overriding the reflection probe in the mesh".
I'm trying to override it in the shader itself because my reflection is a pair of plain texture2Ds rather than a cubemap and I need to stretch and wrap them around the object correctly only by matrix multiplication to mimic ordinary reflections.
currently, I can do such a thing and push them to the Emission input but that would act as a separate reflection ins$$anonymous$$d of the main reflection which gets affected by "metallic" and "smoothness" properties.