44#ifndef _NBL_BUILTIN_HLSL_BXDF_REFLECTION_OREN_NAYAR_INCLUDED_
55#define _NBL_BUILTIN_HLSL_BXDF_REFLECTION_OREN_NAYAR_INCLUDED_
66
7- #include "nbl/builtin/hlsl/bxdf/common.hlsl"
8- #include "nbl/builtin/hlsl/bxdf/config.hlsl"
97#include "nbl/builtin/hlsl/bxdf/bxdf_traits.hlsl"
10- #include "nbl/builtin/hlsl/sampling/cos_weighted_spheres .hlsl"
8+ #include "nbl/builtin/hlsl/bxdf/base/oren_nayar .hlsl"
119
1210namespace nbl
1311{
@@ -26,87 +24,49 @@ struct SOrenNayar
2624
2725 NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = BxDFClampMode::BCM_MAX;
2826
29- struct SCreationParams
30- {
31- scalar_type A;
32- };
33- using creation_type = SCreationParams;
34-
35- struct SQuery
36- {
37- scalar_type getVdotL () NBL_CONST_MEMBER_FUNC { return VdotL; }
38- scalar_type VdotL;
39- };
27+ using base_type = base::SOrenNayarBase<Config, false >;
28+ using creation_type = typename base_type::creation_type;
4029
4130 static this_t create (NBL_CONST_REF_ARG (creation_type) params)
4231 {
4332 this_t retval;
44- retval.A2 = params.A * 0.5 ;
45- retval.AB = vector2_type (1.0 , 0.0 ) + vector2_type (-0.5 , 0.45 ) * vector2_type (retval.A2, retval.A2) / vector2_type (retval.A2 + 0.33 , retval.A2 + 0.09 );
33+ retval.__base = base_type::create (params);
4634 return retval;
4735 }
4836
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- }
55- template<typename Query>
56- spectral_type __eval (NBL_CONST_REF_ARG (Query) query, NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (isotropic_interaction_type) interaction)
57- {
58- scalar_type NdotL = _sample.getNdotL (_clamp);
59- return hlsl::promote<spectral_type>(NdotL * numbers::inv_pi<scalar_type> * __rec_pi_factored_out_wo_clamps (query.getVdotL (), NdotL, interaction.getNdotV (_clamp)));
60- }
61-
6237 spectral_type eval (NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (isotropic_interaction_type) interaction)
6338 {
64- SQuery query;
65- query.VdotL = hlsl::dot (interaction.getV ().getDirection (), _sample.getL ().getDirection ());
66- return __eval<SQuery>(query, _sample, interaction);
39+ return __base.eval (_sample, interaction);
6740 }
6841 spectral_type eval (NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (anisotropic_interaction_type) interaction)
6942 {
70- return eval (_sample, interaction.isotropic);
43+ return __base. eval (_sample, interaction.isotropic);
7144 }
7245
73- sample_type generate (NBL_CONST_REF_ARG (anisotropic_interaction_type ) interaction, const vector2_type u)
46+ sample_type generate (NBL_CONST_REF_ARG (isotropic_interaction_type ) interaction, const vector2_type u)
7447 {
75- ray_dir_info_type L;
76- L.direction = sampling::ProjectedHemisphere<scalar_type>::generate (u);
77- return sample_type::createFromTangentSpace (L, interaction.getFromTangentSpace ());
48+ return __base.generate (anisotropic_interaction_type::create (interaction), u);
7849 }
79-
80- sample_type generate (NBL_CONST_REF_ARG (isotropic_interaction_type) interaction, const vector2_type u)
50+ sample_type generate (NBL_CONST_REF_ARG (anisotropic_interaction_type) interaction, const vector2_type u)
8151 {
82- return generate (anisotropic_interaction_type:: create ( interaction) , u);
52+ return __base. generate (interaction, u);
8353 }
8454
8555 scalar_type pdf (NBL_CONST_REF_ARG (sample_type) _sample)
8656 {
87- return sampling::ProjectedHemisphere<scalar_type>:: pdf (_sample. getNdotL (_clamp) );
57+ return __base. pdf (_sample);
8858 }
8959
90- template<typename Query>
91- 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)
92- {
93- scalar_type _pdf = pdf (_sample);
94- scalar_type q = __rec_pi_factored_out_wo_clamps (query.getVdotL (), _sample.getNdotL (_clamp), interaction.getNdotV (_clamp));
95- return quotient_pdf_type::create (q, _pdf);
96- }
9760 quotient_pdf_type quotient_and_pdf (NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (isotropic_interaction_type) interaction)
9861 {
99- SQuery query;
100- query.VdotL = hlsl::dot (interaction.getV ().getDirection (), _sample.getL ().getDirection ());
101- return __quotient_and_pdf<SQuery>(query, _sample, interaction);
62+ return __base.quotient_and_pdf (_sample, interaction);
10263 }
10364 quotient_pdf_type quotient_and_pdf (NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (anisotropic_interaction_type) interaction)
10465 {
105- return quotient_and_pdf (_sample, interaction.isotropic);
66+ return __base. quotient_and_pdf (_sample, interaction.isotropic);
10667 }
10768
108- scalar_type A2;
109- vector2_type AB;
69+ base_type __base;
11070};
11171
11272}
0 commit comments