ludic/packages/ludic.render3d/shaders/adapt.frag
Orkuncakilkaya f25289db20
Some checks failed
ci / build-and-test (push) Waiting to run
commit-lint / conventional-commits (push) Waiting to run
bootstrap / cfree-fixpoint (push) Has been cancelled
docs / build-and-deploy (push) Successful in 34s
feat(gl): OpenGL 4.1 and the ludic.render3d renderer
`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>
2026-09-10 03:31:12 +03:00

23 lines
934 B
GLSL

// auto-exposure on the GPU: the scene's mean luminance from the top of its mip chain,
// eased toward from the previous frame's value, written to a 1x1 texture the tonemapper
// reads. Nothing comes back to the CPU (a readback there waited for the whole frame's
// GPU work and serialised the two: 34 ms -> the sum of both, measured 2026-09-09).
in vec2 v_uv;
out vec4 o_color;
uniform sampler2D u_scene;
uniform sampler2D u_prev;
uniform float u_lod;
uniform float u_key;
uniform float u_max;
uniform float u_rate;
uniform float u_reset;
void main() {
vec3 c = textureLod(u_scene, vec2(0.5), u_lod).rgb;
c = clamp(c, vec3(0.0), vec3(1.0e5));
float lum = dot(c, vec3(0.2126, 0.7152, 0.0722));
float target = clamp(u_key / max(lum, 0.001), 0.02, u_max);
float prev = texture(u_prev, vec2(0.5)).r;
float e = mix(prev, target, u_rate);
if (u_reset > 0.5 || !(prev > 0.0)) e = target;
o_color = vec4(e, 0.0, 0.0, 1.0);
}