Skip to content

Add color space selection to particles sample - #574

Open
beaufortfrancois wants to merge 5 commits into
webgpu:mainfrom
beaufortfrancois:colorspace
Open

beaufortfrancois wants to merge 5 commits into
webgpu:mainfrom
beaufortfrancois:colorspace

Conversation

@beaufortfrancois

@beaufortfrancois beaufortfrancois commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Let users pick the canvas colorSpace (srgb, srgb-linear, display-p3, display-p3-linear) in a new "Color settings" folder. Only color spaces supported by the browser are listed, and a warning is shown when a display-p3 space is selected on a non wide gamut display.

It also passes the selected color space to copyExternalImageToTexture and re-copy the image when it changes. Switch the texture to rgba16float to avoid banding with linear color spaces.

ChromeStatus entry: https://chromestatus.com/feature/5122501071994880

image

Try it live in https://webgpu.github.io/webgpu-samples/?sample=particles

FYI @ccameron-chromium

Let users pick the canvas colorSpace (srgb, srgb-linear, display-p3, display-p3-linear) in a new "Color settings" folder. Only color spaces supported by the browser are listed, and a warning is shown when a display-p3 space is selected on a non wide gamut display.
Pass the selected color space to copyExternalImageToTexture and re-copy
the image when it changes. Switch the texture to rgba16float to avoid
banding with linear color spaces.
Comment thread sample/particles/main.ts Outdated
Comment thread sample/particles/main.ts Outdated
Comment thread sample/particles/main.ts Outdated
Comment thread sample/particles/main.ts Outdated
{ source: imageBitmap },
{
texture: texture,
colorSpace: simulationParams.colorSpace as PredefinedColorSpace,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't doing this mean that the colorSpace option will never make a visual difference? webgpu.png is sRGB, so if we color-manage it correctly, it's always going to stay in sRGB.

We should use an image that is Display-P3 or wider (something like https://webkit.org/blog-files/color-gamut/Webkit-logo-P3.png from https://webkit.org/blog-files/color-gamut/) so we can see a difference.

But actually, there should* still be no difference because both the texture and the canvas are float formats so they don't get clamped. Would need to change the texture back to unorm.

* I tried hacking in the webkit image (keeping the float format) and it does make a visible difference so I'm not sure if I'm missing something or there is a chrome bug.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ccameron-chromium Your help would be appreciated there.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't doing this mean that the colorSpace option will never make a visual difference? webgpu.png is sRGB, so if we color-manage it correctly, it's always going to stay in sRGB.

Yeah, I suggested matching the import to the swapchain so that the result would be not be affected by the color space choice.

  • I tried hacking in the webkit image (keeping the float format) and it does make a visible difference so I'm not sure if I'm missing something or there is a chrome bug.

CoreAnimation doesn't always behave well with sRGB-linear spaces ... like, it seems to do strange things slightly outside of the sRGB gamut for reasons I don't understand.

The main place where the -linear formats are useful is if you're doing some effect that either needs to be done in linear space or is more convenient to do in linear space. E.g, any sort of physically-based rendering using light transport is always done in linear-float. So if we wanted to model the particle decay using some physical process, then when outputting to the -linear formats, we wouldn't need to convert based to the sRGB transfer function in a final pass.

@kainino0x kainino0x Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can always have a toggle for unorm/float formats on the input/output or something like that. I just would like to show various options enabling something you couldn't do before.

I put up my hacked version here for testing https://kai.graphics/webgpu-samples/?sample=particles

https://github.com/kainino0x/webgpu-samples/commits/main/

This branch has not been deployed

No deployments
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