Skip to content

Commit dee1b61

Browse files
committed
init ndf quants, minor cook torrance fixes
1 parent 8a71f40 commit dee1b61

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,10 @@ struct SCookTorrance
191191
}
192192

193193
sample_type __generate_common(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector3_type localH,
194-
const scalar_type NdotV, const scalar_type VdotH, bool transmitted,
194+
const scalar_type NdotV, const scalar_type VdotH, const scalar_type LdotH, bool transmitted,
195195
NBL_CONST_REF_ARG(fresnel::OrientedEtaRcps<monochrome_type>) rcpEta,
196-
NBL_REF_ARG(anisocache_type) cache, NBL_REF_ARG(bool) valid)
196+
NBL_REF_ARG(bool) valid)
197197
{
198-
const scalar_type LdotH = hlsl::mix(VdotH, ieee754::copySign(hlsl::sqrt(rcpEta.value2[0]*VdotH*VdotH + scalar_type(1.0) - rcpEta.value2[0]), -VdotH), transmitted);
199-
200198
// fail if samples have invalid paths
201199
const scalar_type NdotL = hlsl::mix(scalar_type(2.0) * VdotH * localH.z - NdotV,
202200
localH.z * (VdotH * rcpEta.value[0] + LdotH) - NdotV * rcpEta.value[0], transmitted);
@@ -208,8 +206,6 @@ struct SCookTorrance
208206
return sample_type::createInvalid(); // should check if sample direction is invalid
209207
}
210208

211-
cache = anisocache_type::createPartial(VdotH, LdotH, localH.z, transmitted, rcpEta);
212-
213209
ray_dir_info_type V = interaction.getV();
214210
const matrix3x3_type fromTangent = interaction.getFromTangentSpace();
215211
// tangent frame orthonormality
@@ -268,7 +264,7 @@ struct SCookTorrance
268264

269265
fresnel::OrientedEtaRcps<monochrome_type> dummy;
270266
bool valid;
271-
sample_type s = __generate_common(interaction, localH, NdotV, VdotH, false, dummy, cache, valid);
267+
sample_type s = __generate_common(interaction, localH, NdotV, VdotH, VdotH, false, dummy, valid);
272268
if (valid)
273269
cache = anisocache_type::createForReflection(localV, localH);
274270
return s;
@@ -304,10 +300,12 @@ struct SCookTorrance
304300
scalar_type z = u.z;
305301
bool transmitted = math::partitionRandVariable(reflectance, z, rcpChoiceProb);
306302

303+
const scalar_type LdotH = hlsl::mix(VdotH, ieee754::copySign(hlsl::sqrt(rcpEta.value2[0]*VdotH*VdotH + scalar_type(1.0) - rcpEta.value2[0]), -VdotH), transmitted);
307304
bool valid;
308-
sample_type s = __generate_common(interaction, localH, NdotV, VdotH, transmitted, rcpEta, cache, valid);
305+
sample_type s = __generate_common(interaction, localH, NdotV, VdotH, LdotH, transmitted, rcpEta, valid);
309306
if (valid)
310307
{
308+
cache = anisocache_type::createPartial(VdotH, LdotH, localH.z, transmitted, rcpEta);
311309
assert(cache.isValid(fresnel::OrientedEtas<monochrome_type>::create(scalar_type(1.0), hlsl::promote<monochrome_type>(_f.getRefractionOrientedEta()))));
312310
const vector3_type T = interaction.getT();
313311
const vector3_type B = interaction.getB();
@@ -387,10 +385,15 @@ struct SCookTorrance
387385
spectral_type quo;
388386
NBL_IF_CONSTEXPR(IsBSDF)
389387
{
390-
const scalar_type scaled_reflectance = __getScaledReflectance(_f, interaction, hlsl::abs(cache.getVdotH()));
391-
spectral_type reflectance = impl::__implicit_promote<spectral_type, typename fresnel_type::vector_type>::__call(_f(hlsl::abs(cache.getVdotH())));
392-
quo = hlsl::mix(reflectance / scaled_reflectance,
393-
(hlsl::promote<spectral_type>(1.0) - reflectance) / (scalar_type(1.0) - scaled_reflectance), cache.isTransmission()) * G2_over_G1;
388+
NBL_IF_CONSTEXPR(fresnel_type::ReturnsMonochrome)
389+
quo = hlsl::promote<spectral_type>(G2_over_G1);
390+
else
391+
{
392+
const scalar_type scaled_reflectance = __getScaledReflectance(_f, interaction, hlsl::abs(cache.getVdotH()));
393+
spectral_type reflectance = impl::__implicit_promote<spectral_type, typename fresnel_type::vector_type>::__call(_f(hlsl::abs(cache.getVdotH())));
394+
quo = hlsl::mix(reflectance / scaled_reflectance,
395+
(hlsl::promote<spectral_type>(1.0) - reflectance) / (scalar_type(1.0) - scaled_reflectance), cache.isTransmission()) * G2_over_G1;
396+
}
394397
}
395398
else
396399
{

include/nbl/builtin/hlsl/bxdf/ndf/beckmann.hlsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ struct Beckmann
339339
if (isInfinity)
340340
{
341341
quant_type dmq;
342+
dmq.microfacetMeasure = scalar_type(0.0);
343+
dmq.projectedLightMeasure = scalar_type(0.0);
342344
return dmq;
343345
}
344346
scalar_type dg1 = D / (scalar_type(1.0) + query.getLambdaV());

include/nbl/builtin/hlsl/bxdf/ndf/ggx.hlsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,11 @@ struct GGX
278278
isInfinity = hlsl::isinf(D);
279279
quant_type dmq;
280280
if (isInfinity)
281+
{
282+
dmq.microfacetMeasure = scalar_type(0.0);
283+
dmq.projectedLightMeasure = scalar_type(0.0);
281284
return dmq;
285+
}
282286

283287
scalar_type dg1_over_2NdotV = D * query.getG1over2NdotV();
284288
dmq.microfacetMeasure = scalar_type(2.0) * interaction.getNdotV(BxDFClampMode::BCM_ABS) * dg1_over_2NdotV;

0 commit comments

Comments
 (0)