Skip to content

Address path tracer merge leftover comments#991

Open
keptsecret wants to merge 76 commits intomasterfrom
path_tracer_leftover_cleanup
Open

Address path tracer merge leftover comments#991
keptsecret wants to merge 76 commits intomasterfrom
path_tracer_leftover_cleanup

Conversation

@keptsecret
Copy link
Contributor

Makes changes left from #966

@keptsecret
Copy link
Contributor Author

hlsl/matrix_utils/transformation_matrix_utils.hlsl removed because of https://github.com/Devsh-Graphics-Programming/Nabla/pull/966/files#r2618467323

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most parameters should be members #966 (comment)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for next sampling PR, to rework in line with concepts of #1001

return retval;
}

vector4_type computeBilinearPatch(const vector3_type receiverNormal, bool isBSDF)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this returning vector4_type instead of sampling::bilinear

Copy link
Member

@devshgraphicsprogramming devshgraphicsprogramming Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sampling PR

Comment on lines 29 to 34
static ProjectedSphericalTriangle<T> create(NBL_CONST_REF_ARG(shapes::SphericalTriangle<T>) tri)
{
ProjectedSphericalTriangle<T> retval;
retval.tri = tri;
return retval;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove, see #966 (comment)

Copy link
Member

@devshgraphicsprogramming devshgraphicsprogramming Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sampling PR

Comment on lines 67 to 68
vector3_type cos_vertices, sin_vertices;
const scalar_type solidAngle = tri.solidAngleOfTriangle(cos_vertices, sin_vertices, cos_a, cos_c, csc_b, csc_c);
const scalar_type solidAngle = tri.solidAngle(cos_vertices, sin_vertices);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be precomputed and stored as members #966 (comment)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sampling PR

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again function with bazillion parameters that are really local members

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sampling PR


scalar_type bxdfPdfThreshold;
scalar_type lumaContributionThreshold; // OETF smallest perceptible value
measure_type spectralTypeToLumaCoeffs;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

measure_type is NOT the same thing as spectral_type I'll want to return normals, albedo and other things from the measure

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keptsecret still a TODO

scalar_type rcpChoiceProb;
sampling::PartitionRandVariable<scalar_type> partitionRandVariable;
partitionRandVariable.leftProb = neeProbability;
assert(neeProbability >= 0.0 && neeProbability <= 1.0)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing ; at EOL

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keptsecret you still have a missing semicolon after the asseert

Comment on lines 111 to 120
// We don't allow non watertight transmitters in this renderer
// but if we allowed non-watertight transmitters (single water surface), it would make sense just to apply this line by itself
const scalar_type monochromeEta = materialSystem.setMonochromeEta(matID, throughputCIE_Y);
bxdf::fresnel::OrientedEtas<monochrome_type> orientedEta = bxdf::fresnel::OrientedEtas<monochrome_type>::create(interaction.getNdotV(), hlsl::promote<monochrome_type>(monochromeEta));
anisocache_type _cache = anisocache_type::template create<anisotropic_interaction_type, sample_type>(interaction, nee_sample, orientedEta);

if (neeContrib.pdf > scalar_type(0.0))
{
// example only uses isotropic bxdfs
quotient_pdf_type bsdf_quotient_pdf = materialSystem.quotient_and_pdf(matID, nee_sample, interaction.isotropic, _cache.iso_cache);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whole clump of code is super weird, it wont generalize to multi-layer materials, etc.

the cache shouldn't be exposed here at all (your material system in userspace could keep a cache around as a hidden variable)

The cache only applies to cook torrance materials and those are a high specialization.

You're abusing a quotient_and_pdf to just give you the pdf of a light sample, you shouldf be using pdf and eval separately instead.

Our dirac delta BxDFs will return Quotient of 1 and PDF of INF always!

Simply because the quotient still has dirac deltas in it, and the pdf does too, if you're doing NEE, you're supposed to completely remove those from the lighting integral - otherwise if you accidentally hit a Dirac Delta lobe the MIS weight for NEE goes to 0 which means that any non-dirac (such as plastic material which has diffuse mixed by fresnel with specular) lobes won't get any NEE at all!

also this can cause your problems with MIS weights not liking the NEE PDF being high!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after leave comment that we'll need an eval_and_mis_weight https://discord.com/channels/593902898015109131/1400024201682747512/1400024205050908783

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok you can let the material system define a cache_type but then its geenrate must initialize it and pass it to quotient_and_pdf

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keptsecret next item on the agenda

Comment on lines 119 to 122
// example only uses isotropic bxdfs
quotient_pdf_type bsdf_quotient_pdf = materialSystem.quotient_and_pdf(matID, nee_sample, interaction.isotropic, _cache.iso_cache);
neeContrib.quotient *= materialSystem.eval(matID, nee_sample, interaction.isotropic, _cache.iso_cache) * rcpChoiceProb;
const scalar_type otherGenOverLightAndChoice = bsdf_quotient_pdf.pdf * rcpChoiceProb / neeContrib.pdf;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass full aniso interaction, let the material system deal with only using the isotropic part

Also your PDF is mismatched.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keptsecret still using the wrong PDF to pair with eval

Comment on lines 35 to 45
namespace impl
{
struct DummyInteraction {};
}

#define NBL_CONCEPT_NAME Ray
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
#define NBL_CONCEPT_PARAM_0 (ray, T)
#define NBL_CONCEPT_PARAM_1 (v, typename T::vector3_type)
#define NBL_CONCEPT_PARAM_2 (b, bool)
#define NBL_CONCEPT_PARAM_2 (interaction, impl::DummyInteraction)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure how an empty struct tests any better than a real default aniso interaction

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to include the bxdf/common.hlsl in here.
But could change to surface_interaction::SIsotropic if that's better?

Comment on lines 330 to 343
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((scene.getNormal(id, intersectP)), ::nbl::hlsl::is_same_v, typename T::vector3_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((scene.template getInteraction<impl::DummyRay>(id, intersectP, ray)), ::nbl::hlsl::is_same_v, typename T::interaction_type))
);
#undef ray

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you still adamant on the scene giving you an interaction and not the closestHit trace ray of the intersector !?

You do realize that in general thats not possible with a ray, intersection position and an object ID ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(well or possible, but you'd need to re-intersect the BLAS just for that)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scene already does give a closest hit ray. This is for filling out the interaction member of the closest hit return struct.
Regardless, I've now made the scene handle all of creating the closest hit return struct.

vector3_type direction = bxdfSample;
ray.init(origin, direction);
ray.template initInteraction<anisotropic_interaction_type>(interaction);
ray.setT(1.0/*kSceneSize*/);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh? why 1.0 ?

Comment on lines 124 to 125
quotient_pdf_type bsdf_quotient_pdf = materialSystem.quotient_and_pdf(matID, nee_sample, iso_interaction, _cache.iso_cache);
neeContrib.quotient *= materialSystem.eval(matID, nee_sample, iso_interaction, _cache.iso_cache) * rcpChoiceProb;
Copy link
Member

@devshgraphicsprogramming devshgraphicsprogramming Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

material system shall always take aniso interaction

Comment on lines 148 to 153
quotient_pdf_type bsdf_quotient_pdf = materialSystem.quotient_and_pdf(matID, bsdf_sample, interaction.isotropic, _cache.iso_cache);
quotient_pdf_type bsdf_quotient_pdf = materialSystem.quotient_and_pdf(matID, bsdf_sample, iso_interaction, _cache.iso_cache);
Copy link
Member

@devshgraphicsprogramming devshgraphicsprogramming Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

material system shall always take aniso interaction

{
anisotropic_interaction_type interaction = intersectData.getInteraction();
isotropic_interaction_type iso_interaction = interaction.isotropic;
isotropic_interaction_type iso_interaction = interaction.getIsotropic();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in essence this should be an unused variable and removed

Comment on lines 93 to 97
const vector3_type throughputCIE_Y = hlsl::normalize(spectralTypeToLumaCoeffs * throughput);
measure_type throughputCIE_Y = spectralTypeToLumaCoeffs * throughput;
{
scalar_type sum_throughput = throughputCIE_Y[0];
NBL_UNROLL for (uint16_t i = 1; i < vector_traits<measure_type>::Dimension; i++)
sum_throughput += throughputCIE_Y[i];
throughputCIE_Y /= sum_throughput;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, now this needs to in the interaction

if (bxdfPdf > bxdfPdfThreshold && getLuma(throughput) > lumaThroughputThreshold)
{
scalar_type otherTechniqueHeuristic = neeProbability / bxdfPdf; // numerically stable, don't touch
ray.setPayloadMISWeights(throughput, otherTechniqueHeuristic * otherTechniqueHeuristic);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this update your thoroughput in the payload as well?

Then rename the function to updateThroughputAndMISWeights

vector3_type direction = bxdfSample;
ray.initData(origin, direction, interaction.getN(), isBSDF);
ray.init(origin, direction);
ray.template initInteraction<anisotropic_interaction_type>(interaction);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setInteraction maybe would be a better name ?

Comment on lines +33 to +34
int32_t PackedRcpLog2BaseAndLog2BaseRoot;
float32_t BrightSampleLumaBias;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do ou have two members now !?

nee_ray.init(origin, direction);
nee_ray.template initInteraction<anisotropic_interaction_type>(interaction);
nee_ray.setT(t);
tolerance_method_type::template adjust<ray_type>(nee_ray, direction, depth);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't the direction already in the ray ?

you need to give it the geometric normal (not the interaction which has the shading normal) if you want to know why read the PBRT book, but offsetting the origin by geo normal keeps your t modification small, while offsetting along the ray can be potentially unbounded with a surface-grazing ray if you want to not self-intersect

rayAlive = closestHitProgram(d, sampleIndex, ray, intersection);
continuePath = intersection.foundHit();
if (continuePath)
continuePath &= closestHitProgram(d, sampleIndex, ray, intersection);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't even need a &= just a = will do, you're in the if statement, so its already true

materialSystem, scene, intersectP, interaction,
isBSDF, eps0, depth
scene, materialSystem, intersectP, interaction,
eps0, depth

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need depth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants