Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for sRGB framebuffer on WebGPU #6838

Merged
merged 3 commits into from
Jul 23, 2024
Merged

Conversation

mvaligursky
Copy link
Contributor

@mvaligursky mvaligursky commented Jul 22, 2024

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 accepts displayFormat 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

@mvaligursky mvaligursky merged commit 0ab8933 into main Jul 23, 2024
8 checks passed
@mvaligursky mvaligursky deleted the mv-linear-framebuffer branch July 23, 2024 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: graphics Graphics related issue feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants