Reflection Probe Box Projection in Graph

Hi All,

The box projection feature that is now available in URP12 in the “complex lit” shader gives really nice results.

I’ve built a shader based on “baked lit” and added realtime planar reflections. It looks cool but rendering the whole scene in the reflection is heavy. I want the static elements to be baked in the reflection probe and mix them with the realtime reflections of only the non-static elements.

Any idea on how to make the “reflection probe node” in shadergraph return the same type of reflection as the “complex lit” shader does when box-projection is checked? Or any other node for that matter. I get reflections but they’re not box projected.

Thanks!
7910278--1008628--upload_2022-2-19_19-7-39.png

1 Like

Hi, I know it’s late, but since this is the first result on Google, I think it’s worth answering.

I solved this by creating a Custom Function node with box projection code. It uses the standard unity variables passed from Reflection Probe, so it will have the same projection as all other materials inside the affected box.

The inputs and outputs are:
8046899--1038446--upload_2022-4-14_10-49-57.png
WS - World Space

And the code is:

float3 viewDirWS = normalize(ViewDirWS);
float3 normalWS = normalize(NormalWS);
float3 reflDir = normalize(reflect(-viewDirWS, normalWS));

float3 factors = ((reflDir > 0 ? unity_SpecCube0_BoxMax.xyz : unity_SpecCube0_BoxMin.xyz) - PositionWS) / reflDir;
float scalar = min(min(factors.x, factors.y), factors.z);
float3 uvw = reflDir * scalar + (PositionWS - unity_SpecCube0_ProbePosition.xyz);

float4 sampleRefl = SAMPLE_TEXTURECUBE_LOD(unity_SpecCube0, samplerunity_SpecCube0, uvw, LOD);
float3 specCol = DecodeHDREnvironment(sampleRefl, unity_SpecCube0_HDR);
Color = specCol;

You can now use this instead of the Reflection Probe node.

4 Likes

@GreenDave113
Your shader returns an error:

Edit: The error disappeared, I don’t know what I did, maybe because I changed the shader type to Lit and then back to Unlit, it now works flawlessly…

8355003--1099593--upload_2022-8-11_11-14-39.png