4
4
#ifndef _NBL_BUILTIN_HLSL_BXDF_REFLECTION_OREN_NAYAR_INCLUDED_
5
5
#define _NBL_BUILTIN_HLSL_BXDF_REFLECTION_OREN_NAYAR_INCLUDED_
6
6
7
- #include "nbl/builtin/hlsl/bxdf/common.hlsl"
8
- #include "nbl/builtin/hlsl/bxdf/config.hlsl"
9
7
#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"
11
9
12
10
namespace nbl
13
11
{
@@ -26,87 +24,49 @@ struct SOrenNayar
26
24
27
25
NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = BxDFClampMode::BCM_MAX;
28
26
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;
40
29
41
30
static this_t create (NBL_CONST_REF_ARG (creation_type) params)
42
31
{
43
32
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);
46
34
return retval;
47
35
}
48
36
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
-
62
37
spectral_type eval (NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (isotropic_interaction_type) interaction)
63
38
{
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);
67
40
}
68
41
spectral_type eval (NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (anisotropic_interaction_type) interaction)
69
42
{
70
- return eval (_sample, interaction.isotropic);
43
+ return __base. eval (_sample, interaction.isotropic);
71
44
}
72
45
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)
74
47
{
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);
78
49
}
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)
81
51
{
82
- return generate (anisotropic_interaction_type:: create ( interaction) , u);
52
+ return __base. generate (interaction, u);
83
53
}
84
54
85
55
scalar_type pdf (NBL_CONST_REF_ARG (sample_type) _sample)
86
56
{
87
- return sampling::ProjectedHemisphere<scalar_type>:: pdf (_sample. getNdotL (_clamp) );
57
+ return __base. pdf (_sample);
88
58
}
89
59
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
- }
97
60
quotient_pdf_type quotient_and_pdf (NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (isotropic_interaction_type) interaction)
98
61
{
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);
102
63
}
103
64
quotient_pdf_type quotient_and_pdf (NBL_CONST_REF_ARG (sample_type) _sample, NBL_CONST_REF_ARG (anisotropic_interaction_type) interaction)
104
65
{
105
- return quotient_and_pdf (_sample, interaction.isotropic);
66
+ return __base. quotient_and_pdf (_sample, interaction.isotropic);
106
67
}
107
68
108
- scalar_type A2;
109
- vector2_type AB;
69
+ base_type __base;
110
70
};
111
71
112
72
}
0 commit comments