Skip to content

Commit e0e5370

Browse files
authored
Node: Document more modules. (#30001)
* Node: Document more modules. * Docs: Fix typo. * Docs: More clean up.
1 parent 8ec7166 commit e0e5370

File tree

12 files changed

+455
-10
lines changed

12 files changed

+455
-10
lines changed

src/nodes/code/CodeNode.js

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import Node from '../core/Node.js';
22
import { nodeProxy } from '../tsl/TSLBase.js';
33

4+
/**
5+
* This class represents native code sections. It is the base
6+
* class for modules like {@link FunctionNode} which allows to implement
7+
* functions with native shader languages.
8+
*
9+
* @augments Node
10+
*/
411
class CodeNode extends Node {
512

613
static get type() {
@@ -9,25 +16,69 @@ class CodeNode extends Node {
916

1017
}
1118

19+
/**
20+
* Constructs a new code node.
21+
*
22+
* @param {String} [code=''] - The native code.
23+
* @param {Array<Node>} [includes=[]] - An array of includes.
24+
* @param {('js'|'wgsl'|'glsl')} [language=''] - The used language.
25+
*/
1226
constructor( code = '', includes = [], language = '' ) {
1327

1428
super( 'code' );
1529

30+
/**
31+
* This flag can be used for type testing.
32+
*
33+
* @type {Boolean}
34+
* @readonly
35+
* @default true
36+
*/
1637
this.isCodeNode = true;
1738

39+
/**
40+
* The native code.
41+
*
42+
* @type {String}
43+
* @default ''
44+
*/
1845
this.code = code;
19-
this.language = language;
2046

47+
/**
48+
* An array of includes
49+
*
50+
* @type {Array<Node>}
51+
* @default []
52+
*/
2153
this.includes = includes;
2254

55+
/**
56+
* The used language.
57+
*
58+
* @type {('js'|'wgsl'|'glsl')}
59+
* @default ''
60+
*/
61+
this.language = language;
62+
2363
}
2464

65+
/**
66+
* The method is overwritten so it always returns `true`.
67+
*
68+
* @return {Boolean} Whether this node is global or not.
69+
*/
2570
isGlobal() {
2671

2772
return true;
2873

2974
}
3075

76+
/**
77+
* Sets the includes of this code node.
78+
*
79+
* @param {Array<Node>} includes - The includes to set.
80+
* @return {CodeNode} A reference to this node.
81+
*/
3182
setIncludes( includes ) {
3283

3384
this.includes = includes;
@@ -36,6 +87,12 @@ class CodeNode extends Node {
3687

3788
}
3889

90+
/**
91+
* Returns the includes of this code node.
92+
*
93+
* @param {NodeBuilder} builder - The current node builder.
94+
* @return {Array<Node>} The includes.
95+
*/
3996
getIncludes( /*builder*/ ) {
4097

4198
return this.includes;

src/nodes/code/ExpressionNode.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import Node from '../core/Node.js';
22
import { nodeProxy } from '../tsl/TSLCore.js';
33

4+
/**
5+
* This class can be used to implement basic expressions in shader code.
6+
* Basic examples for that are `return`, `continue` or `discard` statements.
7+
*
8+
* @augments Node
9+
*/
410
class ExpressionNode extends Node {
511

612
static get type() {
@@ -9,10 +15,22 @@ class ExpressionNode extends Node {
915

1016
}
1117

18+
/**
19+
* Constructs a new expression node.
20+
*
21+
* @param {String} [snippet=''] - The native code snippet.
22+
* @param {String} [includes='void'] - The node type.
23+
*/
1224
constructor( snippet = '', nodeType = 'void' ) {
1325

1426
super( nodeType );
1527

28+
/**
29+
* The native code snippet.
30+
*
31+
* @type {String}
32+
* @default ''
33+
*/
1634
this.snippet = snippet;
1735

1836
}

src/nodes/core/ContextNode.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import Node from './Node.js';
22
import { addMethodChaining, nodeProxy } from '../tsl/TSLCore.js';
33

4+
/**
5+
* This node can be used as a context management component for another node.
6+
* {@link NodeBuilder} performs its node building process in a specific context and
7+
* this node allows the modify the context. A typical use case is to overwrite `getUV()` e.g.:
8+
*
9+
* ```js
10+
*node.context( { getUV: () => customCoord } );
11+
*```
12+
* @augments Node
13+
*/
414
class ContextNode extends Node {
515

616
static get type() {
@@ -9,23 +19,59 @@ class ContextNode extends Node {
919

1020
}
1121

22+
/**
23+
* Constructs a new context node.
24+
*
25+
* @param {Node} node - The node whose context should be modified.
26+
* @param {Object} [value={}] - The modified context data.
27+
*/
1228
constructor( node, value = {} ) {
1329

1430
super();
1531

32+
/**
33+
* This flag can be used for type testing.
34+
*
35+
* @type {Boolean}
36+
* @readonly
37+
* @default true
38+
*/
1639
this.isContextNode = true;
1740

41+
/**
42+
* The node whose context should be modified.
43+
*
44+
* @type {Node}
45+
*/
1846
this.node = node;
47+
48+
/**
49+
* The modified context data.
50+
*
51+
* @type {Object}
52+
* @default {}
53+
*/
1954
this.value = value;
2055

2156
}
2257

58+
/**
59+
* This method is overwritten to ensure it returns the reference to {@link ContextNode#node}.
60+
*
61+
* @return {Node} A reference to {@link ContextNode#node}.
62+
*/
2363
getScope() {
2464

2565
return this.node.getScope();
2666

2767
}
2868

69+
/**
70+
* This method is overwritten to ensure it returns the type to {@link ContextNode#node}.
71+
*
72+
* @param {NodeBuilder} builder - The current node builder.
73+
* @return {String} The type of {@link ContextNode#node}.
74+
*/
2975
getNodeType( builder ) {
3076

3177
return this.node.getNodeType( builder );

src/nodes/core/IndexNode.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
import Node from './Node.js';
22
import { nodeImmutable, varying } from '../tsl/TSLBase.js';
33

4+
/**
5+
* This class represents shader indices of different types. The following predefined node
6+
* objects cover frequent use cases:
7+
*
8+
* - `vertexIndex`: The index of a vertex within a mesh.
9+
* - `instanceIndex`: The index of either a mesh instance or an invocation of a compute shader.
10+
* - `drawIndex`: The index of a draw call.
11+
* - `invocationLocalIndex`: The index of a compute invocation within the scope of a workgroup load.
12+
* - `invocationSubgroupIndex`: The index of a compute invocation within the scope of a subgroup.
13+
* - `subgroupIndex`: The index of the subgroup the current compute invocation belongs to.
14+
*
15+
* @augments Node
16+
*/
417
class IndexNode extends Node {
518

619
static get type() {
@@ -9,13 +22,30 @@ class IndexNode extends Node {
922

1023
}
1124

25+
/**
26+
* Constructs a new index node.
27+
*
28+
* @param {('vertex'|'instance'|'subgroup'|'invocationLocal'|'invocationSubgroup'|'draw')} value - The scope of the index node.
29+
*/
1230
constructor( scope ) {
1331

1432
super( 'uint' );
1533

34+
/**
35+
* The scope of the index node.
36+
*
37+
* @type {String}
38+
*/
1639
this.scope = scope;
1740

18-
this.isInstanceIndexNode = true;
41+
/**
42+
* This flag can be used for type testing.
43+
*
44+
* @type {Boolean}
45+
* @readonly
46+
* @default true
47+
*/
48+
this.isIndexNode = true;
1949

2050
}
2151

@@ -28,32 +58,26 @@ class IndexNode extends Node {
2858

2959
if ( scope === IndexNode.VERTEX ) {
3060

31-
// The index of a vertex within a mesh.
3261
propertyName = builder.getVertexIndex();
3362

3463
} else if ( scope === IndexNode.INSTANCE ) {
3564

36-
// The index of either a mesh instance or an invocation of a compute shader.
3765
propertyName = builder.getInstanceIndex();
3866

3967
} else if ( scope === IndexNode.DRAW ) {
4068

41-
// The index of a draw call.
4269
propertyName = builder.getDrawIndex();
4370

4471
} else if ( scope === IndexNode.INVOCATION_LOCAL ) {
4572

46-
// The index of a compute invocation within the scope of a workgroup load.
4773
propertyName = builder.getInvocationLocalIndex();
4874

4975
} else if ( scope === IndexNode.INVOCATION_SUBGROUP ) {
5076

51-
// The index of a compute invocation within the scope of a subgroup.
5277
propertyName = builder.getInvocationSubgroupIndex();
5378

5479
} else if ( scope === IndexNode.SUBGROUP ) {
5580

56-
// The index of the subgroup the current compute invocation belongs to.
5781
propertyName = builder.getSubgroupIndex();
5882

5983
} else {

src/nodes/core/LightingModel.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,69 @@
1+
/**
2+
* Abstract class for implementing lighting models. The module defines
3+
* multiple methods that concrete lighting models can implement. These
4+
* methods are executed at different points during the light evaluation
5+
* process.
6+
*/
17
class LightingModel {
28

9+
/**
10+
* This method is intended for setting up lighting model and context data
11+
* which are later used in the evaluation process.
12+
*
13+
* @param {ContextNode} input - The current node context.
14+
* @param {StackNode} stack - The current stack.
15+
* @param {NodeBuilder} builder - The current node builder.
16+
*/
317
start( /*input, stack, builder*/ ) { }
418

19+
/**
20+
* This method is intended for executing final tasks like final updates
21+
* to the outgoing light.
22+
*
23+
* @param {ContextNode} input - The current node context.
24+
* @param {StackNode} stack - The current stack.
25+
* @param {NodeBuilder} builder - The current node builder.
26+
*/
527
finish( /*input, stack, builder*/ ) { }
628

29+
/**
30+
* This method is intended for implementing the direct light term and
31+
* executed during the build process of directional, point and spot light nodes.
32+
*
33+
* @param {Object} input - The input data.
34+
* @param {StackNode} stack - The current stack.
35+
* @param {NodeBuilder} builder - The current node builder.
36+
*/
737
direct( /*input, stack, builder*/ ) { }
838

39+
/**
40+
* This method is intended for implementing the direct light term for
41+
* rect area light nodes.
42+
*
43+
* @param {Object} input - The input data.
44+
* @param {StackNode} stack - The current stack.
45+
* @param {NodeBuilder} builder - The current node builder.
46+
*/
947
directRectArea( /*input, stack, builder*/ ) {}
1048

49+
/**
50+
* This method is intended for implementing the indirect light term.
51+
*
52+
* @param {ContextNode} input - The current node context.
53+
* @param {StackNode} stack - The current stack.
54+
* @param {NodeBuilder} builder - The current node builder.
55+
*/
1156
indirect( /*input, stack, builder*/ ) { }
1257

58+
/**
59+
* This method is intended for implementing the ambient occlusion term.
60+
* Unlike other methods, this method must be called manually by the lighting
61+
* model in its indirect term.
62+
*
63+
* @param {ContextNode} input - The current node context.
64+
* @param {StackNode} stack - The current stack.
65+
* @param {NodeBuilder} builder - The current node builder.
66+
*/
1367
ambientOcclusion( /*input, stack, builder*/ ) { }
1468

1569
}

0 commit comments

Comments
 (0)