Skip to content

Fix background MIS, NumShadowRays != 1 and some few other tweaks - #37

Merged
pgrit merged 10 commits into
masterfrom
fix/vcm-bias-robustness
Jul 24, 2026
Merged

Fix background MIS, NumShadowRays != 1 and some few other tweaks#37
pgrit merged 10 commits into
masterfrom
fix/vcm-bias-robustness

Conversation

@PearCoding

Copy link
Copy Markdown
Collaborator

Handling of NumShadowRays is now in BidirBase. This fixes wrong pdf scaling when NumShadowRays != 1.

NumShadowRays == 1 stays identical to previous results. Tests still fine.
All fixes are propagated to CameraStoringVCM as well.

Also includes:

  • Dispose the photon map when rendering aborts on an exception (potential memory leak).
  • Track the average camera path length in the path tracer as well.

pdfNextEvent *= backgroundProbability;
// Compute the pdf of sampling the same connection via next event estimation.
float pdfNextEvent = NextEventPdf(new SurfacePoint { Position = ray.Origin },
new SurfacePoint { Position = ray.Origin + ray.Direction });

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Btw, this isn't the best approach, given that we only care about the direction. But improving this would have needed larger changes.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

why not just do a * NumShadowRays here then instead of obfuscating the code with arbitrary parameter values?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

because thats what all the VertexCacheBidir and others did as well.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

or do you mean the new SurfacePoint ... stuff?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

yes, why create arbitrary SurfacePoint objects if you can just do the missing multiplication here directly

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Encapsulation and one place to change the PDF computation, but yes it works with "just" multiplying too

{
base.Render(scene);
}
catch

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why dispose on exception but keep otherwise?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It does get disposed at the end of the function as usual, but due to the exception it never reaches so far.

@pgrit
pgrit self-requested a review July 24, 2026 09:53
pdfNextEvent *= backgroundProbability;
// Compute the pdf of sampling the same connection via next event estimation.
// TODO get the actual previous point (need the mesh, not just the position)
float pdfNextEvent = NextEventPdf(new SurfacePoint(), SurfacePoint.Invalid);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

isn't that trash parameters now? What happens with to.Position - from.Position in NextEventPdf?

@pgrit
pgrit merged commit 475327f into master Jul 24, 2026
5 checks passed
@PearCoding
PearCoding deleted the fix/vcm-bias-robustness branch July 30, 2026 11:24
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.

2 participants