Skip to content

Commit 444b656

Browse files
committed
removed passthrough funcs, template directly on required interaction/cache with defaults
1 parent b55bdef commit 444b656

File tree

4 files changed

+26
-46
lines changed

4 files changed

+26
-46
lines changed

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

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ struct SCookTorrance
133133

134134
NBL_CONSTEXPR_STATIC_INLINE bool IsAnisotropic = ndf_type::IsAnisotropic;
135135
NBL_CONSTEXPR_STATIC_INLINE bool IsBSDF = ndf_type::SupportedPaths != ndf::MTT_REFLECT;
136+
NBL_HLSL_BXDF_ANISOTROPIC_COND_DECLS(IsAnisotropic);
136137

137138
template<class Interaction, class MicrofacetCache>
138139
static bool __checkValid(NBL_CONST_REF_ARG(fresnel_type) f, NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(Interaction) interaction, NBL_CONST_REF_ARG(MicrofacetCache) cache)
@@ -143,8 +144,10 @@ struct SCookTorrance
143144
return _sample.getNdotL() > numeric_limits<scalar_type>::min && interaction.getNdotV() > numeric_limits<scalar_type>::min;
144145
}
145146

146-
template<class Interaction, class MicrofacetCache>
147-
spectral_type __eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(Interaction) interaction, NBL_CONST_REF_ARG(MicrofacetCache) cache)
147+
template<class Interaction=conditional_t<IsAnisotropic,anisotropic_interaction_type,isotropic_interaction_type>,
148+
class MicrofacetCache=conditional_t<IsAnisotropic,anisocache_type,isocache_type>
149+
NBL_FUNC_REQUIRES(RequiredInteraction<Interaction> && RequiredMicrofacetCache<MicrofacetCache>)
150+
spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(Interaction) interaction, NBL_CONST_REF_ARG(MicrofacetCache) cache)
148151
{
149152
fresnel_type _f = fresnel;
150153
NBL_IF_CONSTEXPR(IsBSDF)
@@ -170,15 +173,6 @@ struct SCookTorrance
170173
clampedVdotH = hlsl::abs(clampedVdotH);
171174
return impl::__implicit_promote<spectral_type, typename fresnel_type::vector_type>::__call(_f(clampedVdotH)) * DG;
172175
}
173-
template<typename C=bool_constant<!IsAnisotropic> >
174-
enable_if_t<C::value && !IsAnisotropic, spectral_type> eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction, NBL_CONST_REF_ARG(isocache_type) cache)
175-
{
176-
return __eval<isotropic_interaction_type, isocache_type>(_sample, interaction, cache);
177-
}
178-
spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, NBL_CONST_REF_ARG(anisocache_type) cache)
179-
{
180-
return __eval<anisotropic_interaction_type, anisocache_type>(_sample, interaction, cache);
181-
}
182176

183177
template<typename C=bool_constant<!IsBSDF> >
184178
enable_if_t<C::value && !IsBSDF, sample_type> generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector2_type u, NBL_REF_ARG(anisocache_type) cache)
@@ -318,19 +312,10 @@ struct SCookTorrance
318312
return DG1.projectedLightMeasure;
319313
}
320314
}
321-
template<typename C=bool_constant<!IsAnisotropic> >
322-
enable_if_t<C::value && !IsAnisotropic, 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)
323-
{
324-
fresnel_type _f = fresnel;
325-
NBL_IF_CONSTEXPR(IsBSDF)
326-
_f = impl::getOrientedFresnel<fresnel_type, IsBSDF>::__call(fresnel, interaction.getNdotV());
327-
if (!__checkValid<isotropic_interaction_type, isocache_type>(_f, _sample, interaction, cache))
328-
return scalar_type(0.0);
329-
330-
scalar_type _pdf = __pdf<isotropic_interaction_type, isocache_type>(_sample, interaction, cache);
331-
return hlsl::mix(scalar_type(0.0), _pdf, _pdf < bit_cast<scalar_type>(numeric_limits<scalar_type>::infinity));
332-
}
333-
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)
315+
template<class Interaction=conditional_t<IsAnisotropic,anisotropic_interaction_type,isotropic_interaction_type>,
316+
class MicrofacetCache=conditional_t<IsAnisotropic,anisocache_type,isocache_type>
317+
NBL_FUNC_REQUIRES(RequiredInteraction<Interaction> && RequiredMicrofacetCache<MicrofacetCache>)
318+
scalar_type pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(Interaction) interaction, NBL_CONST_REF_ARG(MicrofacetCache) cache)
334319
{
335320
fresnel_type _f = fresnel;
336321
NBL_IF_CONSTEXPR(IsBSDF)
@@ -342,8 +327,10 @@ struct SCookTorrance
342327
return hlsl::mix(scalar_type(0.0), _pdf, _pdf < bit_cast<scalar_type>(numeric_limits<scalar_type>::infinity));
343328
}
344329

