Skip to content

Commit

Permalink
Node: Document more modules. (#30027)
Browse files Browse the repository at this point in the history
* Node: Document more modules.

* Docs: Minor fixes.

* Docs: More fixes.
  • Loading branch information
Mugen87 authored Dec 3, 2024
1 parent 0c45156 commit 93dccc1
Show file tree
Hide file tree
Showing 13 changed files with 499 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/nodes/core/LightingModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class LightingModel {
* This method is intended for setting up lighting model and context data
* which are later used in the evaluation process.
*
* @abstract
* @param {ContextNode} input - The current node context.
* @param {StackNode} stack - The current stack.
* @param {NodeBuilder} builder - The current node builder.
Expand All @@ -20,6 +21,7 @@ class LightingModel {
* This method is intended for executing final tasks like final updates
* to the outgoing light.
*
* @abstract
* @param {ContextNode} input - The current node context.
* @param {StackNode} stack - The current stack.
* @param {NodeBuilder} builder - The current node builder.
Expand All @@ -30,6 +32,7 @@ class LightingModel {
* This method is intended for implementing the direct light term and
* executed during the build process of directional, point and spot light nodes.
*
* @abstract
* @param {Object} input - The input data.
* @param {StackNode} stack - The current stack.
* @param {NodeBuilder} builder - The current node builder.
Expand All @@ -40,6 +43,7 @@ class LightingModel {
* This method is intended for implementing the direct light term for
* rect area light nodes.
*
* @abstract
* @param {Object} input - The input data.
* @param {StackNode} stack - The current stack.
* @param {NodeBuilder} builder - The current node builder.
Expand All @@ -49,6 +53,7 @@ class LightingModel {
/**
* This method is intended for implementing the indirect light term.
*
* @abstract
* @param {ContextNode} input - The current node context.
* @param {StackNode} stack - The current stack.
* @param {NodeBuilder} builder - The current node builder.
Expand All @@ -60,6 +65,7 @@ class LightingModel {
* Unlike other methods, this method must be called manually by the lighting
* model in its indirect term.
*
* @abstract
* @param {ContextNode} input - The current node context.
* @param {StackNode} stack - The current stack.
* @param {NodeBuilder} builder - The current node builder.
Expand Down
18 changes: 18 additions & 0 deletions src/nodes/core/ParameterNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { nodeObject } from '../tsl/TSLBase.js';
import PropertyNode from './PropertyNode.js';

/**
* Special version of {@link PropertyNode} which is used for parameters.
*
* @augments PropertyNode
*/
class ParameterNode extends PropertyNode {

static get type() {
Expand All @@ -9,10 +14,23 @@ class ParameterNode extends PropertyNode {

}

/**
* Constructs a new parameter node.
*
* @param {String} nodeType - The type of the node.
* @param {String?} [name=null] - The name of the parameter in the shader.
*/
constructor( nodeType, name = null ) {

super( nodeType, name );

/**
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
* @default true
*/
this.isParameterNode = true;

}
Expand Down
46 changes: 46 additions & 0 deletions src/nodes/core/PropertyNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import Node from './Node.js';
import { nodeImmutable, nodeObject } from '../tsl/TSLCore.js';

/**
* This class represents a shader property. It can be used on
* to explicitely define a property and assign a value to it.
*
* ```js
* const threshold = property( 'float', 'threshold' ).assign( THRESHOLD );
*```
* `PropertyNode` is used by the engine to predefined common material properties
* for TSL code.
*
* @augments Node
*/
class PropertyNode extends Node {

static get type() {
Expand All @@ -9,13 +21,41 @@ class PropertyNode extends Node {

}

/**
* Constructs a new property node.
*
* @param {String} nodeType - The type of the node.
* @param {String?} [name=null] - The name of the property in the shader.
* @param {Boolean} [varying=false] - Whether this property is a varying or not.
*/
constructor( nodeType, name = null, varying = false ) {

super( nodeType );

/**
* The name of the property in the shader. If no name is defined,
* the node system auto-generates one.
*
* @type {String?}
* @default null
*/
this.name = name;

/**
* Whether this property is a varying or not.
*
* @type {Boolean}
* @default false
*/
this.varying = varying;

/**
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
* @default true
*/
this.isPropertyNode = true;

}
Expand All @@ -26,6 +66,12 @@ class PropertyNode extends Node {

}

/**
* The method is overwritten so it always returns `true`.
*
* @param {NodeBuilder} builder - The current node builder.
* @return {Boolean} Whether this node is global or not.
*/
isGlobal( /*builder*/ ) {

return true;
Expand Down
68 changes: 68 additions & 0 deletions src/nodes/core/StackNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import Node from './Node.js';
import { select } from '../math/ConditionalNode.js';
import { ShaderNode, nodeProxy, getCurrentStack, setCurrentStack } from '../tsl/TSLBase.js';

/**
* TODO
*
* @augments Node
*/
class StackNode extends Node {

static get type() {
Expand All @@ -10,17 +15,54 @@ class StackNode extends Node {

}

/**
* Constructs a new stack node.
*
* @param {StackNode?} [parent=null] - The parent stack node.
*/
constructor( parent = null ) {

super();

/**
* List of nodes.
*
* @type {Array<Node>}
*/
this.nodes = [];

/**
* The output node.
*
* @type {Node?}
* @default null
*/
this.outputNode = null;

/**
* The parent stack node.
*
* @type {StackNode}
* @default null
*/
this.parent = parent;

/**
* The current conditional node.
*
* @private
* @type {ConditionalNode}
* @default null
*/
this._currentCond = null;

/**
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
* @default true
*/
this.isStackNode = true;

}
Expand All @@ -31,6 +73,12 @@ class StackNode extends Node {

}

/**
* Adds a node to this stack.
*
* @param {Node} node - The node to add.
* @return {StackNode} A reference to this stack node.
*/
add( node ) {

this.nodes.push( node );
Expand All @@ -39,6 +87,13 @@ class StackNode extends Node {

}

/**
* Represent an `if` statement in TSL.
*
* @param {Node} boolNode - Represents the condition.
* @param {Function} method - TSL code which is executed if the condition evaluates to `true`.
* @return {StackNode} A reference to this stack node.
*/
If( boolNode, method ) {

const methodNode = new ShaderNode( method );
Expand All @@ -48,6 +103,13 @@ class StackNode extends Node {

}

/**
* Represent an `elseif` statement in TSL.
*
* @param {Node} boolNode - Represents the condition.
* @param {Function} method - TSL code which is executed if the condition evaluates to `true`.
* @return {StackNode} A reference to this stack node.
*/
ElseIf( boolNode, method ) {

const methodNode = new ShaderNode( method );
Expand All @@ -60,6 +122,12 @@ class StackNode extends Node {

}

/**
* Represent an `else` statement in TSL.
*
* @param {Function} method - TSL code which is executed in the `else` case.
* @return {StackNode} A reference to this stack node.
*/
Else( method ) {

this._currentCond.elseNode = new ShaderNode( method );
Expand Down
3 changes: 2 additions & 1 deletion src/nodes/core/VaryingNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ class VaryingNode extends Node {
/**
* The method is overwritten so it always returns `true`.
*
* @param {NodeBuilder} builder - The current node builder.
* @return {Boolean} Whether this node is global or not.
*/
isGlobal() {
isGlobal( /*builder*/ ) {

return true;

Expand Down
27 changes: 26 additions & 1 deletion src/nodes/fog/FogExp2Node.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import FogNode from './FogNode.js';
import { nodeProxy } from '../tsl/TSLBase.js';

/**
* Represents an exponential squared fog. This type of fog gives
* a clear view near the camera and a faster than exponentially
* densening fog farther from the camera.
*
* @augments FogNode
*/
class FogExp2Node extends FogNode {

static get type() {
Expand All @@ -9,12 +16,30 @@ class FogExp2Node extends FogNode {

}

/**
* Constructs a new exponential squared fog node.
*
* @param {Node} colorNode - Defines the color of the fog.
* @param {Node} densityNode - Defines the fog densitiy.
*/
constructor( colorNode, densityNode ) {

super( colorNode );
super( colorNode, null );

/**
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
* @default true
*/
this.isFogExp2Node = true;

/**
* Defines the fog densitiy.
*
* @type {Node}
*/
this.densityNode = densityNode;

}
Expand Down
Loading

0 comments on commit 93dccc1

Please sign in to comment.