Skip to content

Commit 5229d25

Browse files
committed
eval transmitted should do 1-F
1 parent 79aea6d commit 5229d25

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,14 @@ struct SCookTorrance
184184
scalar_type clampedVdotH = cache.getVdotH();
185185
NBL_IF_CONSTEXPR(IsBSDF)
186186
clampedVdotH = hlsl::abs(clampedVdotH);
187-
return impl::__implicit_promote<spectral_type, typename fresnel_type::vector_type>::__call(_f(clampedVdotH)) * DG;
187+
188+
NBL_IF_CONSTEXPR(IsBSDF)
189+
{
190+
const scalar_type reflectance = _f(clampedVdotH)[0];
191+
return hlsl::promote<spectral_type>(hlsl::mix(reflectance, scalar_type(1.0) - reflectance, cache.isTransmission())) * DG;
192+
}
193+
else
194+
return impl::__implicit_promote<spectral_type, typename fresnel_type::vector_type>::__call(_f(clampedVdotH)) * DG;
188195
}
189196

190197
template<typename C=bool_constant<!IsBSDF> >
@@ -267,7 +274,7 @@ struct SCookTorrance
267274
return sample_type::createInvalid(); // should check if sample direction is invalid
268275

269276
cache = anisocache_type::createPartial(VdotH, LdotH, localH.z, transmitted, rcpEta);
270-
// assert(cache.isValid(fresnel.getRefractionOrientedEta())); TODO get clarification on case NdotV<0, transmitted=false (technically not TIR?)
277+
// assert(cache.isValid(fresnel.getRefractionOrientedEta()));
271278

272279
struct reflect_refract_wrapper // so we don't recalculate LdotH
273280
{
@@ -347,7 +354,7 @@ struct SCookTorrance
347354
fresnel_type _f = impl::getOrientedFresnel<fresnel_type, IsBSDF>::__call(fresnel, interaction.getNdotV());
348355

349356
const bool valid = impl::checkValid<fresnel_type, IsBSDF>::template __call<sample_type, Interaction, MicrofacetCache>(_f, _sample, interaction, cache);
350-
assert(valid);
357+
// assert(valid);
351358

352359
scalar_type G2_over_G1 = scalar_type(1.0);
353360
if (_pdf < bit_cast<scalar_type>(numeric_limits<scalar_type>::infinity))

include/nbl/builtin/hlsl/bxdf/fresnel.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ struct Dielectric
438438

439439
static T __call(NBL_CONST_REF_ARG(T) orientedEta2, const scalar_type clampedCosTheta)
440440
{
441-
const scalar_type sinTheta2 = 1.0 - clampedCosTheta * clampedCosTheta;
441+
const scalar_type sinTheta2 = scalar_type(1.0) - clampedCosTheta * clampedCosTheta;
442442

443443
// the max() clamping can handle TIR when orientedEta2<1.0
444444
const T t0 = hlsl::sqrt<T>(hlsl::max<T>(orientedEta2 - sinTheta2, hlsl::promote<T>(0.0)));
@@ -447,7 +447,7 @@ struct Dielectric
447447
const T t2 = orientedEta2 * clampedCosTheta;
448448
const T rp = (t0 - t2) / (t0 + t2);
449449

450-
return (rs * rs + rp * rp) * 0.5f;
450+
return (rs * rs + rp * rp) * scalar_type(0.5);
451451
}
452452

453453
T operator()(const scalar_type clampedCosTheta)

0 commit comments

Comments
 (0)