Skip to content

Commit 40d585c

Browse files
committed
added some comments regarding future use of MIS, scene takes and intersected ray and gives intersection
1 parent 5e243d9 commit 40d585c

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

include/nbl/builtin/hlsl/path_tracing/concepts.hlsl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -318,32 +318,30 @@ NBL_CONCEPT_END(
318318
namespace impl
319319
{
320320
struct DummyRay {};
321+
struct DummyIntersect {};
321322
}
322323

323324
#define NBL_CONCEPT_NAME Scene
324325
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
325326
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
326327
#define NBL_CONCEPT_PARAM_0 (scene, T)
327-
#define NBL_CONCEPT_PARAM_1 (intersectP, typename T::vector3_type)
328-
#define NBL_CONCEPT_PARAM_2 (id, typename T::object_handle_type)
329-
#define NBL_CONCEPT_PARAM_3 (ray, impl::DummyRay)
330-
NBL_CONCEPT_BEGIN(4)
328+
#define NBL_CONCEPT_PARAM_1 (id, typename T::object_handle_type)
329+
#define NBL_CONCEPT_PARAM_2 (ray, impl::DummyRay)
330+
NBL_CONCEPT_BEGIN(3)
331331
#define scene NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
332-
#define intersectP NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
333-
#define id NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
334-
#define ray NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_3
332+
#define id NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
333+
#define ray NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
335334
NBL_CONCEPT_END(
336335
((NBL_CONCEPT_REQ_TYPE)(T::vector3_type))
337336
((NBL_CONCEPT_REQ_TYPE)(T::object_handle_type))
338337
((NBL_CONCEPT_REQ_TYPE)(T::mat_light_id_type))
339338
((NBL_CONCEPT_REQ_TYPE)(T::interaction_type))
340339
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(MaterialLightID, typename T::mat_light_id_type))
341340
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((scene.getMatLightIDs(id)), ::nbl::hlsl::is_same_v, typename T::mat_light_id_type))
342-
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((scene.template getInteraction<impl::DummyRay>(id, intersectP, ray)), ::nbl::hlsl::is_same_v, typename T::interaction_type))
341+
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((scene.template getIntersection<impl::DummyIntersect, impl::DummyRay>(id, ray)), ::nbl::hlsl::is_same_v, impl::DummyIntersect))
343342
);
344343
#undef ray
345344
#undef id
346-
#undef intersectP
347345
#undef scene
348346
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
349347

include/nbl/builtin/hlsl/path_tracing/unidirectional.hlsl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ struct Unidirectional
5555
return hlsl::dot(spectralTypeToLumaCoeffs, col);
5656
}
5757

58-
// TODO: will only work with isotropic surfaces, need to do aniso
5958
bool closestHitProgram(uint16_t depth, uint32_t _sample, NBL_REF_ARG(ray_type) ray, NBL_CONST_REF_ARG(closest_hit_type) intersectData)
6059
{
6160
anisotropic_interaction_type interaction = intersectData.getInteraction();
@@ -117,8 +116,13 @@ struct Unidirectional
117116
bxdf::fresnel::OrientedEtas<monochrome_type> orientedEta = bxdf::fresnel::OrientedEtas<monochrome_type>::create(interaction.getNdotV(), hlsl::promote<monochrome_type>(monochromeEta));
118117
anisocache_type _cache = anisocache_type::template create<anisotropic_interaction_type, sample_type>(interaction, nee_sample, orientedEta);
119118

119+
// While NEE or other generators are not supposed to pick up Delta lobes by accident, we need the MIS weights to add up to 1 for the non-delta lobes.
120+
// So we need to weigh the Delta lobes as if the MIS weight is always 1, but other areas regularly.
121+
// Meaning that eval's pdf should equal quotient's pdf , this way even the diffuse contributions coming from within a specular lobe get a MIS weight near 0 for NEE.
122+
// This stops a discrepancy in MIS weights and NEE mistakenly trying to add non-delta lobe contributions with a MIS weight > 0 and creating energy from thin air.
120123
if (neeContrib.pdf > scalar_type(0.0))
121124
{
125+
// we'll need an `eval_and_mis_weight` and `quotient_and_mis_weight`
122126
const scalar_type bsdf_pdf = materialSystem.pdf(matID, nee_sample, interaction, _cache);
123127
neeContrib.quotient *= materialSystem.eval(matID, nee_sample, interaction, _cache) * rcpChoiceProb;
124128
const scalar_type otherGenOverLightAndChoice = bsdf_pdf * rcpChoiceProb / neeContrib.pdf;

0 commit comments

Comments
 (0)