@@ -31,6 +31,14 @@ half3 SampleScreenSpaceGI(float2 pos)
31
31
#define _MIXED_LIGHTING_SUBTRACTIVE
32
32
#endif
33
33
34
+ #if !defined (_REFLECTION_PROBE_BLENDING_KEYWORD_DECLARED)
35
+ #define _REFLECTION_PROBE_BLENDING 0
36
+ #endif
37
+
38
+ #if !defined (_REFLECTION_PROBE_BOX_PROJECTION_KEYWORD_DECLARED)
39
+ #define _REFLECTION_PROBE_BOX_PROJECTION 0
40
+ #endif
41
+
34
42
// SH Vertex Evaluation. Depending on target SH sampling might be
35
43
// done completely per vertex or mixed with L2 term per vertex and L0, L1
36
44
// per pixel. See SampleSHPixel
@@ -300,13 +308,14 @@ half3 CalculateIrradianceFromReflectionProbes(half3 reflectVector, float3 positi
300
308
weight = min (weight, 1.0f - totalWeight);
301
309
302
310
half3 sampleVector = reflectVector;
303
- #ifdef _REFLECTION_PROBE_BOX_PROJECTION
304
- #if defined (REFLECTION_PROBE_ROTATION)
305
- sampleVector = BoxProjectedCubemapDirection (urp_ReflProbes_Rotation[probeIndex], reflectVector, rotPosWS, urp_ReflProbes_ProbePosition[probeIndex], urp_ReflProbes_BoxMin[probeIndex], urp_ReflProbes_BoxMax[probeIndex]);
306
- #else
307
- sampleVector = BoxProjectedCubemapDirection (reflectVector, rotPosWS, urp_ReflProbes_ProbePosition[probeIndex], urp_ReflProbes_BoxMin[probeIndex], urp_ReflProbes_BoxMax[probeIndex]);
308
- #endif
309
- #endif // _REFLECTION_PROBE_BOX_PROJECTION
311
+ if (_REFLECTION_PROBE_BOX_PROJECTION)
312
+ {
313
+ #if defined (REFLECTION_PROBE_ROTATION)
314
+ sampleVector = BoxProjectedCubemapDirection (urp_ReflProbes_Rotation[probeIndex], reflectVector, rotPosWS, urp_ReflProbes_ProbePosition[probeIndex], urp_ReflProbes_BoxMin[probeIndex], urp_ReflProbes_BoxMax[probeIndex]);
315
+ #else
316
+ sampleVector = BoxProjectedCubemapDirection (reflectVector, rotPosWS, urp_ReflProbes_ProbePosition[probeIndex], urp_ReflProbes_BoxMin[probeIndex], urp_ReflProbes_BoxMax[probeIndex]);
317
+ #endif
318
+ }
310
319
311
320
uint maxMip = (uint )abs (urp_ReflProbes_ProbePosition[probeIndex].w) - 1 ;
312
321
half probeMip = min (mip, maxMip);
@@ -365,13 +374,14 @@ half3 CalculateIrradianceFromReflectionProbes(half3 reflectVector, float3 positi
365
374
if (weightProbe0 > 0.01f )
366
375
{
367
376
half3 reflectVector0 = reflectVector;
368
- #ifdef _REFLECTION_PROBE_BOX_PROJECTION
369
- #if defined (REFLECTION_PROBE_ROTATION)
370
- reflectVector0 = BoxProjectedCubemapDirection (unity_SpecCube0_Rotation, reflectVector, rotPosWS0, unity_SpecCube0_ProbePosition, unity_SpecCube0_BoxMin, unity_SpecCube0_BoxMax);
371
- #else
372
- reflectVector0 = BoxProjectedCubemapDirection (reflectVector, rotPosWS0, unity_SpecCube0_ProbePosition, unity_SpecCube0_BoxMin, unity_SpecCube0_BoxMax);
373
- #endif
374
- #endif // _REFLECTION_PROBE_BOX_PROJECTION
377
+ if (_REFLECTION_PROBE_BOX_PROJECTION)
378
+ {
379
+ #if defined (REFLECTION_PROBE_ROTATION)
380
+ reflectVector0 = BoxProjectedCubemapDirection (unity_SpecCube0_Rotation, reflectVector, rotPosWS0, unity_SpecCube0_ProbePosition, unity_SpecCube0_BoxMin, unity_SpecCube0_BoxMax);
381
+ #else
382
+ reflectVector0 = BoxProjectedCubemapDirection (reflectVector, rotPosWS0, unity_SpecCube0_ProbePosition, unity_SpecCube0_BoxMin, unity_SpecCube0_BoxMax);
383
+ #endif
384
+ }
375
385
376
386
half4 encodedIrradiance = half4 (SAMPLE_TEXTURECUBE_LOD (unity_SpecCube0, samplerunity_SpecCube0, reflectVector0, mip));
377
387
@@ -382,13 +392,14 @@ half3 CalculateIrradianceFromReflectionProbes(half3 reflectVector, float3 positi
382
392
if (weightProbe1 > 0.01f )
383
393
{
384
394
half3 reflectVector1 = reflectVector;
385
- #ifdef _REFLECTION_PROBE_BOX_PROJECTION
386
- #if defined (REFLECTION_PROBE_ROTATION)
387
- reflectVector1 = BoxProjectedCubemapDirection (unity_SpecCube1_Rotation, reflectVector, rotPosWS1, unity_SpecCube1_ProbePosition, unity_SpecCube1_BoxMin, unity_SpecCube1_BoxMax);
388
- #else
389
- reflectVector1 = BoxProjectedCubemapDirection (reflectVector, rotPosWS1, unity_SpecCube1_ProbePosition, unity_SpecCube1_BoxMin, unity_SpecCube1_BoxMax);
390
- #endif
391
- #endif // _REFLECTION_PROBE_BOX_PROJECTION
395
+ if (_REFLECTION_PROBE_BOX_PROJECTION)
396
+ {
397
+ #if defined (REFLECTION_PROBE_ROTATION)
398
+ reflectVector1 = BoxProjectedCubemapDirection (unity_SpecCube1_Rotation, reflectVector, rotPosWS1, unity_SpecCube1_ProbePosition, unity_SpecCube1_BoxMin, unity_SpecCube1_BoxMax);
399
+ #else
400
+ reflectVector1 = BoxProjectedCubemapDirection (reflectVector, rotPosWS1, unity_SpecCube1_ProbePosition, unity_SpecCube1_BoxMin, unity_SpecCube1_BoxMax);
401
+ #endif
402
+ }
392
403
half4 encodedIrradiance = half4 (SAMPLE_TEXTURECUBE_LOD (unity_SpecCube1, samplerunity_SpecCube1, reflectVector1, mip));
393
404
394
405
irradiance += weightProbe1 * DecodeHDREnvironment (encodedIrradiance, unity_SpecCube1_HDR);
@@ -411,27 +422,31 @@ half3 GlossyEnvironmentReflection(half3 reflectVector, float3 positionWS, half p
411
422
half3 irradiance;
412
423
413
424
#if !defined (_ENVIRONMENTREFLECTIONS_OFF)
414
- #if defined (_REFLECTION_PROBE_BLENDING)
415
- irradiance = CalculateIrradianceFromReflectionProbes (reflectVector, positionWS, perceptualRoughness, normalizedScreenSpaceUV);
416
- #else
417
- #ifdef _REFLECTION_PROBE_BOX_PROJECTION
418
- #if defined (REFLECTION_PROBE_ROTATION)
419
- float3 probeCenterPosWS0 = unity_SpecCube0_BoxMin.xyz + (unity_SpecCube0_BoxMax.xyz - unity_SpecCube0_BoxMin.xyz) / 2 ;
420
- float3 rotPosWS0 = RotateVectorByQuat (unity_SpecCube0_Rotation, positionWS - probeCenterPosWS0) + probeCenterPosWS0;
421
- half3 rotReflectVector0 = RotateVectorByQuat (unity_SpecCube0_Rotation, reflectVector);
422
- float4 inverseRotation0 = -unity_SpecCube0_Rotation;
423
- inverseRotation0.w = -inverseRotation0.w;
424
- reflectVector = BoxProjectedCubemapDirection (rotReflectVector0, rotPosWS0, unity_SpecCube0_ProbePosition, unity_SpecCube0_BoxMin, unity_SpecCube0_BoxMax);
425
- reflectVector = RotateVectorByQuat (inverseRotation0, reflectVector);
426
- #else
427
- reflectVector = BoxProjectedCubemapDirection (reflectVector, positionWS, unity_SpecCube0_ProbePosition, unity_SpecCube0_BoxMin, unity_SpecCube0_BoxMax);
428
- #endif
429
- #endif // _REFLECTION_PROBE_BOX_PROJECTION
430
- half mip = PerceptualRoughnessToMipmapLevel (perceptualRoughness);
431
- half4 encodedIrradiance = half4 (SAMPLE_TEXTURECUBE_LOD (unity_SpecCube0, samplerunity_SpecCube0, reflectVector, mip));
432
-
433
- irradiance = DecodeHDREnvironment (encodedIrradiance, unity_SpecCube0_HDR);
434
- #endif // _REFLECTION_PROBE_BLENDING
425
+ if (_REFLECTION_PROBE_BLENDING)
426
+ {
427
+ irradiance = CalculateIrradianceFromReflectionProbes (reflectVector, positionWS, perceptualRoughness, normalizedScreenSpaceUV);
428
+ }
429
+ else
430
+ {
431
+ if (_REFLECTION_PROBE_BOX_PROJECTION)
432
+ {
433
+ #if defined (REFLECTION_PROBE_ROTATION)
434
+ float3 probeCenterPosWS0 = unity_SpecCube0_BoxMin.xyz + (unity_SpecCube0_BoxMax.xyz - unity_SpecCube0_BoxMin.xyz) / 2 ;
435
+ float3 rotPosWS0 = RotateVectorByQuat (unity_SpecCube0_Rotation, positionWS - probeCenterPosWS0) + probeCenterPosWS0;
436
+ half3 rotReflectVector0 = RotateVectorByQuat (unity_SpecCube0_Rotation, reflectVector);
437
+ float4 inverseRotation0 = -unity_SpecCube0_Rotation;
438
+ inverseRotation0.w = -inverseRotation0.w;
439
+ reflectVector = BoxProjectedCubemapDirection (rotReflectVector0, rotPosWS0, unity_SpecCube0_ProbePosition, unity_SpecCube0_BoxMin, unity_SpecCube0_BoxMax);
440
+ reflectVector = RotateVectorByQuat (inverseRotation0, reflectVector);
441
+ #else
442
+ reflectVector = BoxProjectedCubemapDirection (reflectVector, positionWS, unity_SpecCube0_ProbePosition, unity_SpecCube0_BoxMin, unity_SpecCube0_BoxMax);
443
+ #endif
444
+ }
445
+ half mip = PerceptualRoughnessToMipmapLevel (perceptualRoughness);
446
+ half4 encodedIrradiance = half4 (SAMPLE_TEXTURECUBE_LOD (unity_SpecCube0, samplerunity_SpecCube0, reflectVector, mip));
447
+
448
+ irradiance = DecodeHDREnvironment (encodedIrradiance, unity_SpecCube0_HDR);
449
+ }
435
450
#else // _ENVIRONMENTREFLECTIONS_OFF
436
451
irradiance = _GlossyEnvironmentColor.rgb;
437
452
#endif // !_ENVIRONMENTREFLECTIONS_OFF
0 commit comments