Skip to content

Commit e1d47d1

Browse files
handle a NaN issue
1 parent 4a0d652 commit e1d47d1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

examples_tests/42.FragmentShaderPathTracer/litByTriangle.frag

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ vec3 irr_glsl_sampling_generateSphericalTriangleSample(out float rcpPdf, in mat3
208208

209209
vec4 irr_glsl_sampling_computeBilinearPatchForProjSphericalTriangle(in mat3 sphericalVertices, in vec3 receiverNormal, in bool isBSDF)
210210
{
211-
// I don't see any problems with this being 0
211+
// a positive would prevent us from a scenario where `irr_glsl_sampling_rcpProbBilinearSample` will return NAN
212212
const float minimumProjSolidAngle = 0.0;
213213

214214
vec3 bxdfPdfAtVertex = transpose(sphericalVertices)*receiverNormal;
@@ -292,7 +292,8 @@ vec3 irr_glsl_light_deferred_eval_and_prob(out float pdf, in vec3 origin, in vec
292292
#elif TRIANGLE_METHOD==2
293293
float rcpProb = irr_glsl_sampling_rcpProbProjectedSphericalTriangleSample(sphericalVertices,normalAtOrigin,wasBSDFAtOrigin,interaction.isotropic.V.dir);
294294
#endif
295-
pdf /= isnan(rcpProb) ? 0.0:rcpProb;
295+
// if `rcpProb` is NAN or INF then the triangle's projectedSolidAngle was close to 0.0
296+
pdf = rcpProb<=FLT_MAX ? (pdf/rcpProb):0.0;
296297
#endif
297298
return Light_getRadiance(light);
298299
}

0 commit comments

Comments
 (0)