Skip to content

Commit 87988c3

Browse files
authored
Merge pull request #539 from gkjohnson/fixes
Fixes
2 parents 50bf681 + 73f83a1 commit 87988c3

File tree

7 files changed

+23
-13
lines changed

7 files changed

+23
-13
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"rollup": "^2.70.0",
4343
"simple-git": "^3.10.0",
4444
"three": "^0.160.0",
45-
"three-mesh-bvh": "0.7.2",
45+
"three-mesh-bvh": "0.7.3",
4646
"yargs": "^17.5.1"
4747
},
4848
"peerDependencies": {

src/materials/pathtracing/PhysicalPathTracingMaterial.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,10 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
309309
// inverse environment rotation
310310
envRotation3x3 = mat3( environmentRotation );
311311
invEnvRotation3x3 = inverse( envRotation3x3 );
312-
lightsDenom = environmentIntensity == 0.0 && lights.count != 0u ? float( lights.count ) : float( lights.count + 1u );
312+
lightsDenom =
313+
( environmentIntensity == 0.0 || envMapInfo.totalSum == 0.0 ) && lights.count != 0u ?
314+
float( lights.count ) :
315+
float( lights.count + 1u );
313316
314317
// final color
315318
gl_FragColor = vec4( 0, 0, 0, 1 );

src/materials/pathtracing/glsl/directLightContribution.glsl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const directLightContributionGLSL = /*glsl*/`
4343
4444
}
4545
46-
} else {
46+
} else if ( envMapInfo.totalSum != 0.0 && environmentIntensity != 0.0 ) {
4747
4848
// find a sample in the environment map to include in the contribution
4949
vec3 envColor, envDirection;

src/shader/sampling/equirectSampling.glsl.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,17 @@ export const equirectSamplingGLSL = /* glsl */`
2626
// samples the color given env map with CDF and returns the pdf of the direction
2727
float sampleEquirect( vec3 direction, inout vec3 color ) {
2828
29+
float totalSum = envMapInfo.totalSum;
30+
if ( totalSum == 0.0 ) {
31+
32+
color = vec3( 0.0 );
33+
return 1.0;
34+
35+
}
36+
2937
vec2 uv = equirectDirectionToUv( direction );
3038
color = texture2D( envMapInfo.map, uv ).rgb;
3139
32-
float totalSum = envMapInfo.totalSum;
3340
float lum = luminance( color );
3441
ivec2 resolution = textureSize( envMapInfo.map, 0 );
3542
float pdf = lum / totalSum;

src/uniforms/LightsInfoUniformStruct.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class LightsInfoUniformStruct {
5858
let index = 0;
5959

6060
// initialize to 0
61-
for ( let p = 0; p < LIGHT_PIXELS; p ++ ) {
61+
for ( let p = 0; p < LIGHT_PIXELS * 4; p ++ ) {
6262

6363
floatArray[ baseIndex + p ] = 0;
6464

src/uniforms/MaterialsTexture.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export class MaterialsTexture extends DataTexture {
186186

187187
let index = 0;
188188
const pixelCount = materials.length * MATERIAL_PIXELS;
189-
const dimension = Math.ceil( Math.sqrt( pixelCount ) );
189+
const dimension = Math.ceil( Math.sqrt( pixelCount ) ) || 1;
190190
const { threeCompatibilityTransforms, image, features } = this;
191191

192192
// get the list of textures with unique sources

0 commit comments

Comments
 (0)