vxl

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 11 Imported by: 1 module, 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

Voxel rendering for terminals, a lit rasterizer, voxel grids, posable figures and cell encoders

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ANSIQuantizer

func ANSIQuantizer(palette [16]color.Color) func(RGB) color.Color

Quantizer to the nearest of sixteen terminal colors, the given palette where it names them

func ApproachYaw

func ApproachYaw(yaw, target, step float64) float64

Yaw turned toward a target yaw by at most a step

func GlyphMask

func GlyphMask(glyph string) (mask uint32, ok bool)

Lit pixel mask of a glyph in any library, bit i the pixel i%4 across and i/4 down

func Hash2

func Hash2(x, y int) float64

Pseudo random share from 0 to 1 for two integers

func Hash3

func Hash3(x, y, z int) float64

Pseudo random share from 0 to 1 for three integers

func HeadingOf

func HeadingOf(d Vec3) float64

Heading on the floor as a yaw, zero facing south

func LineCells

func LineCells(x0, z0, x1, z1 int) [][2]int

Cells on a straight line between two cells on the floor, ends included

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

func Smoothstep(t float64) float64

Share eased with a cubic curve, flat at both ends

func TurnBetween

func TurnBetween(from, to float64) float64

Shortest signed turn from one yaw to another

func Workers

func Workers() int

Goroutines the passes of the package spread over, every CPU until SetWorkers lowers it

Types

type Camera

type Camera struct {
	Target Vec3
	Yaw    float64
	Pitch  float64
	Dist   float64
	FOV    float64
}

Orbit camera looking at a target from a yaw, a pitch and a distance

func (Camera) Eye

func (c Camera) Eye() Vec3

Position of the camera

type CellMode

type CellMode int

Glyph library a cell may pick its glyph from

const (
	ModeHalf CellMode = iota
	ModeQuadrant
	ModeSextant
	ModeOctant
	ModeShapes
	ModeLegacy
	ModeAll
)

func CellModeOf

func CellModeOf(name string) CellMode

Cell mode by its setting name, shapes for an unknown one

func (CellMode) PixelAspect

func (m CellMode) PixelAspect() float64

Width over height of one pixel on screen, a cell being half as wide as it is tall

func (CellMode) Pixels

func (m CellMode) Pixels() (px, py int)

Pixels across and down one cell samples

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

func (*Changes) All

func (c *Changes) All() bool

Reports whether every pixel of every set is marked

func (*Changes) CopyFrom

func (c *Changes) CopyFrom(o *Changes)

Takes every set of other changes

func (*Changes) Fill

func (c *Changes) Fill()

Marks every pixel in every set

func (*Changes) Norm

func (c *Changes) Norm()

Sorts and merges the runs of every set

func (*Changes) Reset

func (c *Changes) Reset(w, h int)

Empties every set over a frame of the size

func (*Changes) Union

func (c *Changes) Union(o *Changes)

Adds every run of other changes

type Chunk

type Chunk struct {
	Lo, Hi Vec3
	Quads  []Quad
}

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

func (d *Dirt) Add(y, x0, x1 int)

Adds a run of a row, ends inclusive and clamped to the frame, safe from one goroutine per row

func (*Dirt) AddRect

func (d *Dirt) AddRect(x0, y0, x1, y1 int)

Adds a box of pixels, corners inclusive

func (*Dirt) Bounds

func (d *Dirt) Bounds() (x0, y0, x1, y1 int, ok bool)

Smallest box around every marked pixel, false when none is

func (*Dirt) CopyFrom

func (d *Dirt) CopyFrom(o *Dirt)

Takes the size and every run of another set

func (*Dirt) Count

func (d *Dirt) Count() int

Pixels marked

func (*Dirt) Each

func (d *Dirt) Each(y int, fn func(x0, x1 int))

Calls fn for every run of a row, ends inclusive, the whole row when every pixel is marked

func (*Dirt) Empty

func (d *Dirt) Empty() bool

Reports whether no pixel is marked

func (*Dirt) Fill

func (d *Dirt) Fill()

Marks every pixel changed

func (*Dirt) Grow

func (d *Dirt) Grow(dx, dy int)

Widens every run by dx pixels on either side and copies it onto the dy rows above and below

