Documentation
¶
Overview ¶
Voxel rendering for terminals, a lit rasterizer, voxel grids, posable figures and cell encoders
Index ¶
- func ANSIQuantizer(palette [16]color.Color) func(RGB) color.Color
- func ApproachYaw(yaw, target, step float64) float64
- func GlyphMask(glyph string) (mask uint32, ok bool)
- func Hash2(x, y int) float64
- func Hash3(x, y, z int) float64
- func HeadingOf(d Vec3) float64
- func LineCells(x0, z0, x1, z1 int) [][2]int
- func SetWorkers(n int)
- func Smoothstep(t float64) float64
- func TurnBetween(from, to float64) float64
- func Workers() int
- type Camera
- type CellMode
- type Changes
- type Chunk
- type Dirt
- func (d *Dirt) Add(y, x0, x1 int)
- func (d *Dirt) AddRect(x0, y0, x1, y1 int)
- func (d *Dirt) Bounds() (x0, y0, x1, y1 int, ok bool)
- func (d *Dirt) CopyFrom(o *Dirt)
- func (d *Dirt) Count() int
- func (d *Dirt) Each(y int, fn func(x0, x1 int))
- func (d *Dirt) Empty() bool
- func (d *Dirt) Fill()
- func (d *Dirt) Grow(dx, dy int)
- func (d *Dirt) Has(x, y int) bool
- func (d *Dirt) Hull(y int) (x0, x1 int, ok bool)
- func (d *Dirt) Norm()
- func (d *Dirt) Reset(w, h int)
- func (d *Dirt) Touches(x0, y0, x1, y1 int) bool
- func (d *Dirt) Union(o *Dirt)
- type Encoder
- type Finish
- type Frame
- func (fr *Frame) At(x, y int) RGB
- func (fr *Frame) Bloom(p *Post, threshold, strength float64)
- func (fr *Frame) Bytes(dst []byte) []byte
- func (fr *Frame) Clear(bg func(x, y int) RGB)
- func (fr *Frame) CopyFrom(o *Frame)
- func (fr *Frame) Encode(buf *uv.Buffer, x0, y0, cols, rows int, mode CellMode, ...)
- func (fr *Frame) Grade(g Grade)
- func (fr *Frame) Outline(strength float64)
- func (fr *Frame) Resize(w, h int)
- func (fr *Frame) Vignette(strength float64)
- type Grade
- type Grid
- func (g Grid) Bounds() (lo, hi Vec3, ok bool)
- func (g Grid) Box(x, y, z, w, h, d int, col RGB)
- func (g Grid) BoxTex(x, y, z, w, h, d int, col RGB, tex Texture)
- func (g Grid) Del(x, y, z int)
- func (g Grid) Emitters(cluster int, radius float64) []Light
- func (g Grid) Fill(x, y, z, w, h, d int, v Voxel)
- func (g Grid) Mesh(r *Raster) []Chunk
- func (g Grid) Put(x, y, z int, v Voxel)
- func (g Grid) Set(x, y, z int, col RGB)
- func (g Grid) SetTex(x, y, z int, col RGB, tex Texture)
- func (g Grid) Solid(x, y, z int) bool
- func (g Grid) SunBounce(sun Vec3, sunColor RGB, sm *ShadowMap, cluster int, radius, share float64) []Light
- type Haze
- type Layer
- type Light
- type Model
- type Occlusion
- type Output
- type Palette
- type Part
- type Particle
- type Particles
- type Pose
- type Post
- type Quad
- type RGB
- func (c RGB) Add(o RGB) RGB
- func (c RGB) Clamp() RGB
- func (c RGB) Color() color.RGBA
- func (c RGB) Dist(o RGB) float64
- func (c RGB) Dot3(o RGB) float64
- func (c RGB) Luma() float64
- func (c RGB) Mix(o RGB, t float64) RGB
- func (c RGB) Mul(o RGB) RGB
- func (c RGB) Scale(f float64) RGB
- func (c RGB) Sub(o RGB) RGB
- func (c RGB) Sub3(o RGB) RGB
- type RNG
- type Raster
- func (r *Raster) Basis() (right, up, forward Vec3)
- func (r *Raster) Begin(fr *Frame, cam Camera)
- func (r *Raster) Billboard(center Vec3, size float64, col RGB, alpha float64, additive bool)
- func (r *Raster) Changes() *Changes
- func (r *Raster) Chunks(chunks []Chunk)
- func (r *Raster) EmissiveBox(center, size Vec3, yaw float64, col RGB, alpha float64, light float64)
- func (r *Raster) Eye() Vec3
- func (r *Raster) Flush()
- func (r *Raster) FlushInto(l *Layer)
- func (r *Raster) FlushOver(l *Layer)
- func (r *Raster) OrientedBox(center, size Vec3, yaw float64, col RGB, alpha float64)
- func (r *Raster) Project(p Vec3) (sx, sy, depth float64, ok bool)
- func (r *Raster) Quad(q Quad)
- func (r *Raster) Queued() int
- func (r *Raster) Ray(x, y float64) Vec3
- func (r *Raster) Relight(l *Layer)
- func (r *Raster) Scale(depth float64) float64
- func (r *Raster) ScaleY(depth float64) float64
- func (r *Raster) SetLights(ls []Light)
- func (r *Raster) Shade(q *Quad, n Vec3)
- func (r *Raster) Visible(lo, hi Vec3) bool
- type Reflection
- type ShadowMap
- type Stance
- type Texture
- type Vec3
- func (a Vec3) Add(b Vec3) Vec3
- func (a Vec3) Cross(b Vec3) Vec3
- func (a Vec3) Dot(b Vec3) float64
- func (a Vec3) Flat(b Vec3) float64
- func (a Vec3) Len() float64
- func (a Vec3) Lerp(b Vec3, t float64) Vec3
- func (a Vec3) Mul(f float64) Vec3
- func (a Vec3) Norm() Vec3
- func (a Vec3) RotateX(pitch float64) Vec3
- func (a Vec3) RotateY(yaw float64) Vec3
- func (a Vec3) RotateZ(roll float64) Vec3
- func (a Vec3) Sub(b Vec3) Vec3
- type Volume
- func (v *Volume) Add(p Vec3, c RGB)
- func (v *Volume) Bounds() (lo, hi Vec3)
- func (v *Volume) Clear()
- func (v *Volume) Occupy(g Grid)
- func (v *Volume) Sample(p Vec3) RGB
- func (v *Volume) Scale(k float64)
- func (v *Volume) Seal()
- func (v *Volume) Smooth(passes int)
- func (v *Volume) Solid(p Vec3) bool
- func (v *Volume) Splat(srcs []Light)
- type Voxel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ANSIQuantizer ¶
Quantizer to the nearest of sixteen terminal colors, the given palette where it names them
func ApproachYaw ¶
Yaw turned toward a target yaw by at most a step
func SetWorkers ¶
func SetWorkers(n int)
Caps the goroutines the passes of the package spread over, so the rest of the program keeps its CPUs
func Smoothstep ¶
Share eased with a cubic curve, flat at both ends
func TurnBetween ¶
Shortest signed turn from one yaw to another
Types ¶
type CellMode ¶
type CellMode int
Glyph library a cell may pick its glyph from
func CellModeOf ¶
Cell mode by its setting name, shapes for an unknown one
func (CellMode) PixelAspect ¶
Width over height of one pixel on screen, a cell being half as wide as it is tall
type Changes ¶
type Changes struct {
// Every pixel whose color changed
Color Dirt
// Pixels whose surface, depth or facing changed
Drawn Dirt
// Pixels whose light changed, the drawn ones lit anew and the rest by what moved around them
Lit Dirt
}
Pixels a flush changed, the ones it drew surfaces on and the ones it lit anew
type Chunk ¶
Faces of one block of cells with the box around them, so a block out of view is skipped whole
type Dirt ¶
type Dirt struct {
W, H int
// Whether every pixel counts as changed
All bool
// contains filtered or unexported fields
}
Pixels a pass changed, as runs across every row, or every pixel at once
func (*Dirt) Add ¶
Adds a run of a row, ends inclusive and clamped to the frame, safe from one goroutine per row
func (*Dirt) Each ¶
Calls fn for every run of a row, ends inclusive, the whole row when every pixel is marked
func (*Dirt) Grow ¶
Widens every run by dx pixels on either side and copies it onto the dy rows above and below
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Writes frames into cells, holding each cell to its glyph and colors of the frame before while they still fit
func (*Encoder) Encode ¶
func (e *Encoder) Encode(fr *Frame, buf *uv.Buffer, x0, y0, cols, rows int, mode CellMode, quantize func(RGB) color.Color, changed *Dirt)
Writes the frame into cells, each keeping its glyph and colors while they stay within slack of the best fit, cells over no changed pixel kept as they were
type Finish ¶
type Finish struct {
Outline float64
BloomThreshold float64
BloomStrength float64
Grade Grade
Vignette float64
}
Look of a finished frame, the outline, the bloom, the grade and the vignette
type Frame ¶
type Frame struct {
W, H int
Color []RGB
// Color of each opaque pixel before scene light and fog, its reflectance where the facing is marked lit
Albedo []RGB
// One over the view depth of the pixel, zero where nothing was drawn
Depth []float32
// Packed facing of the opaque face the pixel shows, bit 25 marking it lit and gloss above, zero where none
Normal []uint32
// Width of one pixel over its height as the screen shows it
PixelAspect float64
// contains filtered or unexported fields
}
Pixel grid with the surface, depth and facing of every opaque pixel and the shape of its pixels on screen
func (*Frame) Bloom ¶
Spreads the light of bright pixels into their surroundings through a chain of halved blurs, the glow added at the strength
func (*Frame) Bytes ¶
Red, green and blue of every pixel as bytes, row by row, written over the slice given
func (*Frame) Clear ¶
Paints the background from a function of the pixel, called from several goroutines, and clears depth and facing
func (*Frame) Encode ¶
func (fr *Frame) Encode(buf *uv.Buffer, x0, y0, cols, rows int, mode CellMode, quantize func(RGB) color.Color)
Writes the frame into cells, each the glyph and two colors nearest its pixels, remembering no earlier frame
func (*Frame) Outline ¶
Darkens pixels beside a nearer surface into silhouettes and pixels where faces turn apart into crease lines
type Grade ¶
type Grade struct {
// Factor every pixel is scaled by before the curve, one when zero
Exposure float64
// Filmic curve rolling bright light off toward white instead of clipping it
Tonemap bool
// Factor the distance of every color from grey is scaled by, one when zero
Saturation float64
// Pixels the red and blue channels slide apart by at the corners of the frame, none at zero
Aberration float64
}
Look of the finished frame, exposure and a filmic curve over the light, then saturation and color fringing
type Grid ¶
Static voxels by integer cell
func (Grid) Emitters ¶
Emitters of a grid, the open faces of glowing voxels grouped in blocks of a side
func (Grid) Mesh ¶
Open voxel faces merged into rectangles of one voxel and crowding, patterns tiling in world units
type Haze ¶
type Haze struct {
// Share of light the air scatters per world unit, none at zero
Density float64
// Samples taken along every ray, at least four
Steps int
// Pixels across and down each cell of the shrunken grid one ray stands for
Shrink int
// Farthest world distance a ray marches
Reach float64
// Glow of the air everywhere, the share of the baked radiance, the point lights and the sun it takes
Color RGB
Ambient float64
Lights float64
Sun float64
// Forward scattering of the sun, from none at zero toward a tight halo near one
Forward float64
}
Light the air scatters toward the camera, marched at a shrunken resolution and laid over the frame by depth
type Layer ¶
type Layer struct {
// contains filtered or unexported fields
}
Lit frame later flushes draw over, lit once and then only where something changed in front of it
type Model ¶
Figure built from posable parts, every voxel one scale wide in the world
func (*Model) Add ¶
Adds a part built from layers of text, front layer last, each row read from the top down
func (*Model) Draw ¶
Queues every front face of the model in its stance, lit by the raster with corner occlusion, glowing keys unlit
type Occlusion ¶
type Occlusion struct {
// World units the crowding is looked for within
Radius float64
// Share of the ambient light a fully crowded surface loses, none at zero
Strength float64
// Depth samples taken around every pixel, at least four
Samples int
// Pixels across and down each cell of the grid the crowding is read on, one pixel at zero
Shrink int
}
Crowding read off the depth buffer, darkening the ambient light of surfaces hemmed in by nearer ones
type Output ¶
type Output struct {
W, H int
// Finished color of every pixel and the same as bytes of red, green and blue, row by row
Color []RGB
Bytes []byte
// contains filtered or unexported fields
}
Finished pixels of a frame kept between frames, so each finish reworks only the pixels that changed
type Palette ¶
type Palette struct {
Colors map[rune]RGB
// Keys that glow on their own, drawn unlit and bright
Glow map[rune]bool
}
Paint keys of a model resolved to colors when it is drawn
type Part ¶
type Part struct {
Name string
// Where the voxel origin of the part sits in the model, in voxel units
At Vec3
// Point the part turns around, in its own voxel units
Pivot Vec3
// contains filtered or unexported fields
}
Rigid piece of a model, turned around its pivot and carried by its parent
type Particle ¶
type Particle struct {
Pos Vec3
Vel Vec3
Age float64
Life float64
Col RGB
Size float64
Weight float64
Drag float64
Additive bool
// Height the mote comes to rest at, none when zero
Floor float64
}
Mote of light with a life, falling under gravity when it has weight
type Particles ¶
type Particles struct {
Max int
// contains filtered or unexported fields
}
Pool of motes capped at a count, the oldest dropped first past it
type Post ¶
type Post struct {
// contains filtered or unexported fields
}
Scratch buffers of the bloom pass, reused across frames
type Quad ¶
type Quad struct {
P [4]Vec3
Color RGB
// Light each corner reflects, multiplied into the color, only the occlusion once the face is lit
Light [4]RGB
// Pattern scaling the color and its place at every corner, in world units for the tiling ones
Tex Texture
UV [4][2]float64
// Share of the face laid over what is behind it, one covering it
Alpha float64
// Share of the light the face mirrors, highlights and reflections growing with it
Gloss float64
// Light added instead of laid over, for glows
Additive bool
// Face drawn from either side, for decals and billboards
TwoSided bool
// Lit by the raster, per pixel when opaque and per corner when see through, set by Shade
Lit bool
// contains filtered or unexported fields
}
Flat face in the world with a color, a light per corner, a pattern and how it blends
type RNG ¶
type RNG struct{ Seed uint32 }
Linear congruential stream of pseudo random shares
type Raster ¶
type Raster struct {
// Fog toward a color between two view depths
FogColor RGB
FogNear float64
FogFar float64
// Light the fog adds looking toward the sun, none when zero
FogSun RGB
// Direction toward the key light, unit length, and its color
Sun Vec3
SunColor RGB
// Light every face gets from everywhere
Ambient RGB
// Baked radiance the ambient light varies by from place to place, nil for even ambient
GI *Volume
// Crowding read off the depth buffer darkening the ambient light, off at zero strength
AO Occlusion
// Mirror images glossy faces show of what the frame holds, off at zero strength
Reflect Reflection
// Light the air scatters toward the camera, off at zero density
Haze Haze
// Point lights every lit face takes, binned again by Begin and SetLights
Lights []Light
// Depth map the sun is shaded by, nil leaving every face in full sun
Shadows *ShadowMap
// Goroutines Flush draws with, the usable CPU count when zero
Workers int
// contains filtered or unexported fields
}
Draws faces through a camera, lit per pixel by sun, ambient, radiance and point lights, with fog, occlusion, reflections and haze
func (*Raster) Billboard ¶
Draws a camera facing square of the size at a point, for particles and glows
func (*Raster) Changes ¶
Pixels the last flush changed, drew on and lit anew, every pixel after a flush without a layer
func (*Raster) EmissiveBox ¶
Box lit evenly, for things that glow on their own
func (*Raster) Flush ¶
func (r *Raster) Flush()
Draws opaque faces, reads crowding, lights and fogs them, mirrors the glossy ones, scatters the air, then lays blended faces
func (*Raster) FlushInto ¶
Flushes and keeps the frame as lit, before mirroring and haze, in a layer later flushes draw over
func (*Raster) FlushOver ¶
Flushes over a restored layer, lighting anew only the drawn pixels and the rest by what moved since the layer
func (*Raster) OrientedBox ¶
Box turned by a yaw around its own center, lit by the raster on its turned sides
func (*Raster) Quad ¶
Queues a face, clipped to the near plane, back faces skipped unless it is two sided
func (*Raster) Ray ¶
Unit direction into the world through a place on the frame, in pixels from its top left corner
func (*Raster) Relight ¶
Lights a layer anew by the lights of the raster over a frame restored from it with nothing queued, reworking only the pixels, mirrors and haze the lights it lacks or has lost reach
func (*Raster) SetLights ¶
Replaces the point lights and bins them for the corner light of see through faces
type Reflection ¶
type Reflection struct {
// Share of the mirrored light a face of full gloss adds, none at zero
Strength float64
// Steps a ray marches and the world distance it covers
Steps int
Distance float64
// Color a ray that leaves the frame or finds nothing mirrors, black for none
Sky RGB
// Pixels across and down each cell of the grid the rays are marched on, one pixel at zero
Shrink int
}
Mirror images glossy faces show of what the frame holds, found by marching the mirrored view ray through the depth buffer
type ShadowMap ¶
type ShadowMap struct {
// contains filtered or unexported fields
}
Depths toward the sun of the two faces nearest it across a grid, shading what lies past their midpoint
func NewShadowMap ¶
Orthographic depth map looking down the sun over a world box, texels widened so no side passes the cap
func (*ShadowMap) Box ¶
Casts a box turned by a yaw about its center, every face a solid caster whatever it is painted with
func (*ShadowMap) CopyFrom ¶
Takes the axes, extent and depths of another map, keeping its own texel storage
type Stance ¶
type Stance struct {
Pos Vec3
Yaw float64
Poses map[string]Pose
// Recolors every lit face, nil for none
Tint func(RGB) RGB
// Share of the way the model has faded out, none when zero
Fade float64
}
Where a model stands and turns, with the pose of every part
type Texture ¶
type Texture uint8
Procedural pattern a face is painted with, scaling its color by a factor near one
const ( TexNone Texture = iota // Panels one unit square with beveled seams and a shade each TexPanel // Bars a quarter unit apart under a frame line every unit TexGrate // Traces and pads routed over a half unit grid TexCircuit // Blocks of one unit in uneven shades with sparks and a fine grain TexNoise // Pulses travelling along u, read as a phase in radians TexFlow )
type Vec3 ¶
type Vec3 struct{ X, Y, Z float64 }
Point or direction in the world, x east, y up, z south
type Volume ¶
type Volume struct {
// contains filtered or unexported fields
}
Radiance baked over a grid of cells from emitters with a line of sight, varying the ambient light
func (*Volume) Sample ¶
Light at a point, blended from the eight open cells around it, none outside the volume
func (*Volume) Seal ¶
func (v *Volume) Seal()
Fills solid cells from their open neighbors over three passes, so sampling needs no solid checks
func (*Volume) Smooth ¶
Blends every open cell toward the mean of its open neighbors, over a count of passes