@@ -191,12 +191,10 @@ struct SCookTorrance
191191 }
192192
193193 sample_type __generate_common (NBL_CONST_REF_ARG (anisotropic_interaction_type) interaction, const vector3_type localH,
194- const scalar_type NdotV, const scalar_type VdotH, bool transmitted,
194+ const scalar_type NdotV, const scalar_type VdotH, const scalar_type LdotH, bool transmitted,
195195 NBL_CONST_REF_ARG (fresnel::OrientedEtaRcps<monochrome_type>) rcpEta,
196- NBL_REF_ARG (anisocache_type) cache, NBL_REF_ARG ( bool ) valid)
196+ NBL_REF_ARG (bool ) valid)
197197 {
198- const scalar_type LdotH = hlsl::mix (VdotH, ieee754::copySign (hlsl::sqrt (rcpEta.value2[0 ]*VdotH*VdotH + scalar_type (1.0 ) - rcpEta.value2[0 ]), -VdotH), transmitted);
199-
200198 // fail if samples have invalid paths
201199 const scalar_type NdotL = hlsl::mix (scalar_type (2.0 ) * VdotH * localH.z - NdotV,
202200 localH.z * (VdotH * rcpEta.value[0 ] + LdotH) - NdotV * rcpEta.value[0 ], transmitted);
@@ -208,8 +206,6 @@ struct SCookTorrance
208206 return sample_type::createInvalid (); // should check if sample direction is invalid
209207 }
210208
211- cache = anisocache_type::createPartial (VdotH, LdotH, localH.z, transmitted, rcpEta);
212-
213209 ray_dir_info_type V = interaction.getV ();
214210 const matrix3x3_type fromTangent = interaction.getFromTangentSpace ();
215211 // tangent frame orthonormality
@@ -268,7 +264,7 @@ struct SCookTorrance
268264
269265 fresnel::OrientedEtaRcps<monochrome_type> dummy;
270266 bool valid;
271- sample_type s = __generate_common (interaction, localH, NdotV, VdotH, false , dummy, cache , valid);
267+ sample_type s = __generate_common (interaction, localH, NdotV, VdotH, VdotH, false , dummy , valid);
272268 if (valid)
273269 cache = anisocache_type::createForReflection (localV, localH);
274270 return s;
@@ -304,10 +300,12 @@ struct SCookTorrance
304300 scalar_type z = u.z;
305301 bool transmitted = math::partitionRandVariable (reflectance, z, rcpChoiceProb);
306302
303+ const scalar_type LdotH = hlsl::mix (VdotH, ieee754::copySign (hlsl::sqrt (rcpEta.value2[0 ]*VdotH*VdotH + scalar_type (1.0 ) - rcpEta.value2[0 ]), -VdotH), transmitted);
307304 bool valid;
308- sample_type s = __generate_common (interaction, localH, NdotV, VdotH, transmitted, rcpEta, cache , valid);
305+ sample_type s = __generate_common (interaction, localH, NdotV, VdotH, LdotH, transmitted, rcpEta , valid);
309306 if (valid)
310307 {
308+ cache = anisocache_type::createPartial (VdotH, LdotH, localH.z, transmitted, rcpEta);
311309 assert (cache.isValid (fresnel::OrientedEtas<monochrome_type>::create (scalar_type (1.0 ), hlsl::promote<monochrome_type>(_f.getRefractionOrientedEta ()))));
312310 const vector3_type T = interaction.getT ();
313311 const vector3_type B = interaction.getB ();
@@ -387,10 +385,15 @@ struct SCookTorrance
387385 spectral_type quo;
388386 NBL_IF_CONSTEXPR (IsBSDF)
389387 {
390- const scalar_type scaled_reflectance = __getScaledReflectance (_f, interaction, hlsl::abs (cache.getVdotH ()));
391- spectral_type reflectance = impl::__implicit_promote<spectral_type, typename fresnel_type::vector_type>::__call (_f (hlsl::abs (cache.getVdotH ())));
392- quo = hlsl::mix (reflectance / scaled_reflectance,
393- (hlsl::promote<spectral_type>(1.0 ) - reflectance) / (scalar_type (1.0 ) - scaled_reflectance), cache.isTransmission ()) * G2_over_G1;
388+ NBL_IF_CONSTEXPR (fresnel_type::ReturnsMonochrome)
389+ quo = hlsl::promote<spectral_type>(G2_over_G1);
390+ else
391+ {
392+ const scalar_type scaled_reflectance = __getScaledReflectance (_f, interaction, hlsl::abs (cache.getVdotH ()));
393+ spectral_type reflectance = impl::__implicit_promote<spectral_type, typename fresnel_type::vector_type>::__call (_f (hlsl::abs (cache.getVdotH ())));
394+ quo = hlsl::mix (reflectance / scaled_reflectance,
395+ (hlsl::promote<spectral_type>(1.0 ) - reflectance) / (scalar_type (1.0 ) - scaled_reflectance), cache.isTransmission ()) * G2_over_G1;
396+ }
394397 }
395398 else
396399 {
0 commit comments