Skip to content

Commit ca8f2ec

Browse files
committed
some minor corrections
1 parent 79ee9da commit ca8f2ec

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

31_HLSLPathTracer/app_resources/hlsl/common.hlsl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct Ray
6868
vector3_type origin;
6969
vector3_type direction;
7070

71-
// TODO: polygon method == 2 stuff
71+
// polygon method == PPM_APPROX_PROJECTED_SOLID_ANGLE
7272
vector3_type normalAtOrigin;
7373
bool wasBSDFAtOrigin;
7474

@@ -246,7 +246,6 @@ struct Shape<PST_TRIANGLE>
246246
retval.vertex1 = vertex1;
247247
retval.vertex2 = vertex2;
248248
retval.bsdfLightIDs = bsdfLightIDs;
249-
retval.polygonMethod = PPM_SOLID_ANGLE;
250249
return retval;
251250
}
252251

@@ -288,7 +287,6 @@ struct Shape<PST_TRIANGLE>
288287
float32_t3 vertex1;
289288
float32_t3 vertex2;
290289
uint32_t bsdfLightIDs;
291-
PTPolygonMethod polygonMethod;
292290
};
293291

294292
template<>
@@ -301,7 +299,6 @@ struct Shape<PST_RECTANGLE>
301299
retval.edge0 = edge0;
302300
retval.edge1 = edge1;
303301
retval.bsdfLightIDs = bsdfLightIDs;
304-
retval.polygonMethod = PPM_SOLID_ANGLE;
305302
return retval;
306303
}
307304

@@ -348,7 +345,6 @@ struct Shape<PST_RECTANGLE>
348345
float32_t3 edge0;
349346
float32_t3 edge1;
350347
uint32_t bsdfLightIDs;
351-
PTPolygonMethod polygonMethod;
352348
};
353349

354350
}

31_HLSLPathTracer/app_resources/hlsl/next_event_estimator.hlsl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ struct Estimator<Scene, Ray, LightSample, Aniso, IM_PROCEDURAL, PST_SPHERE, PPM>
298298
using sample_type = LightSample;
299299
using ray_dir_info_type = typename sample_type::ray_dir_info_type;
300300

