@@ -43,7 +43,6 @@ NBL_CONCEPT_END(
4343 ((NBL_CONCEPT_REQ_TYPE)(T::scalar_type))
4444 ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((query.getDevshV ()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
4545 ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((query.getDevshL ()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
46- ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((query.getClampMode ()), ::nbl::hlsl::is_same_v, BxDFClampMode))
4746);
4847#undef query
4948#include <nbl/builtin/hlsl/concepts/__end.hlsl>
@@ -71,22 +70,22 @@ struct SGGXG2XQuery
7170
7271 scalar_type getDevshV () NBL_CONST_MEMBER_FUNC { return devsh_v; }
7372 scalar_type getDevshL () NBL_CONST_MEMBER_FUNC { return devsh_l; }
74- BxDFClampMode getClampMode () NBL_CONST_MEMBER_FUNC { return _clamp; }
7573
7674 scalar_type devsh_v;
7775 scalar_type devsh_l;
78- BxDFClampMode _clamp;
7976};
8077
81- template<typename T, bool IsAnisotropic=false NBL_STRUCT_CONSTRAINABLE>
78+ template<typename T, bool IsBSDF, bool IsAnisotropic=false NBL_STRUCT_CONSTRAINABLE>
8279struct GGXCommon;
8380
84- template<typename T>
81+ template<typename T, bool IsBSDF >
8582NBL_PARTIAL_REQ_TOP (concepts::FloatingPointScalar<T>)
86- struct GGXCommon<T,false NBL_PARTIAL_REQ_BOT (concepts::FloatingPointScalar<T>) >
83+ struct GGXCommon<T,IsBSDF, false NBL_PARTIAL_REQ_BOT (concepts::FloatingPointScalar<T>) >
8784{
8885 using scalar_type = T;
8986
87+ NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = IsBSDF ? BxDFClampMode::BCM_ABS : BxDFClampMode::BCM_MAX;
88+
9089 // trowbridge-reitz
9190 template<class MicrofacetCache NBL_FUNC_REQUIRES (ReadableIsotropicMicrofacetCache<MicrofacetCache>)
9291 scalar_type D (NBL_CONST_REF_ARG (MicrofacetCache) cache)
@@ -122,9 +121,6 @@ struct GGXCommon<T,false NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T>) >
122121 template<class Query, class LS, class Interaction NBL_FUNC_REQUIRES (ggx_concepts::G2overG1Query<Query> && LightSample<LS> && surface_interactions::Isotropic<Interaction>)
123122 static scalar_type correlated_wo_numerator (NBL_CONST_REF_ARG (Query) query, NBL_CONST_REF_ARG (LS) _sample, NBL_CONST_REF_ARG (Interaction) interaction)
124123 {
125- BxDFClampMode _clamp = query.getClampMode ();
126- assert (_clamp != BxDFClampMode::BCM_NONE);
127-
128124 scalar_type Vterm = _sample.getNdotL (_clamp) * query.getDevshV ();
129125 scalar_type Lterm = interaction.getNdotV (_clamp) * query.getDevshL ();
130126 return scalar_type (0.5 ) / (Vterm + Lterm);
@@ -133,17 +129,12 @@ struct GGXCommon<T,false NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T>) >
133129 template<class Query, class LS, class Interaction NBL_FUNC_REQUIRES (ggx_concepts::G2overG1Query<Query> && LightSample<LS> && surface_interactions::Isotropic<Interaction>)
134130 static scalar_type correlated (NBL_CONST_REF_ARG (Query) query, NBL_CONST_REF_ARG (LS) _sample, NBL_CONST_REF_ARG (Interaction) interaction)
135131 {
136- BxDFClampMode _clamp = query.getClampMode ();
137- assert (_clamp != BxDFClampMode::BCM_NONE);
138132 return scalar_type (4.0 ) * interaction.getNdotV (_clamp) * _sample.getNdotL (_clamp) * correlated_wo_numerator<LS, Interaction>(query, _sample, interaction);
139133 }
140134
141135 template<class Query, class LS, class Interaction, class MicrofacetCache NBL_FUNC_REQUIRES (ggx_concepts::G2overG1Query<Query> && LightSample<LS> && surface_interactions::Isotropic<Interaction> && ReadableIsotropicMicrofacetCache<MicrofacetCache>)
142136 static scalar_type G2_over_G1 (NBL_CONST_REF_ARG (Query) query, NBL_CONST_REF_ARG (LS) _sample, NBL_CONST_REF_ARG (Interaction) interaction, NBL_CONST_REF_ARG (MicrofacetCache) cache)
143137 {
144- BxDFClampMode _clamp = query.getClampMode ();
145- assert (_clamp != BxDFClampMode::BCM_NONE);
146-
147138 scalar_type G2_over_G1;
148139 scalar_type NdotV = interaction.getNdotV (_clamp);
149140 scalar_type NdotL = _sample.getNdotL (_clamp);
@@ -171,12 +162,14 @@ struct GGXCommon<T,false NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T>) >
171162 scalar_type one_minus_a2;
172163};
173164
174- template<typename T>
165+ template<typename T, bool IsBSDF >
175166NBL_PARTIAL_REQ_TOP (concepts::FloatingPointScalar<T>)
176- struct GGXCommon<T,true NBL_PARTIAL_REQ_BOT (concepts::FloatingPointScalar<T>) >
167+ struct GGXCommon<T,IsBSDF, true NBL_PARTIAL_REQ_BOT (concepts::FloatingPointScalar<T>) >
177168{
178169 using scalar_type = T;
179170
171+ NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = IsBSDF ? BxDFClampMode::BCM_ABS : BxDFClampMode::BCM_MAX;
172+
180173 template<class MicrofacetCache NBL_FUNC_REQUIRES (AnisotropicMicrofacetCache<MicrofacetCache>)
181174 scalar_type D (NBL_CONST_REF_ARG (MicrofacetCache) cache)
182175 {
@@ -186,17 +179,6 @@ struct GGXCommon<T,true NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T>) >
186179
187180 // TODO: potential idea for making GGX spin using covariance matrix of sorts: https://www.desmos.com/3d/weq2ginq9o
188181
189- // burley
190- scalar_type D (scalar_type a2, scalar_type TdotH, scalar_type BdotH, scalar_type NdotH, scalar_type anisotropy)
191- {
192- scalar_type antiAniso = scalar_type (1.0 ) - anisotropy;
193- scalar_type atab = a2 * antiAniso;
194- scalar_type anisoTdotH = antiAniso * TdotH;
195- scalar_type anisoNdotH = antiAniso * NdotH;
196- scalar_type w2 = antiAniso/(BdotH * BdotH + anisoTdotH * anisoTdotH + anisoNdotH * anisoNdotH * a2);
197- return w2 * w2 * atab * numbers::inv_pi<scalar_type>;
198- }
199-
200182 template<class Query NBL_FUNC_REQUIRES (ggx_concepts::DG1Query<Query>)
201183 static scalar_type DG1 (NBL_CONST_REF_ARG (Query) query)
202184 {
@@ -224,9 +206,6 @@ struct GGXCommon<T,true NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T>) >
224206 template<class Query, class LS, class Interaction NBL_FUNC_REQUIRES (ggx_concepts::G2overG1Query<Query> && LightSample<LS> && surface_interactions::Anisotropic <Interaction>)
225207 static scalar_type correlated_wo_numerator (NBL_CONST_REF_ARG (Query) query, NBL_CONST_REF_ARG (LS) _sample, NBL_CONST_REF_ARG (Interaction) interaction)
226208 {
227- BxDFClampMode _clamp = query.getClampMode ();
228- assert (_clamp != BxDFClampMode::BCM_NONE);
229-
230209 scalar_type Vterm = _sample.getNdotL (_clamp) * query.getDevshV ();
231210 scalar_type Lterm = interaction.getNdotV (_clamp) * query.getDevshL ();
232211 return scalar_type (0.5 ) / (Vterm + Lterm);
@@ -235,17 +214,12 @@ struct GGXCommon<T,true NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T>) >
235214 template<class Query, class LS, class Interaction NBL_FUNC_REQUIRES (ggx_concepts::G2overG1Query<Query> && LightSample<LS> && surface_interactions::Anisotropic <Interaction>)
236215 static scalar_type correlated (NBL_CONST_REF_ARG (Query) query, NBL_CONST_REF_ARG (LS) _sample, NBL_CONST_REF_ARG (Interaction) interaction)
237216 {
238- BxDFClampMode _clamp = query.getClampMode ();
239- assert (_clamp != BxDFClampMode::BCM_NONE);
240217 return scalar_type (4.0 ) * interaction.getNdotV (_clamp) * _sample.getNdotL (_clamp) * correlated_wo_numerator<LS, Interaction>(query, _sample, interaction);
241218 }
242219
243220 template<class Query, class LS, class Interaction, class MicrofacetCache NBL_FUNC_REQUIRES (ggx_concepts::G2overG1Query<Query> && LightSample<LS> && surface_interactions::Anisotropic <Interaction> && AnisotropicMicrofacetCache<MicrofacetCache>)
244221 static scalar_type G2_over_G1 (NBL_CONST_REF_ARG (Query) query, NBL_CONST_REF_ARG (LS) _sample, NBL_CONST_REF_ARG (Interaction) interaction, NBL_CONST_REF_ARG (MicrofacetCache) cache)
245222 {
246- BxDFClampMode _clamp = query.getClampMode ();
247- assert (_clamp != BxDFClampMode::BCM_NONE);
248-
249223 scalar_type G2_over_G1;
250224 scalar_type NdotV = interaction.getNdotV (_clamp);
251225 scalar_type NdotL = _sample.getNdotL (_clamp);
@@ -309,8 +283,10 @@ struct GGXGenerateH
309283template<typename T, bool IsAnisotropic, MicrofacetTransformTypes reflect_refract NBL_PRIMARY_REQUIRES (concepts::FloatingPointScalar<T>)
310284struct GGX
311285{
286+ NBL_CONSTEXPR_STATIC_INLINE bool IsBSDF = reflect_refract != MTT_REFLECT;
287+
312288 using scalar_type = T;
313- using base_type = impl::GGXCommon<T,IsAnisotropic>;
289+ using base_type = impl::GGXCommon<T,IsBSDF, IsAnisotropic>;
314290 using quant_type = SDualMeasureQuant<scalar_type>;
315291 using vector2_type = vector <T, 2 >;
316292 using vector3_type = vector <T, 3 >;
@@ -319,8 +295,7 @@ struct GGX
319295 using g2g1_query_type = impl::SGGXG2XQuery<scalar_type>;
320296 using quant_query_type = impl::NDFQuantQuery<scalar_type>;
321297
322- NBL_CONSTEXPR_STATIC_INLINE bool IsBSDF = reflect_refract != MTT_REFLECT;
323- NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = IsBSDF ? BxDFClampMode::BCM_ABS : BxDFClampMode::BCM_MAX;
298+ NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = IsBSDF ? BxDFClampMode::BCM_ABS : BxDFClampMode::BCM_NONE;
324299 template<class Interaction>
325300 NBL_CONSTEXPR_STATIC_INLINE bool RequiredInteraction = IsAnisotropic ? surface_interactions::Anisotropic <Interaction> : surface_interactions::Isotropic<Interaction>;
326301 template<class MicrofacetCache>
@@ -355,7 +330,6 @@ struct GGX
355330 g2g1_query_type g2_query;
356331 g2_query.devsh_l = __base.devsh_part (_sample.getNdotL2 ());
357332 g2_query.devsh_v = __base.devsh_part (interaction.getNdotV2 ());
358- g2_query._clamp = _clamp;
359333 return g2_query;
360334 }
361335 template<class Interaction, class MicrofacetCache, typename C=bool_constant<IsAnisotropic> NBL_FUNC_REQUIRES (RequiredInteraction<Interaction> && RequiredMicrofacetCache<MicrofacetCache>)
@@ -373,7 +347,6 @@ struct GGX
373347 g2g1_query_type g2_query;
374348 g2_query.devsh_l = __base.devsh_part (_sample.getTdotL2 (), _sample.getBdotL2 (), _sample.getNdotL2 ());
375349 g2_query.devsh_v = __base.devsh_part (interaction.getTdotV2 (), interaction.getBdotV2 (), interaction.getNdotV2 ());
376- g2_query._clamp = _clamp;
377350 return g2_query;
378351 }
379352
0 commit comments