Skip to content

Commit 011fbfb

Browse files
committed
simplified material data
1 parent 1eee3ca commit 011fbfb

File tree

4 files changed

+49
-48
lines changed

4 files changed

+49
-48
lines changed

31_HLSLPathTracer/app_resources/hlsl/material_system.hlsl

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,27 @@ namespace ext
1414
namespace MaterialSystem
1515
{
1616

17-
struct Material
18-
{
19-
enum Type : uint32_t // enum class?
20-
{
21-
DIFFUSE,
22-
CONDUCTOR,
23-
DIELECTRIC
24-
};
17+
// struct Material
18+
// {
19+
// enum Type : uint32_t // enum class?
20+
// {
21+
// DIFFUSE,
22+
// CONDUCTOR,
23+
// DIELECTRIC
24+
// };
2525

26-
NBL_CONSTEXPR_STATIC_INLINE uint32_t DataSize = 1;
26+
// NBL_CONSTEXPR_STATIC_INLINE uint32_t DataSize = 1;
2727

28-
uint32_t type : 2;
29-
uint32_t unused : 30; // possible space for flags
30-
uint32_t data[DataSize];
28+
// uint32_t type : 2;
29+
// uint32_t unused : 30; // possible space for flags
30+
// uint32_t data[DataSize];
31+
// };
32+
33+
enum MaterialType : uint32_t // enum class?
34+
{
35+
DIFFUSE,
36+
CONDUCTOR,
37+
DIELECTRIC
3138
};
3239

3340
template<class DiffuseBxDF, class ConductorBxDF, class DielectricBxDF> // NOTE: these bxdfs should match the ones in Scene BxDFNode
@@ -59,23 +66,23 @@ struct System
5966
return retval;
6067
}
6168

62-
measure_type eval(NBL_CONST_REF_ARG(Material) material, NBL_CONST_REF_ARG(create_params_t) cparams, NBL_CONST_REF_ARG(params_t) params)
69+
measure_type eval(uint32_t material, NBL_CONST_REF_ARG(create_params_t) cparams, NBL_CONST_REF_ARG(params_t) params)
6370
{
64-
switch(material.type)
71+
switch(material)
6572
{
66-
case Material::Type::DIFFUSE:
73+
case MaterialType::DIFFUSE:
6774
{
6875
diffuseBxDF.init(cparams);
6976
return (measure_type)diffuseBxDF.eval(params);
7077
}
7178
break;
72-
case Material::Type::CONDUCTOR:
79+
case MaterialType::CONDUCTOR:
7380
{
7481
conductorBxDF.init(cparams);
7582
return conductorBxDF.eval(params);
7683
}
7784
break;
78-
case Material::Type::DIELECTRIC:
85+
case MaterialType::DIELECTRIC:
7986
{
8087
dielectricBxDF.init(cparams);
8188
return dielectricBxDF.eval(params);
@@ -86,23 +93,23 @@ struct System
8693
}
8794
}
8895

89-
sample_type generate(NBL_CONST_REF_ARG(Material) material, NBL_CONST_REF_ARG(create_params_t) cparams, NBL_CONST_REF_ARG(anisotropic_type) interaction, NBL_CONST_REF_ARG(vector3_type) u, NBL_REF_ARG(anisocache_type) _cache)
96+
sample_type generate(uint32_t material, NBL_CONST_REF_ARG(create_params_t) cparams, NBL_CONST_REF_ARG(anisotropic_type) interaction, NBL_CONST_REF_ARG(vector3_type) u, NBL_REF_ARG(anisocache_type) _cache)
9097
{
91-
switch(material.type)
98+
switch(material)
9299
{
93-
case Material::Type::DIFFUSE:
100+
case MaterialType::DIFFUSE:
94101
{
95102
diffuseBxDF.init(cparams);
96103
return diffuseBxDF.generate(interaction, u.xy);
97104
}
98105
break;
99-
case Material::Type::CONDUCTOR:
106+
case MaterialType::CONDUCTOR:
100107
{
101108
conductorBxDF.init(cparams);
102109
return conductorBxDF.generate(interaction, u.xy, _cache);
103110
}
104111
break;
105-
case Material::Type::DIELECTRIC:
112+
case MaterialType::DIELECTRIC:
106113
{
107114
dielectricBxDF.init(cparams);
108115
return dielectricBxDF.generate(interaction, u, _cache);
@@ -121,26 +128,26 @@ struct System
121128
return sample_type::create(L, 0, (vector3_type)0);
122129
}
123130

124-
quotient_pdf_type quotient_and_pdf(NBL_CONST_REF_ARG(Material) material, NBL_CONST_REF_ARG(create_params_t) cparams, NBL_CONST_REF_ARG(params_t) params)
131+
quotient_pdf_type quotient_and_pdf(uint32_t material, NBL_CONST_REF_ARG(create_params_t) cparams, NBL_CONST_REF_ARG(params_t) params)
125132
{
126133
const float minimumProjVectorLen = 0.00000001;
127134
if (params.NdotV > minimumProjVectorLen && params.NdotL > minimumProjVectorLen)
128135
{
129-
switch(material.type)
136+
switch(material)
130137
{
131-
case Material::Type::DIFFUSE:
138+
case MaterialType::DIFFUSE:
132139
{
133140
diffuseBxDF.init(cparams);
134141
return diffuseBxDF.quotient_and_pdf(params);
135142
}
136143
break;
137-
case Material::Type::CONDUCTOR:
144+
case MaterialType::CONDUCTOR:
138145
{
139146
conductorBxDF.init(cparams);
140147
return conductorBxDF.quotient_and_pdf(params);
141148
}
142149
break;
143-
case Material::Type::DIELECTRIC:
150+
case MaterialType::DIELECTRIC:
144151
{
145152
dielectricBxDF.init(cparams);
146153
return dielectricBxDF.quotient_and_pdf(params);

31_HLSLPathTracer/app_resources/hlsl/pathtracer.hlsl

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ struct Unidirectional
150150

151151
// TODO: ifdef kill diffuse specular paths
152152

153-
const bool isBSDF = (bxdf.materialType == ext::MaterialSystem::Material::Type::DIFFUSE) ? bxdf_traits<diffuse_op_type>::type == BT_BSDF :
154-
(bxdf.materialType == ext::MaterialSystem::Material::Type::CONDUCTOR) ? bxdf_traits<conductor_op_type>::type == BT_BSDF :
153+
const bool isBSDF = (bxdf.materialType == ext::MaterialSystem::MaterialType::DIFFUSE) ? bxdf_traits<diffuse_op_type>::type == BT_BSDF :
154+
(bxdf.materialType == ext::MaterialSystem::MaterialType::CONDUCTOR) ? bxdf_traits<conductor_op_type>::type == BT_BSDF :
155155
bxdf_traits<dielectric_op_type>::type == BT_BSDF;
156156

157157
vector3_type eps0 = rand3d(depth, _sample, 0u);
@@ -193,11 +193,8 @@ struct Unidirectional
193193
ray.payload.accumulation += vector3_type(0.f, 1000.f, 0.f);
194194
else if (validPath)
195195
{
196-
ext::MaterialSystem::Material material;
197-
material.type = bxdf.materialType;
198-
199196
bxdf::BxDFClampMode _clamp;
200-
_clamp = (bxdf.materialType == ext::MaterialSystem::Material::Type::DIELECTRIC) ? bxdf::BxDFClampMode::BCM_ABS : bxdf::BxDFClampMode::BCM_MAX;
197+
_clamp = (bxdf.materialType == ext::MaterialSystem::MaterialType::DIELECTRIC) ? bxdf::BxDFClampMode::BCM_ABS : bxdf::BxDFClampMode::BCM_MAX;
201198
// example only uses isotropic bxdfs
202199
params_type params = params_type::template create<sample_type, isotropic_type, isocache_type>(nee_sample, interaction.isotropic, _cache.iso_cache, _clamp);
203200

@@ -231,7 +228,7 @@ struct Unidirectional
231228
// }
232229
// }
233230

234-
quotient_pdf_type bsdf_quotient_pdf = materialSystem.quotient_and_pdf(material, bxdf.params, params);
231+
quotient_pdf_type bsdf_quotient_pdf = materialSystem.quotient_and_pdf(bxdf.materialType, bxdf.params, params);
235232
neeContrib_pdf.quotient *= bxdf.albedo * throughput * bsdf_quotient_pdf.quotient;
236233
const scalar_type otherGenOverChoice = bsdf_quotient_pdf.pdf * rcpChoiceProb;
237234
const scalar_type otherGenOverLightAndChoice = otherGenOverChoice / bsdf_quotient_pdf.pdf;
@@ -256,14 +253,11 @@ struct Unidirectional
256253
scalar_type bxdfPdf;
257254
vector3_type bxdfSample;
258255
{
259-
ext::MaterialSystem::Material material;
260-
material.type = bxdf.materialType;
261-
262256
anisocache_type _cache;
263-
sample_type bsdf_sample = materialSystem.generate(material, bxdf.params, interaction, eps1, _cache);
257+
sample_type bsdf_sample = materialSystem.generate(bxdf.materialType, bxdf.params, interaction, eps1, _cache);
264258

265259
bxdf::BxDFClampMode _clamp;
266-
_clamp = (bxdf.materialType == ext::MaterialSystem::Material::Type::DIELECTRIC) ? bxdf::BxDFClampMode::BCM_ABS : bxdf::BxDFClampMode::BCM_MAX;
260+
_clamp = (bxdf.materialType == ext::MaterialSystem::MaterialType::DIELECTRIC) ? bxdf::BxDFClampMode::BCM_ABS : bxdf::BxDFClampMode::BCM_MAX;
267261
// example only uses isotropic bxdfs
268262
params_type params = params_type::template create<sample_type, isotropic_type, isocache_type>(bsdf_sample, interaction.isotropic, _cache.iso_cache, _clamp);
269263

@@ -299,7 +293,7 @@ struct Unidirectional
299293
// }
300294

301295
// the value of the bsdf divided by the probability of the sample being generated
302-
quotient_pdf_type bsdf_quotient_pdf = materialSystem.quotient_and_pdf(material, bxdf.params, params);
296+
quotient_pdf_type bsdf_quotient_pdf = materialSystem.quotient_and_pdf(bxdf.materialType, bxdf.params, params);
303297
throughput *= bxdf.albedo * bsdf_quotient_pdf.quotient;
304298
bxdfPdf = bsdf_quotient_pdf.pdf;
305299
bxdfSample = bsdf_sample.L.direction;

31_HLSLPathTracer/app_resources/hlsl/render.comp.hlsl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ static const light_type lights[LIGHT_COUNT] = {
108108

109109
#define BXDF_COUNT 7
110110
static const bxdfnode_type bxdfs[BXDF_COUNT] = {
111-
bxdfnode_type::create(ext::MaterialSystem::Material::Type::DIFFUSE, false, float2(0,0), spectral_t(0.8,0.8,0.8)),
112-
bxdfnode_type::create(ext::MaterialSystem::Material::Type::DIFFUSE, false, float2(0,0), spectral_t(0.8,0.4,0.4)),
113-
bxdfnode_type::create(ext::MaterialSystem::Material::Type::DIFFUSE, false, float2(0,0), spectral_t(0.4,0.8,0.4)),
114-
bxdfnode_type::create(ext::MaterialSystem::Material::Type::CONDUCTOR, false, float2(0,0), spectral_t(1,1,1), spectral_t(0.98,0.98,0.77)),
115-
bxdfnode_type::create(ext::MaterialSystem::Material::Type::CONDUCTOR, false, float2(0,0), spectral_t(1,1,1), spectral_t(0.98,0.77,0.98)),
116-
bxdfnode_type::create(ext::MaterialSystem::Material::Type::CONDUCTOR, false, float2(0.15,0.15), spectral_t(1,1,1), spectral_t(0.98,0.77,0.98)),
117-
bxdfnode_type::create(ext::MaterialSystem::Material::Type::DIELECTRIC, false, float2(0.0625,0.0625), spectral_t(1,1,1), spectral_t(0.71,0.69,0.67))
111+
bxdfnode_type::create(ext::MaterialSystem::MaterialType::DIFFUSE, false, float2(0,0), spectral_t(0.8,0.8,0.8)),
112+
bxdfnode_type::create(ext::MaterialSystem::MaterialType::DIFFUSE, false, float2(0,0), spectral_t(0.8,0.4,0.4)),
113+
bxdfnode_type::create(ext::MaterialSystem::MaterialType::DIFFUSE, false, float2(0,0), spectral_t(0.4,0.8,0.4)),
114+
bxdfnode_type::create(ext::MaterialSystem::MaterialType::CONDUCTOR, false, float2(0,0), spectral_t(1,1,1), spectral_t(0.98,0.98,0.77)),
115+
bxdfnode_type::create(ext::MaterialSystem::MaterialType::CONDUCTOR, false, float2(0,0), spectral_t(1,1,1), spectral_t(0.98,0.77,0.98)),
116+
bxdfnode_type::create(ext::MaterialSystem::MaterialType::CONDUCTOR, false, float2(0.15,0.15), spectral_t(1,1,1), spectral_t(0.98,0.77,0.98)),
117+
bxdfnode_type::create(ext::MaterialSystem::MaterialType::DIELECTRIC, false, float2(0.0625,0.0625), spectral_t(1,1,1), spectral_t(0.71,0.69,0.67))
118118
};
119119

120120
[numthreads(WorkgroupSize, WorkgroupSize, 1)]

31_HLSLPathTracer/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ class HLSLComputePathtracer final : public examples::SimpleWindowedApplication,
13501350
int PTPipline = E_LIGHT_GEOMETRY::ELG_SPHERE;
13511351
int renderMode = E_RENDER_MODE::ERM_HLSL;
13521352
int spp = 32;
1353-
int depth = 1;
1353+
int depth = 3;
13541354

13551355
bool m_firstFrame = true;
13561356
IGPUCommandBuffer::SClearColorValue clearColor = { .float32 = {0.f,0.f,0.f,1.f} };

0 commit comments

Comments
 (0)