Skip to content

Commit cb5662a

Browse files
committed
fix bugs again
1 parent b1831d9 commit cb5662a

File tree

5 files changed

+38
-19
lines changed

5 files changed

+38
-19
lines changed

31_HLSLPathTracer/app_resources/hlsl/common.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct Ray
6666
// immutable
6767
vector3_type origin;
6868
vector3_type direction;
69-
69+
7070
// TODO: polygon method == 2 stuff
7171
vector3_type normalAtOrigin;
7272
bool wasBSDFAtOrigin;
@@ -417,7 +417,7 @@ struct Shape<PST_TRIANGLE>
417417
shapes::SphericalTriangle<float> st = shapes::SphericalTriangle<float>::create(vertex0, vertex1, vertex2, origin);
418418
sampling::ProjectedSphericalTriangle<float> sst = sampling::ProjectedSphericalTriangle<float>::create(st);
419419

420-
const float32_t3 L = sst.generate(rcpPdf, interaction.N, isBSDF, xi.xy);
420+
const float32_t3 L = sst.generate(rcpPdf, interaction.isotropic.N, isBSDF, xi.xy);
421421

422422
pdf = rcpPdf > numeric_limits<float>::min ? (1.0 / rcpPdf) : 0.0;
423423

31_HLSLPathTracer/app_resources/hlsl/material_system.hlsl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct System
3939
using vector3_type = vector<scalar_type, 3>;
4040
using measure_type = typename DiffuseBxDF::spectral_type;
4141
using sample_type = typename DiffuseBxDF::sample_type;
42+
using ray_dir_info_type = typename sample_type::ray_dir_info_type;
4243
using quotient_pdf_type = typename DiffuseBxDF::quotient_pdf_type;
4344
using anisotropic_type = typename DiffuseBxDF::anisotropic_type;
4445
using anisocache_type = typename ConductorBxDF::anisocache_type;
@@ -85,7 +86,7 @@ struct System
8586
}
8687
}
8788

88-
sample_type generate(NBL_CONST_REF_ARG(Material) material, NBL_CONST_REF_ARG(create_params_t) cparams, anisotropic_type interaction, NBL_CONST_REF_ARG(vector3_type) u, NBL_REF_ARG(anisocache_type) cache)
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)
8990
{
9091
switch(material.type)
9192
{
@@ -98,18 +99,26 @@ struct System
9899
case Material::Type::CONDUCTOR:
99100
{
100101
conductorBxDF.init(cparams);
101-
return conductorBxDF.generate(interaction, u.xy, cache);
102+
return conductorBxDF.generate(interaction, u.xy, _cache);
102103
}
103104
break;
104105
case Material::Type::DIELECTRIC:
105106
{
106107
dielectricBxDF.init(cparams);
107-
return dielectricBxDF.generate(interaction, u, cache);
108+
return dielectricBxDF.generate(interaction, u, _cache);
108109
}
109110
break;
110111
default:
111-
return (sample_type)numeric_limits<float>::infinity;
112+
{
113+
ray_dir_info_type L;
114+
L.direction = (vector3_type)0;
115+
return sample_type::create(L, 0, (vector3_type)0);
116+
}
112117
}
118+
119+
ray_dir_info_type L;
120+
L.direction = (vector3_type)0;
121+
return sample_type::create(L, 0, (vector3_type)0);
113122
}
114123

115124
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)

31_HLSLPathTracer/app_resources/hlsl/next_event_estimator.hlsl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct Estimator
2323
using interaction_type = Aniso;
2424
using quotient_pdf_type = bxdf::quotient_and_pdf<spectral_type, scalar_type>;
2525
using sample_type = LightSample;
26+
using ray_dir_info_type = typename sample_type::ray_dir_info_type;
2627

2728
static spectral_type proceduralDeferredEvalAndPdf(NBL_REF_ARG(scalar_type) pdf, NBL_CONST_REF_ARG(light_type) light, NBL_CONST_REF_ARG(ray_type) ray, NBL_CONST_REF_ARG(Event) event)
2829
{
@@ -88,6 +89,7 @@ struct Estimator
8889
default:
8990
return (spectral_type)0.0;
9091
}
92+
return (spectral_type)0.0;
9193
}
9294

