light

package
v0.27.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package light is how render lights a scene: the distant light and the lamps, the light on what is drawn, and the shadows cast.

Index

Constants

View Source
const MaxOpenings = 32

MaxOpenings is how many of a shelter's openings let the distant light in.

View Source
const ShadowReach = 6

ShadowReach is how many times its caster's height a shadow reaches at most, whatever casts it (a unit, a baked block, a cloud) and under whatever light: a light on the horizon would cast a shadow for ever. Every shadow in gram keeps to it; nothing caps a shadow of its own.

View Source
const ShelterTexels = 8 + 6*MaxOpenings

ShelterTexels is how many texels a shelter's row of the frame's Shelters image holds: its floor, its shares, its lamp, by day, how many openings, then six an opening.

Variables

This section is empty.

Functions

func ShelterRows added in v0.22.0

func ShelterRows(dst []byte, shelters []Shelter) []byte

ShelterRows appends to dst the shelters' rows of the frame's Shelters image, a float32 a texel in its four bytes (light.wgsl's shelterFloat).

Types

type Beam

type Beam struct {
	// contains filtered or unexported fields
}

Beam is a Distant ready to light many surfaces.

func (Beam) Shaded

func (l Beam) Shaded(nx, ny, nz, lit float32) Light

Shaded is the light on a surface whose normal is (nx, ny, nz), lit of the light reaching it.

type Block

type Block struct{ X, Y, UX, UY, Along, Wide, Bottom, Top float32 }

Block is a solid whose shadow the ground bakes: a rectangle round (X, Y) running (UX, UY), Along from its middle that way and Wide across, standing from Bottom up to Top.

type BlockSet added in v0.20.0

type BlockSet struct {
	Box     [4]float32
	Top     float32
	Version uint64
	Blocks  []Block
}

BlockSet is the blocks standing in one part of the world, their joint rectangle Box (origin and size) and the highest of their tops, so the shade is baked anew only where a set changed. Its Version is raised whenever its blocks stand other than before, and a set at the same place in Lights.Casts is the same part from frame to frame.

type Casting

type Casting uint8

Casting is how a thing casts its shadow on the ground.

const (
	// Patch casts a soft patch every frame, away from the light: what moves.
	Patch Casting = iota
	// Silhouette casts the thing's own drawn shape every frame, away from the light: a figure
	// worth the cost.
	Silhouette
	// Baked has the ground bake the shadow of the thing's solid with its own: what stands still.
	Baked
	// NoShadow casts none.
	NoShadow
)

type Distant

type Distant struct {
	Dir          [3]float32
	Strength     float32
	Ambient      float32
	Color        Light
	AmbientColor Light
}

Distant is a light from far off, the same everywhere: Dir points from the ground towards it (z up), Strength is how much it lights a surface facing it square on, Ambient how much light every surface gets anyway, in AmbientColor; a zero Color or AmbientColor is white.

func (Distant) AmbientLight

func (s Distant) AmbientLight() Light

AmbientLight is the colour of the ambient light, white for the zero one.

func (Distant) Beam

func (s Distant) Beam() Beam

Beam is the light made ready to light many surfaces.

func (Distant) Frame

func (s Distant) Frame(f Uniformer)

Frame hands f the light's uniforms (the library's light.wgsl).

func (Distant) Light

func (s Distant) Light(nx, ny, nz float32) Light

Light is the light cast on a surface whose normal is (nx, ny, nz).

func (Distant) Shaded

func (s Distant) Shaded(nx, ny, nz, lit float32) Light

Shaded is Light where only lit of the direct light, 0 to 1, reaches the surface.

func (Distant) ShadowOf

func (s Distant) ShadowOf(box geom.AABB, alt, height float32,
	groundAt func(x, y float32) float32) (Umbra, bool)

ShadowOf is the shadow of what stands in box from alt up height, on the ground groundAt gives (nil: level at 0). It is false with the light below the horizon or too faint.

func (Distant) SilhouetteOf

func (s Distant) SilhouetteOf(box geom.AABB, alt, height float32,
	groundAt func(x, y float32) float32) (Umbra, bool)

SilhouetteOf is where the drawn shape of what stands in box from alt up height lies on the ground groundAt gives (nil: level at 0): from its feet away from the light, as long as it stands tall there, as wide as its box across, unfaded. It is false with the light down or too faint.

type Illumination

type Illumination struct {
	Light, Lamps Light
	// Direct is the share of Light that is the distant light's, 0 to 1: what a shadow takes away.
	Direct float32
	Takes  Taking
	// Shelter is the shelter it is drawn under, as Shadowing's: its Light then the lamps' alone,
	// the shaders adding what of the sky's light gets in pixel by pixel.
	Shelter uint16
}