func (*Dirt) Has

func (d *Dirt) Has(x, y int) bool

Reports whether a pixel is marked

func (*Dirt) Hull

func (d *Dirt) Hull(y int) (x0, x1 int, ok bool)

First and last marked pixel of a row, false for a row without any

func (*Dirt) Norm

func (d *Dirt) Norm()

Sorts and merges the runs of every row

func (*Dirt) Reset

func (d *Dirt) Reset(w, h int)

Empties the set over a frame of the size, keeping the storage of its rows

func (*Dirt) Touches

func (d *Dirt) Touches(x0, y0, x1, y1 int) bool

Reports whether any pixel of a box is marked, corners inclusive

func (*Dirt) Union

func (d *Dirt) Union(o *Dirt)

Adds every run of another set over the same frame

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

func (*Encoder) Reset

func (e *Encoder) Reset()

Forgets every cell, so the next frame encodes as if none came before

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

func (fr *Frame) At(x, y int) RGB

Pixel color, the nearest pixel of the frame past its edge

func (*Frame) Bloom

func (fr *Frame) Bloom(p *Post, threshold, strength float64)

Spreads the light of bright pixels into their surroundings through a chain of halved blurs, the glow added at the strength

func (*Frame) Bytes

func (fr *Frame) Bytes(dst []byte) []byte

Red, green and blue of every pixel as bytes, row by row, written over the slice given

func (*Frame) Clear

func (fr *Frame) Clear(bg func(x, y int) RGB)

Paints the background from a function of the pixel, called from several goroutines, and clears depth and facing

func (*Frame) CopyFrom

func (fr *Frame) CopyFrom(o *Frame)

Copies the pixels, surfaces, depths and facings of a frame

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

func (fr *Frame) Grade(g Grade)

Applies the grade to every pixel, the fringing read from a copy of the frame

func (*Frame) Outline

func (fr *Frame) Outline(strength float64)

Darkens pixels beside a nearer surface into silhouettes and pixels where faces turn apart into crease lines

func (*Frame) Resize

func (fr *Frame) Resize(w, h int)

Frame of the size, the buffers kept and cut to fit while their capacity holds the pixels

func (*Frame) Vignette

func (fr *Frame) Vignette(strength float64)

Darkens the pixels toward the edges of the frame by the strength

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

type Grid map[[3]int]Voxel

Static voxels by integer cell

func (Grid) Bounds

func (g Grid) Bounds() (lo, hi Vec3, ok bool)

Least and greatest corner of the voxels, false for an empty grid

func (Grid) Box

func (g Grid) Box(x, y, z, w, h, d int, col RGB)

Fills a box of plain voxels from a least corner and a size in cells

func (Grid) BoxTex

func (g Grid) BoxTex(x, y, z, w, h, d int, col RGB, tex Texture)

Fills a box of patterned voxels from a least corner and a size in cells

func (Grid) Del

func (g Grid) Del(x, y, z int)

Removes the voxel at a cell

func (Grid) Emitters

func (g Grid) Emitters(cluster int, radius float64) []Light

Emitters of a grid, the open faces of glowing voxels grouped in blocks of a side

func (Grid) Fill

func (g Grid) Fill(x, y, z, w, h, d int, v Voxel)

Fills a box of voxels of one make from a least corner and a size in cells

func (Grid) Mesh

func (g Grid) Mesh(r *Raster) []Chunk

Open voxel faces merged into rectangles of one voxel and crowding, patterns tiling in world units

func (Grid) Put

func (g Grid) Put(x, y, z int, v Voxel)

Sets a voxel of any make at a cell

func (Grid) Set

func (g Grid) Set(x, y, z int, col RGB)

Sets a plain voxel at a cell

func (Grid) SetTex

func (g Grid) SetTex(x, y, z int, col RGB, tex Texture)

Sets a voxel painted with a pattern at a cell

func (Grid) Solid

func (g Grid) Solid(x, y, z int) bool

Reports whether a cell holds a voxel

func (Grid) SunBounce

func (g Grid) SunBounce(sun Vec3, sunColor RGB, sm *ShadowMap, cluster int, radius, share float64) []Light

Emitters standing in for the sun bouncing off the grid, one per block of sunlit open faces

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

func (*Layer) Fits

