Skip to content

Conversation

@GapingPixel
Copy link

Added Stabilizer for variance floor & Delta Clamp to avoid tails

Copilot AI review requested due to automatic review settings January 28, 2026 16:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves numerical stability of DDGI visibility computation by adding a variance floor and clamping the distance delta to reduce extreme-tail behavior.

Changes:

  • Adds a variance “stabilizer” floor based on mean^2.
  • Clamps delta to mean * 3.0f before computing Chebyshev visibility.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

variance = max(variance, 0.0001f * mean * mean);

float delta = max(distanceToSample - mean, 0.0f);
delta = min(delta, mean * 3.0f); //Tries to avoid tails @test if neccesary
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

delta = min(delta, mean * 3.0f) can clamp delta to 0 when mean is 0 (or very small), which makes chebyshev become variance/(variance+0) (often 1) and can even produce 0/0 NaNs when variance is also 0. Since probe distance moments can legitimately have mean == 0 (e.g., empty/invalid samples), clamp using an epsilon (e.g., max(mean, eps)), clamp to an absolute distance, or gate the clamp so it only applies when mean is above a threshold.

Suggested change
delta = min(delta, mean * 3.0f); //Tries to avoid tails @test if neccesary
// Clamp delta using a safe mean to avoid forcing delta to 0 when mean is 0 (or very small)
float meanForClamp = max(mean, 0.001f);
delta = min(delta, meanForClamp * 3.0f); // Tries to avoid tails @test if necessary

Copilot uses AI. Check for mistakes.
Comment on lines +185 to +188

// Minimal stabilizer
variance = max(variance, 0.0001f * mean * mean);

Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The newly added lines use tab indentation and introduce trailing whitespace, while surrounding code in this file uses spaces. Please re-indent these lines to match the file’s existing spacing to avoid noisy diffs and style inconsistencies.

Copilot uses AI. Check for mistakes.
variance = max(variance, 0.0001f * mean * mean);

float delta = max(distanceToSample - mean, 0.0f);
delta = min(delta, mean * 3.0f); //Tries to avoid tails @test if neccesary
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

Comment has spelling/wording issues (e.g., "neccesary") and includes internal notes like "@test" that read as temporary. Please correct the spelling and either remove the TODO-style note or turn it into a clear, actionable comment describing when/why the clamp should be enabled.

Suggested change
delta = min(delta, mean * 3.0f); //Tries to avoid tails @test if neccesary
delta = min(delta, mean * 3.0f); // Clamp delta to limit tail contribution and stabilize visibility; adjust the factor if stronger tail suppression is necessary.

Copilot uses AI. Check for mistakes.
@sampavlovic sampavlovic added the triaged triaged pull-requests are replicated on the internal sbox repo label Jan 30, 2026
@sampavlovic
Copy link
Contributor

sampavlovic commented Jan 30, 2026

Seems right, can't find any meaningful difference even in edge case tests though, could you give more details on the edge cases this is solving

@DrakeFruit

This comment was marked as off-topic.

@sampavlovic
Copy link
Contributor

Iterating on this and getting somewhere, I get what it's been trying to do now

ezgif-45af2699792aef40

@sboxbot sboxbot added the accepted this pull request was accepted, hurrah! label Feb 4, 2026
@sboxbot
Copy link
Contributor

sboxbot commented Feb 4, 2026

This PR has been merged upstream.

@sboxbot sboxbot closed this Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accepted this pull request was accepted, hurrah! triaged triaged pull-requests are replicated on the internal sbox repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants