Skip to content

Commit 434234c

Browse files
committed
derive trait from cook torrance base
1 parent dc8b5bc commit 434234c

File tree

7 files changed

+24
-90
lines changed

7 files changed

+24
-90
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ struct SCookTorrance
133133
static scalar_type __getScaledReflectance(NBL_CONST_REF_ARG(fresnel_type) orientedFresnel, NBL_CONST_REF_ARG(Interaction) interaction, scalar_type clampedVdotH)
134134
{
135135
spectral_type throughputWeights = interaction.getLuminosityContributionHint();
136-
return hlsl::dot<spectral_type>(impl::__implicit_promote<spectral_type, typename fresnel_type::vector_type>::__call(orientedFresnel(clampedVdotH)), throughputWeights);
136+
return hlsl::dot<spectral_type>(orientedFresnel(clampedVdotH), throughputWeights);
137137
}
138138
template<class Interaction=conditional_t<IsAnisotropic,anisotropic_interaction_type,isotropic_interaction_type>,
139139
typename C=bool_constant<fresnel_type::ReturnsMonochrome> NBL_FUNC_REQUIRES(C::value && fresnel_type::ReturnsMonochrome)
@@ -142,7 +142,7 @@ struct SCookTorrance
142142
return orientedFresnel(clampedVdotH)[0];
143143
}
144144

145-
bool __dotIsUnity(const vector3_type a, const vector3_type b, const scalar_type value)
145+
bool __dotIsValue(const vector3_type a, const vector3_type b, const scalar_type value)
146146
{
147147
const scalar_type ab = hlsl::dot(a, b);
148148
return hlsl::max(ab, value / ab) <= scalar_type(value + 1e-3);
@@ -209,11 +209,11 @@ struct SCookTorrance
209209
ray_dir_info_type V = interaction.getV();
210210
const matrix3x3_type fromTangent = interaction.getFromTangentSpace();
211211
// tangent frame orthonormality
212-
assert(__dotIsUnity(fromTangent[0],fromTangent[1],0.0));
213-
assert(__dotIsUnity(fromTangent[1],fromTangent[2],0.0));
214-
assert(__dotIsUnity(fromTangent[2],fromTangent[0],0.0));
212+
assert(__dotIsValue(fromTangent[0],fromTangent[1],0.0));
213+
assert(__dotIsValue(fromTangent[1],fromTangent[2],0.0));
214+
assert(__dotIsValue(fromTangent[2],fromTangent[0],0.0));
215215
// NDF sampling produced a unit length direction
216-
assert(__dotIsUnity(localH,localH,1.0));
216+
assert(__dotIsValue(localH,localH,1.0));
217217
const vector3_type H = hlsl::mul(interaction.getFromTangentSpace(), localH);
218218
Refract<scalar_type> r = Refract<scalar_type>::create(V.getDirection(), H);
219219

@@ -409,6 +409,18 @@ struct SCookTorrance
409409
fresnel_type fresnel; // always front-facing
410410
};
411411

412+
413+
template<class Config, class N, class F>
414+
struct traits<SCookTorrance<Config,N,F> >
415+
{
416+
using __type = SCookTorrance<Config,N,F>;
417+
418+
NBL_CONSTEXPR_STATIC_INLINE BxDFType type = conditional_value<__type::IsBSDF, BxDFType, BxDFType::BT_BSDF, BxDFType::BT_BRDF>::value;
419+
NBL_CONSTEXPR_STATIC_INLINE bool IsMicrofacet = true;
420+
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotV = !__type::IsBSDF;
421+
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotL = !__type::IsBSDF;
422+
};
423+
412424
}
413425
}
414426
}

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,7 @@ using SBeckmannAnisotropic = SCookTorrance<Config, ndf::Beckmann<typename Config
2727

2828
}
2929

30-
template<typename C>
31-
struct traits<bxdf::reflection::SBeckmannIsotropic<C> >
32-
{
33-
NBL_CONSTEXPR_STATIC_INLINE BxDFType type = BT_BRDF;
34-
NBL_CONSTEXPR_STATIC_INLINE bool IsMicrofacet = true;
35-
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotV = true;
36-
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotL = true;
37-
};
38-
39-
template<typename C>
40-
struct traits<bxdf::reflection::SBeckmannAnisotropic<C> >
41-
{
42-
NBL_CONSTEXPR_STATIC_INLINE BxDFType type = BT_BRDF;
43-
NBL_CONSTEXPR_STATIC_INLINE bool IsMicrofacet = true;
44-
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotV = true;
45-
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotL = true;
46-
};
30+
// inherit trait from cook torrance base
4731

