@@ -88,47 +88,47 @@ struct SCookTorrance
8888 template<class Interaction=conditional_t<IsAnisotropic,anisotropic_interaction_type,isotropic_interaction_type>,
8989 class MicrofacetCache=conditional_t<IsAnisotropic,anisocache_type,isocache_type>
9090 NBL_FUNC_REQUIRES (!ndf::NDF_CanOverwriteDG<ndf_type> && RequiredInteraction<Interaction> && RequiredMicrofacetCache<MicrofacetCache>)
91- static void overwriteDG (NBL_REF_ARG (scalar_type) DG, ndf_type ndf, NBL_CONST_REF_ARG (typename ndf_type::g2g1_query_type) query, NBL_CONST_REF_ARG (typename ndf_type::quant_query_type) quant_query,
91+ static void __overwriteDG (NBL_REF_ARG (scalar_type) DG, ndf_type ndf, NBL_CONST_REF_ARG (typename ndf_type::g2g1_query_type) query, NBL_CONST_REF_ARG (typename ndf_type::quant_query_type) quant_query,
9292 NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (Interaction) interaction, NBL_CONST_REF_ARG (MicrofacetCache) cache, NBL_REF_ARG (bool ) isInfinity)
9393 {
9494 }
9595 template<class Interaction=conditional_t<IsAnisotropic,anisotropic_interaction_type,isotropic_interaction_type>,
9696 class MicrofacetCache=conditional_t<IsAnisotropic,anisocache_type,isocache_type>
9797 NBL_FUNC_REQUIRES (ndf::NDF_CanOverwriteDG<ndf_type> && RequiredInteraction<Interaction> && RequiredMicrofacetCache<MicrofacetCache>)
98- static void overwriteDG (NBL_REF_ARG (scalar_type) DG, ndf_type ndf, NBL_CONST_REF_ARG (typename ndf_type::g2g1_query_type) query, NBL_CONST_REF_ARG (typename ndf_type::quant_query_type) quant_query,
98+ static void __overwriteDG (NBL_REF_ARG (scalar_type) DG, ndf_type ndf, NBL_CONST_REF_ARG (typename ndf_type::g2g1_query_type) query, NBL_CONST_REF_ARG (typename ndf_type::quant_query_type) quant_query,
9999 NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (Interaction) interaction, NBL_CONST_REF_ARG (MicrofacetCache) cache, NBL_REF_ARG (bool ) isInfinity)
100100 {
101101 quant_type dg = ndf.template Dcorrelated<sample_type, Interaction, MicrofacetCache>(query, quant_query, _sample, interaction, cache, isInfinity);
102102 DG = dg.projectedLightMeasure;
103103 }
104104
105105 template<typename PH=fresnel_type NBL_FUNC_REQUIRES (!fresnel::TwoSidedFresnel<PH>)
106- static fresnel_type getOrientedFresnel (NBL_CONST_REF_ARG (fresnel_type) fresnel, scalar_type NdotV)
106+ static fresnel_type __getOrientedFresnel (NBL_CONST_REF_ARG (fresnel_type) fresnel, scalar_type NdotV)
107107 {
108108 // expect conductor fresnel
109109 return fresnel;
110110 }
111111 template<typename PH=fresnel_type NBL_FUNC_REQUIRES (fresnel::TwoSidedFresnel<PH>)
112- static fresnel_type getOrientedFresnel (NBL_CONST_REF_ARG (fresnel_type) fresnel, scalar_type NdotV)
112+ static fresnel_type __getOrientedFresnel (NBL_CONST_REF_ARG (fresnel_type) fresnel, scalar_type NdotV)
113113 {
114114 return fresnel.getReorientedFresnel (NdotV);
115115 }
116116
117117 template<class Interaction=conditional_t<IsAnisotropic,anisotropic_interaction_type,isotropic_interaction_type>,
118- class MicrofacetCache=conditional_t<IsAnisotropic,anisocache_type,isocache_type>, typename C=bool_constant<!IsBSDF> >
119- static enable_if_t<C::value && !IsBSDF, bool > checkValid (NBL_CONST_REF_ARG (fresnel_type) orientedFresnel, NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (Interaction) interaction, NBL_CONST_REF_ARG (MicrofacetCache) cache)
118+ class MicrofacetCache=conditional_t<IsAnisotropic,anisocache_type,isocache_type>, typename C=bool_constant<!IsBSDF> NBL_FUNC_REQUIRES (C::value && !IsBSDF)
119+ static bool __checkValid (NBL_CONST_REF_ARG (fresnel_type) orientedFresnel, NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (Interaction) interaction, NBL_CONST_REF_ARG (MicrofacetCache) cache)
120120 {
121121 return _sample.getNdotL () > numeric_limits<scalar_type>::min && interaction.getNdotV () > numeric_limits<scalar_type>::min ;
122122 }
123123 template<class Interaction=conditional_t<IsAnisotropic,anisotropic_interaction_type,isotropic_interaction_type>,
124- class MicrofacetCache=conditional_t<IsAnisotropic,anisocache_type,isocache_type>, typename C=bool_constant<IsBSDF> >
125- static enable_if_t<C::value && IsBSDF, bool > checkValid (NBL_CONST_REF_ARG (fresnel_type) orientedFresnel, NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (Interaction) interaction, NBL_CONST_REF_ARG (MicrofacetCache) cache)
124+ class MicrofacetCache=conditional_t<IsAnisotropic,anisocache_type,isocache_type>, typename C=bool_constant<IsBSDF> NBL_FUNC_REQUIRES (C::value && IsBSDF)
125+ static bool __checkValid (NBL_CONST_REF_ARG (fresnel_type) orientedFresnel, NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (Interaction) interaction, NBL_CONST_REF_ARG (MicrofacetCache) cache)
126126 {
127127 fresnel::OrientedEtas<monochrome_type> orientedEta = fresnel::OrientedEtas<monochrome_type>::create (scalar_type (1.0 ), hlsl::promote<monochrome_type>(orientedFresnel.getRefractionOrientedEta ()));
128128 return cache.isValid (orientedEta);
129129 }
130130
131- bool dotIsUnity (const vector3_type a, const vector3_type b, const scalar_type value)
131+ bool __dotIsUnity (const vector3_type a, const vector3_type b, const scalar_type value)
132132 {
133133 const scalar_type ab = hlsl::dot (a, b);
134134 return hlsl::max (ab, value / ab) <= scalar_type (value + 1e-3 );
@@ -140,8 +140,8 @@ struct SCookTorrance
140140 NBL_FUNC_REQUIRES (RequiredInteraction<Interaction> && RequiredMicrofacetCache<MicrofacetCache>)
141141 spectral_type eval (NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (Interaction) interaction, NBL_CONST_REF_ARG (MicrofacetCache) cache)
142142 {
143- fresnel_type _f = getOrientedFresnel (fresnel, interaction.getNdotV ());
144- if (!checkValid <Interaction, MicrofacetCache>(_f, _sample, interaction, cache))
143+ fresnel_type _f = __getOrientedFresnel (fresnel, interaction.getNdotV ());
144+ if (!__checkValid <Interaction, MicrofacetCache>(_f, _sample, interaction, cache))
145145 return hlsl::promote<spectral_type>(0.0 );
146146
147147 using quant_query_type = typename ndf_type::quant_query_type;
@@ -156,9 +156,11 @@ struct SCookTorrance
156156 if (!isInfinity)
157157 DG *= ndf.template correlated<sample_type, Interaction, MicrofacetCache>(gq, _sample, interaction, cache);
158158
159- overwriteDG <Interaction, MicrofacetCache>(DG, ndf, gq, qq, _sample, interaction, cache, isInfinity);
159+ __overwriteDG <Interaction, MicrofacetCache>(DG, ndf, gq, qq, _sample, interaction, cache, isInfinity);
160160
161- if (isInfinity) // after all calls setting DG, allows compiler to throw away calls to ndf.D if using overwriteDG
161+ // immediately return only after all calls setting DG
162+ // allows compiler to throw away calls to ndf.D if using __overwriteDG, before that we only avoid computation for G2(correlated)
163+ if (isInfinity)
162164 return hlsl::promote<spectral_type>(0.0 );
163165
164166 scalar_type clampedVdotH = cache.getVdotH ();
@@ -197,11 +199,11 @@ struct SCookTorrance
197199 ray_dir_info_type V = interaction.getV ();
198200 const matrix3x3_type fromTangent = interaction.getFromTangentSpace ();
199201 // tangent frame orthonormality
200- assert (dotIsUnity (fromTangent[0 ],fromTangent[1 ],0.0 ));
201- assert (dotIsUnity (fromTangent[1 ],fromTangent[2 ],0.0 ));
202- assert (dotIsUnity (fromTangent[2 ],fromTangent[0 ],0.0 ));
202+ assert (__dotIsUnity (fromTangent[0 ],fromTangent[1 ],0.0 ));
203+ assert (__dotIsUnity (fromTangent[1 ],fromTangent[2 ],0.0 ));
204+ assert (__dotIsUnity (fromTangent[2 ],fromTangent[0 ],0.0 ));
203205 // NDF sampling produced a unit length direction
204- assert (dotIsUnity (localH,localH,1.0 ));
206+ assert (__dotIsUnity (localH,localH,1.0 ));
205207 const vector3_type H = hlsl::mul (interaction.getFromTangentSpace (), localH);
206208 Refract<scalar_type> r = Refract<scalar_type>::create (V.getDirection (), H);
207209
@@ -227,8 +229,8 @@ struct SCookTorrance
227229 valid = true ;
228230 return sample_type::create (L, T, B, NdotL);
229231 }
230- template<typename C=bool_constant<!IsBSDF> >
231- 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)
232+ template<typename C=bool_constant<!IsBSDF> NBL_FUNC_REQUIRES (C::value && !IsBSDF)
233+ sample_type generate (NBL_CONST_REF_ARG (anisotropic_interaction_type) interaction, const vector2_type u, NBL_REF_ARG (anisocache_type) cache)
232234 {
233235 const scalar_type NdotV = interaction.getNdotV ();
234236 if (NdotV < numeric_limits<scalar_type>::min )
@@ -257,13 +259,13 @@ struct SCookTorrance
257259 cache = anisocache_type::createForReflection (localV, localH);
258260 return s;
259261 }
260- template<typename C=bool_constant<IsBSDF> >
261- enable_if_t<C::value && IsBSDF, sample_type> generate (NBL_CONST_REF_ARG (anisotropic_interaction_type) interaction, const vector3_type u, NBL_REF_ARG (anisocache_type) cache)
262+ template<typename C=bool_constant<IsBSDF> NBL_FUNC_REQUIRES (C::value && IsBSDF)
263+ sample_type generate (NBL_CONST_REF_ARG (anisotropic_interaction_type) interaction, const vector3_type u, NBL_REF_ARG (anisocache_type) cache)
262264 {
263265 const vector3_type localV = interaction.getTangentSpaceV ();
264266 const scalar_type NdotV = localV.z;
265267
266- fresnel_type _f = getOrientedFresnel (fresnel, NdotV);
268+ fresnel_type _f = __getOrientedFresnel (fresnel, NdotV);
267269 fresnel::OrientedEtaRcps<monochrome_type> rcpEta = _f.getOrientedEtaRcps ();
268270
269271 const vector3_type upperHemisphereV = ieee754::flipSignIfRHSNegative<vector3_type>(localV, hlsl::promote<vector3_type>(NdotV));
@@ -301,8 +303,8 @@ struct SCookTorrance
301303 }
302304 return s;
303305 }
304- template<typename C=bool_constant<!IsAnisotropic> >
305- enable_if_t<C::value && !IsAnisotropic, sample_type> generate (NBL_CONST_REF_ARG (isotropic_interaction_type) interaction, const conditional_t<IsBSDF, vector3_type, vector2_type> u, NBL_REF_ARG (isocache_type) cache)
306+ template<typename C=bool_constant<!IsAnisotropic> NBL_FUNC_REQUIRES (C::value && !IsAnisotropic)
307+ sample_type generate (NBL_CONST_REF_ARG (isotropic_interaction_type) interaction, const conditional_t<IsBSDF, vector3_type, vector2_type> u, NBL_REF_ARG (isocache_type) cache)
306308 {
307309 anisocache_type aniso_cache;
308310 sample_type s = generate (anisotropic_interaction_type::create (interaction), u, aniso_cache);
@@ -318,7 +320,7 @@ struct SCookTorrance
318320
319321 dg1_query_type dq = ndf.template createDG1Query<Interaction, MicrofacetCache>(interaction, cache);
320322
321- fresnel_type _f = getOrientedFresnel (fresnel, interaction.getNdotV ());
323+ fresnel_type _f = __getOrientedFresnel (fresnel, interaction.getNdotV ());
322324 quant_query_type qq = impl::quant_query_helper<ndf_type, fresnel_type, IsBSDF>::template __call<Interaction, MicrofacetCache>(ndf, _f, interaction, cache);
323325 quant_type DG1 = ndf.template DG1<sample_type, Interaction>(dq, qq, _sample, interaction, isInfinity);
324326
@@ -338,8 +340,8 @@ struct SCookTorrance
338340 NBL_FUNC_REQUIRES (RequiredInteraction<Interaction> && RequiredMicrofacetCache<MicrofacetCache>)
339341 scalar_type pdf (NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (Interaction) interaction, NBL_CONST_REF_ARG (MicrofacetCache) cache)
340342 {
341- fresnel_type _f = getOrientedFresnel (fresnel, interaction.getNdotV ());
342- if (!checkValid <Interaction, MicrofacetCache>(_f, _sample, interaction, cache))
343+ fresnel_type _f = __getOrientedFresnel (fresnel, interaction.getNdotV ());
344+ if (!__checkValid <Interaction, MicrofacetCache>(_f, _sample, interaction, cache))
343345 return scalar_type (0.0 );
344346
345347 bool isInfinity;
@@ -357,9 +359,9 @@ struct SCookTorrance
357359
358360 bool isInfinity;
359361 scalar_type _pdf = __pdf<Interaction, MicrofacetCache>(_sample, interaction, cache, isInfinity);
360- fresnel_type _f = getOrientedFresnel (fresnel, interaction.getNdotV ());
362+ fresnel_type _f = __getOrientedFresnel (fresnel, interaction.getNdotV ());
361363
362- const bool valid = checkValid <Interaction, MicrofacetCache>(_f, _sample, interaction, cache);
364+ const bool valid = __checkValid <Interaction, MicrofacetCache>(_f, _sample, interaction, cache);
363365 assert (valid); // expect the generated sample to always be valid, different checks for brdf and btdf
364366
365367 scalar_type G2_over_G1 = scalar_type (1.0 );
0 commit comments