Skip to content

Commit 9eeb248

Browse files
committed
make lambertian + oren nayar bxdfs typedefs of corresponding base, functionality moved into base
1 parent c0586f5 commit 9eeb248

File tree

6 files changed

+52
-198
lines changed

6 files changed

+52
-198
lines changed

include/nbl/builtin/hlsl/bxdf/base/lambertian.hlsl

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,35 @@ struct SLambertianBase
2929
{
3030
return hlsl::promote<spectral_type>(_sample.getNdotL(_clamp) * numbers::inv_pi<scalar_type> * hlsl::mix(1.0, 0.5, IsBSDF));
3131
}
32+
spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction)
33+
{
34+
return eval(_sample, interaction.isotropic);
35+
}
3236

33-
template<typename T NBL_FUNC_REQUIRES(is_same_v<T, vector2_type>)
34-
sample_type generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const T u)
37+
template<typename C=bool_constant<!IsBSDF> >
38+
enable_if_t<C::value && !IsBSDF, sample_type> generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector2_type u)
3539
{
3640
ray_dir_info_type L;
3741
L.direction = sampling::ProjectedHemisphere<scalar_type>::generate(u);
3842
return sample_type::createFromTangentSpace(L, interaction.getFromTangentSpace());
3943
}
40-
41-
template<typename T NBL_FUNC_REQUIRES(is_same_v<T, vector3_type>)
42-
sample_type generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const T u)
44+
template<typename C=bool_constant<IsBSDF> >
45+
enable_if_t<C::value && IsBSDF, sample_type> generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector3_type u)
4346
{
4447
ray_dir_info_type L;
4548
L.direction = sampling::ProjectedSphere<scalar_type>::generate(u);
4649
return sample_type::createFromTangentSpace(L, interaction.getFromTangentSpace());
4750
}
51+
template<typename C=bool_constant<!IsBSDF> >
52+
enable_if_t<C::value && !IsBSDF, sample_type> generate(NBL_CONST_REF_ARG(isotropic_interaction_type) interaction, const vector2_type u)
53+
{
54+
return generate(anisotropic_interaction_type::create(interaction), u);
55+
}
56+
template<typename C=bool_constant<IsBSDF> >
57+
enable_if_t<C::value && IsBSDF, sample_type> generate(NBL_CONST_REF_ARG(isotropic_interaction_type) interaction, const vector3_type u)
58+
{
59+
return generate(anisotropic_interaction_type::create(interaction), u);
60+
}
4861

4962
scalar_type pdf(NBL_CONST_REF_ARG(sample_type) _sample)
5063
{
@@ -63,6 +76,10 @@ struct SLambertianBase
6376
qp = sampling::ProjectedHemisphere<scalar_type>::template quotient_and_pdf(_sample.getNdotL(_clamp));
6477
return quotient_pdf_type::create(qp.quotient[0], qp.pdf);
6578
}
79+
quotient_pdf_type quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction)
80+
{
81+
return quotient_and_pdf(_sample, interaction.isotropic);
82+
}
6683
};
6784

6885
}

include/nbl/builtin/hlsl/bxdf/base/oren_nayar.hlsl

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,35 @@ struct SOrenNayarBase
6464
query.VdotL = hlsl::dot(interaction.getV().getDirection(), _sample.getL().getDirection());
6565
return __eval<SQuery>(query, _sample, interaction);
6666
}
67+
spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction)
68+
{
69+
return eval(_sample, interaction.isotropic);
70+
}
6771

68-
template<typename T NBL_FUNC_REQUIRES(is_same_v<T, vector2_type>)
69-
sample_type generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const T u)
72+
template<typename C=bool_constant<!IsBSDF> >
73+
enable_if_t<C::value && !IsBSDF, sample_type> generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector2_type u)
7074
{
7175
ray_dir_info_type L;
7276
L.direction = sampling::ProjectedHemisphere<scalar_type>::generate(u);
7377
return sample_type::createFromTangentSpace(L, interaction.getFromTangentSpace());
7478
}
75-
76-
template<typename T NBL_FUNC_REQUIRES(is_same_v<T, vector3_type>)
77-
sample_type generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const T u)
79+
template<typename C=bool_constant<IsBSDF> >
80+
enable_if_t<C::value && IsBSDF, sample_type> generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector3_type u)
7881
{
7982
ray_dir_info_type L;
8083
L.direction = sampling::ProjectedSphere<scalar_type>::generate(u);
8184
return sample_type::createFromTangentSpace(L, interaction.getFromTangentSpace());
8285
}
86+
template<typename C=bool_constant<!IsBSDF> >
87+
enable_if_t<C::value && !IsBSDF, sample_type> generate(NBL_CONST_REF_ARG(isotropic_interaction_type) interaction, const vector2_type u)
88+
{
89+
return generate(anisotropic_interaction_type::create(interaction), u);
90+
}
91+
template<typename C=bool_constant<IsBSDF> >
92+
enable_if_t<C::value && IsBSDF, sample_type> generate(NBL_CONST_REF_ARG(isotropic_interaction_type) interaction, const vector3_type u)
93+
{
94+
return generate(anisotropic_interaction_type::create(interaction), u);
95+
}
8396

