diff --git a/examples/webgl_test_wide_gamut.html b/examples/webgl_test_wide_gamut.html index 3838b0c59e35ea..89a88962a23817 100644 --- a/examples/webgl_test_wide_gamut.html +++ b/examples/webgl_test_wide_gamut.html @@ -111,11 +111,6 @@ loader = new THREE.TextureLoader().setPath( 'textures/wide_gamut/' ); - const light = new THREE.HemisphereLight( 0xffffff, 0x444444, 3 ); - light.position.set( - 2, 2, 2 ); - sceneL.add( light.clone() ); - sceneR.add( light.clone() ); - initTextures(); initSlider(); @@ -142,11 +137,6 @@ async function initTextures() { - // TODO: With workingColorSpace="p3-linear", outputColorSpace="srgb", images display quite differently. Expected? - // TODO: Where should .unpackColorSpace be set? Per texture or globally on the renderer? - // TODO: What happens given a Linear-sRGB texture when working color space is Linear-P3? Can we support that? - // TODO: How to detect support for drawingBufferColorSpace="display-p3"? - textureL = await loader.loadAsync( params.image.replace( '{colorSpace}', 'srgb' ) ); textureR = await loader.loadAsync( params.image.replace( '{colorSpace}', 'p3' ) ); @@ -209,6 +199,7 @@ // Sets the matrix uv transform so the texture image is contained in a region having the specified aspect ratio, // and does so without distortion. Akin to CSS object-fit: contain. + // Source: https://github.com/mrdoob/three.js/pull/17199 var imageAspect = ( target.image && target.image.width ) ? target.image.width / target.image.height : 1; diff --git a/src/math/ColorManagement.js b/src/math/ColorManagement.js index 7364c3f71ae8de..e6bbce2344e765 100644 --- a/src/math/ColorManagement.js +++ b/src/math/ColorManagement.js @@ -75,8 +75,16 @@ const TO_REFERENCE = { const FROM_REFERENCE = { [ LinearSRGBColorSpace ]: ( color ) => color, [ SRGBColorSpace ]: ( color ) => color.convertLinearToSRGB(), - [ DisplayP3ColorSpace ]: LinearSRGBToDisplayP3, [ LinearDisplayP3ColorSpace ]: LinearSRGBToLinearDisplayP3, + [ DisplayP3ColorSpace ]: LinearSRGBToDisplayP3, +}; + +const COLOR_SPACE_COMPONENTS = { + [ NoColorSpace ]: { transfer: LinearTransfer, primaries: undefined }, + [ LinearSRGBColorSpace ]: { transfer: LinearTransfer, primaries: Rec709Primaries }, + [ SRGBColorSpace ]: { transfer: SRGBTransfer, primaries: Rec709Primaries }, + [ LinearDisplayP3ColorSpace ]: { transfer: LinearTransfer, primaries: P3Primaries }, + [ DisplayP3ColorSpace ]: { transfer: SRGBTransfer, primaries: P3Primaries }, }; const SUPPORTED_WORKING_COLOR_SPACES = new Set( [ LinearSRGBColorSpace, LinearDisplayP3ColorSpace ] ); @@ -156,55 +164,14 @@ export const ColorManagement = { getPrimaries: function ( colorSpace ) { - switch ( colorSpace ) { - - case SRGBColorSpace: - case LinearSRGBColorSpace: - return Rec709Primaries; - - case DisplayP3ColorSpace: - case LinearDisplayP3ColorSpace: - return P3Primaries; - - default: - throw new Error( `Unsupported color space, "${ colorSpace }."` ); - - } + return COLOR_SPACE_COMPONENTS[ colorSpace ].primaries; }, getTransfer: function ( colorSpace ) { - switch ( colorSpace ) { - - case SRGBColorSpace: - case DisplayP3ColorSpace: - return SRGBTransfer; - - case LinearSRGBColorSpace: - case LinearDisplayP3ColorSpace: - case NoColorSpace: - return LinearTransfer; - - default: - throw new Error( `Unsupported color space, "${ colorSpace }."` ); - - } + return COLOR_SPACE_COMPONENTS[ colorSpace ].transfer; }, - getUnpackColorSpace: function () { - - switch ( this._workingColorSpace ) { - - case LinearSRGBColorSpace: - return SRGBColorSpace; - - case LinearDisplayP3ColorSpace: - return DisplayP3ColorSpace; - - } - - } - };