Clamp PBR surface opacity before shader construction - #3019
Open
tdavidovicNV wants to merge 2 commits into
Open
Conversation
tdavidovicNV
marked this pull request as draft
July 27, 2026 17:17
tdavidovicNV
marked this pull request as ready for review
July 27, 2026 18:20
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.
The PBR specification defines surface cutout opacity (O) over the range
[0, 1], but does not specify how values outside that range are handled.Consider this shader:
OSL clamps opacity at each leaf surface, giving:
mix(clamp(0.2, 0, 1), clamp(2.0, 0, 1), 0.25) = 0.4GLSL and MDL effectively clamp only the final result, giving:
clamp(mix(0.2, 2.0, 0.25), 0, 1) = 0.65Clamping at each
surfacenode is preferable because opacity represents coverage in[0, 1]. A surface with opacity2.0has no meaningful coverage interpretation, and allowing that invalid value to participate in later surface operations can produce valid-looking but unintuitive downstream results.This PR:
O = clamp(opacity, 0, 1)before the surface shader is constructed.[0, 1]UI bounds and documentation toND_surface.If clamping is not the intended policy, the specification should instead explicitly declare out-of-range opacity inputs undefined. In either case, the current disagreement between backends should be resolved or documented.