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. |
Classes
Members
ambientStrength
color
directionalStrength
lightDirection
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. |
(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. |
getDirectionalStrength() → {number}
Returns:
- Returns the directional strength multiplier value.
- Type
- number
isLightingEnabled() → {boolean}
Returns:
- Returns current lighting enabled state.
- Type
- boolean
setAmbientStrength(value)
Sets ambient strength multiplier.
Parameters:
| Name | Type | Description |
|---|---|---|
value |
number | Ambient multiplier. |
setColor(color)
Sets the diffuse/base RGB color.
Parameters:
| Name | Type | Description |
|---|---|---|
color |
Float32Array | Array.<number> | [red, green, blue] in [0..1] range. |
setDirectionalEnabled(enabled) → {void}
Enables or disables the directional light contribution.
Parameters:
| Name | Type | Description |
|---|---|---|
enabled |
boolean | Whether directional lighting should be enabled. |
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. |
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). |
setLightingEnabled(enabled) → {void}
Sets lighting enabled state.
Parameters:
| Name | Type | Description |
|---|---|---|
enabled |
boolean | number | Boolean or a [0..1] numeric flag. |
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. |