func (l *Layer) Fits(w, h int) bool

Reports whether the layer holds a lit frame of the size

func (*Layer) Restore

func (l *Layer) Restore(fr *Frame, c *Changes)

Writes the finished color of the layer back over the pixels whose color changed and its surfaces over the pixels drawn on, every pixel for nil, which a flush over the layer then draws on

type Light

type Light struct {
	Pos    Vec3
	Color  RGB
	Radius float64
}

Point light coloring faces within its radius

type Model

type Model struct {
	Parts []*Part
	Scale float64
	// contains filtered or unexported fields
}

Figure built from posable parts, every voxel one scale wide in the world

func (*Model) Add

func (m *Model) Add(name string, at, pivot Vec3, layers []string, rows int) *Part

Adds a part built from layers of text, front layer last, each row read from the top down

func (*Model) Draw

func (m *Model) Draw(r *Raster, pal Palette, st Stance)

Queues every front face of the model in its stance, lit by the raster with corner occlusion, glowing keys unlit

func (*Model) Height

func (m *Model) Height() float64

Rest stature in world units, every part raised by the parts carrying it

func (m *Model) Link(child, parent string)

Hangs a part on another so it follows the turns of its parent

func (*Model) Part

func (m *Model) Part(name string) *Part

Part of a model by name, nil for an unknown one

func (*Model) World

func (m *Model) World(v Vec3, st Stance) Vec3

Point of the model in the world for a point in its voxel units, before any pose

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

func (*Output) Dirt

func (o *Output) Dirt() *Dirt

Pixels the last finish changed

func (*Output) Finish

func (o *Output) Finish(fr *Frame, fin Finish, c *Changes)

Finishes the changed pixels whose color moved since the last finish and whatever they touch, every pixel for nil

func (*Output) Moved

func (o *Output) Moved() int

Pixels whose finished bytes the last finish 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

func (*Part) Hidden

func (p *Part) Hidden(poses map[string]Pose) bool

Reports whether a part or any part carrying it is hidden

func (*Part) Orient

func (p *Part) Orient(v Vec3, poses map[string]Pose) Vec3

Direction of a part in the model, after the turns of the chain

func (*Part) Place

func (p *Part) Place(v Vec3, poses map[string]Pose) Vec3

Point of a part in the model, after its own turn and those of every part carrying it

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

func (*Particles) Add

func (ps *Particles) Add(p Particle)

Adds a mote while there is room for it

func (*Particles) Clear

func (ps *Particles) Clear()

Drops every mote

func (*Particles) Draw

func (ps *Particles) Draw(r *Raster)

Draws every mote as a billboard fading with its age

func (*Particles) Len

func (ps *Particles) Len() int

Count of motes alive

func (*Particles) Room

func (ps *Particles) Room(n int) bool

Reports whether a count of motes still fits

func (*Particles) Update

func (ps *Particles) Update(dt float64)

Advances every mote by dt seconds, dropping the ones past their life

type Pose

type Pose struct {
	Pitch, Yaw, Roll float64
	Shift            Vec3
	Hidden           bool
}

Turn and shift of a part for one frame

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

func FlatQuad

func FlatQuad(p [4]Vec3, col RGB, light float64) Quad

Face lit evenly by one light level

type RGB

type RGB struct{ R, G, B float64 }

Color with channels from 0 to 1, open to arithmetic

func FromColor

func FromColor(c color.Color) RGB

Color from any color, black for nil

func Grey

func Grey(v float64) RGB

Grey of one level

func Hex

func Hex(v uint32) RGB

Color from a 24 bit value

func (RGB) Add

func (c RGB) Add(o RGB) RGB

Sum of two colors

func (RGB) Clamp

func (c RGB) Clamp() RGB

Color with every channel held between 0 and 1

func (RGB) Color

func (c RGB) Color() color.RGBA

Opaque color with every channel clamped

func (RGB) Dist

func (c RGB) Dist(o RGB) float64

Squared distance between two colors

func (RGB) Dot3

func (c RGB) Dot3(o RGB) float64

Dot product of two colors taken as vectors

func (RGB) Luma

func (c RGB) Luma() float64

Perceived brightness from 0 to 1

func (RGB) Mix

func (c RGB) Mix(o RGB, t float64) RGB

