Skip to content

Commit 8b8fab0

Browse files
committed
added checks to invalid samples
1 parent aced36c commit 8b8fab0

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

31_HLSLPathTracer/app_resources/hlsl/next_event_estimator.hlsl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ struct ShapeSampling<PST_RECTANGLE, PPM_SOLID_ANGLE>
265265
{
266266
float32_t3 sph_sample = sphUv[0] * rect.edge0 + sphUv[1] * rect.edge1 + rect.offset;
267267
L = sph_sample - origin;
268-
L = hlsl::mix(nbl::hlsl::normalize(L), hlsl::promote<float32_t3>(0.0), hlsl::abs<float32_t3>(L) > (float32_t3)numeric_limits<float>::min); // TODO? sometimes L is vec3(0), find cause
268+
L = hlsl::mix(hlsl::normalize(L), hlsl::promote<float32_t3>(0.0), hlsl::all(hlsl::abs(L) > hlsl::promote<float32_t3>(numeric_limits<float>::min))); // TODO? sometimes L is vec3(0), find cause
269269
pdf = 1.f / solidAngle;
270270
}
271271
else
@@ -423,9 +423,16 @@ struct Estimator<Scene, Ray, LightSample, Aniso, IM_PROCEDURAL, PST_RECTANGLE, P
423423

424424
scalar_type pdf;
425425
const vector3_type sampleL = sampling.template generate_and_pdf<interaction_type>(pdf, newRayMaxT, origin, interaction, isBSDF, xi);
426+
ray_dir_info_type rayL;
427+
if (hlsl::isinf(pdf))
428+
{
429+
quotient_pdf = quotient_pdf_type::create(hlsl::promote<spectral_type>(0.0), 0.0);
430+
return sample_type::createInvalid();
431+
}
432+
426433
const vector3_type N = interaction.getN();
427434
const scalar_type NdotL = nbl::hlsl::dot<vector3_type>(N, sampleL);
428-
ray_dir_info_type rayL;
435+
429436
rayL.setDirection(sampleL);
430437
sample_type L = sample_type::create(rayL,interaction.getT(),interaction.getB(),NdotL);
431438

31_HLSLPathTracer/app_resources/hlsl/pathtracer.hlsl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ struct Unidirectional
164164
);
165165

166166
// We don't allow non watertight transmitters in this renderer
167-
bool validPath = nee_sample.getNdotL() > numeric_limits<scalar_type>::min;
167+
bool validPath = nee_sample.getNdotL() > numeric_limits<scalar_type>::min && nee_sample.isValid();
168168
// but if we allowed non-watertight transmitters (single water surface), it would make sense just to apply this line by itself
169169
bxdf::fresnel::OrientedEtas<monochrome_type> orientedEta = bxdf::fresnel::OrientedEtas<monochrome_type>::create(interaction.getNdotV(), hlsl::promote<monochrome_type>(monochromeEta));
170170
anisocache_type _cache = anisocache_type::template create<anisotropic_interaction_type, sample_type>(interaction, nee_sample, orientedEta);
@@ -208,6 +208,9 @@ struct Unidirectional
208208
anisocache_type _cache;
209209
sample_type bsdf_sample = materialSystem.generate(bxdf.materialType, bxdf.params, interaction, eps1, _cache);
210210

211+
if (!bsdf_sample.isValid())
212+
return false;
213+
211214
// example only uses isotropic bxdfs
212215
// the value of the bsdf divided by the probability of the sample being generated
213216
quotient_pdf_type bsdf_quotient_pdf = materialSystem.quotient_and_pdf(bxdf.materialType, bxdf.params, bsdf_sample, interaction.isotropic, _cache.iso_cache);

31_HLSLPathTracer/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
9494
if (!m_surface)
9595
{
9696
{
97-
auto windowCallback = core::make_smart_refctd_ptr<examples::CEventCallback>(smart_refctd_ptr(m_inputSystem), smart_refctd_ptr(m_logger));
97+
auto windowCallback = core::make_smart_refctd_ptr<CEventCallback>(smart_refctd_ptr(m_inputSystem), smart_refctd_ptr(m_logger));
9898
IWindow::SCreationParams params = {};
9999
params.callback = core::make_smart_refctd_ptr<nbl::video::ISimpleManagedSurface::ICallback>();
100100
params.width = WindowDimensions.x;
@@ -121,7 +121,7 @@ class HLSLComputePathtracer final : public SimpleWindowedApplication, public Bui
121121
{
122122
// Init systems
123123
{
124-
m_inputSystem = make_smart_refctd_ptr<examples::InputSystem>(logger_opt_smart_ptr(smart_refctd_ptr(m_logger)));
124+
m_inputSystem = make_smart_refctd_ptr<InputSystem>(logger_opt_smart_ptr(smart_refctd_ptr(m_logger)));
125125

126126
// Remember to call the base class initialization!
127127
if (!device_base_t::onAppInitialized(smart_refctd_ptr(system)))

0 commit comments

Comments
 (0)