`Gl.*` binds the whole OpenGL 4.1 core API — every entry point of the platform gl3.h with every GL_* constant, generated by `ludic-dev glgen` with per-call ABI thunks. Windowed builds get an NSOpenGLContext on the existing window at Retina resolution; headless builds render into an offscreen CGL context, so a program that uses Gl.* renders and screenshots identically under the test harness. It links gl.ll, the thunks and OpenGL.framework only when used; every other build stays byte-identical. packages/ludic.render3d is a physically based renderer written on that surface: HDRI image-based lighting, GPU-generated terrain with scanned PBR materials, CDLOD, cascaded shadows, glTF with skinning, instanced vegetation with impostors, procedural grass, water, SSAO, and an HDR pipeline with bloom, auto-exposure and ACES. It also carries this session's work on it: the terrain at half its cost (10.3 -> 5.4 ms of frame), the streaming hitch that got worse the longer you played, a resize that emptied the world, and the packaging that lets a game use the renderer from its own repository — `ludic assets`, the material manifest shipping with the package, and shader lookup falling back to the install root. See changes/ for each, with its numbers. The camping game that drove all of it has moved out to its own repository, Maroon Lake; examples/rendering/smooth.ludic stays as the renderer's example here. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
39 lines
1.7 KiB
GLSL
39 lines
1.7 KiB
GLSL
// Height-field sun shadow, baked once per sun direction (the sun is fixed per scene).
|
|
//
|
|
// For every height-map texel: the lowest height at which a point above that texel still
|
|
// sees the sun. A point (xz, y) is lit iff the ray toward the sun clears the ground
|
|
// everywhere along it, i.e. y > h(xz + d.xz t) - d.y t for all t — so the value stored
|
|
// is the maximum of that expression over the ray. Every receiver in the scene (ground,
|
|
// trunk, crown, card, water) compares its own height against it: one march per texel,
|
|
// once, instead of 28 taps per terrain pixel per frame, and vegetation standing in a
|
|
// hillside's shadow goes dark with the hillside instead of glowing in front of it.
|
|
// The second channel is the distance to the occluder that set the bound, which widens
|
|
// the penumbra the way a real shadow softens with distance from its caster.
|
|
in vec2 v_uv;
|
|
out vec4 o;
|
|
uniform sampler2D u_height;
|
|
uniform float u_half;
|
|
uniform vec3 u_sun;
|
|
void main() {
|
|
vec2 xz = (v_uv - 0.5) * 2.0 * u_half;
|
|
vec3 d = u_sun;
|
|
float lit = -1.0e6;
|
|
float at = 0.0;
|
|
if (d.y > 0.02) {
|
|
float t = 1.5, step = 1.5;
|
|
for (int i = 0; i < 128; i++) {
|
|
vec2 q = xz + d.xz * t;
|
|
vec2 uv = q / (2.0 * u_half) + 0.5;
|
|
if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) break;
|
|
float h = texture(u_height, uv).r - d.y * t;
|
|
if (h > lit) { lit = h; at = t; }
|
|
t += step;
|
|
step *= 1.045;
|
|
}
|
|
}
|
|
// the cloud layer's mask, once, into B: sampled by cloudShadow() with the sun offset and
|
|
// the drift applied as a uv shift, instead of a five-octave fbm in every lit pixel of
|
|
// every pass
|
|
float cloud = smoothstep(0.02, 0.32, fbm(xz * 0.0011, 5));
|
|
o = vec4(lit, at, cloud, 1.0);
|
|
}
|