Skip to content

Commit

Permalink
Nodes: Document more modules. (#30075)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 authored Dec 9, 2024
1 parent ef48dee commit 1fc010c
Show file tree
Hide file tree
Showing 19 changed files with 493 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/nodes/core/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ class Node extends EventDispatcher {
* Generate a custom cache key for this node.
*
* @return {Number} The cache key of the node.
* @default 0
*/
customCacheKey() {

Expand Down
17 changes: 17 additions & 0 deletions src/nodes/lighting/AONode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import LightingNode from './LightingNode.js';

/**
* A generic class that can be used by nodes which contribute
* ambient occlusion to the scene. E.g. an ambient occlusion map
* node can be used as input for this module. Used in {@link NodeMaterial}.
*
* @augments LightingNode
*/
class AONode extends LightingNode {

static get type() {
Expand All @@ -8,10 +15,20 @@ class AONode extends LightingNode {

}

/**
* Constructs a new AO node.
*
* @param {Node<float>} aoNode - The ambient occlusion node.
*/
constructor( aoNode = null ) {

super();

/**
* The ambient occlusion node.
*
* @type {Node<float>}
*/
this.aoNode = aoNode;

}
Expand Down
10 changes: 10 additions & 0 deletions src/nodes/lighting/AmbientLightNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import AnalyticLightNode from './AnalyticLightNode.js';

/**
* Module for representing ambient lights as nodes.
*
* @augments AnalyticLightNode
*/
class AmbientLightNode extends AnalyticLightNode {

static get type() {
Expand All @@ -8,6 +13,11 @@ class AmbientLightNode extends AnalyticLightNode {

}

/**
* Constructs a new ambient light node.
*
* @param {AmbientLight?} [light=null] - The ambient light source.
*/
constructor( light = null ) {

super( light );
Expand Down
91 changes: 88 additions & 3 deletions src/nodes/lighting/AnalyticLightNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { hash } from '../core/NodeUtils.js';
import { shadow } from './ShadowNode.js';
import { nodeObject } from '../tsl/TSLCore.js';

/**
* Base class for analytic light nodes.
*
* @augments LightingNode
*/
class AnalyticLightNode extends LightingNode {

static get type() {
Expand All @@ -15,31 +20,85 @@ class AnalyticLightNode extends LightingNode {

}

/**
* Constructs a new analytic light node.
*
* @param {Light?} [light=null] - The light source.
*/
constructor( light = null ) {

super();

/**
* The light source.
*
* @type {Light}
* @default null
*/
this.light = light;

/**
* The light's color value.
*
* @type {Color}
*/
this.color = new Color();

/**
* The light's color node. Points to `colorNode` of the light source, if set. Otherwise
* it creates a uniform node based on {@link AnalyticLightNode#color}.
*
* @type {Node}
*/
this.colorNode = ( light && light.colorNode ) || uniform( this.color ).setGroup( renderGroup );

/**
* This property is used to retain a reference to the original value of {@link AnalyticLightNode#colorNode}.
* The final color node is represented by a differnt node when using shadows.
*
* @type {Node}
*/
this.baseColorNode = null;

/**
* Represents the light's shadow.
*
* @type {ShadowNode}
*/
this.shadowNode = null;

/**
* Represents the light's shadow color.
*
* @type {Node}
*/
this.shadowColorNode = null;

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

/**
* Overwritten since analytic light nodes are updated
* once per frame.
*
* @type {String}
* @default 'frame'
*/
this.updateType = NodeUpdateType.FRAME;

}

/**
* Overwrites the default `customCacheKey()` implementation by including the
* light.id and light.castShadow into the cache key.
* Overwrites the default {@link Node#customCacheKey} implementation by including the
* `light.id` and `light.castShadow` into the cache key.
*
* @return {Number} The hash.
* @return {Number} The custom cache key.
*/
customCacheKey() {

Expand All @@ -53,12 +112,24 @@ class AnalyticLightNode extends LightingNode {

}

/**
* Setups the shadow node for this light. The method exists so concrete light classes
* can setup different types of shadow nodes.
*
* @return {ShadowNode} The created shadow node.
*/
setupShadowNode() {

return shadow( this.light );

}

/**
* Setups the shadow for this light. This method is only executed if the light
* cast shadows and the current build object receives shadows.
*
* @param {NodeBuilder} builder - The current node builder.
*/
setupShadow( builder ) {

const { renderer } = builder;
Expand Down Expand Up @@ -97,6 +168,13 @@ class AnalyticLightNode extends LightingNode {

}

/**
* Unlike most other nodes, lighting nodes do not return a output node in {@link Node#setup}.
* The main purpose of lighting nodes is to configure the current {@link LightingModel} and/or
* invocate the respecitve interface methods.
*
* @param {NodeBuilder} builder - The current node builder.
*/
setup( builder ) {

this.colorNode = this.baseColorNode || this.colorNode;
Expand All @@ -119,6 +197,13 @@ class AnalyticLightNode extends LightingNode {

}

/**
* The update method is used to update light uniforms per frame.
* Potentially overwritten in concrete light nodes to update light
* specific uniforms.
*
* @param {NodeFrame} frame - A reference to the current node frame.
*/
update( /*frame*/ ) {

const { light } = this;
Expand Down
19 changes: 19 additions & 0 deletions src/nodes/lighting/BasicEnvironmentNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import LightingNode from './LightingNode.js';
import { cubeMapNode } from '../utils/CubeMapNode.js';

/**
* Represents a basic model for Image-based lighting (IBL). The environment
* is defined via environment maps in the equirectanular or cube map format.
* `BasicEnvironmentNode` is intended for non-PBR materials like {@link MeshBasicNodeMaterial}
* or {@link MeshPhongNodeMaterial}.
*
* @augments LightingNode
*/
class BasicEnvironmentNode extends LightingNode {

static get type() {
Expand All @@ -9,10 +17,21 @@ class BasicEnvironmentNode extends LightingNode {

}

/**
* Constructs a new basic environment node.
*
* @param {Node} [envNode=null] - A node representing the environment.
*/
constructor( envNode = null ) {

super();

/**
* A node representing the environment.
*
* @type {Node}
* @default null
*/
this.envNode = envNode;

}
Expand Down
17 changes: 17 additions & 0 deletions src/nodes/lighting/BasicLightMapNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import LightingNode from './LightingNode.js';
import { float } from '../tsl/TSLBase.js';

/**
* A specific version of {@link IrradianceNode} that is only relevant
* for {@link MeshBasicNodeMaterial}. Since the material is unlit, it
* requires a special scaling factor for the light map.
*
* @augments LightingNode
*/
class BasicLightMapNode extends LightingNode {

static get type() {
Expand All @@ -9,10 +16,20 @@ class BasicLightMapNode extends LightingNode {

}

/**
* Constructs a new basic light map node.
*
* @param {Node<vec3>} lightMapNode - The light map node.
*/
constructor( lightMapNode = null ) {

super();

/**
* The light map node.
*
* @type {Node<vec3>}
*/
this.lightMapNode = lightMapNode;

}
Expand Down
10 changes: 10 additions & 0 deletions src/nodes/lighting/DirectionalLightNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import AnalyticLightNode from './AnalyticLightNode.js';
import { lightTargetDirection } from '../accessors/Lights.js';

/**
* Module for representing directional lights as nodes.
*
* @augments AnalyticLightNode
*/
class DirectionalLightNode extends AnalyticLightNode {

static get type() {
Expand All @@ -9,6 +14,11 @@ class DirectionalLightNode extends AnalyticLightNode {

}

/**
* Constructs a new directional light node.
*
* @param {DirectionalLight?} [light=null] - The directional light source.
*/
constructor( light = null ) {

super( light );
Expand Down
18 changes: 18 additions & 0 deletions src/nodes/lighting/EnvironmentNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import { pmremTexture } from '../pmrem/PMREMNode.js';

const _envNodeCache = new WeakMap();

/**
* Represents a physical model for Image-based lighting (IBL). The environment
* is defined via environment maps in the equirectanular, cube map or cubeUV (PMREM) format.
* `EnvironmentNode` is intended for PBR materials like {@link MeshStandardNodeMaterial}.
*
* @augments LightingNode
*/
class EnvironmentNode extends LightingNode {

static get type() {
Expand All @@ -19,10 +26,21 @@ class EnvironmentNode extends LightingNode {

}

/**
* Constructs a new environment node.
*
* @param {Node} [envNode=null] - A node representing the environment.
*/
constructor( envNode = null ) {

super();

/**
* A node representing the environment.
*
* @type {Node}
* @default null
*/
this.envNode = envNode;

}
Expand Down
Loading

0 comments on commit 1fc010c

Please sign in to comment.