Illumination is the light a thing is drawn in: Light on a surface facing up, the sun's and the lamps', Lamps the lamps' alone, and which shade it Takes.

func (Illumination) Sheltered added in v0.22.0

func (i Illumination) Sheltered(s uint16) Illumination

Sheltered is i under the shelter s names (Shadowing.Shelter); i itself for none.

type Lamp

type Lamp struct {
	X, Y, Z, Reach float32
	Color          Light
}

Lamp is a lamp in the world: where it stands and how far it reaches, in Color at full strength.

func (Lamp) Light

func (l Lamp) Light(x, y, z float32) (Light, bool)

Light is the lamp's light at (x, y, z), fading by the square of the share of its reach left; false out of its reach.

func (Lamp) ShadowOf

func (l Lamp) ShadowOf(box geom.AABB, alt, height float32, shape bool) (Umbra, bool)

ShadowOf is the shadow the lamp casts of what stands in box from alt up height on level ground: away from the lamp, the longer the nearer the lamp and the higher it stands against it; a patch, or its own shape where shape says. It is false where the lamp's light does not reach it.

type Lattice

type Lattice struct {
	Cols, Rows int
	Cell       float32
	Low, Span  float32
	Version    uint64
}

Lattice is the ground the shade is baked over: Cols by Rows corners Cell world units apart from the origin, the lowest Low high and the highest Low+Span; Version counts the changes to the heights. Level ground is a Lattice of no Span.

type Light

type Light [3]float32

Light is a colour of light, red, green and blue, a colour drawn in it is scaled by; 1 each is white.

type Lights

type Lights struct {
	Sun         Distant
	Lamps       []Lamp
	LampShadows int
	Coarse      bool
	Policy      ShadowPolicy
	Casts       []BlockSet
	Ground      Lattice
	GroundAt    func(x, y float32) float32
	// Shelters are the roofs over the world, a Shadowing's Shelter naming one; their Version is
	// raised whenever they change.
	Shelters        []Shelter
	SheltersVersion uint64
}

Lights are a scene's lights for a frame: the distant light, the lamps, how many lamps nearest a camera cast shadows, whether the ground's shade is baked coarse, how a live shadow is cast by its distance from the eye (nil: as declared), the blocks whose shadows the ground bakes in sets by the part of the world they stand in, the ground they are baked over (one of under two corners a side: none), and the height of the ground under a point (nil: level at 0, where the lamps cast shadows too).

type Opening added in v0.22.0

type Opening struct {
	A, B        [2]float32
	Bottom, Top float32
}

Opening is where a shelter's wall lets the distant light in: the stretch of its line from A to B, from Bottom to Top over the shelter's floor.

type ShadowPolicy

type ShadowPolicy func(declared Casting, distance float32) Casting

ShadowPolicy is how a thing casts its live shadow at distance world units from the eye (0 through a camera without one), declared as it says: Patch, Silhouette or NoShadow.

type Shadowing

type Shadowing struct {
	Cast Casting
	Take Taking
	// Shelter is the shelter it stands under, its place in Lights.Shelters and one more; zero,
	// it stands in the open.
	Shelter uint16
}

Shadowing is how a thing casts its shadow and which shade it takes; the zero one casts a Patch and takes all.

type Shelter added in v0.22.0

type Shelter struct {
	Floor       float32
	Sky, Bounce float32
	Lamp        Light
	ByDay       bool
	Openings    []Opening
}

Shelter is a roof over part of the world: its floor's height, what of the sky's light gets under it, Sky of the sky's and Bounce of the distant light's thrown round from where it falls in, and its own Lamp, burning as the sky's light goes or ByDay too. The distant light gets in by its Openings alone, MaxOpenings of them at the most.

type Taking

type Taking uint8

Taking is which shade a drawn thing takes, bits of it: the relief's shadow, the baked blocks', the clouds', and which light, the lamps'. One taking none shines as it is drawn.

const (
	TakesRelief Taking = 1 << iota
	TakesBlocks
	TakesClouds
	TakesLamps
	// Shines takes nothing: the thing is drawn as it is.
	Shines Taking = 1 << 7
	// TakesAll takes every shade and the lamps' light, as a zero Taking does.
	TakesAll = TakesRelief | TakesBlocks | TakesClouds | TakesLamps
)

type Umbra

type Umbra struct{ X, Y, UX, UY, Along, Wide, Fade, Veil float32 }

Umbra is where a shadow lies on the ground, in world units: its middle (X, Y), the way away from the light (UX, UY), its reach along that way (Along) and across it (Wide), how far in from each side it fades (Fade) and how dark it is (Veil, 0 to 1).

type Uniformer

type Uniformer interface {
	Uniform(name string, v ...float32)
}

Uniformer takes the uniforms of a frame by name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL