Skip to content

Commit b53fa1b

Browse files
committed
cook torrance bsdf can use spectral fresnel, uses interaction.getPrefixThroughputWeights
1 parent aebfecf commit b53fa1b

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ struct SCookTorrance
167167

168168
NBL_IF_CONSTEXPR(IsBSDF)
169169
{
170-
const scalar_type reflectance = _f(clampedVdotH)[0];
171-
return hlsl::promote<spectral_type>(hlsl::mix(reflectance, scalar_type(1.0) - reflectance, cache.isTransmission())) * DG;
170+
const spectral_type reflectance = impl::__implicit_promote<spectral_type, typename fresnel_type::vector_type>::__call(_f(clampedVdotH));
171+
return hlsl::mix(reflectance, hlsl::promote<spectral_type>(1.0) - reflectance, cache.isTransmission()) * DG;
172172
}
173173
else
174174
return impl::__implicit_promote<spectral_type, typename fresnel_type::vector_type>::__call(_f(clampedVdotH)) * DG;
@@ -271,7 +271,9 @@ struct SCookTorrance
271271
{
272272
assert(NdotV*VdotH >= scalar_type(0.0));
273273
}
274-
const scalar_type reflectance = _f(hlsl::abs(VdotH))[0];
274+
275+
spectral_type prefixThroughputWeights = interaction.getPrefixThroughputWeights();
276+
const scalar_type reflectance = hlsl::dot(impl::__implicit_promote<spectral_type, typename fresnel_type::vector_type>::__call(_f(hlsl::abs(VdotH))), prefixThroughputWeights);
275277

276278
scalar_type rcpChoiceProb;
277279
scalar_type z = u.z;
@@ -312,7 +314,8 @@ struct SCookTorrance
312314

313315
NBL_IF_CONSTEXPR(IsBSDF)
314316
{
315-
const scalar_type reflectance = _f(hlsl::abs(cache.getVdotH()))[0];
317+
spectral_type prefixThroughputWeights = interaction.getPrefixThroughputWeights();
318+
const scalar_type reflectance = hlsl::dot(impl::__implicit_promote<spectral_type, typename fresnel_type::vector_type>::__call(_f(hlsl::abs(cache.getVdotH()))), prefixThroughputWeights);
316319
return hlsl::mix(reflectance, scalar_type(1.0) - reflectance, cache.isTransmission()) * DG1.projectedLightMeasure;
317320
}
318321
else
@@ -359,7 +362,13 @@ struct SCookTorrance
359362

360363
spectral_type quo;
361364
NBL_IF_CONSTEXPR(IsBSDF)
362-
quo = hlsl::promote<spectral_type>(G2_over_G1);
365+
{
366+
spectral_type prefixThroughputWeights = interaction.getPrefixThroughputWeights();
367+
spectral_type reflectance = impl::__implicit_promote<spectral_type, typename fresnel_type::vector_type>::__call(_f(hlsl::abs(cache.getVdotH())));
368+
const scalar_type scaled_reflectance = hlsl::dot(reflectance, prefixThroughputWeights);
369+
quo = hlsl::mix(reflectance / scaled_reflectance,
370+
(hlsl::promote<spectral_type>(1.0) - reflectance) / (scalar_type(1.0) - scaled_reflectance), cache.isTransmission()) * G2_over_G1;
371+
}
363372
else
364373
{
365374
const scalar_type VdotH = cache.getVdotH();

include/nbl/builtin/hlsl/math/functions.hlsl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ struct lp_norm<T,0,false NBL_PARTIAL_REQ_BOT(concepts::FloatingPointLikeVectoria
3333
{
3434
array_get<T, scalar_type> getter;
3535

36-
scalar_type retval = abs<T>(getter(v, 0));
37-
for (int i = 1; i < extent<T>::value; i++)
38-
retval = max<T>(abs<T>(getter(v, i)),retval);
36+
scalar_type retval = abs<scalar_type>(getter(v, 0));
37+
for (int i = 1; i < vector_traits<T>::Dimension; i++)
38+
retval = max<scalar_type>(abs<scalar_type>(getter(v, i)),retval);
3939
return retval;
4040
}
4141
};
@@ -49,9 +49,9 @@ struct lp_norm<T,1,true NBL_PARTIAL_REQ_BOT(concepts::FloatingPointLikeVectorial
4949
{
5050
array_get<T, scalar_type> getter;
5151

52-
scalar_type retval = abs<T>(getter(v, 0));
53-
for (int i = 1; i < extent<T>::value; i++)
54-
retval += abs<T>(getter(v, i));
52+
scalar_type retval = abs<scalar_type>(getter(v, 0));
53+
for (int i = 1; i < vector_traits<T>::Dimension; i++)
54+
retval += abs<scalar_type>(getter(v, i));
5555
return retval;
5656
}
5757

0 commit comments

Comments
 (0)