Skip to content

Fix glass shader tint not blending through multiple layers (#10364)#10366

Closed
Infiland wants to merge 1 commit intoFacepunch:masterfrom
Infiland:issue-10364
Closed

Fix glass shader tint not blending through multiple layers (#10364)#10366
Infiland wants to merge 1 commit intoFacepunch:masterfrom
Infiland:issue-10364

Conversation

@Infiland
Copy link
Copy Markdown
Contributor

@Infiland Infiland commented Apr 4, 2026

Summary

Quality glass (refractive mode) writes fully opaque with no blend state, so the front glass pane completely overwrites the back glass pixels. This means only the front glass tint is ever visible when looking through multiple layers.

This PR enables premultiplied alpha blending for quality glass and computes a physically-based alpha from Fresnel reflectance and albedo luminance. Back glass layers now partially show through the front glass, blending their tints together. Clear glass (white albedo) is unaffected (alpha ≈ 1.0). Reflections remain at full strength due to premultiplied alpha.

Motivation & Context

Fixes: #10364

Implementation Details

  • Premultiplied alpha (SrcBlend=ONE, DstBlend=INV_SRC_ALPHA) instead of standard alpha blend — this keeps specular reflections additive at full strength while only the refraction (emission) is pre-scaled by alpha.
  • Alpha formula: saturate(avgFresnel + (1 - avgFresnel) * sqrt(albedoLuminance)). At grazing angles Fresnel pushes alpha to 1.0 (glass is reflective/opaque). At normal incidence, darker tints get lower alpha so more of the back glass shows through. Clear glass gets alpha ≈ 1.0 (no visual change).
  • The original albedo is saved before the quality glass path modifies it, so the luminance calculation uses the unmodified tint color.
  • Cheap glass path is unchanged.
  • Single-pane tinted glass will appear slightly less saturated since emission is scaled by alpha. This is a trade-off to enable multi-layer blending.

Screenshots / Videos (if applicable)

-/-

Checklist

  • Code follows existing style and conventions
  • No unnecessary formatting or unrelated changes
  • Public APIs are documented (if applicable)
  • Unit tests added where applicable and all passing
  • I’m okay with this PR being rejected or requested to change 🙂

@handsomematt handsomematt added the triaged triaged pull-requests are replicated on the internal sbox repo label Apr 5, 2026
@sampavlovic
Copy link
Copy Markdown
Contributor

Pretty clever, makes sense, I need to test it proper

@sboxbot sboxbot added the accepted this pull request was accepted, hurrah! label Apr 7, 2026
@sboxbot
Copy link
Copy Markdown
Contributor

sboxbot commented Apr 7, 2026

This PR has been merged upstream.

@sboxbot sboxbot closed this Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accepted this pull request was accepted, hurrah! triaged triaged pull-requests are replicated on the internal sbox repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Looking through glass (glass shader) with a tint causes all other glass seen through it to have the same tint.

4 participants