Documentation
¶
Overview ¶
Package compose is the world's picture: Sources hand their pieces to a Frame where they lie (At); the Composer draws the opaque ground, then the rest back to front against the depth, the Direct sources in the passes they ask for, then the marks.
Index ¶
- Constants
- Variables
- func Compile() error
- func ShaderSource() string
- type At
- type AtlasSource
- type Baker
- func (b *Baker) Bake(u Uniforms)
- func (b *Baker) Blocks() int
- func (b *Baker) Coarse(on bool)
- func (b *Baker) Coarsened() bool
- func (b *Baker) Drop()
- func (b *Baker) Pending() bool
- func (b *Baker) Plan(lat Lattice, sun [3]float32, casts []BlockSet) (GroundShade, bool)
- func (b *Baker) Shade() GroundShade
- type Block
- type BlockSet
- type Caster
- type Composer
- func (c *Composer) DrawGlass(dst *Image, cam camera.Camera)
- func (c *Composer) DrawLayer(layer *Image, cam camera.Camera, at, hole camera.Window)
- func (c *Composer) DrawOver(screen *Image, cam camera.Camera)
- func (c *Composer) DrawWorld(screen *Image, cam camera.Camera)
- func (c *Composer) Lay(cam camera.Camera, apart bool)
- func (c *Composer) Light(lights func() *light.Lights)
- func (c *Composer) Uniforms() map[string][]float32
- type Corners
- type Depth
- type Direct
- type Fade
- type Frame
- func (f *Frame) At(x, y, z float32) At
- func (f *Frame) Cast(box geom.AABB, alt, height float32, s light.Shadowing, atlas AtlasSource, ...)
- func (f *Frame) DrawAt(at At)
- func (f *Frame) DrawCutout()
- func (f *Frame) DrawOpaque()
- func (f *Frame) DrawUncovered()
- func (f *Frame) Each(fn func(at At, verts []Vertex))
- func (f *Frame) Edge(at At, x0, y0, z0, x1, y1, z1, width float32, c color.RGBA)
- func (f *Frame) Fog(amount [4]float32)
- func (f *Frame) Glaze(at At, atlas AtlasSource, id SpriteID, dst Corners, shade Shade, ...)
- func (f *Frame) Glazed(opacity float32)
- func (f *Frame) GroundHeights(g GroundHeights)
- func (f *Frame) GroundShade(g GroundShade)
- func (f *Frame) Image(name string, img *Image)
- func (f *Frame) Len() int
- func (f *Frame) Lifted(x, y, z, lift float32) At
- func (f *Frame) Line(at At, x0, y0, x1, y1, width float32, c color.RGBA)
- func (f *Frame) Lit(x, y, z float32, take Taking) light.Illumination
- func (f *Frame) Material(at At, dst Corners, o *Overlay)
- func (f *Frame) OnGround(lift float32) At
- func (f *Frame) Overlay(o *Overlay)
- func (f *Frame) Places(fn func(p Pass, at At))
- func (f *Frame) Quad(at At, dst Corners, c [4]color.RGBA)
- func (f *Frame) ReadGround()
- func (f *Frame) Reset(cam camera.Camera)
- func (f *Frame) Soft(at At, dst Corners, c color.RGBA, fade Fade)
- func (f *Frame) Sprite(at At, atlas AtlasSource, id SpriteID, dst Corners, shade Shade)
- func (f *Frame) SpriteBlend(at At, atlas AtlasSource, id SpriteID, dst Corners, shade Shade, ...)
- func (f *Frame) SpriteFan(at At, atlas AtlasSource, id SpriteID, pts [][2]float32, box [4]float32, ...)
- func (f *Frame) SpritePart(at At, atlas AtlasSource, src [4]float32, dst Corners, shade Shade)
- func (f *Frame) SpriteRect(at At, atlas AtlasSource, id SpriteID, x0, y0, x1, y1 float32, shade Shade)
- func (f *Frame) SpriteRectUV(at At, atlas AtlasSource, id SpriteID, x0, y0, x1, y1, u0, v0, u1, v1 float32, ...)
- func (f *Frame) Time() float32
- func (f *Frame) Uniform(name string, v ...float32)
- func (f *Frame) Uniformed(name string) bool
- type Glass
- type GroundHeights
- type GroundShade
- type Image
- type Lattice
- type Light
- type MaterialID
- type Overlay
- type Overlying
- type Pass
- type Shade
- type Source
- type SpriteID
- type Taking
- type Target
- type Uniforms
- type Vertex
- type World
Constants ¶
const ( TakesRelief = light.TakesRelief TakesBlocks = light.TakesBlocks TakesClouds = light.TakesClouds TakesLamps = light.TakesLamps Shines = light.Shines TakesAll = light.TakesAll )
The shades a drawn thing takes (light.TakesAll…).
const ShadeBands = 16
ShadeBands is how many bands of rows down the ground's shade fade on their own from the shade before them to their own.
Variables ¶
var ( // Furthest is behind the whole world: the sky. Furthest = At{/* contains filtered or unexported fields */} // Nearest is before the whole world: what falls through the air. Nearest = At{/* contains filtered or unexported fields */} )
Functions ¶
func Compile ¶
func Compile() error
Compile compiles the composer's shader now rather than at its first draw.
func ShaderSource ¶
func ShaderSource() string
ShaderSource is the composer's shader as it compiles.
Types ¶
type At ¶
type At struct {
// contains filtered or unexported fields
}
At is where a piece of the picture lies: at a height in the world, its depth worked out on the GPU, drawn back to front by its key, or on top of the world as a mark.
func OnTop ¶
OnTop is a mark at level, not the world: drawn over it on the screen, a higher level over a lower, at one level in the order the marks came.
func (At) OverFigures ¶
OverFigures is a drawn over whatever stands, hidden by the ground alone: a look into the world, such as the solids of the entities' boxes, costing a copy of the ground's depth while drawn.
type Baker ¶
type Baker struct {
// contains filtered or unexported fields
}
Baker bakes the shade of one ground.
func (*Baker) Bake ¶
Bake bakes the rows the frame's Plan said, under the light it planned, reading the ground's heights from the frame's uniforms u, keeping each band as it was before for the frame to fade from. Over a relief whose heights the frame does not hold yet it bakes nothing, and the next Plan plans the whole anew.
func (*Baker) Blocks ¶
Blocks is how many blocks the shade is baked with, as the sets last gathered hold them.
func (*Baker) Coarse ¶
Coarse has the shade baked half as fine a side from the next frame on, or as fine as ever again.
func (*Baker) Drop ¶
func (b *Baker) Drop()
Drop lets the shade go: nothing to bake it over any more.
func (*Baker) Pending ¶
Pending reports whether the frame's Plan left anything for its Bake to bake.
func (*Baker) Plan ¶
Plan settles what of the shade over lat the frame's Bake bakes under the light the way sun, with the sets of blocks casts standing on the ground, and how far each band has faded from the shade before into its own since it was last baked. It is the frame's shade, false before any is baked.
func (*Baker) Shade ¶
func (b *Baker) Shade() GroundShade
Shade is the shade as last baked, for a test to read: the image and its area in the world.
type Block ¶
the ground the shade is baked over, a solid whose shadow it bakes, and the solids of a part of the world (light.Lattice, Block, BlockSet)
type BlockSet ¶ added in v0.20.0
the ground the shade is baked over, a solid whose shadow it bakes, and the solids of a part of the world (light.Lattice, Block, BlockSet)
type Caster ¶
type Caster struct {
// contains filtered or unexported fields
}
Caster draws casts over the ground's depth.
func (*Caster) Draw ¶
func (c *Caster) Draw( t Target, cam camera.Camera, atlas AtlasSource, casts []float32, low, high float32, )
Draw lays casts, castFloats each, the sprites' shapes from atlas, on the ground drawn through cam between low and high, read from the target's Ground depth: nothing without one.
type Composer ¶
type Composer struct {
// contains filtered or unexported fields
}
Composer is a Picture drawing its Sources as one picture: the opaque ground first, writing the depth, then the world back to front by where its pieces lie (At), each tested against what lies nearer, then the marks on top in the order they came; a run sampling one sheet in one call.
func NewComposer ¶
NewComposer composes sources into one picture; a nil source is left out.
func (*Composer) DrawGlass ¶
DrawGlass has every Glass source draw on the glass over the picture, dst, through cam.
func (*Composer) DrawLayer ¶
DrawLayer draws what the last Lay composed into layer through cam cropped to the frame's window at, the pieces scaled and moved from the frame's pixels into the layer's, leaving out the frame's window hole where the frame has a ground (a layer drawn after covers it whole; zero, none); a nil layer draws nothing.
func (*Composer) DrawOver ¶
DrawOver composes the Overlying sources through cam, with the uniforms and images the last Lay set, and draws them onto screen, each tested against the grounds of the layers laid since, their depths placed in screen's in the order laid; a nil screen only composes.
func (*Composer) DrawWorld ¶
DrawWorld composes the frame through cam and draws it; a nil screen only composes.
func (*Composer) Lay ¶
Lay composes every source through cam, the ground's alone when apart, for DrawLayer to draw a layer at a time and DrawOver over them; the layers laid before are forgotten.
type Direct ¶
Direct is a Source that draws a part of the picture itself, with a shader of its own, in the passes its Compose asked for (Frame.DrawOpaque, Frame.DrawUncovered, Frame.DrawCutout, Frame.DrawAt): Draw is handed which, and runs once a layer of a picture in layers, so what Compose gathered serves every Draw till the next Compose. A Direct asking for none is not drawn.
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame gathers what the sources of a Composer draw for one viewport, in screen pixels, each piece where it lies (At), and where the Direct sources draw themselves.
func (*Frame) At ¶
At is where the world point (x, y, z) lies through the frame's camera: from above the higher later, in a view that sorts the further back sooner.
func (*Frame) Cast ¶
func (f *Frame) Cast(box geom.AABB, alt, height float32, s light.Shadowing, atlas AtlasSource, sprite SpriteID)
Cast has what stands in box from alt up height cast its live shadow as s says, in the shape of atlas's sprite for a Silhouette, laid on the ground once the frame's sources have composed; nothing without the composer's lights, nor for what is Baked or casts none.
func (*Frame) DrawAt ¶
DrawAt has the composing Direct draw among what is seen through, back to front, at at.
func (*Frame) DrawCutout ¶ added in v0.21.0
func (f *Frame) DrawCutout()
DrawCutout has the composing Direct draw in the cutout pass: after the ground, tested against the depth and writing it, what it draws cut at half its alpha, before anything seen through.
func (*Frame) DrawOpaque ¶
func (f *Frame) DrawOpaque()
DrawOpaque has the composing Direct draw in the opaque pass, the ground's: tested against the depth and writing it, before anything seen through.
func (*Frame) DrawUncovered ¶ added in v0.22.0
func (f *Frame) DrawUncovered()
DrawUncovered has the composing Direct draw what it has uncovered, before the cutouts, into a depth of its own (Target.Uncovered): what gives way is left out over it in the passes after. A frame without a ground has no depth to tell what covers it by, and no such pass.
func (*Frame) Each ¶
Each calls fn with every piece in the order it came: where it lies and its vertices, the frame's own.
func (*Frame) Edge ¶
Edge is Line whose ends lie at the heights z0 and z1 in the world, each tested against the depth where it lies, the line drawn among the pieces at at.
func (*Frame) Fog ¶
Fog has the last plain sprite added turn to the colour of the Fog uniform as much as amount says at each corner, 0 to 1; a rectangle's (SpriteRect) as much as its corners on average, every piece it lies in.
func (*Frame) Glaze ¶
func (f *Frame) Glaze( at At, atlas AtlasSource, id SpriteID, dst Corners, shade Shade, opacity [4]float32, )
Glaze is Sprite laid over what lies under it as much as opacity says at each of its corners, 0 to 1.
func (*Frame) Glazed ¶ added in v0.21.0
Glazed has the last sprite added, every piece of a rectangle's, show as much as opacity says, 0 to 1, over what lies under it.
func (*Frame) GroundHeights ¶
func (f *Frame) GroundHeights(g GroundHeights)
GroundHeights hands every shader drawing this frame the ground's heights g, as whoever draws the ground has them; a frame without them has no ground's heights.
func (*Frame) GroundShade ¶
func (f *Frame) GroundShade(g GroundShade)
GroundShade hands every shader drawing this frame the ground's shade g, as whoever draws the ground bakes it; a frame without it has the sun reach everywhere.
func (*Frame) Image ¶
Image hands every shader drawing this frame the image registered as name (RegisterImage); a name not registered panics.
func (*Frame) Lifted ¶
Lifted is At of the point lift world units over (x, y, z): what lies on a surface, ordered among what lies on it alike.
func (*Frame) Line ¶
Line draws the line from (x0, y0) to (x1, y1) on screen, width pixels wide, in c, its sides fading over a pixel.
func (*Frame) Lit ¶
func (f *Frame) Lit(x, y, z float32, take Taking) light.Illumination
Lit is the light on what stands at (x, y, z) taking take (zero: every shade, Shines: none), as the composer's lights say through the frame's camera; white light taking every shade without them.
func (*Frame) Material ¶
Material lays o on its own, the screen quad dst for o's material to work out.
func (*Frame) OnGround ¶
OnGround is Lifted of the ground at 0 under the middle of the view: for what a Direct lays over the whole ground.
func (*Frame) Places ¶
Places calls fn with every pass a Direct composing into f asked to draw in, and where.
func (*Frame) ReadGround ¶
func (f *Frame) ReadGround()
ReadGround has the ground's depth kept apart this frame, for the composing source to read it (Target.Ground) once the ground is drawn.
func (*Frame) Soft ¶
Soft fills the quad dst in c, fading towards each side over the pixels fade gives it.
func (*Frame) Sprite ¶
Sprite draws sprite id of atlas over the screen corners dst, as bright as shade says.
func (*Frame) SpriteBlend ¶
func (f *Frame) SpriteBlend( at At, atlas AtlasSource, id SpriteID, dst Corners, shade Shade, weight [4]float32, soft float32, )
SpriteBlend draws sprite id over dst where weight, blended between its corners, is over a half, fading in over soft either side of it (0 to a half).
func (*Frame) SpriteFan ¶
func (f *Frame) SpriteFan(at At, atlas AtlasSource, id SpriteID, pts [][2]float32, box [4]float32, opacity float32)
SpriteFan fills the polygon pts, which every point of sees whole from pts[0], with the part of sprite id under it when the sprite is laid over the screen box x0, y0, x1, y1, as opaque as opacity says, 0 to 1.
func (*Frame) SpritePart ¶
SpritePart is Sprite drawing the part src (x0, y0, x1, y1 in the sheet's pixels) of atlas's sheet rather than a sprite of it.
func (*Frame) SpriteRect ¶
func (f *Frame) SpriteRect( at At, atlas AtlasSource, id SpriteID, x0, y0, x1, y1 float32, shade Shade, )
SpriteRect draws sprite id over the world rectangle (x0, y0)-(x1, y1) through the frame's camera, split where it crosses a wrap seam.
func (*Frame) SpriteRectUV ¶
func (f *Frame) SpriteRectUV( at At, atlas AtlasSource, id SpriteID, x0, y0, x1, y1, u0, v0, u1, v1 float32, shade Shade, )
SpriteRectUV is SpriteRect showing only the part u0..u1, v0..v1 of the sprite, 0 to 1 across it.
type Glass ¶
Glass is a Source drawing on the glass over its picture: DrawGlass draws onto dst, the picture as it is shown, in its pixels, after everything the scene lays over the picture, so nothing covers what it draws (the scroll zones).
type GroundHeights ¶
GroundHeights is the ground's heights for the shaders to read (WGSL groundHeightAt): a lattice of Corners corners Cell world units apart from the world's origin, each a pixel of Image, its height Low up to Low+Span in red and green as 16 bits.
type GroundShade ¶
type GroundShade struct {
Now, Was *Image
Area [4]float32
Span float32
Band float32
Mix [ShadeBands]float32
}
GroundShade is the sun on the ground for the shaders to read (WGSL groundShadeOf, groundShadeAt, standingShadeAt): Now over the world box Area (origin and size), each of its ShadeBands bands Band of its height tall faded into from Was as far as Mix says. Its red is the sun reaching the ground, green and blue the roots of how high the relief's and the blocks' shadows reach over it as shares of Span (blue one less), alpha the sun the blocks leave.
type Lattice ¶
the ground the shade is baked over, a solid whose shadow it bakes, and the solids of a part of the world (light.Lattice, Block, BlockSet)
type Overlay ¶
type Overlay struct {
Material MaterialID
World World
Red [4]float32
Fraction [4]float32 // 0 to 1
Custom [4][4]float32
// Blended, over a SpriteBlend, takes the sprite's weight and mark into Custom's third and
// fourth.
Blended bool
}
Overlay is a quad laid over a sprite for a material to work out in the shader: where the sprite's corners lie in the world, and what the material reads at each corner, blended across the quad.
type Overlying ¶
type Overlying interface{ Overlies() }
Overlying is a Source whose pieces lie over the figures' ground: the figures themselves, what falls or floats over them and the marks. A Laid picture composes and draws it in the pass over the layers of the ground, the rest in the ground's.
type Pass ¶
type Pass uint8
Pass is which part of the picture a Direct draws in: the opaque ground first, then what is uncovered, into a depth of its own, then the cutouts, what stands whole cut at half its alpha and writing the depth, in no order, then what is seen through, back to front.
type Shade ¶
type Shade [4]Light
Shade is the light a piece is drawn in at its corners, top-left, top-right, bottom-left, bottom-right, blended across it.
type Target ¶
type Target struct {
Screen *Image
Depth *Depth
Ground *Depth
// Uncovered is where what is uncovered lies, for what gives way to read in the passes after
// (depthAt): one less its depth, the farthest's, 0 where nothing is; nil where no source
// asked (Frame.DrawUncovered). In the pass Uncovered it is Depth, written so, the screen left
// as it is.
Uncovered *Depth
// UncoveredIn is the rectangle of the camera's viewport what is uncovered lies within, x0,
// y0, x1, y1 in pixels: a source grows it by what it draws in the pass Uncovered, and what
// gives way reads no depth outside it. Nil with Uncovered.
UncoveredIn *[4]float32
Pass Pass
// Coarse is how many of the screen's pixels each way a pixel of the ground under the pass
// spans, its coarsest layer's, over grounds laid apart (Laid.DrawOver); 0, as 1, elsewhere.
Coarse float32
}
Target is where a Direct source draws: the screen, nil in a test; the depth buffer every mesh of the frame shares, nil in a frame without a ground; the ground's depth alone for a source that asked for it (Frame.ReadGround), nil in the opaque pass and the cutouts'; and the pass.
type Uniforms ¶
type Uniforms struct {
// contains filtered or unexported fields
}
Uniforms is the composer's shader's uniforms this frame, by name, for a Direct source.
func UniformsOf ¶
UniformsOf is the uniforms m, by name, each a []float32, or an *Image for a frame's image.