Skip to content

⬅️ Back to Table of Contents

📄 ToonLightingModel.js

📊 Analysis Summary

Metric Count
🔧 Functions 10
🧱 Classes 1
📦 Imports 11

📚 Table of Contents

🛠️ File Location:

📂 src/nodes/functions/ToonLightingModel.js

📦 Imports

Name Source
LightingModel ../core/LightingModel.js
BRDF_Lambert ./BSDF/BRDF_Lambert.js
diffuseColor ../core/PropertyNode.js
normalGeometry ../accessors/Normal.js
Fn ../tsl/TSLBase.js
float ../tsl/TSLBase.js
vec2 ../tsl/TSLBase.js
vec3 ../tsl/TSLBase.js
mix ../math/MathNode.js
smoothstep ../math/MathNode.js
materialReference ../accessors/MaterialReferenceNode.js

Functions

getUV(): any

Returns: any

Code
() => coord

getUV(): any

Returns: any

Code
() => coord

getUV(): any

Returns: any

Code
() => coord

getUV(): any

Returns: any

Code
() => coord

getUV(): any

Returns: any

Code
() => coord

getUV(): any

Returns: any

Code
() => coord

getUV(): any

Returns: any

Code
() => coord

getUV(): any

Returns: any

Code
() => coord

ToonLightingModel.direct({ lightDirection, lightColor, reflectedLight }: any, builder: NodeBuilder): void

JSDoc:

/**
     * Implements the direct lighting. Instead of using a conventional smooth irradiance, the irradiance is
     * reduced to a small number of discrete shades to create a comic-like, flat look.
     *
     * @param {Object} lightData - The light data.
     * @param {NodeBuilder} builder - The current node builder.
     */

Parameters:

  • { lightDirection, lightColor, reflectedLight } any
  • builder NodeBuilder

Returns: void

Calls:

  • getGradientIrradiance( { normal: normalGeometry, lightDirection, builder } ).mul
  • reflectedLight.directDiffuse.addAssign
  • irradiance.mul
  • BRDF_Lambert (from ./BSDF/BRDF_Lambert.js)
Code
direct( { lightDirection, lightColor, reflectedLight }, builder ) {

        const irradiance = getGradientIrradiance( { normal: normalGeometry, lightDirection, builder } ).mul( lightColor );

        reflectedLight.directDiffuse.addAssign( irradiance.mul( BRDF_Lambert( { diffuseColor: diffuseColor.rgb } ) ) );

    }

ToonLightingModel.indirect(builder: NodeBuilder): void

JSDoc:

/**
     * Implements the indirect lighting.
     *
     * @param {NodeBuilder} builder - The current node builder.
     */

Parameters:

  • builder NodeBuilder

Returns: void

Calls:

  • reflectedLight.indirectDiffuse.addAssign
  • irradiance.mul
  • BRDF_Lambert (from ./BSDF/BRDF_Lambert.js)
  • reflectedLight.indirectDiffuse.mulAssign
Code
indirect( builder ) {

        const { ambientOcclusion, irradiance, reflectedLight } = builder.context;

        reflectedLight.indirectDiffuse.addAssign( irradiance.mul( BRDF_Lambert( { diffuseColor } ) ) );

        reflectedLight.indirectDiffuse.mulAssign( ambientOcclusion );

    }

Classes

ToonLightingModel

Class Code
class ToonLightingModel extends LightingModel {

    /**
     * Implements the direct lighting. Instead of using a conventional smooth irradiance, the irradiance is
     * reduced to a small number of discrete shades to create a comic-like, flat look.
     *
     * @param {Object} lightData - The light data.
     * @param {NodeBuilder} builder - The current node builder.
     */
    direct( { lightDirection, lightColor, reflectedLight }, builder ) {

        const irradiance = getGradientIrradiance( { normal: normalGeometry, lightDirection, builder } ).mul( lightColor );

        reflectedLight.directDiffuse.addAssign( irradiance.mul( BRDF_Lambert( { diffuseColor: diffuseColor.rgb } ) ) );

    }

    /**
     * Implements the indirect lighting.
     *
     * @param {NodeBuilder} builder - The current node builder.
     */
    indirect( builder ) {

        const { ambientOcclusion, irradiance, reflectedLight } = builder.context;

        reflectedLight.indirectDiffuse.addAssign( irradiance.mul( BRDF_Lambert( { diffuseColor } ) ) );

        reflectedLight.indirectDiffuse.mulAssign( ambientOcclusion );

    }

}

Methods

direct({ lightDirection, lightColor, reflectedLight }: any, builder: NodeBuilder): void
Code
direct( { lightDirection, lightColor, reflectedLight }, builder ) {

        const irradiance = getGradientIrradiance( { normal: normalGeometry, lightDirection, builder } ).mul( lightColor );

        reflectedLight.directDiffuse.addAssign( irradiance.mul( BRDF_Lambert( { diffuseColor: diffuseColor.rgb } ) ) );

    }
indirect(builder: NodeBuilder): void
Code
indirect( builder ) {

        const { ambientOcclusion, irradiance, reflectedLight } = builder.context;

        reflectedLight.indirectDiffuse.addAssign( irradiance.mul( BRDF_Lambert( { diffuseColor } ) ) );

        reflectedLight.indirectDiffuse.mulAssign( ambientOcclusion );

    }