Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 8 additions & 28 deletions examples/jsm/renderers/nodes/display/ColorSpaceNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,6 @@ const EncodingLib = {
LinearTosRGB
};

function getEncodingComponents( encoding ) {

switch ( encoding ) {

case LinearEncoding:
return [ 'Linear' ];
case sRGBEncoding:
return [ 'sRGB' ];

}

}

class ColorSpaceNode extends TempNode {

static LINEAR_TO_LINEAR = 'LinearToLinear';
Expand All @@ -58,29 +45,24 @@ class ColorSpaceNode extends TempNode {
this.method = method;

this.node = node;
this.factor = null;

}

fromEncoding( encoding ) {

const components = getEncodingComponents( encoding );
let method = null;

this.method = 'LinearTo' + components[ 0 ];
this.factor = components[ 1 ];
if ( encoding === LinearEncoding ) {

return this;
method = 'Linear';

}
} else if ( encoding === sRGBEncoding ) {

fromDecoding() {
method = 'sRGB';

// TODO: Remove fromDecoding()

const components = getEncodingComponents( LinearEncoding );
}

this.method = components[ 0 ] + 'ToLinear';
this.factor = components[ 1 ];
this.method = 'LinearTo' + method;

return this;

Expand All @@ -96,11 +78,9 @@ class ColorSpaceNode extends TempNode {
if ( method !== ColorSpaceNode.LINEAR_TO_LINEAR ) {

const encodingFunctionNode = EncodingLib[ method ];
const factor = this.factor;

return encodingFunctionNode( {
value: node,
factor
value: node
} ).build( builder, type );

} else {
Expand Down
15 changes: 5 additions & 10 deletions examples/jsm/renderers/nodes/inputs/TextureNode.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import InputNode from '../core/InputNode.js';
import ExpressionNode from '../core/ExpressionNode.js';
import UVNode from '../accessors/UVNode.js';
import ColorSpaceNode from '../display/ColorSpaceNode.js';

class TextureNode extends InputNode {

Expand Down Expand Up @@ -41,9 +40,9 @@ class TextureNode extends InputNode {

const nodeData = builder.getDataFromNode( this );

let colorSpace = nodeData.colorSpace;
let snippet = nodeData.snippet;

if ( colorSpace === undefined ) {
if ( snippet === undefined ) {

const uvSnippet = this.uv.build( builder, 'vec2' );
const bias = this.bias;
Expand All @@ -56,17 +55,13 @@ class TextureNode extends InputNode {

}

const textureCallSnippet = builder.getTexture( textureProperty, uvSnippet, biasSnippet );
snippet = builder.getTexture( textureProperty, uvSnippet, biasSnippet );

colorSpace = new ColorSpaceNode();
colorSpace.node = new ExpressionNode( textureCallSnippet, 'vec4' );
colorSpace.fromDecoding( builder.getTextureEncodingFromMap( texture ) );

nodeData.colorSpace = colorSpace;
nodeData.snippet = snippet;

}

return colorSpace.build( builder, output );
return builder.format( snippet, 'vec4', output );

}

Expand Down