diff --git a/examples/files.json b/examples/files.json index 8dfa83ef7e2ece..73fba1cdf2f222 100644 --- a/examples/files.json +++ b/examples/files.json @@ -213,6 +213,7 @@ "webgl_sprites", "webgl_test_memory", "webgl_test_memory2", + "webgl_test_wide_gamut", "webgl_tonemapping", "webgl_video_kinect", "webgl_video_panorama_equirectangular", diff --git a/src/math/ColorManagement.js b/src/math/ColorManagement.js index d15d3d3539c98e..f928ebc6108b47 100644 --- a/src/math/ColorManagement.js +++ b/src/math/ColorManagement.js @@ -1,4 +1,4 @@ -import { SRGBColorSpace, LinearSRGBColorSpace, DisplayP3ColorSpace, } from '../constants.js'; +import { SRGBColorSpace, LinearSRGBColorSpace, DisplayP3ColorSpace, LinearDisplayP3ColorSpace, } from '../constants.js'; import { Matrix3 } from './Matrix3.js'; export function SRGBToLinear( c ) { @@ -51,24 +51,40 @@ function LinearSRGBToDisplayP3( color ) { } +function LinearDisplayP3ToLinearSRGB( color ) { + + return color.applyMatrix3( LINEAR_DISPLAY_P3_TO_LINEAR_SRGB ); + +} + +function LinearSRGBToLinearDisplayP3( color ) { + + return color.applyMatrix3( LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 ); + +} + // Conversions from to Linear-sRGB reference space. -const TO_LINEAR = { +const TO_REFERENCE = { [ LinearSRGBColorSpace ]: ( color ) => color, [ SRGBColorSpace ]: ( color ) => color.convertSRGBToLinear(), [ DisplayP3ColorSpace ]: DisplayP3ToLinearSRGB, + [ LinearDisplayP3ColorSpace ]: LinearDisplayP3ToLinearSRGB, }; // Conversions to from Linear-sRGB reference space. -const FROM_LINEAR = { +const FROM_REFERENCE = { [ LinearSRGBColorSpace ]: ( color ) => color, [ SRGBColorSpace ]: ( color ) => color.convertLinearToSRGB(), [ DisplayP3ColorSpace ]: LinearSRGBToDisplayP3, + [ LinearDisplayP3ColorSpace ]: LinearSRGBToLinearDisplayP3, }; export const ColorManagement = { enabled: true, + _workingColorSpace: LinearSRGBColorSpace, + get legacyMode() { console.warn( 'THREE.ColorManagement: .legacyMode=false renamed to .enabled=true in r150.' ); @@ -87,13 +103,13 @@ export const ColorManagement = { get workingColorSpace() { - return LinearSRGBColorSpace; + return this._workingColorSpace; }, set workingColorSpace( colorSpace ) { - console.warn( 'THREE.ColorManagement: .workingColorSpace is readonly.' ); + this._workingColorSpace = colorSpace; }, @@ -105,8 +121,8 @@ export const ColorManagement = { } - const sourceToLinear = TO_LINEAR[ sourceColorSpace ]; - const targetFromLinear = FROM_LINEAR[ targetColorSpace ]; + const sourceToLinear = TO_REFERENCE[ sourceColorSpace ]; + const targetFromLinear = FROM_REFERENCE[ targetColorSpace ]; if ( sourceToLinear === undefined || targetFromLinear === undefined ) {