render3d + lab: bakes as PNGs, and impostors, the sky's light and the carpet read from their bakes

ludic.lab: lab_png_write / lab_png_write_from (raw 8-bit, 1-4 channels, stored deflate) in png_write.ludic,
importable alone with its own LabPngState; png_convert.ludic's previews of float textures (R32F min..max,
RG16F x255, HDR x/(1+x) + sRGB); lab_ppm_to_png on the same encoder.
render3d: bake_load.ludic - impostor_from_baked / impostor_source / impostor_refill (a fog re-open reads
the bake), sky_baked_in and sky_precompute trying the bake at the start yaw (sky_compute is the
convolution, and sky_ibl_bytes always uses it), carpet_from_baked / carpet_bytes / carpet_finish,
bake_part_count / _len / _off. Compile-only: nothing run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-29 19:10:06 +03:00
parent f79390838a
commit 6c690c5db6
15 changed files with 396 additions and 107 deletions

View file

@ -36,6 +36,12 @@ function bake_unpack(render3d_st: mut Render3dState, data: []byte, texs: words)
return true
}
@alloc_ok("a bake's list of textures, once")
function bake_list1(a: int) -> words {
let w = words(1)
w[0] = a
return w
}
@alloc_ok("a bake's list of textures, once")
function bake_list2(a: int, b: int) -> words {
let w = words(2)
@ -52,13 +58,15 @@ function bake_list3(a: int, b: int, c: int) -> words {
# ---- an impostor: its albedo and normal atlases (level 0; mips are made after) ----
function impostor_bytes(render3d_st: mut Render3dState, im: Impostor) -> []byte { return bake_pack(render3d_st, bake_list2(im.albedo, im.normal)) }
# an impostor with the bake's shape (model, tiles and tile size as impostor_bake takes them) from bytes
# an impostor with the bake's shape (model, tiles and tile size as impostor_bake takes them) from bytes;
# null, and nothing kept, when the bytes are not that shape
function impostor_from_bytes(render3d_st: mut Render3dState, model: Model, tiles: int, tw: int, th: int, data: []byte) -> Impostor {
let im = new Impostor
im.tiles = tiles; im.radius = model.radius * 1.02; im.height = model.height
im.model = model; im.tw = tw; im.th = th; im.flower = render3d_st.sc_bake_flower
impostor_fill(render3d_st, im, data)
return im
if impostor_fill(render3d_st, im, data) { return im }
gpu_tex_free(render3d_st, im.albedo); gpu_tex_free(render3d_st, im.normal)
return null
}
# an impostor's atlases made and filled from bytes (at a load, or when a fog opens past its cards)
@ -96,7 +104,7 @@ function terrain_shadow_from_bytes(render3d_st: mut Render3dState, data: []byte)
# ---- the sky's image-based lighting: irradiance, the prefiltered levels, the BRDF table ----
# for the HDRI already loaded and the yaw already set (the yaw is part of what a bake is keyed on)
function sky_ibl_bytes(render3d_st: mut Render3dState) -> []byte {
sky_precompute(render3d_st)
sky_compute(render3d_st) # never from an older bake
return bake_pack(render3d_st, bake_list3(render3d_st.sky_irradiance, render3d_st.sky_prefilter, render3d_st.sky_brdf))
}