Skip to content

Commit 4d186db

Browse files
committed
nee method to get env light id, added minor checks for pdf=0 and stuff
1 parent 960704d commit 4d186db

2 files changed

Lines changed: 11 additions & 17 deletions

File tree

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#define _NBL_BUILTIN_HLSL_PATH_TRACING_CONCEPTS_INCLUDED_
66

77
#include <nbl/builtin/hlsl/concepts.hlsl>
8+
#include <nbl/builtin/hlsl/bxdf/common.hlsl>
89

910
namespace nbl
1011
{
@@ -32,17 +33,12 @@ NBL_CONCEPT_END(
3233
#undef rand
3334
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
3435

35-
namespace impl
36-
{
37-
struct DummyInteraction {};
38-
}
39-
4036
#define NBL_CONCEPT_NAME Ray
4137
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
4238
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
4339
#define NBL_CONCEPT_PARAM_0 (ray, T)
4440
#define NBL_CONCEPT_PARAM_1 (v, typename T::vector3_type)
45-
#define NBL_CONCEPT_PARAM_2 (interaction, impl::DummyInteraction)
41+
#define NBL_CONCEPT_PARAM_2 (interaction, bxdf::surface_interactions::SIsotropic<bxdf::ray_dir_info::SBasic<float>, typename T::spectral_type>)
4642
#define NBL_CONCEPT_PARAM_3 (scalar, typename T::scalar_type)
4743
#define NBL_CONCEPT_PARAM_4 (color, typename T::spectral_type)
4844
NBL_CONCEPT_BEGIN(5)
@@ -56,7 +52,7 @@ NBL_CONCEPT_END(
5652
((NBL_CONCEPT_REQ_TYPE)(T::vector3_type))
5753
((NBL_CONCEPT_REQ_TYPE)(T::spectral_type))
5854
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((ray.init(v/*origin*/, v/*direction*/)), ::nbl::hlsl::is_same_v, void))
59-
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((ray.template setInteraction<impl::DummyInteraction>(interaction)), ::nbl::hlsl::is_same_v, void))
55+
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((ray.template setInteraction<bxdf::surface_interactions::SIsotropic<bxdf::ray_dir_info::SBasic<float>, typename T::spectral_type> >(interaction)), ::nbl::hlsl::is_same_v, void))
6056
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((ray.initPayload()), ::nbl::hlsl::is_same_v, void))
6157
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((ray.shouldDoMIS()), ::nbl::hlsl::is_same_v, bool))
6258
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((ray.foundEmissiveMIS(scalar)), ::nbl::hlsl::is_same_v, typename T::spectral_type))
@@ -267,6 +263,7 @@ NBL_CONCEPT_END(
267263
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(Ray, typename T::ray_type))
268264
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((nee.deferred_pdf(scene, id, ray)), ::nbl::hlsl::is_same_v, typename T::scalar_type))
269265
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((nee.template generate_and_quotient_and_pdf<impl::DummyMaterialSystem>(scene, matSys, v/*origin*/, interaction, v/*xi*/, depth)), ::nbl::hlsl::is_same_v, typename T::sample_quotient_return_type))
266+
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((nee.get_env_light_id()), ::nbl::hlsl::is_same_v, typename T::light_id_type))
270267
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((nee.get_environment_radiance(ray)), ::nbl::hlsl::is_same_v, typename T::spectral_type))
271268
);
272269
#undef scene

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ struct Unidirectional
8484
vector3_type eps1 = randGen(depth * 2u + 1u, _sample);
8585

8686
const vector3_type intersectP = intersectData.getPosition();
87-
measure_type throughputCIE_Y = interaction.getLuminosityContributionHint();
8887

8988
// sample lights
9089
const scalar_type neeProbability = bxdf.getNEEProb();
@@ -102,8 +101,6 @@ struct Unidirectional
102101
sample_type nee_sample = ret.getSample();
103102
quotient_pdf_type neeContrib = ret.getQuotientPdf();
104103

105-
// We don't allow non watertight transmitters in this renderer, one cannot reach a light from the backface (optimization)
106-
107104
// 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.
108105
// So we need to weigh the Delta lobes as if the MIS weight is always 1, but other areas regularly.
109106
// 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.
@@ -113,8 +110,11 @@ struct Unidirectional
113110
// TODO: we'll need an `eval_and_mis_weight` and `quotient_and_mis_weight`
114111
const scalar_type bsdf_pdf = materialSystem.pdf(matID, nee_sample, interaction);
115112
neeContrib.quotient *= materialSystem.eval(matID, nee_sample, interaction) * rcpChoiceProb;
116-
const scalar_type otherGenOverLightAndChoice = bsdf_pdf * rcpChoiceProb / neeContrib.pdf;
117-
neeContrib.quotient /= 1.f + otherGenOverLightAndChoice * otherGenOverLightAndChoice; // balance heuristic
113+
if (!hlsl::isinf(neeContrib.pdf))
114+
{
115+
const scalar_type otherGenOverLightAndChoice = bsdf_pdf * rcpChoiceProb / neeContrib.pdf;
116+
neeContrib.quotient /= 1.f + otherGenOverLightAndChoice * otherGenOverLightAndChoice; // balance heuristic
117+
}
118118

119119
const vector3_type origin = intersectP;
120120
const vector3_type direction = nee_sample.getL().getDirection();
@@ -169,9 +169,8 @@ struct Unidirectional
169169

170170
void missProgram(NBL_REF_ARG(ray_type) ray)
171171
{
172-
vector3_type finalContribution = nee.get_environment_radiance(ray);
173-
typename nee_type::light_id_type env_light_id;
174-
env_light_id.id = 0u;
172+
measure_type finalContribution = nee.get_environment_radiance(ray);
173+
typename nee_type::light_id_type env_light_id = nee.get_env_light_id();
175174
const scalar_type pdf = nee.deferred_pdf(scene, env_light_id, ray);
176175
finalContribution *= ray.foundEmissiveMIS(pdf * pdf);
177176
ray.addPayloadContribution(finalContribution);
@@ -198,8 +197,6 @@ struct Unidirectional
198197
const uint32_t sampleCount = sampleIndex + 1;
199198
accumulator.addSample(sampleCount, ray.getPayloadAccumulatiion());
200199

201-
// TODO: visualize high variance
202-
203200
// TODO: russian roulette early exit?
204201
}
205202

0 commit comments

Comments
 (0)