Repository navigation
Conversation
alice-i-cecile
approved these changes
Nov 10, 2026
barsoosayque
approved these changes
Nov 19, 2026
Member
|
Let me know when merge conflicts are resolved and we'll get this in :) |
Contributor
Author
|
@alice-i-cecile I fixed the merge conflicts, which came from a fix for the same white flashes issue that motivated this PR: #26335 This PR still changes it to the |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
I've only observed this on web, but I've seen it in at least 4 previous jam entries from Bevy Jams 7 and 8. Rarely, at certain camera angles, with the PBR lit surface shader, pixels will become NaN and then get exploded by the bloom shader.
I had Claude diagnose the issue. The problem traces to an unprotected
pow(1.0 - VdotH, 5.0)in the Schlick approximation when calculating fresnel. The BRDF'sNdotVwhich gets passed here can technically be greater than 1.0 due to float rounding.powon negative values is undefined, and may produce a NaN which propagates to the bloom shader, creating the effect seen above.Solution
Similar NaNs can theoretically happen anywhere an input is calculated and assumed to be strictly 0..1, and thus never
saturated or capped, and then passed to functions with restricted domains which might produce NaNs, for examplepow,sqrt,acos,log, etc. I had Claude look for likely problematic sites and checked them against Filament's source code before choosing which fixes to add in this PR.Two approaches:
pow5helper instead ofpow(x, 5.0). The helper just doesx2 * x2 * x, which can't NaN the waypowdoes.saturateormax(0.0, ..)as appropriate or conventional.Note that this is not a comprehensive pass and there may be other problematic areas.
Testing
I confirmed the Schlick NaN fix by running the same game as in the screenshot above on web and confirming the flashes no longer appear. I'm not sure how to test the other potential NaN fixes.
AI Disclosure
I used Claude Opus 5.5 to diagnose this issue and implemented and confirmed the fix myself. I then had Claude search for similar code paths that could NaN in similar ways, and as best I could I researched how Filament and Unreal treat similar cases and followed either their convention or Bevy's convention per call site.