Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSL: Support defined color spaces in ColorSpaceNode #29694

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

donmccurdy
Copy link
Collaborator

@donmccurdy donmccurdy commented Oct 19, 2024

Adds support to 'ColorSpaceNode' (and related chaining helpers) for any color space registered on THREE.ColorManagement. Adds a generic X-to-Y chaining TSL node:

import {
  DisplayP3ColorSpace,
  DisplayP3ColorSpaceImpl,
  LinearDisplayP3ColorSpace,
  LinearDisplayP3ColorSpaceImpl
} from 'three/addons/math/ColorSpaces.js';

THREE.ColorManagement.define( {
  [ DisplayP3ColorSpace ]: DisplayP3ColorSpaceImpl,
  [ LinearDisplayP3ColorSpace ]: LinearDisplayP3ColorSpaceImpl,
} );

const color1 = color2.convertColorSpace( LinearDisplayP3ColorSpace, DisplayP3ColorSpace );

Related:

/cc @WestLangley @sunag

Copy link

github-actions bot commented Oct 19, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 692.42
171.34
692.42
171.34
+0 B
+0 B
WebGPU 816.84
220.03
816.59
220.02
-246 B
-9 B
WebGPU Nodes 816.35
219.9
816.1
219.89
-246 B
-5 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 464.65
112.12
464.65
112.12
+0 B
+0 B
WebGPU 538.6
145.39
538.35
145.36
-248 B
-31 B
WebGPU Nodes 494.71
135.27
494.46
135.22
-248 B
-49 B

@donmccurdy
Copy link
Collaborator Author

Hm, I'm not sure what to do with this circular dependency:

  • src/nodes/tsl/TSLBase.js
    • src/nodes/display/ColorSpaceNode.js
      • src/nodes/display/ColorSpaceFunctions.js
        • src/nodes/tsl/TSLBase.js

I'm tempted to move the EOTF and OETF implementations into ColorSpaceNode.js. @sunag do you have a preference?

@sunag sunag added this to the r170 milestone Oct 20, 2024
addMethodChaining( 'toOutputColorSpace', toOutputColorSpace );
addMethodChaining( 'toWorkingColorSpace', toWorkingColorSpace );

addMethodChaining( 'workingToColorSpace', workingToColorSpace );
addMethodChaining( 'colorSpaceToWorking', colorSpaceToWorking );

addMethodChaining( 'convertColorSpace', convertColorSpace );
Copy link
Collaborator

@sunag sunag Oct 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have plans to have the color space information present in the flow of code, that way we will always know what the color space source of the current value. I was thinking about adding a node.toColorSpace( targetColorSpace ) function in the method chaining.

Maybe we could reverse the order to:

addMethodChaining( 'toColorSpace', ( node, targetColorSpace, sourceColorSpace = null  ) => convertColorSpace( node, sourceColorSpace, targetColorSpace ) );

Thinking about the future... Or maybe just remove this method from chaning for now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants