Support for sRGB framebuffer on WebGPU #6838
Merged
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.
This PR wraps up the recent work on a path to fully linear rendering mode. In the engine 1.x.x, only the standard material worked in linear space, where input colors were converted from sRGB to linear space, and output converted back to sRGB space when storing in 8bit per channel render targets. Other shaders (particle, UI, Basic, custom user shaders) worked in gamma space. This PR finalizes the linear implementation for all shaders and examples. These are the changes required of the users of the engine now:
all input color textures need to be created as sRGB now for all shaders. This requirement is not enforced for StandardMaterial, and the sRGB->linear correction is done inside the shader at small cost if not set up correctly, to ease the transition.
all color uniforms need to be converted to linear color as well, if the source values are specified in sRGB space
gammaCorrectOutput function needs to be called on the output color of the shader
API change:
createGraphicsDevice
function acceptsdisplayFormat
option now, which can be:DISPLAYFORMAT_LDR - existing rendering, and a default value. The framebuffer is RGBA8 format, with manual gamma correction
DISPLAYFORMAT_LDR_SRGB - framebuffer uses sRGB format, which automatically handles linear->sRGB conversion. Currently only supported on WebGPU. Allows for linear alpha blending. See more here: Issues and possible improvements to transparency rendering #5943
DISPLAYFORMAT_HDR - non public enum, designed to support P3 extended HDR format
recently added ShaderMaterial automatically handles output gamma correction (manual or by sRGB render target format), this is now used by the example to correctly work on both displayFormat modes
particle shader works in linear space, and so it's input textures now used sRGB format
shader used by gizmo rendering handles output gamma conversion
compose render pass now handles output gamma correcttion based on the render target format
post-effects used gamma format to match the framebuffer format
exposed new (internal) format for WebGPU internal use PIXELFORMAT_SBGRA8
clear color is now converted to linear space for sRGB targets
When DISPLAYFORMAT_LDR_SRGB display format is used on WebGPU, RGBA8 format is used for backbuffer, and SRGBA8 format is used as its view format
debug line rendering handles output gamma correction
opacity dithering noise is converted from perceptual space to linear space when compared against linear alpha value
material-transparency shader, comparing alpha blending vs dithered blending, match is a lot better when framebuffer is in sRGB format on WebGPU