Skip to content

Commit

Permalink
WIP: Display P3 render example
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy committed Aug 24, 2023
1 parent 6162a7e commit d1042cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions examples/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 23 additions & 7 deletions src/math/ColorManagement.js
Original file line number Diff line number Diff line change
@@ -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 ) {
Expand Down Expand Up @@ -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 <source> to Linear-sRGB reference space.
const TO_LINEAR = {
const TO_REFERENCE = {
[ LinearSRGBColorSpace ]: ( color ) => color,
[ SRGBColorSpace ]: ( color ) => color.convertSRGBToLinear(),
[ DisplayP3ColorSpace ]: DisplayP3ToLinearSRGB,
[ LinearDisplayP3ColorSpace ]: LinearDisplayP3ToLinearSRGB,
};

// Conversions to <target> 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.' );
Expand All @@ -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;

},

Expand All @@ -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 ) {

Expand Down

0 comments on commit d1042cb

Please sign in to comment.