Skip to content

fix: apply DirectBRDFSpecular FP16 overflow clamp unconditionally (fix Linux/Vulkan/GLCORE)#93

Merged
eordano merged 2 commits into
mainfrom
fix/92-directbrdfspecular-fp16-linux-vulkan
Jun 25, 2026
Merged

fix: apply DirectBRDFSpecular FP16 overflow clamp unconditionally (fix Linux/Vulkan/GLCORE)#93
eordano merged 2 commits into
mainfrom
fix/92-directbrdfspecular-fp16-linux-vulkan

Conversation

@decentraland-bot

Copy link
Copy Markdown
Contributor

Summary

  • The DirectBRDFSpecular function 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)
  • Removed the #if/#endif guard and apply the clamp unconditionally
  • On full-float platforms (DX11/DX12 on Windows), half is promoted to float32 so the clamp is a no-op — no cost, no behavior change
  • On true FP16 platforms (mobile, Switch, Vulkan on Linux/Android, GLCORE on Linux/Mac) the clamp now correctly prevents overflow

Root Cause

SHADER_API_VULKAN (used by Linux and Android Vulkan) and SHADER_API_GLCORE (used by Linux and Mac OpenGL) support true 16-bit half types. When specularTerm is computed via FP16 division with a near-zero denominator, the result can overflow without the clamp, causing rendering artifacts (broken specular highlights).

Changes

Runtime/Shaders/Scene/URP/Lighting.hlsl — removed #if SHADER_API_MOBILE / SHADER_API_SWITCH guard, apply clamp unconditionally

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

@github-actions

Copy link
Copy Markdown

🔗 Merge Alignment Reminder

If this PR targets main, please make sure the corresponding changes in unity-explorer are also ready to merge.

Both repos should be merged in coordination to avoid breaking changes. Do not merge one without the other being ready.

@eordano
eordano merged commit facd86e into main Jun 25, 2026
@eordano
eordano deleted the fix/92-directbrdfspecular-fp16-linux-vulkan branch June 25, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants