Class: DirectionalLightMaterial

DirectionalLightMaterial(webglContext, shaderProgram, optionsopt, materialOptionsopt)

Base class for materials that use a single directional light and require normals. Provides: - shared constants (attribute locations, common uniform names) - shared option parsing (color, lightDirection, ambientStrength) - shared setters with validation - a unified `apply(finalMatrix, worldMatrix, worldInverseTransposeMatrix, cameraPosition)` contract Subclasses may override `applyAdditionalUniforms(worldMatrix, cameraPosition)`.

Constructor

new DirectionalLightMaterial(webglContext, shaderProgram, optionsopt, materialOptionsopt)

Creates a new directional-light material.
Parameters:
Name Type Attributes Description
webglContext WebGL2RenderingContext WebGL2 rendering context used to create the GPU resources.
shaderProgram ShaderProgram Compiled shader program instance.
options DirectionalLightMaterialOptions <optional>
Common material options.
materialOptions DirectionalLightMaterialBaseOptions <optional>
Material base options.
Source:

Classes

DirectionalLightMaterial

Members

ambientStrength

Source:

color

Source:

directionalStrength

Source:

lightDirection

Source:

Methods

apply(finalMatrix, worldMatrix, worldInverseTransposeMatrix, cameraPosition)

Uploads per-object uniforms for a draw call. Unified contract for directional-light materials. Renderer passes: - finalMatrix (view projection * world) - worldMatrix - worldInverseTransposeMatrix - cameraPosition
Parameters:
Name Type Description
finalMatrix Float32Array View projection * world matrix.
worldMatrix Float32Array World matrix.
worldInverseTransposeMatrix Float32Array `(world ^ -1) ^ T` used to transform normals.
cameraPosition Float32Array Camera position, world space.
Source:

(protected) applyAdditionalUniforms(worldMatrix, cameraPosition)

Hook for subclasses to upload additional per-object uniforms. Default implementation in this class does nothing.
Parameters:
Name Type Description
worldMatrix Float32Array World matrix.
cameraPosition Float32Array Camera position, world space.
Source:

getDirectionalStrength() → {number}

Source:
Returns:
- Returns the directional strength multiplier value.
Type
number

isLightingEnabled() → {boolean}

Source:
Returns:
- Returns current lighting enabled state.
Type
boolean

setAmbientStrength(value)

Sets ambient strength multiplier.
Parameters:
Name Type Description
value number Ambient multiplier.
Source:

setColor(color)

Sets the diffuse/base RGB color.
Parameters:
Name Type Description
color Float32Array | Array.<number> [red, green, blue] in [0..1] range.
Source:

setDirectionalEnabled(enabled) → {void}

Enables or disables the directional light contribution.
Parameters:
Name Type Description
enabled boolean Whether directional lighting should be enabled.
Source:
Throws:
When the value is invalid.
Type
TypeError
Returns:
Type
void

setDirectionalStrength(value) → {void}

Sets directional strength multiplier.
Parameters:
Name Type Description
value number Directional strength multiplier.
Source:
Throws:
When the value is invalid.
Type
TypeError
Returns:
Type
void

setLightDirection(direction)

Sets the light direction (world space). The direction is normalized internally.
Parameters:
Name Type Description
direction Float32Array | Array.<number> [x, y, z] direction vector (non-zero).
Source:

setLightingEnabled(enabled) → {void}

Sets lighting enabled state.
Parameters:
Name Type Description
enabled boolean | number Boolean or a [0..1] numeric flag.
Source:
Throws:
  • When the value type is invalid.
    Type
    TypeError
  • When the value is outside [0..1].
    Type
    RangeError
Returns:
Type
void

(static) assertVector3(methodName, vector3)

Validates a vector3-like input.
Parameters:
Name Type Description
methodName string Method name for error messages.
vector3 Float32Array | Array.<number> Vector to validate.
Source: