ExRatatui.ThreeD.Light (ExRatatui v0.11.0)

Copy Markdown View Source

A light source: ambient, directional, or point.

Fields

  • :type - :ambient, :directional, or :point
  • :color - {r, g, b} color, channels 0-255
  • :intensity - scalar brightness (defaults to 1.0)
  • :direction - {x, y, z} direction toward the light (only for :directional)
  • :position - {x, y, z} world position (only for :point)

Prefer the constructors over building the struct by hand.

Examples

iex> light = ExRatatui.ThreeD.Light.ambient({255, 255, 255}, 0.15)
iex> {light.type, light.color, light.intensity}
{:ambient, {255, 255, 255}, 0.15}

iex> light = ExRatatui.ThreeD.Light.directional({-1.0, -1.0, -1.0}, {255, 255, 255})
iex> {light.type, light.direction, light.intensity}
{:directional, {-1.0, -1.0, -1.0}, 1.0}

iex> light = ExRatatui.ThreeD.Light.point({2.0, 3.0, 2.0}, {255, 220, 180})
iex> {light.type, light.position}
{:point, {2.0, 3.0, 2.0}}

Summary

Functions

Constant ambient illumination.

A directional light. direction points toward the light source.

A point light at position.

Types

kind()

@type kind() :: :ambient | :directional | :point

rgb()

@type rgb() :: {0..255, 0..255, 0..255}

t()

@type t() :: %ExRatatui.ThreeD.Light{
  color: rgb(),
  direction: vec3() | nil,
  intensity: float(),
  position: vec3() | nil,
  type: kind()
}

vec3()

@type vec3() :: {number(), number(), number()}

Functions

ambient(color, intensity \\ 1.0)

@spec ambient(rgb(), number()) :: t()

Constant ambient illumination.

directional(direction, color, opts \\ [])

@spec directional(vec3(), rgb(), keyword()) :: t()

A directional light. direction points toward the light source.

Options: :intensity (defaults to 1.0).

point(position, color, opts \\ [])

@spec point(vec3(), rgb(), keyword()) :: t()

A point light at position.

Options: :intensity (defaults to 1.0).