8497
scalar_type pdf(NBL_CONST_REF_ARG(sample_type) _sample)
8598
{
@@ -102,6 +115,10 @@ struct SOrenNayarBase
102115
query.VdotL = hlsl::dot(interaction.getV().getDirection(), _sample.getL().getDirection());
103116
return __quotient_and_pdf<SQuery>(query, _sample, interaction);
104117
}
118+
quotient_pdf_type quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction)
119+
{
120+
return quotient_and_pdf(_sample, interaction.isotropic);
121+
}
105122

106123
scalar_type A2;
107124
vector2_type AB;

include/nbl/builtin/hlsl/bxdf/reflection/lambertian.hlsl

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,48 +16,8 @@ namespace bxdf
1616
namespace reflection
1717
{
1818

19-
template<class Config NBL_PRIMARY_REQUIRES(config_concepts::BasicConfiguration<Config>)
20-
struct SLambertian
21-
{
22-
using this_t = SLambertian<Config>;
23-
BXDF_CONFIG_TYPE_ALIASES(Config);
24-
25-
NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = BxDFClampMode::BCM_MAX;
26-
27-
spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
28-
{
29-
return __base.eval(_sample, interaction);
30-
}
31-
spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction)
32-
{
33-
return __base.eval(_sample, interaction.isotropic);
34-
}
35-
36-
sample_type generate(NBL_CONST_REF_ARG(isotropic_interaction_type) interaction, const vector2_type u)
37-
{
38-
return __base.template generate<vector2_type>(anisotropic_interaction_type::create(interaction), u);
39-
}
40-
sample_type generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector2_type u)
41-
{
42-
return __base.template generate<vector2_type>(interaction, u);
43-
}
44-
45-
scalar_type pdf(NBL_CONST_REF_ARG(sample_type) _sample)
46-
{
47-
return __base.pdf(_sample);
48-
}
49-
50-
quotient_pdf_type quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
51-
{
52-
return __base.quotient_and_pdf(_sample, interaction);
53-
}
54-
quotient_pdf_type quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction)
55-
{
56-
return __base.quotient_and_pdf(_sample, interaction.isotropic);
57-
}
58-
59-
base::SLambertianBase<Config, false> __base;
60-
};
19+
template<class Config>
20+
using SLambertian = base::SLambertianBase<Config, false>;
6121

6222
}
6323

include/nbl/builtin/hlsl/bxdf/reflection/oren_nayar.hlsl

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,58 +16,8 @@ namespace bxdf
1616
namespace reflection
1717
{
1818

19-
template<class Config NBL_PRIMARY_REQUIRES(config_concepts::BasicConfiguration<Config>)
20-
struct SOrenNayar
21-
{
22-
using this_t = SOrenNayar<Config>;
23-
BXDF_CONFIG_TYPE_ALIASES(Config);
24-
25-
NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = BxDFClampMode::BCM_MAX;
26-
27-
using base_type = base::SOrenNayarBase<Config, false>;
28-
using creation_type = typename base_type::creation_type;
29-
30-
static this_t create(NBL_CONST_REF_ARG(creation_type) params)
31-
{
32-
this_t retval;
33-
retval.__base = base_type::create(params);
34-
return retval;
35-
}
36-
37-
spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
38-
{
39-
return __base.eval(_sample, interaction);
40-
}
41-
spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction)
42-
{
43-
return __base.eval(_sample, interaction.isotropic);
44-
}
45-
46-
sample_type generate(NBL_CONST_REF_ARG(isotropic_interaction_type) interaction, const vector2_type u)
47-
{
48-
return __base.template generate<vector2_type>(anisotropic_interaction_type::create(interaction), u);
49-
}
50-
sample_type generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector2_type u)
51-
{
52-
return __base.template generate<vector2_type>(interaction, u);
53-
}
54-
55-
scalar_type pdf(NBL_CONST_REF_ARG(sample_type) _sample)
56-
{
57-
return __base.pdf(_sample);
58-
}
59-
60-
quotient_pdf_type quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
61-
{
62-
return __base.quotient_and_pdf(_sample, interaction);
63-
}
64-
quotient_pdf_type quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction)
65-
{
66-
return __base.quotient_and_pdf(_sample, interaction.isotropic);
67-
}
68-
69-
base_type __base;
70-
};
19+
template<class Config>
20+
using SOrenNayar = base::SOrenNayarBase<Config, false>;
7121