4832
}
4933
}

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,7 @@ using SGGXAnisotropic = SCookTorrance<Config, ndf::GGX<typename Config::scalar_t
2727

2828
}
2929

30-
template<typename C>
31-
struct traits<bxdf::reflection::SGGXIsotropic<C> >
32-
{
33-
NBL_CONSTEXPR_STATIC_INLINE BxDFType type = BT_BRDF;
34-
NBL_CONSTEXPR_STATIC_INLINE bool IsMicrofacet = true;
35-
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotV = true;
36-
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotL = true;
37-
};
38-
39-
template<typename C>
40-
struct traits<bxdf::reflection::SGGXAnisotropic<C> >
41-
{
42-
NBL_CONSTEXPR_STATIC_INLINE BxDFType type = BT_BRDF;
43-
NBL_CONSTEXPR_STATIC_INLINE bool IsMicrofacet = true;
44-
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotV = true;
45-
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotL = true;
46-
};
30+
// inherit trait from cook torrance base
4731

4832
}
4933
}

include/nbl/builtin/hlsl/bxdf/reflection/iridescent.hlsl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,7 @@ using SIridescent = SCookTorrance<Config, ndf::GGX<typename Config::scalar_type,
2020

2121
}
2222

23-
template<typename C>
24-
struct traits<bxdf::reflection::SIridescent<C> >
25-
{
26-
NBL_CONSTEXPR_STATIC_INLINE BxDFType type = BT_BRDF;
27-
NBL_CONSTEXPR_STATIC_INLINE bool IsMicrofacet = true;
28-
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotV = true;
29-
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotL = true;
30-
};
23+
// inherit trait from cook torrance base
3124

3225
}
3326
}

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,7 @@ using SBeckmannDielectricAnisotropic = SCookTorrance<Config, ndf::Beckmann<typen
2727

2828
}
2929

30-
template<typename C>
31-
struct traits<bxdf::transmission::SBeckmannDielectricIsotropic<C> >
32-
{
33-
NBL_CONSTEXPR_STATIC_INLINE BxDFType type = BT_BSDF;
34-
NBL_CONSTEXPR_STATIC_INLINE bool IsMicrofacet = true;
35-
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotV = true;
36-
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotL = true;
37-
};
38-
39-
template<typename C>
40-
struct traits<bxdf::transmission::SBeckmannDielectricAnisotropic<C> >
41-
{
42-
NBL_CONSTEXPR_STATIC_INLINE BxDFType type = BT_BSDF;
43-
NBL_CONSTEXPR_STATIC_INLINE bool IsMicrofacet = true;
44-
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotV = true;
45-
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotL = true;
46-
};
30+
// inherit trait from cook torrance base
4731

4832
}
4933
}

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,7 @@ using SGGXDielectricAnisotropic = SCookTorrance<Config, ndf::GGX<typename Config
2727

2828
}
2929

30-
template<typename C>
31-
struct traits<bxdf::transmission::SGGXDielectricIsotropic<C> >
32-
{
33-
NBL_CONSTEXPR_STATIC_INLINE BxDFType type = BT_BSDF;
34-
NBL_CONSTEXPR_STATIC_INLINE bool IsMicrofacet = true;
35-
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotV = true;
36-
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotL = true;
37-
};
38-
39-
template<typename C>
40-
struct traits<bxdf::transmission::SGGXDielectricAnisotropic<C> >
41-
{
42-
NBL_CONSTEXPR_STATIC_INLINE BxDFType type = BT_BSDF;
43-
NBL_CONSTEXPR_STATIC_INLINE bool IsMicrofacet = true;
44-
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotV = true;
45-
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotL = true;
46-
};
30+
// inherit trait from cook torrance base
4731

4832
}
4933
}

include/nbl/builtin/hlsl/bxdf/transmission/iridescent.hlsl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,7 @@ using SIridescent = SCookTorrance<Config, ndf::GGX<typename Config::scalar_type,
2020

2121
}
2222

23-
template<typename C>
24-
struct traits<bxdf::transmission::SIridescent<C> >
25-
{
26-
NBL_CONSTEXPR_STATIC_INLINE BxDFType type = BT_BSDF;
27-
NBL_CONSTEXPR_STATIC_INLINE bool IsMicrofacet = true;
28-
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotV = true;
29-
NBL_CONSTEXPR_STATIC_INLINE bool clampNdotL = true;
30-
};
23+
// inherit trait from cook torrance base
3124

3225
}
3326
}

0 commit comments

Comments
 (0)