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

Node: Document more modules. #30117

Merged
merged 4 commits into from
Dec 13, 2024
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
27 changes: 27 additions & 0 deletions src/nodes/accessors/AccessorsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,38 @@ import { mix } from '../math/MathNode.js';
import { anisotropy, anisotropyB, roughness } from '../core/PropertyNode.js';
import { positionViewDirection } from './Position.js';

/** @module AccessorsUtils **/

/**
* TSL object that represents the TBN matrix in view space.
*
* @type {Node<mat3>}
*/
export const TBNViewMatrix = /*@__PURE__*/ mat3( tangentView, bitangentView, normalView );

/**
* TSL object that represents the parallax direction.
*
* @type {Node<mat3>}
*/
export const parallaxDirection = /*@__PURE__*/ positionViewDirection.mul( TBNViewMatrix )/*.normalize()*/;

/**
* TSL function for computing parallax uv coordinates.
*
* @function
* @param {Node<vec2>} uv - A uv node.
* @param {Node<vec2>} scale - A scale node.
* @returns {Node<vec2>} Parallax uv coordinates.
*/
export const parallaxUV = ( uv, scale ) => uv.sub( parallaxDirection.mul( scale ) );

/**
* TSL function for computing bent normals.
*
* @function
* @returns {Node<vec3>} Bent normals.
*/
export const transformedBentNormalView = /*@__PURE__*/ ( () => {

// https://google.github.io/filament/Filament.md.html#lighting/imagebasedlights/anisotropy
Expand Down
42 changes: 39 additions & 3 deletions src/nodes/accessors/BatchNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ import { tangentLocal } from './Tangent.js';
import { instanceIndex, drawIndex } from '../core/IndexNode.js';
import { varyingProperty } from '../core/PropertyNode.js';

/** @module BatchNode **/

/**
* This node implements the vertex shader logic which is required
* when rendering 3D objects via batching. `BatchNode` must be used
* with instances of {@link BatchedMesh}.
*
* @augments Node
*/
class BatchNode extends Node {

static get type() {
Expand All @@ -16,21 +25,41 @@ class BatchNode extends Node {

}

/**
* Constructs a new batch node.
*
* @param {BatchedMesh} batchMesh - A reference to batched mesh.
*/
constructor( batchMesh ) {

super( 'void' );

/**
* A reference to batched mesh.
*
* @type {BatchedMesh}
*/
this.batchMesh = batchMesh;


/**
* The batching index node.
*
* @type {IndexNode?}
* @default null
*/
this.batchingIdNode = null;

}

/**
* Setups the internal buffers and nodes and assigns the transformed vertex data
* to predefined node variables for accumulation. That follows the same patterns
* like with morph and skinning nodes.
*
* @param {NodeBuilder} builder - The current node builder.
*/
setup( builder ) {

// POSITION

if ( this.batchingIdNode === null ) {

if ( builder.getDrawIndex() === null ) {
Expand Down Expand Up @@ -125,4 +154,11 @@ class BatchNode extends Node {

export default BatchNode;

/**
* TSL function for creating a batch node.
*
* @function
* @param {BatchedMesh} batchMesh - A reference to batched mesh.
* @returns {BatchNode}
*/
export const batch = /*@__PURE__*/ nodeProxy( BatchNode );
38 changes: 38 additions & 0 deletions src/nodes/accessors/BuiltinNode.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,49 @@
import Node from '../core/Node.js';
import { nodeProxy } from '../tsl/TSLBase.js';

/** @module BuiltinNode **/

/**
* The node allows to set values for built-in shader variables. That is
* required for features like hardware-accelerated vertex clipping.
*
* @augments Node
*/
class BuiltinNode extends Node {

/**
* Constructs a new builtin node.
*
* @param {String} name - The name of the built-in shader variable.
*/
constructor( name ) {

super( 'float' );

/**
* The name of the built-in shader variable.
*
* @type {String}
*/
this.name = name;

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

}

/**
* Generates the code snippet of the builtin node.
*
* @param {NodeBuilder} builder - The current node builder.
* @return {String} The generated code snippet.
*/
generate( /* builder */ ) {

return this.name;
Expand All @@ -23,4 +54,11 @@ class BuiltinNode extends Node {

export default BuiltinNode;

/**
* TSL function for creating a builtin node.
*
* @function
* @param {String} name - The name of the built-in shader variable.
* @returns {BuiltinNode}
*/
export const builtin = nodeProxy( BuiltinNode );
82 changes: 82 additions & 0 deletions src/nodes/accessors/InstanceNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ import { InstancedInterleavedBuffer } from '../../core/InstancedInterleavedBuffe
import { InstancedBufferAttribute } from '../../core/InstancedBufferAttribute.js';
import { DynamicDrawUsage } from '../../constants.js';

/** @module InstanceNode **/

/**
* This node implements the vertex shader logic which is required
* when rendering 3D objects via instancing. The code makes sure
* vertex position, normal and color data can influenced via instanced data.
*
* @augments Node
*/
class InstanceNode extends Node {

static get type() {
Expand All @@ -20,25 +29,84 @@ class InstanceNode extends Node {

}

/**
* Constructs a new instance node.
*
* @param {Number} count - The number of instances.
* @param {InstancedBufferAttribute} instanceMatrix - Instanced buffer attribute representing the instance transformations.
* @param {InstancedBufferAttribute} instanceColor - Instanced buffer attribute representing the instance colors.
*/
constructor( count, instanceMatrix, instanceColor ) {

super( 'void' );

/**
* The number of instances.
*
* @type {Number}
*/
this.count = count;

/**
* Instanced buffer attribute representing the transformation of instances.
*
* @type {InstancedBufferAttribute}
*/
this.instanceMatrix = instanceMatrix;

/**
* Instanced buffer attribute representing the color of instances.
*
* @type {InstancedBufferAttribute}
*/
this.instanceColor = instanceColor;

/**
* The node that represents the instance matrix data.
*
* @type {Node}
*/
this.instanceMatrixNode = null;

/**
* The node that represents the instance color data.
*
* @type {Node}
*/
this.instanceColorNode = null;

/**
* The update type is set to `frame` since an update
* of instanced buffer data must be checked per frame.
*
* @type {String}
* @default 'frame'
*/
this.updateType = NodeUpdateType.FRAME;

/**
* A reference to a buffer that is used by `instanceMatrixNode`.
*
* @type {InstancedInterleavedBuffer}
*/
this.buffer = null;

/**
* A reference to a buffer that is used by `instanceColorNode`.
*
* @type {InstancedInterleavedBuffer}
*/
this.bufferColor = null;

}

/**
* Setups the internal buffers and nodes and assigns the transformed vertex data
* to predefined node variables for accumulation. That follows the same patterns
* like with morph and skinning nodes.
*
* @param {NodeBuilder} builder - The current node builder.
*/
setup( builder ) {

const { count, instanceMatrix, instanceColor } = this;
Expand Down Expand Up @@ -118,6 +186,11 @@ class InstanceNode extends Node {

}

/**
* Checks if the internal buffers required an update.
*
* @param {NodeFrame} frame - The current node frame.
*/
update( /*frame*/ ) {

if ( this.instanceMatrix.usage !== DynamicDrawUsage && this.buffer !== null && this.instanceMatrix.version !== this.buffer.version ) {
Expand All @@ -138,4 +211,13 @@ class InstanceNode extends Node {

export default InstanceNode;

/**
* TSL function for creating an instance node.
*
* @function
* @param {Number} count - The number of instances.
* @param {InstancedBufferAttribute} instanceMatrix - Instanced buffer attribute representing the instance transformations.
* @param {InstancedBufferAttribute} instanceColor - Instanced buffer attribute representing the instance colors.
* @returns {InstanceNode}
*/
export const instance = /*@__PURE__*/ nodeProxy( InstanceNode );
31 changes: 28 additions & 3 deletions src/nodes/accessors/InstancedMeshNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import InstanceNode from './InstanceNode.js';
import { nodeProxy } from '../tsl/TSLBase.js';

/** @module InstancedMeshNode **/

/**
* This is a special version of `InstanceNode` which requires the usage of {@link InstancedMesh}.
* It allows an easier setup of the instance node.
*
* @augments module:InstanceNode~InstanceNode
*/
class InstancedMeshNode extends InstanceNode {

static get type() {
Expand All @@ -9,18 +17,35 @@ class InstancedMeshNode extends InstanceNode {

}

constructor( instanceMesh ) {
/**
* Constructs a new instanced mesh node.
*
* @param {InstancedMesh} instancedMesh - The instanced mesh.
*/
constructor( instancedMesh ) {

const { count, instanceMatrix, instanceColor } = instanceMesh;
const { count, instanceMatrix, instanceColor } = instancedMesh;

super( count, instanceMatrix, instanceColor );

this.instanceMesh = instanceMesh;
/**
* A reference to the instanced mesh.
*
* @type {InstancedMesh}
*/
this.instancedMesh = instancedMesh;

}

}

export default InstancedMeshNode;

/**
* TSL function for creating an instanced mesh node.
*
* @function
* @param {InstancedMesh} instancedMesh - The instancedMesh.
* @returns {InstancedMeshNode}
*/
export const instancedMesh = /*@__PURE__*/ nodeProxy( InstancedMeshNode );
13 changes: 13 additions & 0 deletions src/nodes/accessors/InstancedPointsMaterialNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import MaterialNode from './MaterialNode.js';
import { nodeImmutable } from '../tsl/TSLBase.js';

/** @module InstancedPointsMaterialNode **/

/**
* An extension of material node to provide pre-defined
* TSL objects in context of `InstancedPointsNodeMaterial`.
*
* @augments module:MaterialNode~MaterialNode
*/
class InstancedPointsMaterialNode extends MaterialNode {

static get type() {
Expand All @@ -21,4 +29,9 @@ InstancedPointsMaterialNode.POINT_WIDTH = 'pointWidth';

export default InstancedPointsMaterialNode;

/**
* TSL object that represents the point width of the current points material.
*
* @type {InstancedPointsMaterialNode<float>}
*/
export const materialPointWidth = /*@__PURE__*/ nodeImmutable( InstancedPointsMaterialNode, InstancedPointsMaterialNode.POINT_WIDTH );
Loading
Loading