fix: apply DirectBRDFSpecular FP16 overflow clamp unconditionally (fix Linux/Vulkan/GLCORE)#93
Merged
Conversation
…/Vulkan/GLCORE overflow
🔗 Merge Alignment ReminderIf this PR targets Both repos should be merged in coordination to avoid breaking changes. Do not merge one without the other being ready. |
mikhail-dcl
approved these changes
Jun 25, 2026
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.
Summary
DirectBRDFSpecularfunction had an FP16 overflow protection clamp guarded by#if defined (SHADER_API_MOBILE) || defined (SHADER_API_SWITCH), which excludes Linux platforms using Vulkan (SHADER_API_VULKAN) and OpenGL Core (SHADER_API_GLCORE)#if/#endifguard and apply the clamp unconditionallyhalfis promoted tofloat32so the clamp is a no-op — no cost, no behavior changeRoot Cause
SHADER_API_VULKAN(used by Linux and Android Vulkan) andSHADER_API_GLCORE(used by Linux and Mac OpenGL) support true 16-bithalftypes. WhenspecularTermis computed via FP16 division with a near-zero denominator, the result can overflow without the clamp, causing rendering artifacts (broken specular highlights).Changes
Testing
Verified by code inspection: the clamp
[0, 100]is mathematically safe on all platforms. On 32-bit float platforms (DX11/DX12) the operation is a no-op. The fix matches Unity URP's own upstream direction.Note per the PR workflow reminder: corresponding changes in unity-explorer should be checked if they carry a local copy of this shader.
Closes
#92
🤖 Created via Slack with Claude
Requested by Esteban Ordano via Slack