Fix alpha compositing for translucent water surfaces #384
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.
After some investigation, it's become clear that the reference client seems to incorrectly mix sRGB and linear-space colors. While this is a bit of a guess, it would explain why the contrast correction was needed in the first place; it makes up for the underexposure introduced by the lack of gamma-decompression steps after loading sRGB-encoded textures. Indeed, screen blending is used for this exact purpose in digital photo editing (apparently). At least that's the best explanation I could come up with so far.
In order to reproduce the resulting outputs, neither sRGB nor linearized colors can be used. The "in-between" method used so far, however, trips up the alpha blend stage while the underlying texture view is in sRGB format: WebGPU automatically converts the fragment colors - first to sRGB and then back to linear as part of the blend stage. Unfortunately, the color space used is actually neither of the two by this point, and so the results can't possibly match expectations unless a non-sRGB output format is used.
Originally, sRGB was selected because it's the preferred surface format. Using a different one grants full control of the color space used and eliminates the undesirable conversion, but may incur a performance hit. However, conversions between RGBA and sRGB should be hardware-accelerated on any reasonably modern device. Switching to RGBA also simplifies the shader logic as the added linearization step is no longer needed. So overall it's probably a net gain? Either way, for now that's a secondary concern.