301+
// affected by https://github.com/microsoft/DirectXShaderCompiler/issues/7007
302+
// NBL_CONSTEXPR_STATIC_INLINE PTPolygonMethod PolygonMethod = PPM;
303+
enum : uint16_t { PolygonMethod = PPM };
304+
301305
static spectral_type deferredEvalAndPdf(NBL_REF_ARG(scalar_type) pdf, NBL_CONST_REF_ARG(scene_type) scene, uint32_t lightID, NBL_CONST_REF_ARG(ray_type) ray)
302306
{
303307
pdf = 1.0 / scene.lightCount;
@@ -311,19 +315,17 @@ struct Estimator<Scene, Ray, LightSample, Aniso, IM_PROCEDURAL, PST_SPHERE, PPM>
311315

312316
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(scene_type) scene, uint32_t lightID, 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)
313317
{
314-
sample_type L;
315-
scalar_type pdf;
316-
317318
const light_type light = scene.lights[lightID];
318319
const Shape<PST_SPHERE> sphere = scene.spheres[light.objectID.id];
319320
const ShapeSampling<PST_SPHERE, PPM> sampling = ShapeSampling<PST_SPHERE, PPM>::create(sphere);
320321

322+
scalar_type pdf;
321323
const vector3_type sampleL = sampling.template generate_and_pdf<interaction_type>(pdf, newRayMaxT, origin, interaction, isBSDF, xi);
322324
const vector3_type V = interaction.isotropic.V.getDirection();
323325
const scalar_type VdotL = nbl::hlsl::dot<vector3_type>(V, sampleL);
324326
ray_dir_info_type rayL;
325327
rayL.direction = sampleL;
326-
L = sample_type::create(rayL,VdotL,interaction.T,interaction.B,interaction.isotropic.N);
328+
sample_type L = sample_type::create(rayL,VdotL,interaction.T,interaction.B,interaction.isotropic.N);
327329

328330
newRayMaxT *= Tolerance<scalar_type>::getEnd(depth);
329331
pdf *= 1.0 / scalar_type(scene.lightCount);
@@ -348,6 +350,9 @@ struct Estimator<Scene, Ray, LightSample, Aniso, IM_PROCEDURAL, PST_TRIANGLE, PP
348350
using sample_type = LightSample;
349351
using ray_dir_info_type = typename sample_type::ray_dir_info_type;
350352

353+
// NBL_CONSTEXPR_STATIC_INLINE PTPolygonMethod PolygonMethod = PPM;
354+
enum : uint16_t { PolygonMethod = PPM };
355+
351356
static spectral_type deferredEvalAndPdf(NBL_REF_ARG(scalar_type) pdf, NBL_CONST_REF_ARG(scene_type) scene, uint32_t lightID, NBL_CONST_REF_ARG(ray_type) ray)
352357
{
353358
pdf = 1.0 / scene.lightCount;
@@ -361,19 +366,17 @@ struct Estimator<Scene, Ray, LightSample, Aniso, IM_PROCEDURAL, PST_TRIANGLE, PP
361366

362367
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(scene_type) scene, uint32_t lightID, 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)
363368
{
364-
sample_type L;
365-
scalar_type pdf;
366-
367369
const light_type light = scene.lights[lightID];
368370
const Shape<PST_TRIANGLE> tri = scene.triangles[light.objectID.id];
369371
const ShapeSampling<PST_TRIANGLE, PPM> sampling = ShapeSampling<PST_TRIANGLE, PPM>::create(tri);
370372

373+
scalar_type pdf;
371374
const vector3_type sampleL = sampling.template generate_and_pdf<interaction_type>(pdf, newRayMaxT, origin, interaction, isBSDF, xi);
372375
const vector3_type V = interaction.isotropic.V.getDirection();
373376
const scalar_type VdotL = nbl::hlsl::dot<vector3_type>(V, sampleL);
374377
ray_dir_info_type rayL;
375378
rayL.direction = sampleL;
376-
L = sample_type::create(rayL,VdotL,interaction.T,interaction.B,interaction.isotropic.N);
379+
sample_type L = sample_type::create(rayL,VdotL,interaction.T,interaction.B,interaction.isotropic.N);
377380

378381
newRayMaxT *= Tolerance<scalar_type>::getEnd(depth);
379382
pdf *= 1.0 / scalar_type(scene.lightCount);
@@ -398,6 +401,9 @@ struct Estimator<Scene, Ray, LightSample, Aniso, IM_PROCEDURAL, PST_RECTANGLE, P
398401
using sample_type = LightSample;
399402
using ray_dir_info_type = typename sample_type::ray_dir_info_type;
400403

404+
// NBL_CONSTEXPR_STATIC_INLINE PTPolygonMethod PolygonMethod = PPM;
405+
enum : uint16_t { PolygonMethod = PPM };
406+
401407
static spectral_type deferredEvalAndPdf(NBL_REF_ARG(scalar_type) pdf, NBL_CONST_REF_ARG(scene_type) scene, uint32_t lightID, NBL_CONST_REF_ARG(ray_type) ray)
402408
{
403409
pdf = 1.0 / scene.lightCount;
@@ -411,19 +417,17 @@ struct Estimator<Scene, Ray, LightSample, Aniso, IM_PROCEDURAL, PST_RECTANGLE, P
411417

412418
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(scene_type) scene, uint32_t lightID, 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)
413419
{
414-
sample_type L;
415-
scalar_type pdf;
416-
417420
const light_type light = scene.lights[lightID];
418421
const Shape<PST_RECTANGLE> rect = scene.rectangles[light.objectID.id];
419422
const ShapeSampling<PST_RECTANGLE, PPM> sampling = ShapeSampling<PST_RECTANGLE, PPM>::create(rect);
420423

424+
scalar_type pdf;
421425
const vector3_type sampleL = sampling.template generate_and_pdf<interaction_type>(pdf, newRayMaxT, origin, interaction, isBSDF, xi);
422426
const vector3_type V = interaction.isotropic.V.getDirection();
423427
const scalar_type VdotL = nbl::hlsl::dot<vector3_type>(V, sampleL);
424428
ray_dir_info_type rayL;
425429
rayL.direction = sampleL;
426-
L = sample_type::create(rayL,VdotL,interaction.T,interaction.B,interaction.isotropic.N);
430+
sample_type L = sample_type::create(rayL,VdotL,interaction.T,interaction.B,interaction.isotropic.N);
427431

428432
newRayMaxT *= Tolerance<scalar_type>::getEnd(depth);
429433
pdf *= 1.0 / scalar_type(scene.lightCount);

31_HLSLPathTracer/app_resources/hlsl/pathtracer.hlsl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,11 @@ struct Unidirectional
241241
// trace new ray
242242
ray.origin = intersection + bxdfSample * (1.0/*kSceneSize*/) * Tolerance<scalar_type>::getStart(depth);
243243
ray.direction = bxdfSample;
244-
// #if POLYGON_METHOD==2
245-
// ray._immutable.normalAtOrigin = interaction.isotropic.N;
246-
// ray._immutable.wasBSDFAtOrigin = isBSDF;
247-
// #endif
244+
if ((PTPolygonMethod)nee_type::PolygonMethod == PPM_APPROX_PROJECTED_SOLID_ANGLE)
245+
{
246+
ray.normalAtOrigin = interaction.isotropic.N;
247+
ray.wasBSDFAtOrigin = isBSDF;
248+
}
248249
return true;
249250
}
250251

31_HLSLPathTracer/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,7 @@ class HLSLComputePathtracer final : public examples::SimpleWindowedApplication,
13481348
float camYAngle = 165.f / 180.f * 3.14159f;
13491349
float camXAngle = 32.f / 180.f * 3.14159f;
13501350
int PTPipline = E_LIGHT_GEOMETRY::ELG_SPHERE;
1351-
int renderMode = E_RENDER_MODE::ERM_GLSL;
1351+
int renderMode = E_RENDER_MODE::ERM_HLSL;
13521352
int spp = 32;
13531353
int depth = 3;
13541354

0 commit comments

Comments
 (0)