9395
static sample_type procedural_generate_and_quotient_and_pdf(NBL_REF_ARG(quotient_pdf_type) quotient_pdf, NBL_REF_ARG(scalar_type) newRayMaxT, NBL_CONST_REF_ARG(light_type) light, NBL_CONST_REF_ARG(vector3_type) origin, NBL_CONST_REF_ARG(interaction_type) interaction, bool isBSDF, NBL_CONST_REF_ARG(vector3_type) xi, uint32_t depth, NBL_CONST_REF_ARG(Event) event)
@@ -104,9 +106,11 @@ struct Estimator
104106
vector3_type position = vector3_type(asfloat(event.data[2]), asfloat(event.data[3]), asfloat(event.data[4]));
105107
Shape<PST_SPHERE> sphere = Shape<PST_SPHERE>::create(position, asfloat(event.data[5]), event.data[6]);
106108
const vector3_type sampleL = sphere.template generate_and_pdf<interaction_type>(pdf, newRayMaxT, origin, interaction, isBSDF, xi);
107-
const vector3_type V = interaction.V.getDirection();
109+
const vector3_type V = interaction.isotropic.V.getDirection();
108110
const scalar_type VdotL = nbl::hlsl::dot<vector3_type>(V, sampleL);
109-
L = sample_type::create(sampleL,VdotL,interaction.T,interaction.B,interaction.N);
111+
ray_dir_info_type rayL;
112+
rayL.direction = sampleL;
113+
L = sample_type::create(rayL,VdotL,interaction.T,interaction.B,interaction.isotropic.N);
110114
}
111115
break;
112116
case PST_TRIANGLE:
@@ -116,9 +120,11 @@ struct Estimator
116120
vector3_type vertex2 = vector3_type(asfloat(event.data[8]), asfloat(event.data[9]), asfloat(event.data[10]));
117121
Shape<PST_TRIANGLE> tri = Shape<PST_TRIANGLE>::create(vertex0, vertex1, vertex2, event.data[11]);
118122
const vector3_type sampleL = tri.template generate_and_pdf<interaction_type>(pdf, newRayMaxT, origin, interaction, isBSDF, xi);
119-
const vector3_type V = interaction.V.getDirection();
123+
const vector3_type V = interaction.isotropic.V.getDirection();
120124
const scalar_type VdotL = nbl::hlsl::dot<vector3_type>(V, sampleL);
121-
L = sample_type::create(sampleL,VdotL,interaction.T,interaction.B,interaction.N);
125+
ray_dir_info_type rayL;
126+
rayL.direction = sampleL;
127+
L = sample_type::create(rayL,VdotL,interaction.T,interaction.B,interaction.isotropic.N);
122128
}
123129
break;
124130
case PST_RECTANGLE:
@@ -128,9 +134,11 @@ struct Estimator
128134
vector3_type edge1 = vector3_type(asfloat(event.data[8]), asfloat(event.data[9]), asfloat(event.data[10]));
129135
Shape<PST_RECTANGLE> rect = Shape<PST_RECTANGLE>::create(offset, edge0, edge1, event.data[11]);
130136
const vector3_type sampleL = rect.template generate_and_pdf<interaction_type>(pdf, newRayMaxT, origin, interaction, isBSDF, xi);
131-
const vector3_type V = interaction.V.getDirection();
137+
const vector3_type V = interaction.isotropic.V.getDirection();
132138
const scalar_type VdotL = nbl::hlsl::dot<vector3_type>(V, sampleL);
133-
L = sample_type::create(sampleL,VdotL,interaction.T,interaction.B,interaction.N);
139+
ray_dir_info_type rayL;
140+
rayL.direction = sampleL;
141+
L = sample_type::create(rayL,VdotL,interaction.T,interaction.B,interaction.isotropic.N);
134142
}
135143
break;
136144
default:
@@ -149,6 +157,7 @@ struct Estimator
149157
static sample_type generate_and_quotient_and_pdf(NBL_REF_ARG(quotient_pdf_type) quotient_pdf, NBL_REF_ARG(scalar_type) newRayMaxT, NBL_CONST_REF_ARG(light_type) light, NBL_CONST_REF_ARG(vector3_type) origin, NBL_CONST_REF_ARG(interaction_type) interaction, bool isBSDF, NBL_CONST_REF_ARG(vector3_type) xi, uint32_t depth, NBL_CONST_REF_ARG(Event) event)
150158
{
151159
const Event::Mode mode = (Event::Mode)event.mode;
160+
sample_type L;
152161
switch (mode)
153162
{
154163
case Event::Mode::RAY_QUERY:
@@ -168,10 +177,10 @@ struct Estimator
168177
break;
169178
default:
170179
{
171-
sample_type L;
172180
return L;
173181
}
174182
}
183+
return L;
175184
}
176185
};
177186

