Skip to content

⬅️ Back to Table of Contents

📄 PointLightNode.js

📊 Analysis Summary

Metric Count
🔧 Functions 4
🧱 Classes 1
📦 Imports 5

📚 Table of Contents

🛠️ File Location:

📂 src/nodes/lighting/PointLightNode.js

📦 Imports

Name Source
AnalyticLightNode ./AnalyticLightNode.js
getDistanceAttenuation ./LightUtils.js
uniform ../core/UniformNode.js
renderGroup ../core/UniformGroupNode.js
pointShadow ./PointShadowNode.js

Functions

directPointLight({ color, lightVector, cutoffDistance, decayExponent }: any): { lightDirection: any; lightColor: any; }

Parameters:

  • { color, lightVector, cutoffDistance, decayExponent } any

Returns: { lightDirection: any; lightColor: any; }

Calls:

  • lightVector.normalize
  • lightVector.length
  • getDistanceAttenuation (from ./LightUtils.js)
  • color.mul
Code
( { color, lightVector, cutoffDistance, decayExponent } ) => {

    const lightDirection = lightVector.normalize();
    const lightDistance = lightVector.length();

    const attenuation = getDistanceAttenuation( {
        lightDistance,
        cutoffDistance,
        decayExponent
    } );

    const lightColor = color.mul( attenuation );

    return { lightDirection, lightColor };

}

PointLightNode.update(frame: NodeFrame): void

JSDoc:

/**
     * Overwritten to updated point light specific uniforms.
     *
     * @param {NodeFrame} frame - A reference to the current node frame.
     */

Parameters:

  • frame NodeFrame

Returns: void

Calls:

  • super.update
Code
update( frame ) {

        const { light } = this;

        super.update( frame );

        this.cutoffDistanceNode.value = light.distance;
        this.decayExponentNode.value = light.decay;

    }

PointLightNode.setupShadowNode(): PointShadowNode

JSDoc:

/**
     * Overwritten to setup point light specific shadow.
     *
     * @return {PointShadowNode}
     */

Returns: PointShadowNode

Calls:

  • pointShadow (from ./PointShadowNode.js)
Code
setupShadowNode() {

        return pointShadow( this.light );

    }

PointLightNode.setupDirect(builder: any): { lightDirection: any; lightColor: any; }

Parameters:

  • builder any

Returns: { lightDirection: any; lightColor: any; }

Calls:

  • directPointLight
  • this.getLightVector
Code
setupDirect( builder ) {

        return directPointLight( {
            color: this.colorNode,
            lightVector: this.getLightVector( builder ),
            cutoffDistance: this.cutoffDistanceNode,
            decayExponent: this.decayExponentNode
        } );

    }

Classes

PointLightNode

Class Code
class PointLightNode extends AnalyticLightNode {

    static get type() {

        return 'PointLightNode';

    }

    /**
     * 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<float>}
         */
        this.cutoffDistanceNode = uniform( 0 ).setGroup( renderGroup );

        /**
         * Uniform node representing the decay exponent.
         *
         * @type {UniformNode<float>}
         */
        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;

        super.update( frame );

        this.cutoffDistanceNode.value = light.distance;
        this.decayExponentNode.value = light.decay;

    }

    /**
     * Overwritten to setup point light specific shadow.
     *
     * @return {PointShadowNode}
     */
    setupShadowNode() {

        return pointShadow( this.light );

    }

    setupDirect( builder ) {

        return directPointLight( {
            color: this.colorNode,
            lightVector: this.getLightVector( builder ),
            cutoffDistance: this.cutoffDistanceNode,
            decayExponent: this.decayExponentNode
        } );

    }

}

Methods

update(frame: NodeFrame): void
Code
update( frame ) {

        const { light } = this;

        super.update( frame );

        this.cutoffDistanceNode.value = light.distance;
        this.decayExponentNode.value = light.decay;

    }
setupShadowNode(): PointShadowNode
Code
setupShadowNode() {

        return pointShadow( this.light );

    }
setupDirect(builder: any): { lightDirection: any; lightColor: any; }
Code
setupDirect( builder ) {

        return directPointLight( {
            color: this.colorNode,
            lightVector: this.getLightVector( builder ),
            cutoffDistance: this.cutoffDistanceNode,
            decayExponent: this.decayExponentNode
        } );

    }