Skip to content

Commit 9c18828

Browse files
committed
don't handle microfacet cache in path tracer, let mat sys do it; also eval and pdf don't need to take in cache
1 parent 4319536 commit 9c18828

2 files changed

Lines changed: 14 additions & 20 deletions

File tree

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ NBL_CONCEPT_END(
161161
#define NBL_CONCEPT_PARAM_2 (matid, typename T::material_id_type)
162162
#define NBL_CONCEPT_PARAM_3 (aniso_inter, typename T::anisotropic_interaction_type)
163163
#define NBL_CONCEPT_PARAM_4 (iso_inter, typename T::isotropic_interaction_type)
164-
#define NBL_CONCEPT_PARAM_5 (aniso_cache, typename T::anisocache_type)
164+
#define NBL_CONCEPT_PARAM_5 (cache_, typename T::cache_type)
165165
#define NBL_CONCEPT_PARAM_6 (iso_cache, typename T::isocache_type)
166166
#define NBL_CONCEPT_PARAM_7 (u, typename T::vector3_type)
167167
#define NBL_CONCEPT_PARAM_8 (cie_y, typename T::measure_type)
@@ -171,7 +171,7 @@ NBL_CONCEPT_BEGIN(9)
171171
#define matid NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
172172
#define aniso_inter NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_3
173173
#define iso_inter NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_4
174-
#define aniso_cache NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_5
174+
#define cache_ NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_5
175175
#define iso_cache NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_6
176176
#define u NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_7
177177
#define cie_y NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_8
@@ -182,15 +182,14 @@ NBL_CONCEPT_END(
182182
((NBL_CONCEPT_REQ_TYPE)(T::quotient_pdf_type))
183183
((NBL_CONCEPT_REQ_TYPE)(T::measure_type))
184184
((NBL_CONCEPT_REQ_TYPE)(T::anisotropic_interaction_type))
185-
((NBL_CONCEPT_REQ_TYPE)(T::isotropic_interaction_type))
186-
((NBL_CONCEPT_REQ_TYPE)(T::anisocache_type))
187-
((NBL_CONCEPT_REQ_TYPE)(T::isocache_type))
185+
((NBL_CONCEPT_REQ_TYPE)(T::cache_type))
188186
((NBL_CONCEPT_REQ_TYPE)(T::bxdfnode_type))
189187
((NBL_CONCEPT_REQ_TYPE)(T::create_params_t))
190188
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(BxdfNode, typename T::bxdfnode_type))
191-
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((matsys.eval(matid, _sample, aniso_inter, aniso_cache)), ::nbl::hlsl::is_same_v, typename T::measure_type))
192-
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((matsys.generate(matid, aniso_inter, u, aniso_cache)), ::nbl::hlsl::is_same_v, typename T::sample_type))
193-
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((matsys.quotient_and_pdf(matid, _sample, aniso_inter, aniso_cache)), ::nbl::hlsl::is_same_v, typename T::quotient_pdf_type))
189+
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((matsys.eval(matid, _sample, aniso_inter)), ::nbl::hlsl::is_same_v, typename T::measure_type))
190+
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((matsys.generate(matid, aniso_inter, u, cache_)), ::nbl::hlsl::is_same_v, typename T::sample_type))
191+
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((matsys.pdf(matid, _sample, aniso_inter)), ::nbl::hlsl::is_same_v, typename T::scalar_type))
192+
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((matsys.quotient_and_pdf(matid, _sample, aniso_inter, cache_)), ::nbl::hlsl::is_same_v, typename T::quotient_pdf_type))
194193
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((matsys.getBxDFNode(matid, aniso_inter)), ::nbl::hlsl::is_same_v, typename T::bxdfnode_type))
195194
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((matsys.hasEmission(matid)), ::nbl::hlsl::is_same_v, bool))
196195
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((matsys.setMonochromeEta(matid, cie_y)), ::nbl::hlsl::is_same_v, typename T::scalar_type))
@@ -199,7 +198,7 @@ NBL_CONCEPT_END(
199198
#undef cie_y
200199
#undef u
201200
#undef iso_cache
202-
#undef aniso_cache
201+
#undef cache_
203202
#undef iso_inter
204203
#undef aniso_inter
205204
#undef matid

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ struct Unidirectional
4444
using closest_hit_type = typename Intersector::closest_hit_type;
4545
using bxdfnode_type = typename MaterialSystem::bxdfnode_type;
4646
using anisotropic_interaction_type = typename MaterialSystem::anisotropic_interaction_type;
47-
using isotropic_interaction_type = typename anisotropic_interaction_type::isotropic_interaction_type;
48-
using anisocache_type = typename MaterialSystem::anisocache_type;
47+
using cache_type = typename MaterialSystem::cache_type;
4948
using quotient_pdf_type = typename NextEventEstimator::quotient_pdf_type;
5049
using tolerance_method_type = typename NextEventEstimator::tolerance_method_type;
5150

@@ -102,21 +101,17 @@ 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
106-
// but if we allowed non-watertight transmitters (single water surface), it would make sense just to apply this line by itself
107-
const scalar_type monochromeEta = materialSystem.setMonochromeEta(matID, throughputCIE_Y);
108-
bxdf::fresnel::OrientedEtas<monochrome_type> orientedEta = bxdf::fresnel::OrientedEtas<monochrome_type>::create(interaction.getNdotV(), hlsl::promote<monochrome_type>(monochromeEta));
109-
anisocache_type _cache = anisocache_type::template create<anisotropic_interaction_type, sample_type>(interaction, nee_sample, orientedEta);
104+
// We don't allow non watertight transmitters in this renderer, one cannot reach a light from the backface (optimization)
110105

111106
// 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.
112107
// So we need to weigh the Delta lobes as if the MIS weight is always 1, but other areas regularly.
113108
// 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.
114109
// 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.
115110
if (neeContrib.pdf > scalar_type(0.0))
116111
{
117-
// we'll need an `eval_and_mis_weight` and `quotient_and_mis_weight`
118-
const scalar_type bsdf_pdf = materialSystem.pdf(matID, nee_sample, interaction, _cache);
119-
neeContrib.quotient *= materialSystem.eval(matID, nee_sample, interaction, _cache) * rcpChoiceProb;
112+
// TODO: we'll need an `eval_and_mis_weight` and `quotient_and_mis_weight`
113+
const scalar_type bsdf_pdf = materialSystem.pdf(matID, nee_sample, interaction);
114+
neeContrib.quotient *= materialSystem.eval(matID, nee_sample, interaction) * rcpChoiceProb;
120115
const scalar_type otherGenOverLightAndChoice = bsdf_pdf * rcpChoiceProb / neeContrib.pdf;
121116
neeContrib.quotient /= 1.f + otherGenOverLightAndChoice * otherGenOverLightAndChoice; // balance heuristic
122117

@@ -137,7 +132,7 @@ struct Unidirectional
137132
vector3_type bxdfSample;
138133
vector3_type throughput = ray.getPayloadThroughput();
139134
{
140-
anisocache_type _cache;
135+
cache_type _cache;
141136
sample_type bsdf_sample = materialSystem.generate(matID, interaction, eps1, _cache);
142137

143138
if (!bsdf_sample.isValid())

0 commit comments

Comments
 (0)