|
582 | 582 | finalLightingScale = max(finalLightingScale, surface.brightestNonGlobalLightStrength);
|
583 | 583 | finalLightingScale = max(finalLightingScale, minVertLighting); //essentially just the vertColors.r (aka indoor light exposure) multiplied by the time of day scale.
|
584 | 584 |
|
585 |
| - |
586 |
| - #if NB_PROBES > 0 |
587 |
| - float probeNdfSum = 0.0; |
588 |
| - float invProbeNdfSum = 0.0; |
589 |
| - |
590 |
| - #for i=1..4 ( #if NB_PROBES >= $i $0 #endif ) |
591 |
| - vec3 probeColor$i; |
592 |
| - float probeNdf$i = renderProbe( |
| 585 | + #if NB_PROBES >= 1 |
| 586 | + vec3 color1 = vec3(0.0); |
| 587 | + vec3 color2 = vec3(0.0); |
| 588 | + vec3 color3 = vec3(0.0); |
| 589 | + float weight1 = 1.0; |
| 590 | + float weight2 = 0.0; |
| 591 | + float weight3 = 0.0; |
| 592 | + |
| 593 | + float ndf = renderProbe( |
| 594 | + surface.viewDir, |
| 595 | + surface.position, |
| 596 | + surface.normal, |
| 597 | + surface.geometryNormal, |
| 598 | + surface.roughness, |
| 599 | + vec4(surface.diffuseColor, 1.0), |
| 600 | + vec4(surface.specularColor, 1.0), |
| 601 | + surface.NdotV, |
| 602 | + surface.ao, |
| 603 | + g_LightProbeData, g_ShCoeffs, g_PrefEnvMap, color1); |
| 604 | + #if NB_PROBES >= 2 |
| 605 | + float ndf2 = renderProbe( |
593 | 606 | surface.viewDir,
|
594 | 607 | surface.position,
|
595 | 608 | surface.normal,
|
596 | 609 | surface.geometryNormal,
|
597 | 610 | surface.roughness,
|
598 |
| - vec4(surface.diffuseColor,1.0), |
599 |
| - vec4(surface.specularColor,1.0), |
| 611 | + vec4(surface.diffuseColor, 1.0), |
| 612 | + vec4(surface.specularColor, 1.0), |
600 | 613 | surface.NdotV,
|
601 | 614 | surface.ao,
|
602 |
| - #if $i == 1 |
603 |
| - g_LightProbeData, |
604 |
| - #else |
605 |
| - g_LightProbeData$i, |
606 |
| - #endif |
607 |
| - g_ShCoeffs, |
608 |
| - g_PrefEnvMap, |
609 |
| - probeColor$i |
610 |
| - ); |
611 |
| - float probeInvNdf$i = max(1.0 - probeNdf$i,0.0); |
612 |
| - probeNdfSum += probeNdf$i; |
613 |
| - invProbeNdfSum += probeInvNdf$i; |
614 |
| - #ifdef USE_AMBIENT_LIGHT |
615 |
| - probeColor$i.rgb *= g_AmbientLightColor.rgb; |
| 615 | + g_LightProbeData2, |
| 616 | + g_ShCoeffs2, |
| 617 | + g_PrefEnvMap2, |
| 618 | + color2); |
| 619 | + #endif |
| 620 | + #if NB_PROBES == 3 |
| 621 | + float ndf3 = renderProbe( |
| 622 | + surface.viewDir, |
| 623 | + surface.position, |
| 624 | + surface.normal, |
| 625 | + surface.geometryNormal, |
| 626 | + surface.roughness, |
| 627 | + vec4(surface.diffuseColor, 1.0), |
| 628 | + vec4(surface.specularColor, 1.0), |
| 629 | + surface.NdotV, |
| 630 | + surface.ao, |
| 631 | + g_LightProbeData3, |
| 632 | + g_ShCoeffs3, |
| 633 | + g_PrefEnvMap3, |
| 634 | + color3); |
| 635 | + #endif |
| 636 | + |
| 637 | + #if NB_PROBES >= 2 |
| 638 | + float invNdf = max(1.0 - ndf,0.0); |
| 639 | + float invNdf2 = max(1.0 - ndf2,0.0); |
| 640 | + float sumNdf = ndf + ndf2; |
| 641 | + float sumInvNdf = invNdf + invNdf2; |
| 642 | + #if NB_PROBES == 3 |
| 643 | + float invNdf3 = max(1.0 - ndf3,0.0); |
| 644 | + sumNdf += ndf3; |
| 645 | + sumInvNdf += invNdf3; |
| 646 | + weight3 = ((1.0 - (ndf3 / sumNdf)) / (NB_PROBES - 1)) * (invNdf3 / sumInvNdf); |
616 | 647 | #endif
|
617 |
| - probeColor$i.rgb *= finalLightingScale; |
618 |
| - #endfor |
619 |
| - |
620 |
| - #if NB_PROBES > 1 |
621 |
| - float probeWeightSum = 0.0; |
622 |
| - #for i=1..4 ( #if NB_PROBES >= $i $0 #endif ) |
623 |
| - float probeWeight$i = ((1.0 - (probeNdf$i / probeNdfSum)) / (NB_PROBES - 1)) * ( probeInvNdf$i / invProbeNdfSum); |
624 |
| - probeWeightSum += probeWeight$i; |
625 |
| - #endfor |
626 |
| - |
627 |
| - #for i=1..4 ( #if NB_PROBES >= $i $0 #endif ) |
628 |
| - surface.envLightContribution.rgb += probeColor$i * clamp( probeWeight$i / probeWeightSum, 0., 1.); |
629 |
| - #endfor |
630 |
| - #else |
631 |
| - surface.envLightContribution.rgb += probeColor1; |
| 648 | + |
| 649 | + weight1 = ((1.0 - (ndf / sumNdf)) / (NB_PROBES - 1)) * (invNdf / sumInvNdf); |
| 650 | + weight2 = ((1.0 - (ndf2 / sumNdf)) / (NB_PROBES - 1)) * (invNdf2 / sumInvNdf); |
| 651 | + |
| 652 | + float weightSum = weight1 + weight2 + weight3; |
| 653 | + |
| 654 | + weight1 /= weightSum; |
| 655 | + weight2 /= weightSum; |
| 656 | + weight3 /= weightSum; |
| 657 | + #endif |
| 658 | + |
| 659 | + #ifdef USE_AMBIENT_LIGHT |
| 660 | + color1.rgb *= g_AmbientLightColor.rgb; |
| 661 | + color2.rgb *= g_AmbientLightColor.rgb; |
| 662 | + color3.rgb *= g_AmbientLightColor.rgb; |
632 | 663 | #endif
|
| 664 | + |
| 665 | + color1.rgb *= finalLightingScale; |
| 666 | + color2.rgb *= finalLightingScale; |
| 667 | + color3.rgb *= finalLightingScale; |
| 668 | + |
| 669 | + surface.envLightContribution.rgb += color1 * clamp(weight1,0.0,1.0) + color2 * clamp(weight2,0.0,1.0) + color3 * clamp(weight3,0.0,1.0); |
| 670 | + |
633 | 671 | #endif
|
634 | 672 | }
|
635 | 673 | #endif
|
|
0 commit comments