tiramisu/light
Types
Light types for illuminating the scene.
Different lights have different performance impacts and visual characteristics. Most games use a combination of ambient + directional for outdoor scenes, or ambient + point/spot for indoor scenes.
pub opaque type Light
pub type LightError {
NegativeIntensity(Float)
OutOfBoundsColor(Int)
NegativeDistance(Float)
InvalidShadowResolution(Int)
InvalidShadowBias(Float)
}
Constructors
-
NegativeIntensity(Float) -
OutOfBoundsColor(Int) -
NegativeDistance(Float) -
InvalidShadowResolution(Int) -
InvalidShadowBias(Float)
Values
pub fn ambient(
intensity intensity: Float,
color color: Int,
) -> Result(Light, LightError)
pub fn directional(
intensity intensity: Float,
color color: Int,
) -> Result(Light, LightError)
pub fn hemisphere(
intensity intensity: Float,
sky_color sky_color: Int,
ground_color ground_color: Int,
) -> Result(Light, LightError)
pub fn point(
intensity intensity: Float,
color color: Int,
distance distance: Float,
) -> Result(Light, LightError)
pub fn spot(
intensity intensity: Float,
color color: Int,
distance distance: Float,
angle angle: Float,
penumbra penumbra: Float,
) -> Result(Light, LightError)
pub fn with_shadow_bias(
light: Light,
bias: Float,
) -> Result(Light, LightError)
Set shadow bias to reduce shadow acne artifacts.
Typical values: 0.00001 to 0.001 (default: 0.0001). Increase if you see shadow artifacts (shadow acne). Decrease if shadows appear detached from objects.
Example
let assert Ok(sun) = light.directional(intensity: 1.0, color: 0xffffff)
|> light.with_shadows(True)
|> light.with_shadow_bias(0.0005)
pub fn with_shadow_resolution(
light: Light,
resolution: Int,
) -> Result(Light, LightError)
Set shadow map resolution (in pixels).
Higher values produce sharper shadows but use more memory. Common values: 512, 1024 (default), 2048, 4096. Must be a power of 2.
Example
let assert Ok(sun) = light.directional(intensity: 1.0, color: 0xffffff)
|> light.with_shadows(True)
|> light.with_shadow_resolution(2048)
pub fn with_shadows(light: Light, cast_shadow: Bool) -> Light
Enable shadow casting for a light.
Only directional, point, and spot lights can cast shadows. Ambient and hemisphere lights are ignored.
Example
let assert Ok(sun) = light.directional(intensity: 1.0, color: 0xffffff)
|> light.with_shadows(True)