Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 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
4 changes: 2 additions & 2 deletions examples/jsm/nodes/accessors/CubeTextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ class CubeTextureNode extends TextureNode {

const levelSnippet = levelNode.build( builder, 'float' );

snippet = builder.getCubeTextureLevel( textureProperty, uvSnippet, levelSnippet );
snippet = builder.getCubeTextureLevel( this, textureProperty, uvSnippet, levelSnippet );

} else {

snippet = builder.getCubeTexture( textureProperty, uvSnippet );
snippet = builder.getCubeTexture( this, textureProperty, uvSnippet );

}

Expand Down
27 changes: 16 additions & 11 deletions examples/jsm/nodes/accessors/TextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TextureNode extends UniformNode {

constructor( value, uvNode = null, levelNode = null ) {

super( value, 'vec4' );
super( value );

this.isTextureNode = true;

Expand All @@ -24,6 +24,14 @@ class TextureNode extends UniformNode {

}

getNodeType( /*builder*/ ) {

if ( this.value.isDepthTexture === true ) return 'float';

return 'vec4';

}

getInputType( /*builder*/ ) {

return 'texture';
Expand Down Expand Up @@ -81,7 +89,7 @@ class TextureNode extends UniformNode {

}

const textureProperty = super.generate( builder, 'texture' );
const textureProperty = super.generate( builder, 'property' );

if ( output === 'sampler' ) {

Expand All @@ -93,32 +101,29 @@ class TextureNode extends UniformNode {

} else {

const nodeType = this.getNodeType( builder );
const nodeData = builder.getDataFromNode( this );

let propertyName = nodeData.propertyName;

if ( propertyName === undefined ) {

const uvSnippet = uvNode.build( builder, 'vec2' );
const nodeVar = builder.getVarFromNode( this, 'vec4' );
const nodeVar = builder.getVarFromNode( this, nodeType );

propertyName = builder.getPropertyName( nodeVar );

let snippet = null;

if ( texture.isVideoTexture === true ) {

snippet = builder.getVideoTexture( textureProperty, uvSnippet );

} else if ( levelNode && levelNode.isNode === true ) {
if ( levelNode && levelNode.isNode === true ) {

const levelSnippet = levelNode.build( builder, 'float' );

snippet = builder.getTextureLevel( textureProperty, uvSnippet, levelSnippet );
snippet = builder.getTextureLevel( texture, textureProperty, uvSnippet, levelSnippet );

} else {

snippet = builder.getTexture( textureProperty, uvSnippet );
snippet = builder.getTexture( texture, textureProperty, uvSnippet );

}

Expand All @@ -129,7 +134,7 @@ class TextureNode extends UniformNode {

}

return builder.format( propertyName, 'vec4', output );
return builder.format( propertyName, nodeType, output );

}

Expand Down
17 changes: 9 additions & 8 deletions examples/jsm/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@ class NodeBuilder {
constructor( object, renderer, parser ) {

this.object = object;
this.material = object.material || null;
this.geometry = object.geometry || null;
this.material = object && ( object.material || null );
this.geometry = object && ( object.geometry || null );
this.renderer = renderer;
this.parser = parser;

this.nodes = [];
this.updateNodes = [];
this.hashNodes = {};

this.scene = null;
this.lightsNode = null;
this.environmentNode = null;
this.fogNode = null;
this.toneMappingNode = null;

this.vertexShader = null;
this.fragmentShader = null;
Expand All @@ -63,7 +64,7 @@ class NodeBuilder {

this.context = {
keywords: new NodeKeywords(),
material: object.material,
material: this.material,
getMIPLevelAlgorithmNode: ( textureNode, levelNode ) => levelNode.mul( maxMipLevel( textureNode ) )
};

Expand Down Expand Up @@ -209,25 +210,25 @@ class NodeBuilder {

}

getTexture( /* textureProperty, uvSnippet */ ) {
getTexture( /* texture, textureProperty, uvSnippet */ ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can try merging getTexture and getCubeTexture functions together now that we have texture passed as a parameter? (Similar as for VideoTexture you didn't created a separate getVideoTexture function but modified getTexture)


console.warn( 'Abstract function.' );

}

getTextureLevel( /* textureProperty, uvSnippet, levelSnippet */ ) {
getTextureLevel( /* texture, textureProperty, uvSnippet, levelSnippet */ ) {

console.warn( 'Abstract function.' );

}

getCubeTexture( /* textureProperty, uvSnippet */ ) {
getCubeTexture( /* texture, textureProperty, uvSnippet */ ) {

console.warn( 'Abstract function.' );

}

getCubeTextureLevel( /* textureProperty, uvSnippet, levelSnippet */ ) {
getCubeTextureLevel( /* texture, textureProperty, uvSnippet, levelSnippet */ ) {

console.warn( 'Abstract function.' );

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/nodes/fog/FogExp2Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FogExp2Node extends FogNode {
const depthNode = positionView.z.negate();
const densityNode = this.densityNode;

this.factorNode = densityNode.mul( densityNode, depthNode, depthNode ).negate().exp().oneMinus();
return densityNode.mul( densityNode, depthNode, depthNode ).negate().exp().oneMinus();

}

Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/nodes/fog/FogNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class FogNode extends Node {

}

generate( builder ) {
construct() {

return this.factorNode.build( builder, 'float' );
return this.factorNode;

}

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/nodes/fog/FogRangeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FogRangeNode extends FogNode {

construct() {

this.factorNode = smoothstep( this.nearNode, this.farNode, positionView.z.negate() );
return smoothstep( this.nearNode, this.farNode, positionView.z.negate() );

}

Expand Down
64 changes: 7 additions & 57 deletions examples/jsm/nodes/materials/NodeMaterial.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Material, ShaderMaterial, NoToneMapping } from 'three';
import { Material, ShaderMaterial } from 'three';
import { getNodeChildren, getCacheKey } from '../core/NodeUtils.js';
import { attribute } from '../core/AttributeNode.js';
import { diffuseColor } from '../core/PropertyNode.js';
Expand All @@ -8,13 +8,8 @@ import { modelViewProjection } from '../accessors/ModelViewProjectionNode.js';
import { transformedNormalView } from '../accessors/NormalNode.js';
import { instance } from '../accessors/InstanceNode.js';
import { positionLocal } from '../accessors/PositionNode.js';
import { reference } from '../accessors/ReferenceNode.js';
import { skinning } from '../accessors/SkinningNode.js';
import { texture } from '../accessors/TextureNode.js';
import { cubeTexture } from '../accessors/CubeTextureNode.js';
import { toneMapping } from '../display/ToneMappingNode.js';
import { rangeFog } from '../fog/FogRangeNode.js';
import { densityFog } from '../fog/FogExp2Node.js';
import { lightsWithoutWrap } from '../lighting/LightsNode.js';
import AONode from '../lighting/AONode.js';
import EnvironmentNode from '../lighting/EnvironmentNode.js';
Expand Down Expand Up @@ -161,28 +156,7 @@ class NodeMaterial extends ShaderMaterial {

constructLights( builder ) {

let lightsNode = this.lightsNode || builder.lightsNode;
let envNode = this.envNode || builder.scene.environmentNode;

if ( envNode === undefined && builder.scene.environment ) {

const environment = builder.scene.environment;

if ( environment.isCubeTexture === true ) {

envNode = cubeTexture( environment );

} else if ( environment.isTexture === true ) {

envNode = texture( environment );

} else {

console.error( 'NodeMaterial: Unsupported environment configuration.', environment );

}

}
const envNode = this.envNode || builder.environmentNode;

const materialLightsNode = [];

Expand All @@ -198,6 +172,8 @@ class NodeMaterial extends ShaderMaterial {

}

let lightsNode = this.lightsNode || builder.lightsNode;

if ( materialLightsNode.length > 0 ) {

lightsNode = lightsWithoutWrap( [ ...lightsNode.lightNodes, ...materialLightsNode ] );
Expand Down Expand Up @@ -251,15 +227,9 @@ class NodeMaterial extends ShaderMaterial {

// TONE MAPPING

let toneMappingNode = renderer.toneMappingNode;

if ( ! toneMappingNode && renderer.toneMapping !== NoToneMapping ) {
const toneMappingNode = builder.toneMappingNode;

toneMappingNode = toneMapping( renderer.toneMapping, reference( 'toneMappingExposure', 'float', renderer ), outgoingLight );

}

if ( toneMappingNode && toneMappingNode.isNode === true ) {
if ( toneMappingNode ) {

outgoingLight = toneMappingNode.context( { color: outgoingLight } );

Expand All @@ -275,27 +245,7 @@ class NodeMaterial extends ShaderMaterial {

// FOG

let fogNode = builder.fogNode;

if ( ( fogNode && fogNode.isNode !== true ) && builder.scene.fog ) {

const fog = builder.scene.fog;

if ( fog.isFogExp2 ) {

fogNode = densityFog( reference( 'color', 'color', fog ), reference( 'density', 'float', fog ) );

} else if ( fog.isFog ) {

fogNode = rangeFog( reference( 'color', 'color', fog ), reference( 'near', 'float', fog ), reference( 'far', 'float', fog ) );

} else {

console.error( 'NodeMaterial: Unsupported fog configuration.', fog );

}

}
const fogNode = builder.fogNode;

if ( fogNode ) outputNode = vec4( fogNode.mixAssign( outputNode.rgb ), outputNode.a );

Expand Down
8 changes: 4 additions & 4 deletions examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,27 +422,27 @@ class WebGLNodeBuilder extends NodeBuilder {

}

getTexture( textureProperty, uvSnippet ) {
getTexture( texture, textureProperty, uvSnippet ) {

return `texture2D( ${textureProperty}, ${uvSnippet} )`;

}

getTextureBias( textureProperty, uvSnippet, biasSnippet ) {
getTextureBias( texture, textureProperty, uvSnippet, biasSnippet ) {

if ( this.material.extensions !== undefined ) this.material.extensions.shaderTextureLOD = true;

return `textureLod( ${textureProperty}, ${uvSnippet}, ${biasSnippet} )`;

}

getCubeTexture( textureProperty, uvSnippet ) {
getCubeTexture( texture, textureProperty, uvSnippet ) {

return `textureCube( ${textureProperty}, ${uvSnippet} )`;

}

getCubeTextureBias( textureProperty, uvSnippet, biasSnippet ) {
getCubeTextureBias( texture, textureProperty, uvSnippet, biasSnippet ) {

if ( this.material.extensions !== undefined ) this.material.extensions.shaderTextureLOD = true;

Expand Down
Loading