luft/render/shaders.lisp
Match Luvcraft's scene-linear lens defaults. luft uses the same bright
signal and gain while retaining its compact presentation gather.
Return the unjittered previous-minus-current motion MetalFX expects.
The scaler receives the current sampling offset independently through JITTER-OFFSET-{X,Y}. Its default contract consumes these vectors directly, so adding either frame's Halton offset here would invent screen-wide motion for completely static geometry.
A small, rounded traveler for the sanctuary bridge. The proxy is only a
conservative raster bound; every visible contour below comes from this
analytic field. luft is Z-up, unlike luvcraft's first-person figures.
The hermit's little captured firework: a true SDF sphere and four sparks.
The staff gets a visible payoff even before a cast is in flight. Keeping the sparks in the same field means they clip and shade with the body rather than becoming transparent billboard confetti.
Motion vocabulary. Authored channels name the five readable walk poses, while contact placement and two-bone IK remain hard constraints beneath them. The same segment primitive can drive idle, gesture, attack or interaction channels without coupling their timing to the locomotion math.
Height of a fixed-length leg over the active stance contact.
Each half-step advances the root by 0.75 cells. The support foot sits at the half-step midpoint, so its fore-aft lever runs symmetrically from +D/2 to -D/2 and the pelvis rises naturally over mid-stance.
The ankle centre is Z=.26 and the hip is Z=1.27 at double support. This reach therefore makes the stance constraint agree with the actual SDF joint centres, rather than merely producing a plausible amount of bob.
Loading sinks after contact; maximum authored rise follows the passing pose. This rides on the inverted-pendulum constraint rather than replacing it.
The traveler's parts.
He is the sanctuary's own hermit: hat, beard, mantle, staff, and the
copper lozenge the whole site is inlaid with, worn as embroidery. The
vocabulary is deliberately the one luvcraft's garden gnome already uses
(LUVCRAFT/AGENT/SHADERS.LISP) -- a round cone for anything conical, a
leaning hat frame, a nose that is a frank sphere -- rotated into luft's
Z-up frame and given the walking legs that fellow does not have.
A cone capped by a sphere at each end, standing on the Z axis.
The lateral surface is tangent to both caps, so the silhouette has no crease where the cone meets its rounding.
An octahedron scaled by RADII: the site's diamond, as a solid.
The exact octahedron distance is scaled back by the smallest half-extent so the warped field stays a lower bound and the march cannot overstep it.
The hat's own frame: a domain warp that leans the cone's tip forward.
A straight cone is a traffic cone. The lean is what makes it a hat someone is wearing, and it costs one smoothstep.
The brim's frame: a quadratic droop that curls its edge down.
A flat disc reads as a plate balanced on his head. Lifting the sample with the square of its radius is enough to make the felt sag under its own weight, and the extra gradient it costs is paid back by the 0.9 below.
The tall leaning cone and the drooping brim it sits on.
The brim is wide enough to keep his eyes in shadow from the sanctuary's high camera: what the player sees under it is a nose and a beard, which is the whole of what this fellow is willing to say about himself.
A broad beard with a blunt point: the mass that gives him his gravity.
Its top edge is the lower bound of his face, so it sits just under the nose, and its point falls to the middle of his chest.
Cut level under the moustache and rounded off there. An uncut ellipsoid is widest at its middle, which puts a beard's broadest point at his chest and its narrowest at his cheeks -- a cloud rather than a beard.
cos 6*theta around the figure's own axis, without an inverse tangent.
The horizontal direction is squared three times over; what comes out is exactly the sixth harmonic, so a flute stays on the cloth when the figure turns instead of sliding around it like a projected stripe.
Six vertical folds in hanging linen, deepening toward the hem.
Their depth is the difference between a robe and a lampshade, so it is the number to reach for first. A twelfth harmonic rides on the sixth at a third of its depth: the linen then has a coarse drape and a fine crease rather than one honest sine wave.
Strands combed down a beard, and the part a man leaves in the middle.
Measured about the same axis as the robe's flutes, the twelfth harmonic crosses the beard's front about three times, which is a beard. Any more and it is corduroy.
A shallow part. Carved any deeper it stopped being a parting and started being a window onto the robe underneath.
The robe's own frame: hung from the shoulders, resting on the deck.
Above the waist the cloth rides with the body. At the hem it stays where gravity left it, so the walk reads as a hem that swings and trails rather than as a garment sliding up and down the figure. The pelvis lift is subtracted back out with the same weight, which is what keeps a floor-length robe on the floor while its wearer bobs over his stance foot.
A floor-length linen robe: fitted at the chest, flaring to a swept hem.
The bell is a round cone, cut level just above the deck with a rounded
arris so the cloth pools rather than ending in a pastry edge, and fluted
by player-linen-fold. The 0.78 pays for the warps: the fold, the sway and
the drape each steepen the field a little, and the march must never be
told the surface is further away than it is.
A short traveling cape over the robe, open at the throat.
Its hem is the edge the sanctuary's own camera sees most, so the lozenge braid the walls are inlaid with is embroidered along it.
One boot on the contact solver's own foot, with nothing above the ankle.
The legs themselves are gone: under a floor-length robe they were a two-bone chain nobody could see, paid for at every march step. What survives is the part that touches the world, so the stance foot still stands still.
One foot cycle spans two half-steps. Its first half is stance; its second half is the swing to the next fixed contact.
During stance the boot pivots around a stationary heel, lies flat through weight acceptance, then pivots around a stationary toe. During swing its centre follows the authored clearance arc.
Evaluate both fields everywhere. Selecting a foot from POINT.x used to put a discontinuity through the centre plane, visibly slicing the screen-left boot open whenever its silhouette crossed that plane.
One arm swinging free and one closed around the staff.
Both run under the mantle, so what the silhouette actually shows is a sleeve cuff and a mitten: the shoulders belong to the garment.
A copper-shod walking staff, carried plumb while the walker bobs past it.
The shaft is evaluated outside the pelvis pose on purpose: a staff that rose and fell with the hips would be a staff nobody was leaning on.
The two garments hang from the shoulders in their own frames, so they take the unposed sample and carry the walk themselves.
The staff is held, not grown: it meets the mitten with a hard edge rather than a fillet, and stands outside the walk pose.
The lozenge braid. Colour is settled once, at the confirmed hit, so the pattern can afford to be a real pattern rather than a stripe.
The site's diamond motif, wrapped around the figure without a seam.
Two planar lattices -- one read across his front, one along his flank -- blended by which of them the surface actually faces. A single planar lattice smears into stripes exactly where the body turns away from it.
Two dark eyes and a heavy brow, placed by direction from the head centre.
They live almost entirely in the brim's shadow. That is the intent: the sanctuary's camera should find a nose and a beard, and only a closer look should find somebody looking back.
The nearest part decides the colour.
Cream linen, warm copper and one red stone: the walls of the sanctuary, worn. The copper appears only where the site's own inlay would -- along a hem, around a crown, set in a finial -- so the figure and the architecture read as the same culture rather than as a doll placed on a bridge.
Copper braid along both hems: a deep embroidered band at the robe's skirt and a narrower one where the cape is cut. The site's own tonemap compresses hard above half albedo, so the parts that must separate separate by a wide value step and by hue, not by a polite shade apart.
A running nearest-so-far, folded by hand: step answers one when
the candidate is at least as near, and mix takes it.
How much of this point is face, for the details painted on it.
player-march-advance, guarded by whether this ray is already finished.
A finished march carries its answer negated, so both endings -- the surface found and the bound passed -- are visible here before the figure's field is sampled. The billboard is much wider than the body for the sake of the shadow it casts, and nearly every fragment on it is a ray that misses him; without this guard each of those paid fifty-eight whole evaluations of a figure it never touched.
How dark the traveler's own shadow lies on the deck at this ray.
The figure is drawn as a billboard over a bridge that is flat where he walks, so the shadow he owes the deck can be found analytically: intersect the ray with the deck plane and measure the ground point against the segment the sun would sweep his body along. It is a stylised smear, not a projection -- the sanctuary's real occluders already have a shadow map, and what this repays is the one thing the map cannot give a billboard, which is that he is standing on something.
The sun's drift across the deck per unit of height, held to a plausible maximum so a low sun cannot throw the smear off the bridge entirely.
The puddle is deliberately a little wider than he is: an isometric camera hides the deck directly under a robed figure, so a shadow exactly his size is a shadow nobody ever sees.
The quad is not square. The body needs a little over nine tenths of the radius above its centre and no more; the shadow it casts needs the deck below and beside it, which is where the extra room goes rather than into a square nobody looks at.
The game controller rotates world space into the traveler's local forward frame below, so the hermit's authored stride always runs along local +Y.
The hermit's field is rotated into his live walking heading. The branch study's shortcut marched in world axes, which diverged as soon as a player turned and left a transparent robe behind.
The central sphere owns the visible normal. Its tiny firework motes use the same radial answer, which makes the glow read as one spell instead of pixel speckle.
Where the body was missed, the same billboard still owes the deck his shadow. Its own sample of the sun's shadow map keeps him from darkening ground the sanctuary is already shading.
Lifted clear of the deck before it is looked up: sampling the sun's depth map at a point lying exactly on the surface that wrote it is the textbook way to shadow a floor with itself.
Do not emulate face culling by moving a vertex off screen. The facing test is per vertex, so a triangle crossing its threshold turns into an enormous sliver as the camera moves. The closed surface's normal depth test already hides its far side coherently.
`kernel` is a Metal address-space keyword, so keep the closed material-kernel discriminator explicit in generated MSL.
Sky and earth are illumination, not gray absence-of-sun. The constant terms keep vertical and turned-away planes chromatic; the hemispheric terms still tell us which environment they see.
A sun-facing receiver inside a cast shadow still sees warm light returned by the illuminated world around it. This little wash is deliberately conditional on occlusion: it animates sun patches without turning north-facing planes orange.
Keep scene radiance linear and HDR here. The universal presentation pass blooms, tone maps, and grades it exactly once.
Broad directional noise makes sparse watercolor cloud banks. The envelope keeps them above the haze and below the clear zenith.
Match Moppe's broad five-tap probe footprint before the 32x16 reduction. Encoding log luminance into UNORM makes the geometric mean portable through the HAL's compact RGBA8 readback contract.
One low-cost, deliberately broad gather. Linear sampling and the two rings make luminous paper bleed across an edge without erasing the edge itself or turning the whole frame into fog.
Geometry depth carries the subpixel projection jitter consumed by MetalFX; presentation UVs do not. Sample depth at the same current geometry location so the AO does not crawl across a resolved edge.
A common cool shadow pigment makes the depth signal read as an illustrated wash rather than neutral post-process darkening.
A gentle screen-space tilt shift holds the player's projected height crisp and gives the near/far route a miniature depth cue. It is deliberately only a five-tap gather after MetalFX resolves.
MetalFX has already reconstructed GLowing at this point. Grade it once, with a little exposure headroom for the sunlit grass and the wizard's HDR spell rather than clipping both into parchment. Sky is now HDR scene radiance, so it participates in metering and receives exactly the same exposure and paper grade as geometry. Keep geometry-only AO and tilt-shift out of background pixels.
(name parameters &body body)Define a reusable typed shader expression with ordinary source syntax. The body is parsed at each call site, so argument types and quantity meanings flow through the same operator protocol as handwritten shader expressions. LET* is lexical inside the function. The definition macro records source; its body does not…
(&key (code t))Multiplication and scalar scaling.
The inner product of two vectors.
Addition over compatible quantities.
Select and reorder vector components by a designator such as :XYZ or :RGB.
Subtraction or unary negation.
Interpolate compatible quantities by a scalar amount.
Test whether one compatible scalar is less than another.
The componentwise absolute value of a raw value.
Produce dimensionless progress across compatible edges.
The maximum of compatible quantities.
Constrain a quantity between compatible bounds.
Test whether one compatible scalar is greater than another.
Division of two represented quantities.
The minimum of compatible quantities.
Return the unjittered previous-minus-current motion MetalFX expects. The scaler receives the current sampling offset independently through JITTER-OFFSET-{X,Y}. Its default contract consumes these vectors directly, so adding either frame's Halton offset here would invent screen-wide motion for completely static…
Convert one scalar float or unsigned value to a 32-bit float.
Compare compatible quantities and produce dimensionless values.
Compare a depth reference through a comparison sampler at a UV coordinate.
The componentwise square root of a raw value.
The hermit's little captured firework: a true SDF sphere and four sparks. The staff gets a visible payoff even before a cast is in flight. Keeping the sparks in the same field means they clip and shade with the body rather than becoming transparent billboard confetti.
Height of a fixed-length leg over the active stance contact. Each half-step advances the root by 0.75 cells. The support foot sits at the half-step midpoint, so its fore-aft lever runs symmetrically from +D/2 to -D/2 and the pelvis rises naturally over mid-stance.
A cone capped by a sphere at each end, standing on the Z axis. The lateral surface is tangent to both caps, so the silhouette has no crease where the cone meets its rounding.
(arguments)An octahedron scaled by RADII: the site's diamond, as a solid. The exact octahedron distance is scaled back by the smallest half-extent so the warped field stays a lower bound and the march cannot overstep it.
The hat's own frame: a domain warp that leans the cone's tip forward. A straight cone is a traffic cone. The lean is what makes it a hat someone is wearing, and it costs one smoothstep.
The brim's frame: a quadratic droop that curls its edge down. A flat disc reads as a plate balanced on his head. Lifting the sample with the square of its radius is enough to make the felt sag under its own weight, and the extra gradient it costs is paid back by the 0.9 below.
The tall leaning cone and the drooping brim it sits on. The brim is wide enough to keep his eyes in shadow from the sanctuary's high camera: what the player sees under it is a nose and a beard, which is the whole of what this fellow is willing to say about himself.
A broad beard with a blunt point: the mass that gives him his gravity. Its top edge is the lower bound of his face, so it sits just under the nose, and its point falls to the middle of his chest.
Strands combed down a beard, and the part a man leaves in the middle. Measured about the same axis as the robe's flutes, the twelfth harmonic crosses the beard's front about three times, which is a beard. Any more and it is corduroy.
COS 6*theta around the figure's own axis, without an inverse tangent. The horizontal direction is squared three times over; what comes out is exactly the sixth harmonic, so a flute stays on the cloth when the figure turns instead of sliding around it like a projected stripe.
Six vertical folds in hanging linen, deepening toward the hem. Their depth is the difference between a robe and a lampshade, so it is the number to reach for first. A twelfth harmonic rides on the sixth at a third of its depth: the linen then has a coarse drape and a fine crease rather than one honest sine wave.
The robe's own frame: hung from the shoulders, resting on the deck. Above the waist the cloth rides with the body. At the hem it stays where gravity left it, so the walk reads as a hem that swings and trails rather than as a garment sliding up and down the figure. The pelvis lift is subtracted back out with the…
A floor-length linen robe: fitted at the chest, flaring to a swept hem. The bell is a round cone, cut level just above the deck with a rounded arris so the cloth pools rather than ending in a pastry edge, and fluted by PLAYER-LINEN-FOLD. The 0.78 pays for the warps: the fold, the sway and the drape each steepen the…
A short traveling cape over the robe, open at the throat. Its hem is the edge the sanctuary's own camera sees most, so the lozenge braid the walls are inlaid with is embroidered along it.
One boot on the contact solver's own foot, with nothing above the ankle. The legs themselves are gone: under a floor-length robe they were a two-bone chain nobody could see, paid for at every march step. What survives is the part that touches the world, so the stance foot still stands still.
One arm swinging free and one closed around the staff. Both run under the mantle, so what the silhouette actually shows is a sleeve cuff and a mitten: the shoulders belong to the garment.
A copper-shod walking staff, carried plumb while the walker bobs past it. The shaft is evaluated outside the pelvis pose on purpose: a staff that rose and fell with the hips would be a staff nobody was leaning on.
An explicitly owned AVFrame.
Normalize a dimensionless vector.
The site's diamond motif, wrapped around the figure without a seam. Two planar lattices -- one read across his front, one along his flank -- blended by which of them the surface actually faces. A single planar lattice smears into stripes exactly where the body turns away from it.
Two dark eyes and a heavy brow, placed by direction from the head centre. They live almost entirely in the brim's shadow. That is the intent: the sanctuary's camera should find a nose and a beard, and only a closer look should find somebody looking back.
The nearest part decides the colour. Cream linen, warm copper and one red stone: the walls of the sanctuary, worn. The copper appears only where the site's own inlay would -- along a hem, around a crown, set in a finial -- so the figure and the architecture read as the same culture rather than as a doll placed on a…
Sample a two-dimensional texture through a sampler at a UV coordinate.
PLAYER-MARCH-ADVANCE, guarded by whether this ray is already finished. A finished march carries its answer negated, so both endings -- the surface found and the bound passed -- are visible here before the figure's field is sampled. The billboard is much wider than the body for the sake of the shadow it casts, and…
How dark the traveler's own shadow lies on the deck at this ray. The figure is drawn as a billboard over a bridge that is flat where he walks, so the shadow he owes the deck can be found analytically: intersect the ray with the deck plane and measure the ground point against the segment the sun would sweep his body…
An Org headline with its section and subheadings.
(name options &body body)Define NAME as a function that reparses its shader source on every call. Where DEFINE-SHADER parses once at load, this parses each time it is asked, so live named values (SHADER-SOURCE-VALUE) folded into the body are read afresh -- and noted in *SHADER-SOURCE-VALUE-REFERENCES* -- by every pipeline build, exactly as a…
Test whether two compatible scalars are equal.
Raise a dimensionless value to a dimensionless power.
Read one indexed element of a storage buffer resource.
Convert one scalar float or unsigned value to a 32-bit unsigned integer.
Extract the unsigned bit field (BYTE SIZE POSITION) of one unsigned scalar.
One inspectable environment light, packed into raw per-frame GPU lanes.
One authored solid and its vocabulary-closed material-placement field. The solid remains LUFT's topological truth. The sparse authored field stores only dense vocabulary offsets; semantic material objects remain at the scene boundary rather than being allocated per cell.
Site-stream rendering. One UVec4 instance selects a lattice base and a canonical fixed-stride template; the template vertex is a small exact offset plus geometric attributes. The CPU classifies sites and the vertex shader realizes the renderer-global triangle and quad populations.