Color t of the way from c to o

func (RGB) Mul

func (c RGB) Mul(o RGB) RGB

Product of two colors channel by channel

func (RGB) Scale

func (c RGB) Scale(f float64) RGB

Color with every channel multiplied

func (RGB) Sub

func (c RGB) Sub(o RGB) RGB

Channel by channel difference

func (RGB) Sub3

func (c RGB) Sub3(o RGB) RGB

Difference of two colors channel by channel

type RNG

type RNG struct{ Seed uint32 }

Linear congruential stream of pseudo random shares

func (*RNG) Chance

func (r *RNG) Chance(perSecond, dt float64) bool

Reports whether a chance per second fires over a step

func (*RNG) Intn

func (r *RNG) Intn(n int) int

Integer from 0 below n

func (*RNG) Next

func (r *RNG) Next() float64

Share from 0 to 1

func (*RNG) Spread

func (r *RNG) Spread() float64

Share from -1 to 1

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

func (r *Raster) Basis() (right, up, forward Vec3)

Camera basis the raster draws through

func (*Raster) Begin

func (r *Raster) Begin(fr *Frame, cam Camera)

Points the raster at the frame through the camera, dropping anything queued

func (*Raster) Billboard

func (r *Raster) Billboard(center Vec3, size float64, col RGB, alpha float64, additive bool)

Draws a camera facing square of the size at a point, for particles and glows

func (*Raster) Changes

func (r *Raster) Changes() *Changes

Pixels the last flush changed, drew on and lit anew, every pixel after a flush without a layer

func (*Raster) Chunks

func (r *Raster) Chunks(chunks []Chunk)

Queues the faces of every chunk the camera may see

func (*Raster) EmissiveBox

func (r *Raster) EmissiveBox(center, size Vec3, yaw float64, col RGB, alpha float64, light float64)

Box lit evenly, for things that glow on their own

func (*Raster) Eye

func (r *Raster) Eye() Vec3

Where the camera stands

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

func (r *Raster) FlushInto(l *Layer)

Flushes and keeps the frame as lit, before mirroring and haze, in a layer later flushes draw over

func (*Raster) FlushOver

func (r *Raster) FlushOver(l *Layer)

Flushes over a restored layer, lighting anew only the drawn pixels and the rest by what moved since the layer

func (*Raster) OrientedBox

func (r *Raster) OrientedBox(center, size Vec3, yaw float64, col RGB, alpha float64)

Box turned by a yaw around its own center, lit by the raster on its turned sides

func (*Raster) Project

func (r *Raster) Project(p Vec3) (sx, sy, depth float64, ok bool)

Pixel of a world point and its view depth, false behind the camera

func (*Raster) Quad

func (r *Raster) Quad(q Quad)

Queues a face, clipped to the near plane, back faces skipped unless it is two sided

func (*Raster) Queued

func (r *Raster) Queued() int

Count of faces handed to Quad since Begin

func (*Raster) Ray

func (r *Raster) Ray(x, y float64) Vec3

Unit direction into the world through a place on the frame, in pixels from its top left corner

func (*Raster) Relight

func (r *Raster) Relight(l *Layer)

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

func (r *Raster) Scale(depth float64) float64

Pixels one world unit spans at a view depth, sideways

func (*Raster) ScaleY

func (r *Raster) ScaleY(depth float64) float64

Pixels one world unit spans at a view depth, upward

func (*Raster) SetLights

func (r *Raster) SetLights(ls []Light)

Replaces the point lights and bins them for the corner light of see through faces

func (*Raster) Shade

func (r *Raster) Shade(q *Quad, n Vec3)

Marks the face lit by the raster along a facing, every corner light reset to one for occlusion to scale

func (*Raster) Visible

func (r *Raster) Visible(lo, hi Vec3) bool

Reports whether a box may show on the frame, false with every corner behind the camera or past one edge

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

func NewShadowMap(sun Vec3, lo, hi Vec3, texel float64) *ShadowMap

Orthographic depth map looking down the sun over a world box, texels widened so no side passes the cap

func (*ShadowMap) Box

func (sm *ShadowMap) Box(center, size Vec3, yaw float64)

Casts a box turned by a yaw about its center, every face a solid caster whatever it is painted with

