Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy committed Aug 25, 2023
1 parent b8ebf09 commit 053e091
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 54 deletions.
11 changes: 1 addition & 10 deletions examples/webgl_test_wide_gamut.html
Original file line number Diff line number Diff line change
Expand Up @@ -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();

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

Expand Down Expand Up @@ -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;

Expand Down
55 changes: 11 additions & 44 deletions src/math/ColorManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] );
Expand Down Expand Up @@ -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;

}

}

};

0 comments on commit 053e091

Please sign in to comment.