Dragosha/defold-light-and-shadows/light_and_shadows.constants
The light options the render script forwards into shader uniform constants. Scripts
such as light_setting.script and sun.script write them, and light.update and
the render script read them every frame. Vector fields are mutated in place
(constants.fog.x = 20); assigning a new value to a field goes through a cast, since
a namespace import is read-only.
- GitHub: Dragosha/defold-light-and-shadows — pinned to
v0.9.1- Pick a release from Dragosha/defold-light-and-shadows releases and add its Source code (zip) URL (or a packaged
.zipasset, if the library ships one) togame.projectunder[project]dependencies, then Fetch Libraries in the Defold editor. - Run
bunx @defold-typescript/cli resolveto materialize its types. - Import it under a namespace alias of your choice:
import * as constants from "light_and_shadows.constants"
- Pick a release from Dragosha/defold-light-and-shadows releases and add its Source code (zip) URL (or a packaged
Variables
clear_color: Vector4
The color that clears the default render target, which is the background color. RGB in 0..1.
fog: Vector4
The minimum and maximum Z in camera view space between which the fog starts and ends, in x and y.
ambient: Vector4
The ambient color, added after every light source is blended. w is the maximum value of each final color component.
fog_color: Vector4
The fog color, usually the clear color. w is the fog density from 0 to 1, where 0 is the densest.
lights: LightEntry[]
The light sources, their world positions and colors. Only the first
light_and_shadows.max_lights reach the shader; missing ones are sent as zero
vectors.
cam_position: Vector4
The camera world position, which the shader uses for specular light. light.update copies it from light.cam_position.
cam_look_at_position: Vector3
The point the camera looks at, the center of the shadow projection. light.update copies it from light.cam_look_at.
sun_position: Vector4
The sun position, the one light source that casts shadows.
sun_color: Vector4
The sun color.
sun_dir: Vector3
The sun direction, used for shadow casting with a perspective projection.
shadow_color: Vector4
The inverted shadow color, subtracted where shadows fall. light_and_shadows.update sets w to 1 when light_and_shadows.shadow is on and 0 when it is off.
cam_z: number
The camera Z coordinate, the distance from the focus point. light.update copies it from light.cam_z.
focus_range: number
How wide the depth-of-field focus zone is. light_and_shadows.dof sets it from focus_range.
near_z: number
The camera near Z plane. The reference render script reads it from the camera while light_and_shadows.get_far_near_z_from_camera is true.
far_z: number
The camera far Z plane. The reference render script reads it from the camera while light_and_shadows.get_far_near_z_from_camera is true.
Types
LightEntry
LightEntry.position: Vector4
The world position. w carries the spotlight smoothness.
LightEntry.color: Vector4
The color. w is the power after distance attenuation.
LightEntry.direction?: Vector4
The spotlight direction; w above 0 turns the spotlight on. light_and_shadows.update sends a zero vector when it is absent.
LightEntry.distance: number
The squared distance from the point the camera looks at.
LightEntry.power: number
The power before distance attenuation.