func (*ShadowMap) Chunks

func (sm *ShadowMap) Chunks(chunks []Chunk)

Draws the depth of every face of every chunk, in view or not

func (*ShadowMap) Clear

func (sm *ShadowMap) Clear()

Empties every texel so nothing hides the sun

func (*ShadowMap) CopyFrom

func (sm *ShadowMap) CopyFrom(o *ShadowMap)

Takes the axes, extent and depths of another map, keeping its own texel storage

func (*ShadowMap) Lit

func (sm *ShadowMap) Lit(p, n Vec3) float64

Share of the sun reaching a point with a unit facing, four texels filtered after a nudge off the surface

func (*ShadowMap) Quad

func (sm *ShadowMap) Quad(q Quad)

Draws the depth of an opaque lit face from both sides, skipping unlit, glowing and see through faces

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

func FloorQuad

func FloorQuad(at Vec3, w, d, y float64) [4]Vec3

Flat face on the floor around a point, for shadows and light pools

func UnitYaw

func UnitYaw(yaw float64) Vec3

Unit vector along a yaw on the floor

func V

func V(x, y, z float64) Vec3

Point from its three coordinates

func (Vec3) Add

func (a Vec3) Add(b Vec3) Vec3

func (Vec3) Cross

func (a Vec3) Cross(b Vec3) Vec3

func (Vec3) Dot

func (a Vec3) Dot(b Vec3) float64

func (Vec3) Flat

func (a Vec3) Flat(b Vec3) float64

Distance between two points ignoring height

func (Vec3) Len

func (a Vec3) Len() float64

func (Vec3) Lerp

func (a Vec3) Lerp(b Vec3, t float64) Vec3

func (Vec3) Mul

func (a Vec3) Mul(f float64) Vec3

func (Vec3) Norm

func (a Vec3) Norm() Vec3

Vector of length one, the zero vector staying zero

func (Vec3) RotateX

func (a Vec3) RotateX(pitch float64) Vec3

Point turned by pitch radians around the x axis

func (Vec3) RotateY

func (a Vec3) RotateY(yaw float64) Vec3

Point turned by yaw radians around the y axis

func (Vec3) RotateZ

func (a Vec3) RotateZ(roll float64) Vec3

Point turned by roll radians around the z axis

func (Vec3) Sub

func (a Vec3) Sub(b Vec3) Vec3

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 NewVolume

func NewVolume(lo, hi Vec3, cell float64) *Volume

Volume of cells of a side covering a world box, one cell of padding around it

func (*Volume) Add

func (v *Volume) Add(p Vec3, c RGB)

Adds light to the cell holding a point

func (*Volume) Bounds

func (v *Volume) Bounds() (lo, hi Vec3)

World box the cells cover

func (*Volume) Clear

func (v *Volume) Clear()

Drops every light, keeping the solid cells

func (*Volume) Occupy

func (v *Volume) Occupy(g Grid)

Marks solid every cell a voxel of the grid lies in

func (*Volume) Sample

func (v *Volume) Sample(p Vec3) RGB

Light at a point, blended from the eight open cells around it, none outside the volume

func (*Volume) Scale

func (v *Volume) Scale(k float64)

Scales every cell by a factor

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

func (v *Volume) Smooth(passes int)

Blends every open cell toward the mean of its open neighbors, over a count of passes

func (*Volume) Solid

func (v *Volume) Solid(p Vec3) bool

Reports whether the cell holding a point is solid, false outside the volume

func (*Volume) Splat

func (v *Volume) Splat(srcs []Light)

Adds the light of every emitter reaching the volume to every open cell it can see within its reach

type Voxel

type Voxel struct {
	Col RGB
	Tex Texture
	// Share of the light its faces mirror
	Gloss float64
	// Light its faces give off on their own, scaling the color, none at zero
	Emit float64
}

Color, pattern, gloss and glow of one voxel

Directories

Path Synopsis
internal
glyphgen command
Command glyphgen writes pkg/vxl/glyphs.go, every encoder glyph rasterized from the geometry its Unicode name describes
Command glyphgen writes pkg/vxl/glyphs.go, every encoder glyph rasterized from the geometry its Unicode name describes

Jump to

Keyboard shortcuts

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