Documentation
¶
Overview ¶
Package light declares the light over a world: a distant light (the sun) and the lamps, how each thing casts its shadow and what shade it takes. It publishes them once a frame (render.Lights); render lights the frame by them.
Plugin ¶
NewPlugin makes the light over a world (Config: how many lamps nearest a camera cast shadows). A game makes it after motion and before the board and the topography, which draw by it, and runs it after the world (Plugin.RunPlan). From then on the world's entities are marked by it as they are published (world.Lighting) and the world's picture is lit by what it publishes (Plugin.Publish: the sun and the lamps, how it is set, the blocks the ground bakes the shadows of, a set a sector, versioned so the shade is baked anew only where a set changed, the ground under them; world.Read.Lights for what draws). Its state is read through Plugin.Read, the same on every goroutine: the sources as the clock's Replay left them, taken as each Replay ends (clock.Clock.Replayed). It is changed through Plugin.Write, the game's goroutine's.
Sources ¶
What shines is an entity with a Source, a knob: a lamp, reaching as far as its Reach from where the entity stands, or a Distant light, a source of no Reach whose way and strength whoever models it writes beside it each tick (Shining) — the atmosphere's own entity shines the sun of the hour; a scene without a sky has the plugin's own shine one it sets (Plugin.WithDistant, once, or each tick for a sun of the game's own). Two distant lights at once panic. Read.Distant is the distant light this tick, Read.Lamps the lamps; White the light of a world without one, everything lit as it is.
Shadows ¶
Every entity casts and takes as its Shadow says, a knob its kind declares and an effect may turn: a Patch or the Silhouette of its sprite laid over the ground every frame, a Baked block whose shadow the ground's shade holds, gathered anew as its chunk changes or the world's Restills move and standing where it was baked meanwhile, or NoShadow; and which shade it takes (render.Taking), all unless it says. A kind declaring none casts a Patch taking all; what the board stands is Baked. The shade of the ground — the relief's shadows over a Relief the topography gives (Plugin.OverRelief), level ground without one, and the Baked blocks' on either — is baked by render on the GPU as the sun moves, a strip a frame, and handed to every frame (render.GroundShade) for whoever draws the ground and what stands on it to read; CoarseShadows bakes it half as fine. render lays the live shadows over whatever ground the frame drew, read off its depth, as a ShadowPolicy turns them by the distance from the eye (Plugin.WithShadowPolicy): the distant light's everywhere, and on level ground the lamps' too, from the lamps nearest the camera, as many as the Config says or none (LampShadows). Every shadow, live or baked, the sun's or a lamp's, reaches at most render.ShadowReach times its caster's height: a light on the horizon would cast a shadow for ever.
Light on things ¶
Distant is a distant light as the shaders and the CPU take it, render's (render.Distant: Light, Shaded, a Beam ready to light many, Frame the uniforms, ShadowOf and SilhouetteOf where a shadow lies, an Umbra); Lamp a lamp in the world. The lamps nearest a camera, MaxLamps at most, light its picture: the entities as render.Frame.Lit says, the ground through the shaders' lampLightAt. Read.Reporter is the light's line on the telemetry panel, as the frame drawn is lit.
Under a roof ¶
A Shelter is a roof over part of the world, a knob of the entity standing for it, its floor that entity's world.Z: what of the sky's light gets under it, its lamp and its openings, by which alone the distant light gets in. An entity Sheltered under one, as whoever keeps who stands where writes it, is drawn in the light that gets in there, worked out on the GPU pixel by pixel (render.Shelter), taking no shade of the open air and casting no shadow.
Vocabulary ¶
Knobs, for an effect's Alter: Source, what an entity shines with; Shadow, how it casts and what it takes; Shelter, a roof's openings, its shares of the sky's light and its lamp. Components: Sheltered, the roof an entity stands under. Commands, a player's, of the settings screen alone: CoarseShadows, LampShadows. Settings (Settings, saved with the game, in Resources): the shadows coarse, the lamps casting.
Index ¶
- Constants
- Variables
- type AdaptShadows
- type Beam
- type Casting
- type CoarseShadows
- type Config
- type Distant
- type Lamp
- type LampShadows
- type Opening
- type Plugin
- func (p *Plugin) DefaultBindings() []control.Binding
- func (p *Plugin) EventHandler() control.EventHandler
- func (p *Plugin) Install(ctx plugin.Installer) error
- func (p *Plugin) KindTemplates(r *kind.Roster)
- func (p *Plugin) Name() string
- func (p *Plugin) OverRelief(r Relief) *Plugin
- func (p *Plugin) Publish()
- func (p *Plugin) Queues() []command.CommandQueue
- func (p *Plugin) Read(int) *Read
- func (p *Plugin) Restore()
- func (p *Plugin) RunPlan(ctx goke.RunCtx, d time.Duration)
- func (p *Plugin) Serializable() plugin.Serializable
- func (p *Plugin) Settings() []control.Setting
- func (p *Plugin) Swap()
- func (p *Plugin) WithDistant(d Distant) *Plugin
- func (p *Plugin) WithShadowPolicy(policy ShadowPolicy) *Plugin
- func (p *Plugin) Write() *Write
- type Read
- type Relief
- type Resources
- type Settings
- type Shadow
- type ShadowPolicy
- type Shelter
- type Sheltered
- type Shining
- type Source
- type Umbra
- type Write
Constants ¶
const ( Patch = render.Patch Silhouette = render.Silhouette Baked = render.Baked NoShadow = render.NoShadow )
The ways an entity casts its shadow (render.Patch…).
const MaxLamps = render.MaxLamps
MaxLamps is how many lamps at most light a picture: the nearest its camera.
const MaxOpenings = render.MaxOpenings
MaxOpenings is how many openings a shelter keeps: its windows and its doors.
Variables ¶
var White = Distant{Dir: [3]float32{0, 0, 1}, Ambient: 1}
White is the light of a world with no distant light: every surface lit as it is, no shadow.
Functions ¶
This section is empty.
Types ¶
type AdaptShadows ¶
type AdaptShadows struct{ On bool }
AdaptShadows has the shadows follow the cameras' frame budget, or not (Settings.AdaptiveShadows): the light's Write is a cameras.Lever (cameras.Config.Levers), the lamps' shadows dropped first and the shadows baked coarse next as the rate falls under the budget, back the other way as it stays over. The settings screen alone.
func (AdaptShadows) Command ¶
func (AdaptShadows) Command()
type Casting ¶
Casting is how an entity casts its shadow on the ground (render.Casting): Patch every frame, away from the light, what moves; Silhouette its own drawn shape, a figure worth the cost; Baked into the ground with the ground's own, what stands still, one lying flat over the rectangle its Lie says, any other over its box; NoShadow none.
type CoarseShadows ¶
type CoarseShadows struct{ On bool }
CoarseShadows has the shadows baked coarse, half as fine a side, or in full detail (Settings.Coarse). The settings screen alone.
func (CoarseShadows) Command ¶
func (CoarseShadows) Command()
type Config ¶
type Config struct {
// LampShadows is how many lamps nearest the middle of a picture cast shadows; 0 none.
LampShadows int
}
Config is how the light begins.
type Distant ¶
Distant is a light from far off, the same everywhere, the light of a sky or a scene's own (Plugin.WithDistant); render's (render.Distant).
type LampShadows ¶
type LampShadows struct{ Count int }
LampShadows has the Count lamps nearest a picture's camera cast shadows, 0 none (Settings.LampShadows). The settings screen alone: off or as many as the Config says.
func (LampShadows) Command ¶
func (LampShadows) Command()
type Opening ¶ added in v0.22.0
Opening is where a shelter's wall lets the distant light in, a window or a door: the stretch of its line from A to B, from Bottom to Top over the shelter's floor.
type Plugin ¶
Plugin is the light over a world: a Distant light some entity shines with (the sun), and the lamps, the Sources that reach; what lights the entities and the ground, and what shade each takes (Shadow). It bakes the shadows of the relief and of what stands Baked on the ground for every ground to read (render.GroundShade) and lays the live ones over whatever ground is drawn.
func NewPlugin ¶
NewPlugin makes the light over w as cfg says: the world's entities are lit by it from then on. Make it before the board and the topography, which draw by it.
func (*Plugin) DefaultBindings ¶
DefaultBindings are none: the shadows are the settings screen's.
func (*Plugin) EventHandler ¶
func (p *Plugin) EventHandler() control.EventHandler
func (*Plugin) KindTemplates ¶
KindTemplates is what the light asks of the kinds a game defines: of every entity, how it casts its shadow and which shade it takes, a Patch taking all unless its kind says.
func (*Plugin) OverRelief ¶
OverRelief has the shadows fall on the relief r, the topography's, in place of level ground.
func (*Plugin) Publish ¶ added in v0.5.0
func (p *Plugin) Publish()
Publish hands the frame drawn next the light as it stands: the distant light and the lamps, how it is set, the blocks the ground bakes the shadows of, a set a sector, the ground they are baked over and the relief under the live shadows.
func (*Plugin) Queues ¶
func (p *Plugin) Queues() []command.CommandQueue
Queues are where the light's commands land.
func (*Plugin) Read ¶ added in v0.4.0
Read reads the light's state on worker w of the game's pool, 0 the game's own goroutine.
func (*Plugin) Restore ¶
func (p *Plugin) Restore()
Restore takes the Settings loaded and bakes as they say.
func (*Plugin) RunPlan ¶
RunPlan carries the light's commands out and has the plugin's own entity shine the scene's sun; call it after the world's.
func (*Plugin) Serializable ¶
func (p *Plugin) Serializable() plugin.Serializable
Serializable is the light's Settings, kept whole.
func (*Plugin) Settings ¶
Settings are whether the shadows follow the frame budget, the shadows' detail and, with lamps casting shadows at all (Config.LampShadows), whether they do, under Picture/Shadows (plugin.Tunable).
func (*Plugin) Swap ¶ added in v0.5.0
func (p *Plugin) Swap()
Swap has the light published last drawn.
func (*Plugin) WithDistant ¶
WithDistant has the plugin's own entity shine the distant light d over the world, a scene's sun where no sky gives one: set once by a scene, or each tick before RunPlan by a game whose sun moves. A sky's beside it panics.
func (*Plugin) WithShadowPolicy ¶
func (p *Plugin) WithShadowPolicy(policy ShadowPolicy) *Plugin
WithShadowPolicy has the entities cast their live shadows as policy says; nil, as each declares. A Baked shadow is the ground's, asked of no policy.
type Read ¶ added in v0.4.0
type Read struct {
// contains filtered or unexported fields
}
Read reads the light's state, the same on every goroutine: the sources as the clock's last Replay left them.
func (*Read) Distant ¶ added in v0.4.0
Distant is the distant light this tick, the sun's; White without one.
func (*Read) LampShadows ¶ added in v0.4.0
LampShadows is how many lamps nearest a picture's camera cast shadows.
func (*Read) Reporter ¶ added in v0.4.0
Reporter is the light's part of the telemetry panel, as the frame drawn is lit: the distant light's strength, the lamps and how many cast shadows.
func (*Read) ShadowsAdaptive ¶ added in v0.4.0
ShadowsAdaptive reports whether the shadows follow the frame budget.
func (*Read) ShadowsCoarse ¶ added in v0.4.0
ShadowsCoarse reports whether the shadows are baked coarse.
type Relief ¶
type Relief interface {
Lattice() (cols, rows int, cell float32, heights []float32, ok bool)
GroundAt(p geom.Vec) float32
Version() uint64
}
Relief is the ground's heights as the light lays its shadows on them, the topography's (Plugin.OverRelief): a lattice over a square grid, false off one, the height anywhere, and a count of the heights' changes.
type Resources ¶
type Resources struct {
Settings Settings
}
Resources is what the light publishes: its Settings.
type Shadow ¶
Shadow is how an entity casts its shadow and which shade it takes (render.Taking), its kind's to declare and an effect's to turn: a knob. A kind declaring none casts a Patch and takes all.
type ShadowPolicy ¶
type ShadowPolicy = render.ShadowPolicy
ShadowPolicy is how an entity casts its live shadow at distance world units from the eye (0 through a camera without one), its Shadow declaring declared: Patch, Silhouette or NoShadow (render.ShadowPolicy).
type Shelter ¶ added in v0.22.0
type Shelter struct {
Openings [MaxOpenings]Opening
Open int
Sky, Bounce float32
Lamp [3]float32
ByDay bool
}
Shelter is a roof over part of the world, a knob of the entity standing for it, its floor as high as the entity's world.Z: 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, its own Lamp's light, burning as the sky's goes or ByDay too, and its first Open Openings, by which the distant light gets in.
type Sheltered ¶ added in v0.22.0
Sheltered is the entity whose Shelter an entity stands under, as whoever keeps who stands where writes it: it is drawn in the light that gets in there, pixel by pixel, casting no shadow.
type Shining ¶
type Shining struct{ Light Distant }
Shining is the light of a distant source as the sky writes it beside the Source each tick, or a scene once: the sun of the hour, a scene's lamp in the sky. Of a zero one the source shines not at all.
type Source ¶
Source is what an entity shines with, its kind's to declare and an effect's to turn: a knob. A lamp shines from where the entity stands as far as Reach, in Color, Strength strong, fading with the distance; a distant source, Reach 0, is a Distant light (the sun), Color, Strength and Ambient scaling what Shining says of it beside. A zero Color is white; a zero Strength shines not at all.
type Write ¶ added in v0.4.0
type Write struct {
// contains filtered or unexported fields
}
Write changes the light's state and readies it for a picture, on the game's goroutine.
func (*Write) AdaptShadows ¶ added in v0.4.0
AdaptShadows has the shadows follow the cameras' frame budget, or not (Settings.AdaptiveShadows).
func (*Write) Coarser ¶ added in v0.4.0
Coarser drops the lamps' shadows, or bakes the shadows coarse once they are gone, true where it could (cameras.Lever).
func (*Write) Finer ¶ added in v0.4.0
Finer bakes the shadows fine, or brings the lamps' shadows back once they are, as many as the Config says, true where it could (cameras.Lever).
func (*Write) Following ¶ added in v0.4.0
Following is whether the shadows follow the frame budget (cameras.Lever).
func (*Write) SetCoarseShadows ¶ added in v0.4.0
SetCoarseShadows has the shadows baked half as fine a side, a quarter of the GPU's work, or fine again (Settings.Coarse).
func (*Write) SetLampShadows ¶ added in v0.4.0
SetLampShadows has the n lamps nearest a picture's camera cast shadows, 0 none (Settings.LampShadows).