three-gpu-pathtracer 0.0.18 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1995,7 +1995,7 @@ class MaterialsTexture extends DataTexture {
1995
1995
 
1996
1996
  let index = 0;
1997
1997
  const pixelCount = materials.length * MATERIAL_PIXELS;
1998
- const dimension = Math.ceil( Math.sqrt( pixelCount ) );
1998
+ const dimension = Math.ceil( Math.sqrt( pixelCount ) ) || 1;
1999
1999
  const { threeCompatibilityTransforms, image, features } = this;
2000
2000
 
2001
2001
  // get the list of textures with unique sources
@@ -2857,7 +2857,7 @@ class LightsInfoUniformStruct {
2857
2857
  let index = 0;
2858
2858
 
2859
2859
  // initialize to 0
2860
- for ( let p = 0; p < LIGHT_PIXELS; p ++ ) {
2860
+ for ( let p = 0; p < LIGHT_PIXELS * 4; p ++ ) {
2861
2861
 
2862
2862
  floatArray[ baseIndex + p ] = 0;
2863
2863
 
@@ -5588,10 +5588,17 @@ const equirectSamplingGLSL = /* glsl */`
5588
5588
  // samples the color given env map with CDF and returns the pdf of the direction
5589
5589
  float sampleEquirect( vec3 direction, inout vec3 color ) {
5590
5590
 
5591
+ float totalSum = envMapInfo.totalSum;
5592
+ if ( totalSum == 0.0 ) {
5593
+
5594
+ color = vec3( 0.0 );
5595
+ return 1.0;
5596
+
5597
+ }
5598
+
5591
5599
  vec2 uv = equirectDirectionToUv( direction );
5592
5600
  color = texture2D( envMapInfo.map, uv ).rgb;
5593
5601
 
5594
- float totalSum = envMapInfo.totalSum;
5595
5602
  float lum = luminance( color );
5596
5603
  ivec2 resolution = textureSize( envMapInfo.map, 0 );
5597
5604
  float pdf = lum / totalSum;
@@ -6995,7 +7002,7 @@ const directLightContributionGLSL = /*glsl*/`
6995
7002
 
6996
7003
  }
6997
7004
 
6998
- } else {
7005
+ } else if ( envMapInfo.totalSum != 0.0 && environmentIntensity != 0.0 ) {
6999
7006
 
7000
7007
  // find a sample in the environment map to include in the contribution
7001
7008
  vec3 envColor, envDirection;
@@ -7966,7 +7973,10 @@ class PhysicalPathTracingMaterial extends MaterialBase {
7966
7973
  // inverse environment rotation
7967
7974
  envRotation3x3 = mat3( environmentRotation );
7968
7975
  invEnvRotation3x3 = inverse( envRotation3x3 );
7969
- lightsDenom = environmentIntensity == 0.0 && lights.count != 0u ? float( lights.count ) : float( lights.count + 1u );
7976
+ lightsDenom =
7977
+ ( environmentIntensity == 0.0 || envMapInfo.totalSum == 0.0 ) && lights.count != 0u ?
7978
+ float( lights.count ) :
7979
+ float( lights.count + 1u );
7970
7980
 
7971
7981
  // final color
7972
7982
  gl_FragColor = vec4( 0, 0, 0, 1 );