compose

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: 14 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 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

View Source
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…).

View Source
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

View Source
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

func OnTop(level float32) At

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) Before

func (a At) Before(b At) bool

Before reports whether a is drawn before b among what is drawn back to front.

func (At) OverFigures

func (a At) OverFigures() At

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.

func (At) Top

func (a At) Top() bool

Top reports whether a is a mark, drawn over the world.

func (At) Z

func (a At) Z() float32

Z is the height the piece lies at.

type AtlasSource

type AtlasSource = gfx.AtlasSource

the names of gfx's compose draws with

type Baker

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

Baker bakes the shade of one ground.

func (*Baker) Bake

func (b *Baker) Bake(u Uniforms)

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

func (b *Baker) Blocks() int

Blocks is how many blocks the shade is baked with, as the sets last gathered hold them.

func (*Baker) Coarse

func (b *Baker) Coarse(on bool)

Coarse has the shade baked half as fine a side from the next frame on, or as fine as ever again.

func (*Baker) Coarsened

func (b *Baker) Coarsened() bool

Coarsened reports whether the shade is baked coarse.

func (*Baker) Drop

func (b *Baker) Drop()

Drop lets the shade go: nothing to bake it over any more.

func (*Baker) Pending

func (b *Baker) Pending() bool

Pending reports whether the frame's Plan left anything for its Bake to bake.

func (*Baker) Plan

func (b *Baker) Plan(lat Lattice, sun [3]float32, casts []BlockSet) (GroundShade, bool)

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

type Block = light.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

type BlockSet = light.BlockSet

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

func NewComposer(sources ...Source) *Composer

NewComposer composes sources into one picture; a nil source is left out.

func (*Composer) DrawGlass

func (c *Composer) DrawGlass(dst *Image, cam camera.Camera)

DrawGlass has every Glass source draw on the glass over the picture, dst, through cam.

func (*Composer) DrawLayer

func (c *Composer) DrawLayer(layer *Image, cam camera.Camera, at, hole camera.Window)

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

func (c *Composer) DrawOver(screen *Image, cam camera.Camera)

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

func (c *Composer) DrawWorld(screen *Image, cam camera.Camera)

DrawWorld composes the frame through cam and draws it; a nil screen only composes.

func (*Composer) Lay

func (c *Composer) Lay(cam camera.Camera, apart bool)

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.

func (*Composer) Light

func (c *Composer) Light(lights func() *light.Lights)

Light has the frame lit by the scene's lights lights gives as it is composed, none while it gives nil: the lamps nearest the camera, the light on what the sources draw (Frame.Lit), the shadows they cast (Frame.Cast) and the ground's shade baked.

func (*Composer) Uniforms

func (c *Composer) Uniforms() map[string][]float32

Uniforms is what the last frame handed the shader, by name.

type Corners

type Corners = gfx.Corners

the names of gfx's compose draws with

type Depth

type Depth = gfx.Depth

the names of gfx's compose draws with

type Direct

type Direct interface {
	Source
	Draw(t Target, cam camera.Camera, u Uniforms)
}

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 Fade

type Fade = gfx.Fade

the names of gfx's compose draws with

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

func (f *Frame) At(x, y, z float32) 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

func (f *Frame) DrawAt(at At)

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

func (f *Frame) Each(fn func(at At, verts []Vertex))

Each calls fn with every piece in the order it came: where it lies and its vertices, the frame's own.

func (*Frame) Edge

func (f *Frame) Edge(at At, x0, y0, z0, x1, y1, z1, width float32, c color.RGBA)

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

func (f *Frame) Fog(amount [4]float32)

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

func (f *Frame) Glazed(opacity float32)

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

func (f *Frame) Image(name string, img *Image)

Image hands every shader drawing this frame the image registered as name (RegisterImage); a name not registered panics.

func (*Frame) Len

func (f *Frame) Len() int

Len is how many pieces the frame holds: quads and fans.

func (*Frame) Lifted

func (f *Frame) Lifted(x, y, z, lift float32) At

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

func (f *Frame) Line(at At, x0, y0, x1, y1, width float32, c color.RGBA)

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

func (f *Frame) Material(at At, dst Corners, o *Overlay)

Material lays o on its own, the screen quad dst for o's material to work out.

func (*Frame) OnGround

func (f *Frame) OnGround(lift float32) At

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) Overlay

func (f *Frame) Overlay(o *Overlay)

Overlay lays o over the last sprite added, every piece of a SpriteRect's.

func (*Frame) Places

func (f *Frame) Places(fn func(p Pass, at At))

Places calls fn with every pass a Direct composing into f asked to draw in, and where.

func (*Frame) Quad

func (f *Frame) Quad(at At, dst Corners, c [4]color.RGBA)

Quad fills dst in a colour per corner, blended across.

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) Reset

func (f *Frame) Reset(cam camera.Camera)

Reset starts the frame over, drawn through cam.

func (*Frame) Soft

func (f *Frame) Soft(at At, dst Corners, c color.RGBA, fade Fade)

Soft fills the quad dst in c, fading towards each side over the pixels fade gives it.

func (*Frame) Sprite

func (f *Frame) Sprite(at At, atlas AtlasSource, id SpriteID, dst Corners, shade Shade)

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

func (f *Frame) SpritePart(at At, atlas AtlasSource, src [4]float32, dst Corners, shade Shade)

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.

func (*Frame) Time

func (f *Frame) Time() float32

Time is the frame's clock, in seconds, for what moves by itself.

func (*Frame) Uniform

func (f *Frame) Uniform(name string, v ...float32)

Uniform sets the shader's uniform name to v, a float or a vector of two to four, for this frame; what was not set is zero. The names Toward, Clock, Pixel and Fog are the composer's own.

func (*Frame) Uniformed

func (f *Frame) Uniformed(name string) bool

Uniformed reports whether a source composing this frame has set the uniform name already.

type Glass

type Glass interface {
	DrawGlass(dst *Image, cam camera.Camera)
}

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

type GroundHeights struct {
	Image     *Image
	Corners   [2]int
	Cell      float32
	Low, Span float32
}

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 Image

type Image = gfx.Image

the names of gfx's compose draws with

type Lattice

type Lattice = light.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 Light

type Light = light.Light

Light is a colour of light (light.Light).

type MaterialID

type MaterialID = wgsl.MaterialID

the names of gfx's compose draws with

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.

const (
	Opaque Pass = iota
	SeeThrough
	Cutout
	Uncovered
)

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 Source

type Source interface {
	Compose(f *Frame, cam camera.Camera)
}

Source is what draws a part of the world by handing its pieces to a Frame.

type SpriteID

type SpriteID = gfx.SpriteID

the names of gfx's compose draws with

type Taking

type Taking = light.Taking

Taking is which shade a drawn thing takes (light.Taking).

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

func UniformsOf(m map[string]any) Uniforms

UniformsOf is the uniforms m, by name, each a []float32, or an *Image for a frame's image.

func (Uniforms) Get

func (u Uniforms) Get(name string) []float32

Get is the uniform name, nil for one the composer does not have.

func (Uniforms) Into

func (u Uniforms) Into(dst map[string]any)

Into puts every uniform into dst, boxed as the composer holds it.

type Vertex

type Vertex = gfx.Vertex

the names of gfx's compose draws with

type World

type World [4][2]float32

World is where each corner of a piece lies in the world, in the order of its Corners on screen.

Jump to

Keyboard shortcuts

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