Przeglądaj źródła

Prevent SH to explode on extremely high HDR data.

Sebastien Vandenberghe 6 lat temu
rodzic
commit
e15e125d77

+ 7 - 0
src/Misc/HighDynamicRange/cubemapToSphericalPolynomial.ts

@@ -148,6 +148,13 @@ export class CubeMapToSphericalPolynomialTools {
                         b = Math.pow(Scalar.Clamp(b), ToLinearSpace);
                     }
 
+                    // Prevent to explode in case of really high dynamic ranges.
+                    // sh 3 would not be enough to accurately represent it.
+                    const max = 4096;
+                    r = Scalar.Clamp(r, 0, max);
+                    g = Scalar.Clamp(g, 0, max);
+                    b = Scalar.Clamp(b, 0, max);
+
                     var color = new Color3(r, g, b);
 
                     sphericalHarmonics.addLight(worldDirection, color, deltaSolidAngle);