Skip to content

Commit 5f49f11

Browse files
committed
pdf function checks for backfacing V
1 parent d438360 commit 5f49f11

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

include/nbl/builtin/hlsl/bxdf/cook_torrance_base.hlsl

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,17 @@ struct SCookTorrance
183183
}
184184
scalar_type pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction, NBL_CONST_REF_ARG(isocache_type) cache)
185185
{
186-
return __pdf<isotropic_interaction_type, isocache_type>(_sample, interaction, cache);
186+
if (IsBSDF || (_sample.getNdotL() > numeric_limits<scalar_type>::min && interaction.getNdotV() > numeric_limits<scalar_type>::min))
187+
return __pdf<isotropic_interaction_type, isocache_type>(_sample, interaction, cache);
188+
else
189+
return scalar_type(0.0);
187190
}
188191
scalar_type pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, NBL_CONST_REF_ARG(anisocache_type) cache)
189192
{
190-
return __pdf<anisotropic_interaction_type, anisocache_type>(_sample, interaction, cache);
193+
if (IsBSDF || (_sample.getNdotL() > numeric_limits<scalar_type>::min && interaction.getNdotV() > numeric_limits<scalar_type>::min))
194+
return __pdf<anisotropic_interaction_type, anisocache_type>(_sample, interaction, cache);
195+
else
196+
return scalar_type(0.0);
191197
}
192198

193199
template<class Interaction, class MicrofacetCache>
@@ -196,17 +202,14 @@ struct SCookTorrance
196202
scalar_type _pdf = __pdf<Interaction, MicrofacetCache>(_sample, interaction, cache);
197203

198204
spectral_type quo = hlsl::promote<spectral_type>(0.0);
199-
if (IsBSDF || (_sample.getNdotL() > numeric_limits<scalar_type>::min && interaction.getNdotV() > numeric_limits<scalar_type>::min))
200-
{
201-
using g2g1_query_type = typename N::g2g1_query_type;
202-
203-
g2g1_query_type gq = ndf.template createG2G1Query<sample_type, Interaction>(_sample, interaction);
204-
scalar_type G2_over_G1 = ndf.template G2_over_G1<sample_type, Interaction, MicrofacetCache>(gq, _sample, interaction, cache);
205-
NBL_IF_CONSTEXPR(IsBSDF)
206-
quo = hlsl::promote<spectral_type>(G2_over_G1);
207-
else
208-
quo = fresnel(cache.getVdotH()) * G2_over_G1;
209-
}
205+
206+
using g2g1_query_type = typename N::g2g1_query_type;
207+
g2g1_query_type gq = ndf.template createG2G1Query<sample_type, Interaction>(_sample, interaction);
208+
scalar_type G2_over_G1 = ndf.template G2_over_G1<sample_type, Interaction, MicrofacetCache>(gq, _sample, interaction, cache);
209+
NBL_IF_CONSTEXPR(IsBSDF)
210+
quo = hlsl::promote<spectral_type>(G2_over_G1);
211+
else
212+
quo = fresnel(cache.getVdotH()) * G2_over_G1;
210213

211214
return quotient_pdf_type::create(quo, _pdf);
212215
}

0 commit comments

Comments
 (0)