345-
template<class Interaction, class MicrofacetCache>
346-
quotient_pdf_type __quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(Interaction) interaction, NBL_CONST_REF_ARG(MicrofacetCache) cache)
330+
template<class Interaction=conditional_t<IsAnisotropic,anisotropic_interaction_type,isotropic_interaction_type>,
331+
class MicrofacetCache=conditional_t<IsAnisotropic,anisocache_type,isocache_type>
332+
NBL_FUNC_REQUIRES(RequiredInteraction<Interaction> && RequiredMicrofacetCache<MicrofacetCache>)
333+
quotient_pdf_type quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(Interaction) interaction, NBL_CONST_REF_ARG(MicrofacetCache) cache)
347334
{
348335
if (!_sample.isValid())
349336
return quotient_pdf_type::create(scalar_type(0.0), scalar_type(0.0)); // set pdf=0 when quo=0 because we don't want to give high weight to sampling strategy that yields 0 contribution
@@ -374,15 +361,6 @@ struct SCookTorrance
374361

375362
return quotient_pdf_type::create(quo, _pdf);
376363
}
377-
template<typename C=bool_constant<!IsAnisotropic> >
378-
enable_if_t<C::value && !IsAnisotropic, quotient_pdf_type> quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction, NBL_CONST_REF_ARG(isocache_type) cache)
379-
{
380-
return __quotient_and_pdf<isotropic_interaction_type, isocache_type>(_sample, interaction, cache);
381-
}
382-
quotient_pdf_type quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, NBL_CONST_REF_ARG(anisocache_type) cache)
383-
{
384-
return __quotient_and_pdf<anisotropic_interaction_type, anisocache_type>(_sample, interaction, cache);
385-
}
386364