7222
}
7323

include/nbl/builtin/hlsl/bxdf/transmission/lambertian.hlsl

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,48 +16,8 @@ namespace bxdf
1616
namespace transmission
1717
{
1818

19-
template<class Config NBL_PRIMARY_REQUIRES(config_concepts::BasicConfiguration<Config>)
20-
struct SLambertian
21-
{
22-
using this_t = SLambertian<Config>;
23-
BXDF_CONFIG_TYPE_ALIASES(Config);
24-
25-
NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = BxDFClampMode::BCM_ABS;
26-
27-
spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
28-
{
29-
return __base.eval(_sample, interaction);
30-
}
31-
spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction)
32-
{
33-
return __base.eval(_sample, interaction.isotropic);
34-
}
35-
36-
sample_type generate(NBL_CONST_REF_ARG(isotropic_interaction_type) interaction, const vector3_type u)
37-
{
38-
return __base.template generate<vector3_type>(anisotropic_interaction_type::create(interaction), u);
39-
}
40-
sample_type generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector3_type u)
41-
{
42-
return __base.template generate<vector3_type>(interaction, u);
43-
}
44-
45-
scalar_type pdf(NBL_CONST_REF_ARG(sample_type) _sample)
46-
{
47-
return __base.pdf(_sample);
48-
}
49-
50-
quotient_pdf_type quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
51-
{
52-
return __base.quotient_and_pdf(_sample, interaction);
53-
}
54-
quotient_pdf_type quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction)
55-
{
56-
return __base.quotient_and_pdf(_sample, interaction.isotropic);
57-
}
58-
59-
base::SLambertianBase<Config, true> __base;
60-
};
19+
template<class Config>
20+
using SLambertian = base::SLambertianBase<Config, true>;
6121

6222
}
6323

include/nbl/builtin/hlsl/bxdf/transmission/oren_nayar.hlsl

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,58 +16,8 @@ namespace bxdf
1616
namespace transmission
1717
{
1818

19-
template<class Config NBL_PRIMARY_REQUIRES(config_concepts::BasicConfiguration<Config>)
20-
struct SOrenNayar
21-
{
22-
using this_t = SOrenNayar<Config>;
23-
BXDF_CONFIG_TYPE_ALIASES(Config);
24-
25-
NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = BxDFClampMode::BCM_ABS;
26-
27-
using base_type = base::SOrenNayarBase<Config, false>;
28-
using creation_type = typename base_type::creation_type;
29-
30-
static this_t create(NBL_CONST_REF_ARG(creation_type) params)
31-
{
32-
this_t retval;
33-
retval.__base = base_type::create(params);
34-
return retval;
35-
}
36-
37-
spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
38-
{
39-
return __base.eval(_sample, interaction);
40-
}
41-
spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction)
42-
{
43-
return __base.eval(_sample, interaction.isotropic);
44-
}
45-
46-
sample_type generate(NBL_CONST_REF_ARG(isotropic_interaction_type) interaction, const vector3_type u)
47-
{
48-
return __base.template generate<vector3_type>(anisotropic_interaction_type::create(interaction), u);
49-
}
50-
sample_type generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector3_type u)
51-
{
52-
return __base.template generate<vector3_type>(interaction, u);
53-
}
54-
55-
scalar_type pdf(NBL_CONST_REF_ARG(sample_type) _sample)
56-
{
57-
return __base.pdf(_sample);
58-
}
59-
60-
quotient_pdf_type quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
61-
{
62-
return __base.quotient_and_pdf(_sample, interaction);
63-
}
64-
quotient_pdf_type quotient_and_pdf(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction)
65-
{
66-
return __base.quotient_and_pdf(_sample, interaction.isotropic);
67-
}
68-
69-
base_type __base;
70-
};
19+
template<class Config>
20+
using SOrenNayar = base::SOrenNayarBase<Config, true>;
7121

7222
}
7323

0 commit comments

Comments
 (0)