Skip to content

Commit a0dbcc2

Browse files
committed
added macro for bxdf type aliases
1 parent 68c8123 commit a0dbcc2

File tree

7 files changed

+38
-64
lines changed

7 files changed

+38
-64
lines changed

include/nbl/builtin/hlsl/bxdf/config.hlsl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ struct SMicrofacetConfiguration<LS,Interaction,MicrofacetCache,Spectrum NBL_PART
139139

140140
#define NBL_BXDF_CONFIG_ALIAS(TYPE,CONFIG) using TYPE = typename CONFIG::TYPE
141141

142+
143+
#define BXDF_CONFIG_TYPE_ALIASES(Config) NBL_BXDF_CONFIG_ALIAS(scalar_type, Config);\
144+
NBL_BXDF_CONFIG_ALIAS(vector2_type, Config);\
145+
NBL_BXDF_CONFIG_ALIAS(vector3_type, Config);\
146+
NBL_BXDF_CONFIG_ALIAS(monochrome_type, Config);\
147+
NBL_BXDF_CONFIG_ALIAS(ray_dir_info_type, Config);\
148+
NBL_BXDF_CONFIG_ALIAS(isotropic_interaction_type, Config);\
149+
NBL_BXDF_CONFIG_ALIAS(anisotropic_interaction_type, Config);\
150+
NBL_BXDF_CONFIG_ALIAS(sample_type, Config);\
151+
NBL_BXDF_CONFIG_ALIAS(spectral_type, Config);\
152+
NBL_BXDF_CONFIG_ALIAS(quotient_pdf_type, Config);\
153+
154+
#define MICROFACET_BXDF_CONFIG_TYPE_ALIASES(Config) BXDF_CONFIG_TYPE_ALIASES(Config);\
155+
NBL_BXDF_CONFIG_ALIAS(matrix3x3_type, Config);\
156+
NBL_BXDF_CONFIG_ALIAS(isocache_type, Config);\
157+
NBL_BXDF_CONFIG_ALIAS(anisocache_type, Config);\
158+
142159
}
143160
}
144161
}

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,7 @@ template<class Config NBL_PRIMARY_REQUIRES(config_concepts::BasicConfiguration<C
2121
struct SDeltaDistribution
2222
{
2323
using this_t = SDeltaDistribution<Config>;
24-
NBL_BXDF_CONFIG_ALIAS(scalar_type, Config);
25-
NBL_BXDF_CONFIG_ALIAS(vector2_type, Config);
26-
NBL_BXDF_CONFIG_ALIAS(ray_dir_info_type, Config);
27-
NBL_BXDF_CONFIG_ALIAS(isotropic_interaction_type, Config);
28-
NBL_BXDF_CONFIG_ALIAS(anisotropic_interaction_type, Config);
29-
NBL_BXDF_CONFIG_ALIAS(sample_type, Config);
30-
NBL_BXDF_CONFIG_ALIAS(spectral_type, Config);
31-
NBL_BXDF_CONFIG_ALIAS(monochrome_type, Config);
32-
NBL_BXDF_CONFIG_ALIAS(quotient_pdf_type, Config);
24+
BXDF_CONFIG_TYPE_ALIASES(Config);
3325

3426
NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = BxDFClampMode::BCM_MAX;
3527

@@ -44,9 +36,15 @@ struct SDeltaDistribution
4436

4537
sample_type generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector2_type u)
4638
{
47-
bxdf::Reflect<scalar_type> r = bxdf::Reflect<scalar_type>::create(interaction.getV().getDirection(), interaction.getN());
39+
vector3_type V = interaction.getV().getDirection();
40+
bxdf::Reflect<scalar_type> r = bxdf::Reflect<scalar_type>::create(V, interaction.getN());
4841
ray_dir_info_type L = interaction.getV().reflect(r);
49-
return sample_type::createFromTangentSpace(L, interaction.getFromTangentSpace());
42+
sample_type s = sample_type::create(L, interaction.getN());
43+
s.TdotL = -hlsl::dot(V,L.getDirection());
44+
s.BdotL = -hlsl::dot(V,interaction.getB());
45+
s.NdotL = interaction.getNdotV();
46+
s.NdotL2 = interaction.getNdotV2();
47+
return s;
5048
}
5149

5250
sample_type generate(NBL_CONST_REF_ARG(isotropic_interaction_type) interaction, const vector2_type u)

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,7 @@ template<class Config NBL_PRIMARY_REQUIRES(config_concepts::BasicConfiguration<C
2222
struct SLambertian
2323
{
2424
using this_t = SLambertian<Config>;
25-
NBL_BXDF_CONFIG_ALIAS(scalar_type, Config);
26-
NBL_BXDF_CONFIG_ALIAS(vector2_type, Config);
27-
NBL_BXDF_CONFIG_ALIAS(ray_dir_info_type, Config);
28-
NBL_BXDF_CONFIG_ALIAS(isotropic_interaction_type, Config);
29-
NBL_BXDF_CONFIG_ALIAS(anisotropic_interaction_type, Config);
30-
NBL_BXDF_CONFIG_ALIAS(sample_type, Config);
31-
NBL_BXDF_CONFIG_ALIAS(spectral_type, Config);
32-
NBL_BXDF_CONFIG_ALIAS(monochrome_type, Config);
33-
NBL_BXDF_CONFIG_ALIAS(quotient_pdf_type, Config);
25+
BXDF_CONFIG_TYPE_ALIASES(Config);
3426

3527
NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = BxDFClampMode::BCM_MAX;
3628

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,7 @@ template<class Config NBL_PRIMARY_REQUIRES(config_concepts::BasicConfiguration<C
2222
struct SOrenNayar
2323
{
2424
using this_t = SOrenNayar<Config>;
25-
NBL_BXDF_CONFIG_ALIAS(scalar_type, Config);
26-
NBL_BXDF_CONFIG_ALIAS(vector2_type, Config);
27-
NBL_BXDF_CONFIG_ALIAS(ray_dir_info_type, Config);
28-
NBL_BXDF_CONFIG_ALIAS(isotropic_interaction_type, Config);
29-
NBL_BXDF_CONFIG_ALIAS(anisotropic_interaction_type, Config);
30-
NBL_BXDF_CONFIG_ALIAS(sample_type, Config);
31-
NBL_BXDF_CONFIG_ALIAS(spectral_type, Config);
32-
NBL_BXDF_CONFIG_ALIAS(quotient_pdf_type, Config);
25+
BXDF_CONFIG_TYPE_ALIASES(Config);
3326

3427
NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = BxDFClampMode::BCM_MAX;
3528

@@ -48,7 +41,6 @@ struct SOrenNayar
4841
static this_t create(scalar_type A)
4942
{
5043
this_t retval;
51-
retval.A = A;
5244
retval.A2 = A * 0.5;
5345
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);
5446
return retval;
@@ -117,7 +109,6 @@ struct SOrenNayar
117109
return quotient_and_pdf(_sample, interaction.isotropic);
118110
}
119111

120-
scalar_type A;
121112
scalar_type A2;
122113
vector2_type AB;
123114
};

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,9 @@ template<class Config NBL_PRIMARY_REQUIRES(config_concepts::BasicConfiguration<C
2121
struct SDeltaDistribution
2222
{
2323
using this_t = SDeltaDistribution<Config>;
24-
NBL_BXDF_CONFIG_ALIAS(scalar_type, Config);
25-
NBL_BXDF_CONFIG_ALIAS(vector2_type, Config);
26-
NBL_BXDF_CONFIG_ALIAS(ray_dir_info_type, Config);
27-
NBL_BXDF_CONFIG_ALIAS(isotropic_interaction_type, Config);
28-
NBL_BXDF_CONFIG_ALIAS(anisotropic_interaction_type, Config);
29-
NBL_BXDF_CONFIG_ALIAS(sample_type, Config);
30-
NBL_BXDF_CONFIG_ALIAS(spectral_type, Config);
31-
NBL_BXDF_CONFIG_ALIAS(monochrome_type, Config);
32-
NBL_BXDF_CONFIG_ALIAS(quotient_pdf_type, Config);
24+
BXDF_CONFIG_TYPE_ALIASES(Config);
3325

34-
NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = BxDFClampMode::BCM_MAX;
26+
NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = BxDFClampMode::BCM_ABS;
3527

3628
spectral_type eval(NBL_CONST_REF_ARG(sample_type) _sample, NBL_CONST_REF_ARG(isotropic_interaction_type) interaction)
3729
{
@@ -45,7 +37,12 @@ struct SDeltaDistribution
4537
sample_type generate(NBL_CONST_REF_ARG(anisotropic_interaction_type) interaction, const vector2_type u)
4638
{
4739
ray_dir_info_type L = interaction.getV().transmit();
48-
return sample_type::createFromTangentSpace(L, interaction.getFromTangentSpace());
40+
sample_type s = sample_type::create(L, interaction.getN());
41+
s.TdotL = hlsl::dot(L.getDirection(),interaction.getT());
42+
s.BdotL = hlsl::dot(L.getDirection(),interaction.getB());
43+
s.NdotL = -interaction.getNdotV();
44+
s.NdotL2 = interaction.getNdotV2();
45+
return s;
4946
}
5047

5148
sample_type generate(NBL_CONST_REF_ARG(isotropic_interaction_type) interaction, const vector2_type u)

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,7 @@ template<class Config NBL_PRIMARY_REQUIRES(config_concepts::BasicConfiguration<C
2323
struct SLambertian
2424
{
2525
using this_t = SLambertian<Config>;
26-
NBL_BXDF_CONFIG_ALIAS(scalar_type, Config);
27-
NBL_BXDF_CONFIG_ALIAS(vector3_type, Config);
28-
NBL_BXDF_CONFIG_ALIAS(ray_dir_info_type, Config);
29-
NBL_BXDF_CONFIG_ALIAS(isotropic_interaction_type, Config);
30-
NBL_BXDF_CONFIG_ALIAS(anisotropic_interaction_type, Config);
31-
NBL_BXDF_CONFIG_ALIAS(sample_type, Config);
32-
NBL_BXDF_CONFIG_ALIAS(spectral_type, Config);
33-
NBL_BXDF_CONFIG_ALIAS(monochrome_type, Config);
34-
NBL_BXDF_CONFIG_ALIAS(quotient_pdf_type, Config);
26+
BXDF_CONFIG_TYPE_ALIASES(Config);
3527

3628
NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = BxDFClampMode::BCM_ABS;
3729

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,7 @@ template<class Config NBL_PRIMARY_REQUIRES(config_concepts::BasicConfiguration<C
2222
struct SOrenNayar
2323
{
2424
using this_t = SOrenNayar<Config>;
25-
NBL_BXDF_CONFIG_ALIAS(scalar_type, Config);
26-
NBL_BXDF_CONFIG_ALIAS(vector2_type, Config);
27-
NBL_BXDF_CONFIG_ALIAS(vector3_type, Config);
28-
NBL_BXDF_CONFIG_ALIAS(ray_dir_info_type, Config);
29-
NBL_BXDF_CONFIG_ALIAS(isotropic_interaction_type, Config);
30-
NBL_BXDF_CONFIG_ALIAS(anisotropic_interaction_type, Config);
31-
NBL_BXDF_CONFIG_ALIAS(sample_type, Config);
32-
NBL_BXDF_CONFIG_ALIAS(spectral_type, Config);
33-
NBL_BXDF_CONFIG_ALIAS(monochrome_type, Config);
34-
NBL_BXDF_CONFIG_ALIAS(quotient_pdf_type, Config);
25+
BXDF_CONFIG_TYPE_ALIASES(Config);
3526

3627
NBL_CONSTEXPR_STATIC_INLINE BxDFClampMode _clamp = BxDFClampMode::BCM_ABS;
3728

@@ -50,7 +41,6 @@ struct SOrenNayar
5041
static this_t create(scalar_type A)
5142
{
5243
this_t retval;
53-
retval.A = A;
5444
retval.A2 = A * 0.5;
5545
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);
5646
return retval;
@@ -62,8 +52,6 @@ struct SOrenNayar
6252

6353
scalar_type __rec_pi_factored_out_wo_clamps(scalar_type VdotL, scalar_type maxNdotL, scalar_type maxNdotV)
6454
{
65-
scalar_type A2 = A * 0.5;
66-
vector2_type AB = vector2_type(1.0, 0.0) + vector2_type(-0.5, 0.45) * vector2_type(A2, A2) / vector2_type(A2 + 0.33, A2 + 0.09);
6755
scalar_type C = 1.0 / max<scalar_type>(maxNdotL, maxNdotV);
6856

6957
scalar_type cos_phi_sin_theta = max<scalar_type>(VdotL - maxNdotL * maxNdotV, 0.0);
@@ -121,7 +109,6 @@ struct SOrenNayar
121109
return quotient_and_pdf(_sample, interaction.isotropic);
122110
}
123111

124-
scalar_type A;
125112
scalar_type A2;
126113
vector2_type AB;
127114
};

0 commit comments

Comments
 (0)