diff --git a/src/materials/pathtracing/glsl/directLightContribution.glsl.js b/src/materials/pathtracing/glsl/directLightContribution.glsl.js index f2d05c219..fe12f92ad 100644 --- a/src/materials/pathtracing/glsl/directLightContribution.glsl.js +++ b/src/materials/pathtracing/glsl/directLightContribution.glsl.js @@ -29,7 +29,8 @@ export const directLightContributionGLSL = /*glsl*/` // get the material pdf vec3 sampleColor; float lightMaterialPdf = bsdfResult( worldWo, lightRec.direction, surf, sampleColor ); - if ( lightMaterialPdf > 0.0 ) { + bool isValidSampleColor = all( greaterThanEqual( sampleColor, vec3( 0.0 ) ) ); + if ( lightMaterialPdf > 0.0 && isValidSampleColor ) { // weight the direct light contribution float lightPdf = lightRec.pdf / lightsDenom; @@ -71,7 +72,8 @@ export const directLightContributionGLSL = /*glsl*/` // get the material pdf vec3 sampleColor; float envMaterialPdf = bsdfResult( worldWo, envDirection, surf, sampleColor ); - if ( envMaterialPdf > 0.0 ) { + bool isValidSampleColor = all( greaterThanEqual( sampleColor, vec3( 0.0 ) ) ); + if ( envMaterialPdf > 0.0 && isValidSampleColor ) { // weight the direct light contribution envPdf /= lightsDenom;