Skip to content

Commit 7bd69e9

Browse files
committed
fixed most of rectangle light issues, still red pixels
1 parent 63b64e3 commit 7bd69e9

File tree

3 files changed

+56
-57
lines changed

3 files changed

+56
-57
lines changed

31_HLSLPathTracer/app_resources/hlsl/common.hlsl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ struct Shape<PST_TRIANGLE>
388388
sampling::ProjectedSphericalTriangle<float> pst = sampling::ProjectedSphericalTriangle<float>::create(st);
389389
const float pdf = pst.pdf(ray.normalAtOrigin, ray.wasBSDFAtOrigin, L);
390390
// if `pdf` is NAN then the triangle's projected solid angle was close to 0.0, if its close to INF then the triangle was very small
391-
return pdf < numeric_limits<float>::max ? pdf : 0.0;
391+
return pdf < numeric_limits<float>::max ? pdf : numeric_limits<float>::max;
392392
}
393393
break;
394394
default:
@@ -427,7 +427,7 @@ struct Shape<PST_TRIANGLE>
427427

428428
const float32_t3 L = sst.generate(rcpPdf, xi.xy);
429429

430-
pdf = rcpPdf > numeric_limits<float>::min ? (1.0 / rcpPdf) : 0.0;
430+
pdf = rcpPdf > numeric_limits<float>::min ? (1.0 / rcpPdf) : numeric_limits<float>::max;
431431

432432
const float32_t3 N = getNormalTimesArea();
433433
newRayMaxT = hlsl::dot<float32_t3>(N, vertex0 - origin) / hlsl::dot<float32_t3>(N, L);
@@ -443,7 +443,7 @@ struct Shape<PST_TRIANGLE>
443443

444444
const float32_t3 L = sst.generate(rcpPdf, interaction.isotropic.N, isBSDF, xi.xy);
445445

446-
pdf = rcpPdf > numeric_limits<float>::min ? (1.0 / rcpPdf) : 0.0;
446+
pdf = rcpPdf > numeric_limits<float>::min ? (1.0 / rcpPdf) : numeric_limits<float>::max;
447447

448448
const float32_t3 N = getNormalTimesArea();
449449
newRayMaxT = hlsl::dot<float32_t3>(N, vertex0 - origin) / hlsl::dot<float32_t3>(N, L);
@@ -513,8 +513,6 @@ struct Shape<PST_RECTANGLE>
513513
basis[0] = edge0 / extents[0];
514514
basis[1] = edge1 / extents[1];
515515
basis[2] = normalize(cross(basis[0],basis[1]));
516-
517-
basis = nbl::hlsl::transpose<float32_t3x3>(basis); // TODO: double check transpose
518516
}
519517

520518
template<typename Ray>
@@ -541,17 +539,18 @@ struct Shape<PST_RECTANGLE>
541539
if (solidAngle > numeric_limits<float>::min)
542540
pdf = 1.f / solidAngle;
543541
else
544-
pdf = numeric_limits<float>::infinity;
542+
pdf = bit_cast<float>(numeric_limits<float>::infinity);
545543
return pdf;
546544
}
547545
break;
548546
case PPM_APPROX_PROJECTED_SOLID_ANGLE:
549547
{
550-
return numeric_limits<float>::infinity;
548+
// currently broken
549+
return bit_cast<float>(numeric_limits<float>::infinity);
551550
}
552551
break;
553552
default:
554-
return numeric_limits<float>::infinity;
553+
return bit_cast<float>(numeric_limits<float>::infinity);
555554
}
556555
}
557556

@@ -577,7 +576,6 @@ struct Shape<PST_RECTANGLE>
577576
// #ifdef TRIANGLE_REFERENCE ?
578577
case PPM_SOLID_ANGLE:
579578
{
580-
float pdf;
581579
float32_t3x3 rectNormalBasis;
582580
float32_t2 rectExtents;
583581
getNormalBasis(rectNormalBasis, rectExtents);
@@ -594,20 +592,21 @@ struct Shape<PST_RECTANGLE>
594592
pdf = 1.f / solidAngle;
595593
}
596594
else
597-
pdf = numeric_limits<float>::infinity;
595+
pdf = bit_cast<float>(numeric_limits<float>::infinity);
598596

