Skip to content

Commit 8ecf6ef

Browse files
committed
Fix divide-by-zero in BSDF computation
1 parent b35c56f commit 8ecf6ef

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

Source/ZetaRenderPass/Common/BSDF.hlsli

+1-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ namespace BSDF
421421
{
422422
float denom = mad(whdotwo, 1 / eta, whdotwi);
423423
denom *= denom;
424-
float dwh_dwi = whdotwi / denom;
424+
float dwh_dwi = denom > 0 ? whdotwi / denom : 0;
425425

426426
return dwh_dwi;
427427
}

Source/ZetaRenderPass/Common/BSDFSampling.hlsli

+2-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ namespace BSDF
142142
// to 0 and the path-tracing loop is terminated.
143143

144144
ret.f = BSDF::DielectricBaseSpecularTr(surface, eval.Fr_g.x) * func_t;
145-
ret.bsdfOverPdf = ret.f / ret.pdf;
145+
// if code reached here, pdf should > 0 unless dwh_dwi = 0
146+
ret.bsdfOverPdf = ret.pdf > 0 ? ret.f / ret.pdf : 0;
146147
ret.wi = wi_t;
147148
ret.lobe = BSDF::LOBE::GLOSSY_T;
148149
}

0 commit comments

Comments
 (0)