31_HLSLPathTracer/app_resources/hlsl/pathtracer.hlsl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct Unidirectional
5454
using vector3_type = vector<scalar_type, 3>;
5555
using measure_type = typename MaterialSystem::measure_type;
5656
using sample_type = typename NextEventEstimator::sample_type;
57+
using ray_dir_info_type = typename sample_type::ray_dir_info_type;
5758
using ray_type = typename RayGen::ray_type;
5859
using light_type = Light<measure_type>;
5960
using bxdfnode_type = BxDFNode<measure_type>;
@@ -181,7 +182,7 @@ struct Unidirectional
181182
bool validPath = nee_sample.NdotL > numeric_limits<scalar_type>::min;
182183
// but if we allowed non-watertight transmitters (single water surface), it would make sense just to apply this line by itself
183184
anisocache_type _cache;
184-
validPath = validPath && anisocache_type::compute(_cache, interaction, nee_sample, monochromeEta);
185+
validPath = validPath && anisocache_type::template compute<ray_dir_info_type, ray_dir_info_type>(_cache, interaction, nee_sample, monochromeEta);
185186
bxdf.params.A = nbl::hlsl::max(bxdf.params.A, vector<scalar_type, 2>(0,0));
186187
bxdf.params.eta = monochromeEta;
187188

@@ -268,7 +269,7 @@ struct Unidirectional
268269
params = params_type::template create<sample_type, anisotropic_type, anisocache_type>(bsdf_sample, interaction, _cache, bxdf::BCM_MAX);
269270
else
270271
{
271-
isocache_type isocache = (isocache_type)_cache;
272+
isocache_type isocache = _cache.iso_cache;
272273
params = params_type::template create<sample_type, isotropic_type, isocache_type>(bsdf_sample, iso_interaction, isocache, bxdf::BCM_MAX);
273274
}
274275
}
@@ -282,7 +283,7 @@ struct Unidirectional
282283
params = params_type::template create<sample_type, anisotropic_type, anisocache_type>(bsdf_sample, interaction, _cache, bxdf::BCM_ABS);
283284
else
284285
{
285-
isocache_type isocache = (isocache_type)_cache;
286+
isocache_type isocache = _cache.iso_cache;
286287
params = params_type::template create<sample_type, isotropic_type, isocache_type>(bsdf_sample, iso_interaction, isocache, bxdf::BCM_ABS);
287288
}
288289
}

31_HLSLPathTracer/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct PTPushConstant {
2323

2424
// TODO: Add a QueryPool for timestamping once its ready
2525
// TODO: Do buffer creation using assConv
26-
class ComputeShaderPathtracer final : public examples::SimpleWindowedApplication, public application_templates::MonoAssetManagerAndBuiltinResourceApplication
26+
class HLSLComputePathtracer final : public examples::SimpleWindowedApplication, public application_templates::MonoAssetManagerAndBuiltinResourceApplication
2727
{
2828
using device_base_t = examples::SimpleWindowedApplication;
2929
using asset_base_t = application_templates::MonoAssetManagerAndBuiltinResourceApplication;
@@ -69,7 +69,7 @@ class ComputeShaderPathtracer final : public examples::SimpleWindowedApplication
6969
};
7070

7171
public:
72-
inline ComputeShaderPathtracer(const path& _localInputCWD, const path& _localOutputCWD, const path& _sharedInputCWD, const path& _sharedOutputCWD)
72+
inline HLSLComputePathtracer(const path& _localInputCWD, const path& _localOutputCWD, const path& _sharedInputCWD, const path& _sharedOutputCWD)
7373
: IApplicationFramework(_localInputCWD, _localOutputCWD, _sharedInputCWD, _sharedOutputCWD) {}
7474

7575
inline bool isComputeOnly() const override { return false; }
@@ -1349,4 +1349,4 @@ class ComputeShaderPathtracer final : public examples::SimpleWindowedApplication
13491349
IGPUCommandBuffer::SClearColorValue clearColor = { .float32 = {0.f,0.f,0.f,1.f} };
13501350
};
13511351

1352-
NBL_MAIN_FUNC(ComputeShaderPathtracer)
1352+
NBL_MAIN_FUNC(HLSLComputePathtracer)

0 commit comments

Comments
 (0)