387365
ndf_type ndf;
388366
fresnel_type fresnel; // always front-facing

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,21 @@ NBL_CONCEPT_END(
6262
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
6363

6464

65-
#define NDF_CONSTEXPR_DECLS(ANISO,REFLECT_REFRACT) NBL_CONSTEXPR_STATIC_INLINE bool IsAnisotropic = ANISO;\
65+
#define NBL_HLSL_BXDF_ANISOTROPIC_COND_DECLS(IS_ANISO) template<class Interaction>\
66+
NBL_CONSTEXPR_STATIC_INLINE bool RequiredInteraction = IS_ANISO ? surface_interactions::Anisotropic<Interaction> : surface_interactions::Isotropic<Interaction>;\
67+
template<class MicrofacetCache>\
68+
NBL_CONSTEXPR_STATIC_INLINE bool RequiredMicrofacetCache = IS_ANISO ? AnisotropicMicrofacetCache<MicrofacetCache> : ReadableIsotropicMicrofacetCache<MicrofacetCache>;\
69+
70+
#define NBL_HLSL_NDF_CONSTEXPR_DECLS(ANISO,REFLECT_REFRACT) NBL_CONSTEXPR_STATIC_INLINE bool IsAnisotropic = ANISO;\
6671
NBL_CONSTEXPR_STATIC_INLINE MicrofacetTransformTypes SupportedPaths = REFLECT_REFRACT;\
6772
NBL_CONSTEXPR_STATIC_INLINE bool SupportsTransmission = REFLECT_REFRACT != MTT_REFLECT;\
6873
NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = SupportsTransmission ? BxDFClampMode::BCM_ABS : BxDFClampMode::BCM_NONE;\
69-
template<class Interaction>\
70-
NBL_CONSTEXPR_STATIC_INLINE bool RequiredInteraction = IsAnisotropic ? surface_interactions::Anisotropic<Interaction> : surface_interactions::Isotropic<Interaction>;\
71-
template<class MicrofacetCache>\
72-
NBL_CONSTEXPR_STATIC_INLINE bool RequiredMicrofacetCache = IsAnisotropic ? AnisotropicMicrofacetCache<MicrofacetCache> : ReadableIsotropicMicrofacetCache<MicrofacetCache>;\
74+
NBL_HLSL_BXDF_ANISOTROPIC_COND_DECLS(IsAnisotropic);\
7375

7476
// help avoid preprocessor splitting template declarations by comma
75-
#define NDF_SINGLE_ARG(...) __VA_ARGS__
77+
#define NBL_HLSL_NDF_SINGLE_ARG(...) __VA_ARGS__
7678

77-
#define NDF_TYPE_ALIASES(N,BASE,DG1_QUERY,G2_QUERY,QUANT_QUERY) using this_t = N;\
79+
#define NBL_HLSL_NDF_TYPE_ALIASES(N,BASE,DG1_QUERY,G2_QUERY,QUANT_QUERY) using this_t = N;\
7880
using scalar_type = T;\
7981
using base_type = BASE;\
8082
using quant_type = SDualMeasureQuant<scalar_type>;\

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ struct BeckmannGenerateH
230230
template<typename T, bool _IsAnisotropic, MicrofacetTransformTypes reflect_refract NBL_PRIMARY_REQUIRES(concepts::FloatingPointScalar<T>)
231231
struct Beckmann
232232
{
233-
NDF_CONSTEXPR_DECLS(_IsAnisotropic,reflect_refract);
234-
NDF_TYPE_ALIASES(NDF_SINGLE_ARG(Beckmann<T,IsAnisotropic,SupportedPaths>), NDF_SINGLE_ARG(impl::BeckmannCommon<T,IsAnisotropic>), impl::SBeckmannDG1Query<scalar_type>, impl::SBeckmannG2overG1Query<scalar_type>, DualMeasureQuantQuery<scalar_type>);
233+
NBL_HLSL_NDF_CONSTEXPR_DECLS(_IsAnisotropic,reflect_refract);
234+
NBL_HLSL_NDF_TYPE_ALIASES(NBL_HLSL_NDF_SINGLE_ARG(Beckmann<T,IsAnisotropic,SupportedPaths>), NBL_HLSL_NDF_SINGLE_ARG(impl::BeckmannCommon<T,IsAnisotropic>), impl::SBeckmannDG1Query<scalar_type>, impl::SBeckmannG2overG1Query<scalar_type>, DualMeasureQuantQuery<scalar_type>);
235235

236236
template<typename C=bool_constant<!IsAnisotropic> >
237237
static enable_if_t<C::value && !IsAnisotropic, this_t> create(scalar_type A)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ struct GGXGenerateH
174174
template<typename T, bool _IsAnisotropic, MicrofacetTransformTypes reflect_refract NBL_PRIMARY_REQUIRES(concepts::FloatingPointScalar<T>)
175175
struct GGX
176176
{
177-
NDF_CONSTEXPR_DECLS(_IsAnisotropic,reflect_refract);
178-
NDF_TYPE_ALIASES(NDF_SINGLE_ARG(GGX<T,IsAnisotropic,SupportedPaths>), NDF_SINGLE_ARG(impl::GGXCommon<T,SupportsTransmission,IsAnisotropic>), impl::SGGXDG1Query<scalar_type>, impl::SGGXG2XQuery<scalar_type>, DualMeasureQuantQuery<scalar_type>);
177+
NBL_HLSL_NDF_CONSTEXPR_DECLS(_IsAnisotropic,reflect_refract);
178+
NBL_HLSL_NDF_TYPE_ALIASES(NBL_HLSL_NDF_SINGLE_ARG(GGX<T,IsAnisotropic,SupportedPaths>), NBL_HLSL_NDF_SINGLE_ARG(impl::GGXCommon<T,SupportsTransmission,IsAnisotropic>), impl::SGGXDG1Query<scalar_type>, impl::SGGXG2XQuery<scalar_type>, DualMeasureQuantQuery<scalar_type>);
179179

180180
template<typename C=bool_constant<!IsAnisotropic> >
181181
static enable_if_t<C::value && !IsAnisotropic, this_t> create(scalar_type A)

0 commit comments

Comments
 (0)