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

29 lines
1.1 KiB
GLSL

// impostor bake: albedo + coverage, and the model-frame normal
in vec3 v_wpos;
in vec3 v_nrm;
in vec2 v_uv;
in float v_seed;
layout(location = 0) out vec4 o_albedo;
layout(location = 1) out vec4 o_normal;
uniform sampler2D u_diff;
uniform sampler2D u_arm;
void main() {
vec4 d = texture(u_diff, v_uv);
if (d.a < 0.5) discard; // cut-out cards (needles, blades, leaves) bake with their shape
vec3 N = normalize(v_nrm);
if (!gl_FrontFacing) N = -N;
#ifdef FLOWER
float vy = clamp(v_uv.y, 0.0, 1.0);
if (v_uv.x >= 2.0) d.rgb = vec3(0.035, 0.09, 0.02) * (0.7 + 0.6 * vy);
else if (v_uv.x >= 1.0) {
float f = fract(v_uv.x);
vec3 violet = vec3(0.06, 0.03, 0.3);
vec3 lip = vec3(0.4, 0.3, 0.68);
// each floret: a dark keel at the base, a pale standard at the top edge
d.rgb = mix(violet, lip, smoothstep(0.35, 1.0, vy) * 0.6 + 0.25 * smoothstep(0.3, 0.0, abs(f - 0.5)));
d.rgb *= 0.85 + 0.15 * vy;
} else d.rgb = vec3(0.08, 0.17, 0.03);
#endif
o_albedo = vec4(d.rgb, 1.0);
o_normal = vec4(N * 0.5 + 0.5, texture(u_arm, v_uv).r);
}