Skip to content

Commit

Permalink
TSL: Support defined color spaces in ColorSpaceNode (#1349)
Browse files Browse the repository at this point in the history
* TSL: Support defined color spaces in ColorSpaceNode

* Update three.js

* Add src

* Update patch and delete src

* Add src

* Update patch and delete src

* Update declarations
  • Loading branch information
Methuselah96 authored Nov 10, 2024
1 parent 1d1f6cf commit f868463
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 28 deletions.
22 changes: 5 additions & 17 deletions src-testing/changes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6705,10 +6705,10 @@ index 520a3c91..524d188c 100644
} else {
bindings.push(instanceGroup);
diff --git a/src-testing/src/renderers/common/nodes/NodeLibrary.ts b/src-testing/src/renderers/common/nodes/NodeLibrary.ts
index 15931016..2128aa79 100644
index b6738b95..9b23a37b 100644
--- a/src-testing/src/renderers/common/nodes/NodeLibrary.ts
+++ b/src-testing/src/renderers/common/nodes/NodeLibrary.ts
@@ -1,4 +1,21 @@
@@ -1,12 +1,28 @@
+import { Material } from '../../../materials/Material.js';
+import NodeMaterial from '../../../materials/nodes/NodeMaterial.js';
+import { ToneMapping } from '../../../constants.js';
Expand All @@ -6725,13 +6725,11 @@ index 15931016..2128aa79 100644
+ ToneMapping,
+ (color: NodeRepresentation, exposure: NodeRepresentation) => ShaderNodeObject<Node>
+ >;
+ colorSpaceNodes: Map<ColorSpaceMethod, (color: NodeRepresentation) => ShaderNodeObject<Node>>;
+
constructor() {
this.lightNodes = new WeakMap();
this.materialNodes = new Map();
@@ -6,8 +23,8 @@ class NodeLibrary {
this.colorSpaceNodes = new Map();
this.toneMappingNodes = new Map();
}

- fromMaterial(material) {
Expand All @@ -6741,20 +6739,10 @@ index 15931016..2128aa79 100644

let nodeMaterial = null;

@@ -24,39 +41,52 @@ class NodeLibrary {
@@ -23,31 +39,44 @@ class NodeLibrary {
return nodeMaterial;
}

- addColorSpace(colorSpaceNode, colorSpace) {
+ addColorSpace(colorSpaceNode: (color: NodeRepresentation) => ShaderNodeObject<Node>, colorSpace: ColorSpaceMethod) {
this.addType(colorSpaceNode, colorSpace, this.colorSpaceNodes);
}

- getColorSpaceFunction(colorSpace) {
+ getColorSpaceFunction(colorSpace: ColorSpaceMethod) {
return this.colorSpaceNodes.get(colorSpace) || null;
}

- addToneMapping(toneMappingNode, toneMapping) {
+ addToneMapping(
+ toneMappingNode: (color: NodeRepresentation, exposure: NodeRepresentation) => ShaderNodeObject<Node>,
Expand Down Expand Up @@ -6804,7 +6792,7 @@ index 15931016..2128aa79 100644
if (library.has(type)) {
console.warn(`Redefinition of node ${type}`);
return;
@@ -69,7 +99,11 @@ class NodeLibrary {
@@ -60,7 +89,11 @@ class NodeLibrary {
library.set(type, nodeClass);
}

Expand Down
4 changes: 2 additions & 2 deletions types/three/src/nodes/display/ColorSpaceFunctions.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Node from "../core/Node.js";
import { NodeRepresentation, ShaderNodeObject } from "../tsl/TSLCore.js";

export const sRGBToLinearSRGB: (color: NodeRepresentation) => ShaderNodeObject<Node>;
export const sRGBTransferEOTF: (color: NodeRepresentation) => ShaderNodeObject<Node>;

export const linearSRGBTosRGB: (color: NodeRepresentation) => ShaderNodeObject<Node>;
export const sRGBTransferOETF: (color: NodeRepresentation) => ShaderNodeObject<Node>;
8 changes: 7 additions & 1 deletion types/three/src/nodes/display/ColorSpaceNode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class ColorSpaceNode extends TempNode {
target: string,
);

getColorSpace(nodeBuilder: NodeBuilder, colorSpace: WorkingOrOutputColorSpace): string;
resolveColorSpace(nodeBuilder: NodeBuilder, colorSpace: WorkingOrOutputColorSpace): string;
}

export const toOutputColorSpace: (
Expand All @@ -43,6 +43,12 @@ export const colorSpaceToWorking: (
colorSpace: string,
) => ShaderNodeObject<ColorSpaceNode>;

export const convertColorSpace: (
node: NodeRepresentation,
sourceColorSpace: string,
targetColorSpace: string,
) => ShaderNodeObject<ColorSpaceNode>;

declare module "../tsl/TSLCore.js" {
interface NodeElements {
toOutputColorSpace: typeof toOutputColorSpace;
Expand Down
7 changes: 0 additions & 7 deletions types/three/src/renderers/common/nodes/NodeLibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Light } from "../../../lights/Light.js";
import { Material } from "../../../materials/Material.js";
import NodeMaterial from "../../../materials/nodes/NodeMaterial.js";
import Node from "../../../nodes/core/Node.js";
import { ColorSpaceMethod } from "../../../nodes/display/ColorSpaceNode.js";
import AnalyticLightNode from "../../../nodes/lighting/AnalyticLightNode.js";
import { NodeRepresentation, ShaderNodeObject } from "../../../nodes/tsl/TSLCore.js";
declare class NodeLibrary {
Expand All @@ -19,14 +18,8 @@ declare class NodeLibrary {
ToneMapping,
(color: NodeRepresentation, exposure: NodeRepresentation) => ShaderNodeObject<Node>
>;
colorSpaceNodes: Map<ColorSpaceMethod, (color: NodeRepresentation) => ShaderNodeObject<Node>>;
constructor();
fromMaterial(material: Material): Material | null;
addColorSpace(
colorSpaceNode: (color: NodeRepresentation) => ShaderNodeObject<Node>,
colorSpace: ColorSpaceMethod,
): void;
getColorSpaceFunction(colorSpace: ColorSpaceMethod): ((color: NodeRepresentation) => ShaderNodeObject<Node>) | null;
addToneMapping(
toneMappingNode: (color: NodeRepresentation, exposure: NodeRepresentation) => ShaderNodeObject<Node>,
toneMapping: ToneMapping,
Expand Down

0 comments on commit f868463

Please sign in to comment.