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

NodeMaterial: Basic BSDFs of MeshStandardMaterial and NodeBuilder simplification #22398

Merged
merged 3 commits into from
Aug 24, 2021
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
14 changes: 9 additions & 5 deletions examples/jsm/renderers/nodes/accessors/MaterialNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class MaterialNode extends Node {
static OPACITY = 'opacity';
static SPECULAR = 'specular';
static SHININESS = 'shininess';
static ROUGHNESS = 'roughness';
static METALNESS = 'metalness';

constructor( scope = MaterialNode.COLOR ) {

Expand All @@ -21,7 +23,7 @@ class MaterialNode extends Node {
getType( builder ) {

const scope = this.scope;
const material = builder.getContextParameter( 'material' );
const material = builder.getContextValue( 'material' );

if ( scope === MaterialNode.COLOR ) {

Expand All @@ -35,7 +37,7 @@ class MaterialNode extends Node {

return 'vec3';

} else if ( scope === MaterialNode.SHININESS ) {
} else if ( scope === MaterialNode.SHININESS || scope === MaterialNode.ROUGHNESS || scope === MaterialNode.METALNESS ) {

return 'float';

Expand All @@ -45,7 +47,7 @@ class MaterialNode extends Node {

generate( builder, output ) {

const material = builder.getContextParameter( 'material' );
const material = builder.getContextValue( 'material' );
const scope = this.scope;

let node = null;
Expand Down Expand Up @@ -96,9 +98,11 @@ class MaterialNode extends Node {

}

} else if ( scope === MaterialNode.SHININESS ) {
} else {

node = new MaterialReferenceNode( 'shininess', 'float' );
const type = this.getType( builder );

node = new MaterialReferenceNode( scope, type );

}

Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/renderers/nodes/accessors/Object3DNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ class Object3DNode extends Node {

if ( inputNode === null || inputNode.isMatrix4Node !== true ) {

inputNode = new Matrix4Node( null );
inputNode = new Matrix4Node( /*null*/ );

}

} else if ( scope === Object3DNode.NORMAL_MATRIX ) {

if ( inputNode === null || inputNode.isMatrix3Node !== true ) {

inputNode = new Matrix3Node( null );
inputNode = new Matrix3Node( /*null*/ );

}

Expand Down
3 changes: 3 additions & 0 deletions examples/jsm/renderers/nodes/consts/MathConsts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ import ConstNode from '../core/ConstNode.js';

export const PI = new ConstNode( '3.141592653589793', 'float', 'PI' );
export const RECIPROCAL_PI = new ConstNode( '0.3183098861837907', 'float', 'RECIPROCAL_PI' );
export const EPSILON = new ConstNode( '1e-6', 'float', 'EPSILON' );

export const DEFAULT_SPECULAR_COEFFICIENT = new ConstNode( '0.04', 'float', 'DEFAULT_SPECULAR_COEFFICIENT' );
8 changes: 3 additions & 5 deletions examples/jsm/renderers/nodes/core/AttributeNode.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Node from './Node.js';
import VaryNode from './VaryNode.js';

class AttributeNode extends Node {

Expand Down Expand Up @@ -43,16 +44,13 @@ class AttributeNode extends Node {

if ( nodeVary === undefined ) {

nodeVary = builder.getVaryFromNode( this, attribute.type );
nodeVary.snippet = attributeName;
nodeVary = new VaryNode( this );

nodeData.nodeVary = nodeVary;

}

const varyName = builder.getPropertyName( nodeVary );

return builder.format( varyName, attribute.type, output );
return nodeVary.build( builder, output );

}

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/renderers/nodes/core/CodeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CodeNode extends Node {

if ( this.useKeywords === true ) {

const contextKeywords = builder.getContextParameter( 'keywords' );
const contextKeywords = builder.getContextValue( 'keywords' );

if ( contextKeywords !== undefined ) {

Expand Down
18 changes: 10 additions & 8 deletions examples/jsm/renderers/nodes/core/ContextNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@ import Node from './Node.js';

class ContextNode extends Node {

constructor( node, parameters = {} ) {
constructor( node, type, context = {} ) {

super();
super( type );

this.node = node;

this.parameters = parameters;
this.context = context;

Object.defineProperty( this, 'isContextNode', { value: true } );

}

setParameter( name, value ) {
setContextValue( name, value ) {

this.parameters[ name ] = value;
this.context[ name ] = value;

return this;

}

getParameter( name ) {
getContextValue( name ) {

return this.parameters[ name ];
return this.context[ name ];

}

Expand All @@ -36,9 +36,11 @@ class ContextNode extends Node {

generate( builder, output ) {

const type = this.getType( builder );
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems type is not used in this method.


const previousContext = builder.getContext();

builder.setContext( Object.assign( {}, builder.context, this.parameters ) );
builder.setContext( Object.assign( {}, builder.context, this.context ) );

const snippet = this.node.build( builder, output );

Expand Down
24 changes: 24 additions & 0 deletions examples/jsm/renderers/nodes/core/ExpressionNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Node from './Node.js';

class ExpressionNode extends Node {

constructor( snipped = '', type = null ) {

super( type );

this.snipped = snipped;

}

generate( builder, output ) {

const type = this.getType( builder );
const snipped = this.snipped;

return builder.format( `( ${ snipped } )`, type, output );

}

}

export default ExpressionNode;
4 changes: 2 additions & 2 deletions examples/jsm/renderers/nodes/core/FunctionCallNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Node from './Node.js';
import TempNode from './TempNode.js';

class FunctionCallNode extends Node {
class FunctionCallNode extends TempNode {

constructor( functionNode = null, parameters = {} ) {

Expand Down
18 changes: 5 additions & 13 deletions examples/jsm/renderers/nodes/core/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,21 @@ class Node {

}

update( /*frame*/ ) {
getTypeLength( builder ) {

console.warn( 'Abstract function.' );
return builder.getTypeLength( this.getType( builder ) );

}

generate( /*builder, output*/ ) {
update( /*frame*/ ) {

console.warn( 'Abstract function.' );

}

buildStage( builder, shaderStage, output = null ) {

const oldShaderStage = builder.shaderStage;

builder.shaderStage = shaderStage;

const snippet = this.build( builder, output );

builder.shaderStage = oldShaderStage;
generate( /*builder, output*/ ) {

return snippet;
console.warn( 'Abstract function.' );

}

Expand Down
Loading