Browse Source

Prevent SH to explode on extremely high HDR data.

Sebastien Vandenberghe 6 năm trước cách đây
mục cha
commit
e15e125d77
1 tập tin đã thay đổi với 7 bổ sung0 xóa
  1. 7 0
      src/Misc/HighDynamicRange/cubemapToSphericalPolynomial.ts

+ 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);