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
- func ShelterRows(dst []byte, shelters []Shelter) []byte
- type Beam
- type Block
- type BlockSet
- type Casting
- type Distant
- func (s Distant) AmbientLight() Light
- func (s Distant) Beam() Beam
- func (s Distant) Frame(f Uniformer)
- func (s Distant) Light(nx, ny, nz float32) Light
- func (s Distant) Shaded(nx, ny, nz, lit float32) Light
- func (s Distant) ShadowOf(box geom.AABB, alt, height float32, groundAt func(x, y float32) float32) (Umbra, bool)
- func (s Distant) SilhouetteOf(box geom.AABB, alt, height float32, groundAt func(x, y float32) float32) (Umbra, bool)
- type Illumination
- type Lamp
- type Lattice
- type Light
- type Lights
- type Opening
- type ShadowPolicy
- type Shadowing
- type Shelter
- type Taking
- type Umbra
- type Uniformer
Constants ¶
const MaxOpenings = 32
MaxOpenings is how many of a shelter's openings let the distant light in.
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.
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
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.
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
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 ¶
AmbientLight is the colour of the ambient light, white for the zero one.
func (Distant) Shaded ¶
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 ¶
Lamp is a lamp in the world: where it stands and how far it reaches, in Color at full strength.
func (Lamp) Light ¶
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 ¶
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 ¶
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
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 ¶
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
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).