diff --git a/src/nodes/core/Node.js b/src/nodes/core/Node.js index 048db8a97224bd..38cebd0686b55c 100644 --- a/src/nodes/core/Node.js +++ b/src/nodes/core/Node.js @@ -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() { diff --git a/src/nodes/lighting/AONode.js b/src/nodes/lighting/AONode.js index cca37f21cef3a2..66257ff6f48275 100644 --- a/src/nodes/lighting/AONode.js +++ b/src/nodes/lighting/AONode.js @@ -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() { @@ -8,10 +15,20 @@ class AONode extends LightingNode { } + /** + * Constructs a new AO node. + * + * @param {Node} aoNode - The ambient occlusion node. + */ constructor( aoNode = null ) { super(); + /** + * The ambient occlusion node. + * + * @type {Node} + */ this.aoNode = aoNode; } diff --git a/src/nodes/lighting/AmbientLightNode.js b/src/nodes/lighting/AmbientLightNode.js index 2f1a94b3af998d..dd53ab348611db 100644 --- a/src/nodes/lighting/AmbientLightNode.js +++ b/src/nodes/lighting/AmbientLightNode.js @@ -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() { @@ -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 ); diff --git a/src/nodes/lighting/AnalyticLightNode.js b/src/nodes/lighting/AnalyticLightNode.js index 926cd80c24c34b..e94053d9bea011 100644 --- a/src/nodes/lighting/AnalyticLightNode.js +++ b/src/nodes/lighting/AnalyticLightNode.js @@ -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() { @@ -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() { @@ -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; @@ -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; @@ -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; diff --git a/src/nodes/lighting/BasicEnvironmentNode.js b/src/nodes/lighting/BasicEnvironmentNode.js index 50159bc4ad01d2..3f4c73b6008b25 100644 --- a/src/nodes/lighting/BasicEnvironmentNode.js +++ b/src/nodes/lighting/BasicEnvironmentNode.js @@ -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() { @@ -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; } diff --git a/src/nodes/lighting/BasicLightMapNode.js b/src/nodes/lighting/BasicLightMapNode.js index efd1942947437a..0d1ac92e8933e8 100644 --- a/src/nodes/lighting/BasicLightMapNode.js +++ b/src/nodes/lighting/BasicLightMapNode.js @@ -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() { @@ -9,10 +16,20 @@ class BasicLightMapNode extends LightingNode { } + /** + * Constructs a new basic light map node. + * + * @param {Node} lightMapNode - The light map node. + */ constructor( lightMapNode = null ) { super(); + /** + * The light map node. + * + * @type {Node} + */ this.lightMapNode = lightMapNode; } diff --git a/src/nodes/lighting/DirectionalLightNode.js b/src/nodes/lighting/DirectionalLightNode.js index 47b4d4a16eea77..8cc7339c45be8a 100644 --- a/src/nodes/lighting/DirectionalLightNode.js +++ b/src/nodes/lighting/DirectionalLightNode.js @@ -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() { @@ -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 ); diff --git a/src/nodes/lighting/EnvironmentNode.js b/src/nodes/lighting/EnvironmentNode.js index c4f3de3e6db89a..1525ebb1709e9f 100644 --- a/src/nodes/lighting/EnvironmentNode.js +++ b/src/nodes/lighting/EnvironmentNode.js @@ -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() { @@ -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; } diff --git a/src/nodes/lighting/HemisphereLightNode.js b/src/nodes/lighting/HemisphereLightNode.js index 67e349e74496b7..a692f548038ccf 100644 --- a/src/nodes/lighting/HemisphereLightNode.js +++ b/src/nodes/lighting/HemisphereLightNode.js @@ -7,6 +7,11 @@ import { renderGroup } from '../core/UniformGroupNode.js'; import { Color } from '../../math/Color.js'; +/** + * Module for representing hemisphere lights as nodes. + * + * @augments AnalyticLightNode + */ class HemisphereLightNode extends AnalyticLightNode { static get type() { @@ -15,17 +20,43 @@ class HemisphereLightNode extends AnalyticLightNode { } + /** + * Constructs a new hemisphere light node. + * + * @param {HemisphereLight?} [light=null] - The hemisphere light source. + */ constructor( light = null ) { super( light ); + /** + * Uniform node representing the light's position. + * + * @type {UniformNode} + */ this.lightPositionNode = lightPosition( light ); + + /** + * A node representing the light's direction. + * + * @type {Node} + */ this.lightDirectionNode = this.lightPositionNode.normalize(); + /** + * Uniform node representing the light's ground color. + * + * @type {UniformNode} + */ this.groundColorNode = uniform( new Color() ).setGroup( renderGroup ); } + /** + * Overwritten to updated hemisphere light specific uniforms. + * + * @param {NodeFrame} frame - A reference to the current node frame. + */ update( frame ) { const { light } = this; diff --git a/src/nodes/lighting/IESSpotLightNode.js b/src/nodes/lighting/IESSpotLightNode.js index c2b98b9722ffa4..b50a84c6123eb0 100644 --- a/src/nodes/lighting/IESSpotLightNode.js +++ b/src/nodes/lighting/IESSpotLightNode.js @@ -2,6 +2,11 @@ import SpotLightNode from './SpotLightNode.js'; import { texture } from '../accessors/TextureNode.js'; import { vec2 } from '../tsl/TSLBase.js'; +/** + * An IES version of the default spot light node. + * + * @augments SpotLightNode + */ class IESSpotLightNode extends SpotLightNode { static get type() { @@ -10,6 +15,12 @@ class IESSpotLightNode extends SpotLightNode { } + /** + * Overwrites the default implementation to compute an IES conform spot attenuation. + * + * @param {Node} angleCosine - The angle to compute the spot attenuation for. + * @return {Node} The spot attenuation. + */ getSpotAttenuation( angleCosine ) { const iesMap = this.light.iesMap; diff --git a/src/nodes/lighting/IrradianceNode.js b/src/nodes/lighting/IrradianceNode.js index 091f07265dbaa3..760f5486ca501c 100644 --- a/src/nodes/lighting/IrradianceNode.js +++ b/src/nodes/lighting/IrradianceNode.js @@ -1,5 +1,12 @@ import LightingNode from './LightingNode.js'; +/** + * A generic class that can be used by nodes which contribute + * irradiance to the scene. E.g. a light map node can be used + * as input for this module. Used in {@link NodeMaterial}. + * + * @augments LightingNode + */ class IrradianceNode extends LightingNode { static get type() { @@ -8,10 +15,20 @@ class IrradianceNode extends LightingNode { } + /** + * Constructs a new irradiance node. + * + * @param {Node} node - A node contributing irradiance. + */ constructor( node ) { super(); + /** + * A node contributing irradiance. + * + * @type {Node} + */ this.node = node; } diff --git a/src/nodes/lighting/LightProbeNode.js b/src/nodes/lighting/LightProbeNode.js index 4e148d5122739f..d017f3cf38cd2f 100644 --- a/src/nodes/lighting/LightProbeNode.js +++ b/src/nodes/lighting/LightProbeNode.js @@ -4,6 +4,11 @@ import { uniformArray } from '../accessors/UniformArrayNode.js'; import { Vector3 } from '../../math/Vector3.js'; import getShIrradianceAt from '../functions/material/getShIrradianceAt.js'; +/** + * Module for representing light probes as nodes. + * + * @augments AnalyticLightNode + */ class LightProbeNode extends AnalyticLightNode { static get type() { @@ -12,6 +17,11 @@ class LightProbeNode extends AnalyticLightNode { } + /** + * Constructs a new light probe node. + * + * @param {LightProbe?} [light=null] - The light probe. + */ constructor( light = null ) { super( light ); @@ -20,10 +30,20 @@ class LightProbeNode extends AnalyticLightNode { for ( let i = 0; i < 9; i ++ ) array.push( new Vector3() ); + /** + * Light probe represented as a uniform of spherical harmonics. + * + * @type {UniformArrayNode} + */ this.lightProbe = uniformArray( array ); } + /** + * Overwritten to updated light probe specific uniforms. + * + * @param {NodeFrame} frame - A reference to the current node frame. + */ update( frame ) { const { light } = this; diff --git a/src/nodes/lighting/LightUtils.js b/src/nodes/lighting/LightUtils.js index a5785e7800d216..395572815fa7d4 100644 --- a/src/nodes/lighting/LightUtils.js +++ b/src/nodes/lighting/LightUtils.js @@ -1,5 +1,17 @@ import { Fn } from '../tsl/TSLBase.js'; +/** @module LightUtils **/ + +/** + * Represents a `discard` shader operation in TSL. + * + * @method + * @param {Object} inputs - The input parameter object. + * @param {Node} inputs.lightDistance - The distance of the light's position to the current fragment position. + * @param {Node} inputs.cutoffDistance - The light's cutoff distance. + * @param {Node} inputs.decayExponent - The light's decay exponent. + * @return {Node} The distance falloff. + */ export const getDistanceAttenuation = /*@__PURE__*/ Fn( ( inputs ) => { const { lightDistance, cutoffDistance, decayExponent } = inputs; diff --git a/src/nodes/lighting/LightingContextNode.js b/src/nodes/lighting/LightingContextNode.js index da893a347c0577..cc28a5da1ed845 100644 --- a/src/nodes/lighting/LightingContextNode.js +++ b/src/nodes/lighting/LightingContextNode.js @@ -1,6 +1,13 @@ import ContextNode from '../core/ContextNode.js'; import { nodeProxy, float, vec3 } from '../tsl/TSLBase.js'; +/** + * `LightingContextNode` represents an extension of the {@link ContextNode} module + * by adding lighting specific context data. It represents the runtime context of + * {@link LightsNode}. + * + * @augments ContextNode + */ class LightingContextNode extends ContextNode { static get type() { @@ -9,18 +16,59 @@ class LightingContextNode extends ContextNode { } + /** + * Constructs a new lighting context node. + * + * @param {LightsNode} node - The lights node. + * @param {LightingModel} [lightingModel=null] - The current lighting model. + * @param {Node} [backdropNode=null] - A backdrop node. + * @param {Node} [backdropAlphaNode=null] - A backdrop alpha node. + */ constructor( node, lightingModel = null, backdropNode = null, backdropAlphaNode = null ) { super( node ); + /** + * The current lighting model. + * + * @type {LightingModel} + * @default null + */ this.lightingModel = lightingModel; + + /** + * A backdrop node. + * + * @type {Node} + * @default null + */ this.backdropNode = backdropNode; + + /** + * A backdrop alpha node. + * + * @type {Node} + * @default null + */ this.backdropAlphaNode = backdropAlphaNode; this._value = null; } + /** + * Returns a lighting context object. + * + * @return {{ + * radiance: Node, + * irradiance: Node, + * iblIrradiance: Node, + * ambientOcclusion: Node, + * reflectedLight: {directDiffuse: Node, directSpecular: Node, indirectDiffuse: Node, indirectSpecular: Node}, + * backdrop: Node, + * backdropAlpha: Node + * }} The lighting context object. + */ getContext() { const { backdropNode, backdropAlphaNode } = this; diff --git a/src/nodes/lighting/LightingNode.js b/src/nodes/lighting/LightingNode.js index 2a27e23079ccca..c488f52f7a50b8 100644 --- a/src/nodes/lighting/LightingNode.js +++ b/src/nodes/lighting/LightingNode.js @@ -1,5 +1,10 @@ import Node from '../core/Node.js'; +/** + * Base class for lighting nodes. + * + * @augments Node + */ class LightingNode extends Node { static get type() { @@ -8,20 +13,24 @@ class LightingNode extends Node { } + /** + * Constructs a new lighting node. + */ constructor() { super( 'vec3' ); + /** + * This flag can be used for type testing. + * + * @type {Boolean} + * @readonly + * @default true + */ this.isLightingNode = true; } - generate( /*builder*/ ) { - - console.warn( 'Abstract function.' ); - - } - } export default LightingNode; diff --git a/src/nodes/lighting/PointLightNode.js b/src/nodes/lighting/PointLightNode.js index edc4fc8eff8c1f..a6348555e9063c 100644 --- a/src/nodes/lighting/PointLightNode.js +++ b/src/nodes/lighting/PointLightNode.js @@ -34,6 +34,11 @@ export const directPointLight = Fn( ( { color, lightViewPosition, cutoffDistance } ); +/** + * Module for representing point lights as nodes. + * + * @augments AnalyticLightNode + */ class PointLightNode extends AnalyticLightNode { static get type() { @@ -42,15 +47,36 @@ class PointLightNode extends AnalyticLightNode { } + /** + * Constructs a new point light node. + * + * @param {PointLight?} [light=null] - The point light source. + */ constructor( light = null ) { super( light ); + /** + * Uniform node representing the cutoff distance. + * + * @type {UniformNode} + */ this.cutoffDistanceNode = uniform( 0 ).setGroup( renderGroup ); - this.decayExponentNode = uniform( 0 ).setGroup( renderGroup ); + + /** + * Uniform node representing the decay exponent. + * + * @type {UniformNode} + */ + this.decayExponentNode = uniform( 2 ).setGroup( renderGroup ); } + /** + * Overwritten to updated point light specific uniforms. + * + * @param {NodeFrame} frame - A reference to the current node frame. + */ update( frame ) { const { light } = this; @@ -62,6 +88,9 @@ class PointLightNode extends AnalyticLightNode { } + /** + * Overwritten to setup point light specific shadow. + */ setupShadowNode() { return pointShadow( this.light ); diff --git a/src/nodes/lighting/RectAreaLightNode.js b/src/nodes/lighting/RectAreaLightNode.js index c7c79d6ae3b9b3..bb033e6d76ac48 100644 --- a/src/nodes/lighting/RectAreaLightNode.js +++ b/src/nodes/lighting/RectAreaLightNode.js @@ -11,8 +11,13 @@ import { NodeUpdateType } from '../core/constants.js'; const _matrix41 = /*@__PURE__*/ new Matrix4(); const _matrix42 = /*@__PURE__*/ new Matrix4(); -let ltcLib = null; +let _ltcLib = null; +/** + * Module for representing rect area lights as nodes. + * + * @augments AnalyticLightNode + */ class RectAreaLightNode extends AnalyticLightNode { static get type() { @@ -21,17 +26,45 @@ class RectAreaLightNode extends AnalyticLightNode { } + /** + * Constructs a new rect area light node. + * + * @param {RectAreaLight?} [light=null] - The rect area light source. + */ constructor( light = null ) { super( light ); + /** + * Uniform node representing the half height of the are light. + * + * @type {UniformNode} + */ this.halfHeight = uniform( new Vector3() ).setGroup( renderGroup ); + + /** + * Uniform node representing the half width of the are light. + * + * @type {UniformNode} + */ this.halfWidth = uniform( new Vector3() ).setGroup( renderGroup ); + /** + * The `updateType` is set to `NodeUpdateType.RENDER` since the light + * relies on `viewMatrix` which might vary per render call. + * + * @type {String} + * @default 'render' + */ this.updateType = NodeUpdateType.RENDER; } + /** + * Overwritten to updated rect area light specific uniforms. + * + * @param {NodeFrame} frame - A reference to the current node frame. + */ update( frame ) { super.update( frame ); @@ -61,13 +94,13 @@ class RectAreaLightNode extends AnalyticLightNode { if ( builder.isAvailable( 'float32Filterable' ) ) { - ltc_1 = texture( ltcLib.LTC_FLOAT_1 ); - ltc_2 = texture( ltcLib.LTC_FLOAT_2 ); + ltc_1 = texture( _ltcLib.LTC_FLOAT_1 ); + ltc_2 = texture( _ltcLib.LTC_FLOAT_2 ); } else { - ltc_1 = texture( ltcLib.LTC_HALF_1 ); - ltc_2 = texture( ltcLib.LTC_HALF_2 ); + ltc_1 = texture( _ltcLib.LTC_HALF_1 ); + ltc_2 = texture( _ltcLib.LTC_HALF_2 ); } @@ -89,9 +122,14 @@ class RectAreaLightNode extends AnalyticLightNode { } + /** + * Used to configure the internal BRDF approximation texture data. + * + * @param {RectAreaLightTexturesLib} ltc - The BRDF approximation texture data. + */ static setLTC( ltc ) { - ltcLib = ltc; + _ltcLib = ltc; } diff --git a/src/nodes/lighting/SpotLightNode.js b/src/nodes/lighting/SpotLightNode.js index 13a749c1eacc9a..042480e3aa45b2 100644 --- a/src/nodes/lighting/SpotLightNode.js +++ b/src/nodes/lighting/SpotLightNode.js @@ -7,6 +7,11 @@ import { renderGroup } from '../core/UniformGroupNode.js'; import { lightViewPosition, lightTargetDirection, lightProjectionUV } from '../accessors/Lights.js'; import { texture } from '../accessors/TextureNode.js'; +/** + * Module for representing spot lights as nodes. + * + * @augments AnalyticLightNode + */ class SpotLightNode extends AnalyticLightNode { static get type() { @@ -15,18 +20,50 @@ class SpotLightNode extends AnalyticLightNode { } + /** + * Constructs a new spot light node. + * + * @param {SpotLight?} [light=null] - The spot light source. + */ constructor( light = null ) { super( light ); + /** + * Uniform node representing the cone cosinus. + * + * @type {UniformNode} + */ this.coneCosNode = uniform( 0 ).setGroup( renderGroup ); + + /** + * Uniform node representing the penumbra cosinus. + * + * @type {UniformNode} + */ this.penumbraCosNode = uniform( 0 ).setGroup( renderGroup ); + /** + * Uniform node representing the cutoff distance. + * + * @type {UniformNode} + */ this.cutoffDistanceNode = uniform( 0 ).setGroup( renderGroup ); + + /** + * Uniform node representing the decay exponent. + * + * @type {UniformNode} + */ this.decayExponentNode = uniform( 0 ).setGroup( renderGroup ); } + /** + * Overwritten to updated spot light specific uniforms. + * + * @param {NodeFrame} frame - A reference to the current node frame. + */ update( frame ) { super.update( frame ); @@ -41,6 +78,12 @@ class SpotLightNode extends AnalyticLightNode { } + /** + * Computes the spot attenuation for the given angle. + * + * @param {Node} angleCosine - The angle to compute the spot attenuation for. + * @return {Node} The spot attenuation. + */ getSpotAttenuation( angleCosine ) { const { coneCosNode, penumbraCosNode } = this; diff --git a/src/nodes/utils/FunctionOverloadingNode.js b/src/nodes/utils/FunctionOverloadingNode.js index b22db1fc85276a..a916cb64fa7c1b 100644 --- a/src/nodes/utils/FunctionOverloadingNode.js +++ b/src/nodes/utils/FunctionOverloadingNode.js @@ -1,6 +1,13 @@ import Node from '../core/Node.js'; import { nodeProxy } from '../tsl/TSLBase.js'; +/** + * This class allows to define multiple overloaded versions + * of the same function. Depending on the parameters of the function + * call, the node picks the best-fit overloaded version. + * + * @augments Node + */ class FunctionOverloadingNode extends Node { static get type() { @@ -9,19 +16,55 @@ class FunctionOverloadingNode extends Node { } + /** + * Constructs a new function overloading node. + * + * @param {Array} functionNodes - Array of `Fn` function definitions. + * @param {...Node} parametersNodes - A list of paramater nodes. + */ constructor( functionNodes = [], ...parametersNodes ) { super(); + /** + * Array of `Fn` function definitions. + * + * @type {Array} + */ this.functionNodes = functionNodes; + + /** + * A list of paramater nodes. + * + * @type {Array} + */ this.parametersNodes = parametersNodes; + /** + * The selected overloaded function call. + * + * @private + * @type {ShaderCallNodeInternal} + */ this._candidateFnCall = null; + /** + * This node is marked as global. + * + * @type {Boolean} + * @default true + */ this.global = true; } + /** + * This method is overwritten since the node type is inferred from + * the function's return type. + * + * @param {NodeBuilder} builder - The current node builder. + * @return {String} The node type. + */ getNodeType() { return this.functionNodes[ 0 ].shaderNode.layout.type;