WebGLRenderer: Support "Linear Display P3" working color space and "Display P3" unlit rendering#26644
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
|
To summarize a few things happening in this PR and its demo —
As a result of (3) and (4), color images are typically uploaded to WebGL in either sRGB or Display P3 (whichever is the non-linear analog to the linear working color space). When the GPU samples the textures, it decodes each sample by applying the sRGB EOTF, to obtain a sample in the working color space (Linear sRGB or Linear Display P3). |
|
I've simplified the demo, using just a three.js logo. Copyright assigned to the three.js authors, Creative Commons Attribution 3.0. This is ready to merge experimentally, when we are ready. We can then continue working on changes required for lit rendering. |
src/renderers/WebGLRenderer.js
Outdated
| this.resetColorManagement = function () { | ||
|
|
||
| _gl.drawingBufferColorSpace = this._outputColorSpace === DisplayP3ColorSpace ? 'display-p3' : 'srgb'; | ||
| _gl.unpackColorSpace = ColorManagement.workingColorSpace === LinearDisplayP3ColorSpace ? 'display-p3' : 'srgb'; | ||
|
|
||
| }; | ||
|
|
There was a problem hiding this comment.
Do we need this new method?
Could we inline the calls in set outputColorSpace( colorSpace )?
There was a problem hiding this comment.
No need for it – or we don't need a public method, at least. I've inlined the calls in the setter. ✅
Co-authored-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com>
05e3aa0 to
b313f11
Compare
|
FYI, this demo has just broken in Safari on macOS Sonoma: |
### Changelog Now compatible with three.js r157+ ### Docs None ### Description Closes #391 The `LinearTosRGB` function was renamed in r157 mrdoob/three.js#26644 and the old function was removed in r167 mrdoob/three.js#28901
tl;dr — Adds support for wide gamut color spaces in unlit rendering workflows such as 2D games, photogrammetry, and image processing applications.
Extends THREE.ColorManagement and THREE.WebGLRenderer with support — only in "unlit" scenes, currently — for the wide-gamut Display P3 color space. To use this feature, the following steps are required:
ColorManagement.workingColorSpace = LinearDisplayP3ColorSpacerenderer.outputColorSpace = DisplayP3ColorSpacetexture.colorSpace = DisplayP3ColorSpaceAND ensure each texture's ICC Profile (or other color space metadata) is correctly embeddedTo see the difference in this example, you'll need use Chrome or Safari, and a display and operating system that support the Display P3 wide gamut color space. Most newer macOS devices will do fine, but your external monitor may not. The change covers only unlit rendering now, e.g. MeshBasicMaterial. More changes will be required to adjust the lit rendering pipeline for a wider gamut, and @WestLangley and I are still discussing those requirements.
The images attached are borrowed from https://webkit.org/blog-files/color-gamut/comparison.html. We will want to verify the licenses and attribution before merging this PR, or create our own examples.Related