Lattice flow (plane)
A planar lattice flowing under geodesic and horocyclic flows, tracing the orbit of its shortest vectors.
Source
common.glsl
// 2dFlow: a unimodular lattice in the plane under a linear flow. The shared
// lattice driver (_visualisers/lattice/script.js) integrates the flow chosen
// by uFlow at speed uSpeed and pushes the basis as uLattice each frame;
// uScale comes from the UI slider. Buffers: gridTrace accumulates the paths
// of every lattice point; image.glsl draws the current dots on top.
#include "../shared/2d_utils.glsl"
#include "../shared/coord_utils.glsl"
// Compile-time toggles.
bool showDots = true;
bool showBasis = false;
float traceLevel = 0.3; // Strength of the accumulated path trace.
float backFade = .999; // Per-frame retention of the trace buffer.
vec4 dotCol = vec4(.8,.05,.04,1.);
vec4 backCol = vec4(1.,1.,1.,0);
vec4 traceCol = vec4(0.,0.,0.,1.);
vec4 basisCol = vec4(.651,.669,.95,1.); gridTrace.glsl
// Background and full path record: each frame the current lattice dots are
// stamped faintly over the old frame (backFade keeps almost all of it), so
// the trace of every dot's path accumulates. Cleared on the first frame or
// while the pointer is down.
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 p = coords(fragCoord, iResolution, uScale, iResolution.xy * 0.5);
vec2 uv = fragCoord / iResolution.xy;
vec4 col = mix(backCol,vec4(texture(gridTrace,uv).xyz,1),backFade);
col = drGrid(col, p, mat2(uLattice), 0.075, mix(col,traceCol,traceLevel), 2.);
if(iFrame == 0 || iMouse.z > 0.)
{ col = backCol; }
fragColor = col;
} image.glsl
// Composite: the current lattice dots (and optional basis markers) drawn
// directly over the accumulated path trace.
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 p = coords(fragCoord, iResolution, uScale, iResolution.xy * 0.5);
vec2 uv = fragCoord.xy / iResolution.xy;
vec4 col = vec4(texture(gridTrace,uv).xyz,1);
if(showDots)
{
col = drGrid(col, p, mat2(uLattice), 0.2, dotCol, 0.15);
}
// Mark the two basis vectors of the current lattice.
if(showBasis)
{
col = drPt(col, p, uLattice, .4, basisCol, .75);
col = drPt(col, p, vec4(uLattice.zw,0,0), .4, basisCol, .75);
}
fragColor = col;
} lattice/script.js
// 2dFlowJS: the plain lattice-flow shader UI. All the driving logic lives in
// the shared lattice driver; this script is just its instantiation, so state
// is per-instance and other shaders can layer their own UI on the same core.
import { createLatticeDriver } from '../shared/lattice_driver.js';
const driver = createLatticeDriver();
export const setup = driver.setup;
export const onFrame = driver.onFrame;
export const onSetLattice = driver.onSetLattice;