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: Introduction to fragmentNode #27239

Merged
merged 2 commits into from
Nov 23, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -51,7 +49,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 @@ -82,9 +82,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 @@ -93,23 +93,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 @@ -480,6 +480,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