ludic/packages/ludic.render3d/shaders/ibl_irradiance.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

36 lines
1.3 KiB
GLSL

in vec2 v_uv;
out vec4 o_color;
uniform sampler2D u_sky;
uniform float u_sun_clip; // clamp the sun's radiance so it does not alias the convolution
vec3 dirFromUV(vec2 uv) {
float phi = (uv.x - 0.5) * 2.0 * PI;
float theta = uv.y * PI;
return vec3(sin(theta) * sin(phi), cos(theta), -sin(theta) * cos(phi));
}
vec2 hammersley(uint i, uint n) {
uint b = i;
b = (b << 16u) | (b >> 16u);
b = ((b & 0x55555555u) << 1u) | ((b & 0xAAAAAAAAu) >> 1u);
b = ((b & 0x33333333u) << 2u) | ((b & 0xCCCCCCCCu) >> 2u);
b = ((b & 0x0F0F0F0Fu) << 4u) | ((b & 0xF0F0F0F0u) >> 4u);
b = ((b & 0x00FF00FFu) << 8u) | ((b & 0xFF00FF00u) >> 8u);
return vec2(float(i) / float(n), float(b) * 2.3283064365386963e-10);
}
void main() {
vec3 n = dirFromUV(v_uv);
vec3 up = abs(n.y) < 0.999 ? vec3(0, 1, 0) : vec3(1, 0, 0);
vec3 t = normalize(cross(up, n));
vec3 b = cross(n, t);
vec3 acc = vec3(0.0);
const uint N = 512u;
for (uint i = 0u; i < N; i++) {
vec2 h = hammersley(i, N);
float phi = 2.0 * PI * h.x;
float ct = sqrt(1.0 - h.y); // cosine-weighted
float st = sqrt(h.y);
vec3 d = t * (cos(phi) * st) + b * (sin(phi) * st) + n * ct;
vec3 c = textureLod(u_sky, skyUV(d), 5.0).rgb;
acc += min(c, vec3(u_sun_clip));
}
o_color = vec4(acc / float(N), 1.0);
}