599597
newRayMaxT = hlsl::dot<float32_t3>(N, origin2origin) / hlsl::dot<float32_t3>(N, L);
600598
return L;
601599
}
602600
break;
603601
case PPM_APPROX_PROJECTED_SOLID_ANGLE:
604602
{
605-
pdf = numeric_limits<float>::infinity;
603+
// currently broken
604+
pdf = bit_cast<float>(numeric_limits<float>::infinity);
606605
return (float32_t3)0.0;
607606
}
608607
break;
609608
default:
610-
pdf = numeric_limits<float>::infinity;
609+
pdf = bit_cast<float>(numeric_limits<float>::infinity);
611610
return (float32_t3)0.0;
612611
}
613612
}

31_HLSLPathTracer/app_resources/hlsl/next_event_estimator.hlsl

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -89,28 +89,28 @@ struct Estimator
8989

9090
static spectral_type deferredEvalAndPdf(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)
9191
{
92-
const IntersectMode mode = (IntersectMode)event.mode;
93-
switch (mode)
94-
{
95-
case IM_RAY_QUERY:
96-
{
97-
// TODO: do ray query stuff
98-
}
99-
break;
100-
case IM_RAY_TRACING:
101-
{
102-
// TODO: do ray tracing stuff
103-
}
104-
break;
105-
case IM_PROCEDURAL:
106-
{
92+
// const IntersectMode mode = (IntersectMode)event.mode;
93+
// switch (mode)
94+
// {
95+
// case IM_RAY_QUERY:
96+
// {
97+
// // TODO: do ray query stuff
98+
// }
99+
// break;
100+
// case IM_RAY_TRACING:
101+
// {
102+
// // TODO: do ray tracing stuff
103+
// }
104+
// break;
105+
// case IM_PROCEDURAL:
106+
// {
107107
return proceduralDeferredEvalAndPdf(pdf, light, ray, event);
108-
}
109-
break;
110-
default:
111-
return (spectral_type)0.0;
112-
}
113-
return (spectral_type)0.0;
108+
// }
109+
// break;
110+
// default:
111+
// return (spectral_type)0.0;
112+
// }
113+
// return (spectral_type)0.0;
114114
}
115115

116116
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)
@@ -203,29 +203,29 @@ struct Estimator
203203
{
204204
const IntersectMode mode = (IntersectMode)event.mode;
205205
sample_type L;
206-
switch (mode)
207-
{
208-
case IM_RAY_QUERY:
209-
{
210-
// TODO: do ray query stuff
211-
}
212-
break;
213-
case IM_RAY_TRACING:
214-
{
215-
// TODO: do ray tracing stuff
216-
}
217-
break;
218-
case IM_PROCEDURAL:
219-
{
206+
// switch (mode)
207+
// {
208+
// case IM_RAY_QUERY:
209+
// {
210+
// // TODO: do ray query stuff
211+
// }
212+
// break;
213+
// case IM_RAY_TRACING:
214+
// {
215+
// // TODO: do ray tracing stuff
216+
// }
217+
// break;
218+
// case IM_PROCEDURAL:
219+
// {
220220
return procedural_generate_and_quotient_and_pdf(quotient_pdf, newRayMaxT, light, origin, interaction, isBSDF, xi, depth, event);
221-
}
222-
break;
223-
default:
224-
{
225-
return L;
226-
}
227-
}
228-
return L;
221+
// }
222+
// break;
223+
// default:
224+
// {
225+
// return L;
226+
// }
227+
// }
228+
// return L;
229229
}
230230
};
231231

31_HLSLPathTracer/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,10 +1347,10 @@ class HLSLComputePathtracer final : public examples::SimpleWindowedApplication,
13471347
float viewWidth = 10.f;
13481348
float camYAngle = 165.f / 180.f * 3.14159f;
13491349
float camXAngle = 32.f / 180.f * 3.14159f;
1350-
int PTPipline = E_LIGHT_GEOMETRY::ELG_SPHERE;
1350+
int PTPipline = E_LIGHT_GEOMETRY::ELG_RECTANGLE;
13511351
int renderMode = E_RENDER_MODE::ERM_HLSL;
13521352
int spp = 32;
1353-
int depth = 3;
1353+
int depth = 1;
13541354

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

0 commit comments

Comments
 (0)