Skip to content

Commit

Permalink
TSL: Introduction to fragmentNode (#27239)
Browse files Browse the repository at this point in the history
* Introduction to fragmentNode

* revision
  • Loading branch information
sunag committed Nov 23, 2023
1 parent 3b2deb6 commit 1ab4a8a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class InstancedPointsNodeMaterial extends NodeMaterial {

} )();

this.colorNode = tslFn( () => {
this.fragmentNode = tslFn( () => {

const vUv = varying( vec2(), 'vUv' );

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/nodes/materials/Line2NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class Line2NodeMaterial extends NodeMaterial {

} );

this.colorNode = tslFn( () => {
this.fragmentNode = tslFn( () => {

const vUv = varyingProperty( 'vec2', 'vUv' );

Expand Down
22 changes: 12 additions & 10 deletions examples/jsm/nodes/materials/NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ class NodeMaterial extends ShaderMaterial {

this.forceSinglePass = false;

this.unlit = this.constructor === NodeMaterial.prototype.constructor; // Extended materials are not unlit by default

this.fog = true;
this.lights = true;
this.normals = true;
Expand All @@ -52,7 +50,9 @@ class NodeMaterial extends ShaderMaterial {

this.positionNode = null;

this.outputNode = null; // @TODO: Rename to fragmentNode
this.outputNode = null;

this.fragmentNode = null;
this.vertexNode = null;

}
Expand Down Expand Up @@ -83,9 +83,9 @@ class NodeMaterial extends ShaderMaterial {

builder.addStack();

let outputNode;
let resultNode;

if ( this.unlit === false ) {
if ( this.fragmentNode === null ) {

if ( this.normals === true ) this.setupNormal( builder );

Expand All @@ -94,23 +94,23 @@ class NodeMaterial extends ShaderMaterial {

const outgoingLightNode = this.setupLighting( builder );

outputNode = this.setupOutput( builder, vec4( outgoingLightNode, diffuseColor.a ) );
resultNode = this.setupOutput( builder, vec4( outgoingLightNode, diffuseColor.a ) );

// OUTPUT NODE

output.assign( outputNode );
output.assign( resultNode );

//

if ( this.outputNode !== null ) outputNode = this.outputNode;
if ( this.outputNode !== null ) resultNode = this.outputNode;

} else {

outputNode = this.setupOutput( builder, this.outputNode || vec4( 0, 0, 0, 1 ) );
resultNode = this.setupOutput( builder, this.fragmentNode );

}

builder.stack.outputNode = outputNode;
builder.stack.outputNode = resultNode;

builder.addFlow( 'fragment', builder.removeStack() );

Expand Down Expand Up @@ -481,6 +481,8 @@ class NodeMaterial extends ShaderMaterial {
this.positionNode = source.positionNode;

this.outputNode = source.outputNode;

this.fragmentNode = source.fragmentNode;
this.vertexNode = source.vertexNode;

return super.copy( source );
Expand Down
10 changes: 0 additions & 10 deletions examples/jsm/nodes/materials/PointsNodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,10 @@ class PointsNodeMaterial extends NodeMaterial {

this.lights = false;
this.normals = false;

this.transparent = true;

this.colorNode = null;
this.opacityNode = null;

this.alphaTestNode = null;

this.lightNode = null;

this.sizeNode = null;

this.positionNode = null;

this.setDefaultValues( defaultValues );

this.setValues( parameters );
Expand Down
7 changes: 0 additions & 7 deletions examples/jsm/nodes/materials/SpriteNodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ class SpriteNodeMaterial extends NodeMaterial {
this.lights = false;
this.normals = false;

this.colorNode = null;
this.opacityNode = null;

this.alphaTestNode = null;

this.lightNode = null;

this.positionNode = null;
this.rotationNode = null;
this.scaleNode = null;
Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/renderers/common/Background.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ class Background extends DataMap {
viewProj = viewProj.setZ( viewProj.w );

const nodeMaterial = new NodeMaterial();
nodeMaterial.outputNode = this.backgroundMeshNode;
nodeMaterial.side = BackSide;
nodeMaterial.depthTest = false;
nodeMaterial.depthWrite = false;
nodeMaterial.fog = false;
nodeMaterial.vertexNode = viewProj;
nodeMaterial.fragmentNode = this.backgroundMeshNode;

this.backgroundMesh = backgroundMesh = new Mesh( new SphereGeometry( 1, 32, 32 ), nodeMaterial );
backgroundMesh.frustumCulled = false;
Expand Down
4 changes: 2 additions & 2 deletions examples/webgpu_tsl_editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
rendererDOM.appendChild( renderer.domElement );

const material = new Nodes.NodeMaterial();
material.outputNode = Nodes.vec4( 0, 0, 0, 1 );
material.fragmentNode = Nodes.vec4( 0, 0, 0, 1 );

const mesh = new THREE.Mesh( new THREE.PlaneGeometry( 1, 1 ), material );
scene.add( mesh );
Expand Down Expand Up @@ -183,7 +183,7 @@
const tslCode = `let output = null;\n${ editor.getValue() }\nreturn { output };`;
const nodes = new Function( 'THREE', 'TSL', tslCode )( THREE, Nodes );

mesh.material.outputNode = nodes.output;
mesh.material.fragmentNode = nodes.output;
mesh.material.needsUpdate = true;

let NodeBuilder;
Expand Down

0 comments on commit 1ab4a8a

Please sign in to comment.