Skip to content

Clamp roughness before GGX functions to avoid NaNs caused by denormals - #125826

Open
clayjohn wants to merge 1 commit into
godotengine:masterfrom
clayjohn:roughness-clamp
Open

clayjohn wants to merge 1 commit into
godotengine:masterfrom
clayjohn:roughness-clamp

Conversation

@clayjohn

@clayjohn clayjohn commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Fixes: #110207

The rationale is described in detail here: https://google.github.io/filament/Filament.md.html#materialsystem/parameterization/remapping

Our check for roughness being non-zero was ineffective since the GGX functions end up multiplying roughness by itself many times, it quickly gets smaller than the smallest representable value by a half float (and sometimes even by a full float).

By clamping the roughness to a known safe size, we ensure that we don't get any NaNs caused by the specular GGX function.

As a bonus, a simple clamp is theoretically cheaper than a branch. I doubt it makes any difference in practice.

Tested on a MBP with all three renderers. I was able to repro the bug here and confirm that this change fixes it

edit: this will cause a slight change in behaviour as previously setting roughness to 0 had the impact of fully disabling the specular lobe from direct reflections

@clayjohn clayjohn added this to the 4.9 milestone Nov 26, 2026
@clayjohn
clayjohn requested a review from a team as a code owner November 26, 2026 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mobile: NaN is visible in specular reflections on smooth metallic materials (regression from FP16 optimizations)

1 participant