@@ -46,16 +46,19 @@ struct SOrenNayar
4646 return retval;
4747 }
4848
49+ scalar_type __rec_pi_factored_out_wo_clamps (scalar_type VdotL, scalar_type clampedNdotL, scalar_type clampedNdotV)
50+ {
51+ scalar_type C = 1.0 / max <scalar_type>(clampedNdotL, clampedNdotV);
52+ scalar_type cos_phi_sin_theta = max <scalar_type>(VdotL - clampedNdotL * clampedNdotV, 0.0 );
53+ return (AB.x + AB.y * cos_phi_sin_theta * C);
54+ }
4955 template<typename Query>
5056 spectral_type __eval (NBL_CONST_REF_ARG (Query) query, NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (isotropic_interaction_type) interaction)
5157 {
5258 scalar_type NdotL = _sample.getNdotL (_clamp);
53- scalar_type NdotV = interaction.getNdotV (_clamp);
54- scalar_type C = 1.0 / max <scalar_type>(NdotL, NdotV);
55-
56- scalar_type cos_phi_sin_theta = max <scalar_type>(query.getVdotL () - NdotL * NdotV, 0.0 );
57- return hlsl::promote<spectral_type>(NdotL * numbers::inv_pi<scalar_type> * 0.5 * (AB.x + AB.y * cos_phi_sin_theta * C));
59+ return hlsl::promote<spectral_type>(NdotL * numbers::inv_pi<scalar_type> * 0.5 * __rec_pi_factored_out_wo_clamps (query.getVdotL (), NdotL, interaction.getNdotV (_clamp)));
5860 }
61+
5962 spectral_type eval (NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (isotropic_interaction_type) interaction)
6063 {
6164 SQuery query;
@@ -87,13 +90,7 @@ struct SOrenNayar
8790 quotient_pdf_type __quotient_and_pdf (NBL_CONST_REF_ARG (Query) query, NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (isotropic_interaction_type) interaction)
8891 {
8992 scalar_type _pdf = pdf (_sample);
90-
91- scalar_type NdotL = _sample.getNdotL (_clamp);
92- scalar_type NdotV = interaction.getNdotV (_clamp);
93- scalar_type C = 1.0 / max <scalar_type>(NdotL, NdotV);
94-
95- scalar_type cos_phi_sin_theta = max <scalar_type>(query.getVdotL () - NdotL * NdotV, 0.0 );
96- scalar_type q = AB.x + AB.y * cos_phi_sin_theta * C;
93+ scalar_type q = __rec_pi_factored_out_wo_clamps (query.getVdotL (), _sample.getNdotL (_clamp), interaction.getNdotV (_clamp));
9794 return quotient_pdf_type::create (q, _pdf);
9895 }
9996 quotient_pdf_type quotient_and_pdf (NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (isotropic_interaction_type) interaction)
0 commit comments