packages: ludic.ui's render3d backend threads Render3dState; render3d's settable vars (r3d_dem_path, post_*, grass_*, wt_wade_*, ...) are Render3dState's fields again, not lets

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 17:11:15 +03:00
parent ce80e64b24
commit 3a87d02696
15 changed files with 152 additions and 148 deletions

View file

@ -150,8 +150,8 @@ function shadow_pass(render3d_st: mut Render3dState) -> void {
gpu_clear(render3d_st, GL_DEPTH_BUFFER_BIT)
let vp = shadow_cascade_vp(render3d_st, c)
# shadows off (a video setting): the cascades stay cleared, so everything reads lit
if sh_enabled {
if not sh_skip_terrain { terrain_draw_shadow(vp) }
if render3d_st.sh_enabled {
if not render3d_st.sh_skip_terrain { terrain_draw_shadow(vp) }
r3d_scene_casters(render3d_st, vp)
}
}
@ -161,15 +161,15 @@ function shadow_pass(render3d_st: mut Render3dState) -> void {
if render3d_st.r3d_debug_shadow and not render3d_st.sh_printed2 {
render3d_st.sh_printed2 = true
let q = floats(3)
if sh_probe_x != 0.0 {
if render3d_st.sh_probe_x != 0.0 {
let vp = shadow_cascade_vp(render3d_st, 2)
m4_xform_point(q, vp, sh_probe_x, sh_probe_y, sh_probe_z)
m4_xform_point(q, vp, render3d_st.sh_probe_x, render3d_st.sh_probe_y, render3d_st.sh_probe_z)
print(`probe base ndc {fixed(q[0])} {fixed(q[1])} {fixed(q[2])}`)
m4_xform_point(q, vp, sh_probe_x, sh_probe_y + 15.0, sh_probe_z)
m4_xform_point(q, vp, render3d_st.sh_probe_x, render3d_st.sh_probe_y + 15.0, render3d_st.sh_probe_z)
print(`probe top ndc {fixed(q[0])} {fixed(q[1])} {fixed(q[2])} -> map texel {int((q[0] * 0.5 + 0.5) * float(render3d_st.shadow_res))} {int((q[1] * 0.5 + 0.5) * float(render3d_st.shadow_res))}`)
# where the top's shadow lands on the ground: walk down the sun ray
let gx = sh_probe_x + 0.0 - render3d_st.sun_dir[0] * (15.0 / render3d_st.sun_dir[1])
let gz = sh_probe_z - render3d_st.sun_dir[2] * (15.0 / render3d_st.sun_dir[1])
let gx = render3d_st.sh_probe_x + 0.0 - render3d_st.sun_dir[0] * (15.0 / render3d_st.sun_dir[1])
let gz = render3d_st.sh_probe_z - render3d_st.sun_dir[2] * (15.0 / render3d_st.sun_dir[1])
m4_xform_point(q, vp, gx, terrain_height(render3d_st, gx, gz), gz)
print(`shadow-of-top ground ndc {fixed(q[0])} {fixed(q[1])} {fixed(q[2])} at {fixed(gx)} {fixed(gz)}`)
}
@ -183,11 +183,6 @@ function shadow_pass(render3d_st: mut Render3dState) -> void {
free(q)
}
}
let sh_enabled: bool = true
let sh_skip_terrain: bool = false
let sh_probe_x: float = 0.0
let sh_probe_y: float = 0.0
let sh_probe_z: float = 0.0
# Debug: cascade depths as grey PPMs (build/dbg_shadow_<c>.ppm)
function shadow_dump(render3d_st: mut Render3dState) -> void {
@ -197,10 +192,10 @@ function shadow_dump(render3d_st: mut Render3dState) -> void {
gpu_tex_param(render3d_st, GPU_TEX2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_NONE)
gpu_tex_read(render3d_st, GPU_TEX2D_ARRAY, GL_DEPTH_COMPONENT, GL_FLOAT, data_of(buf))
gpu_tex_param(render3d_st, GPU_TEX2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE)
if sh_probe_x != 0.0 {
if render3d_st.sh_probe_x != 0.0 {
let vp = shadow_cascade_vp(render3d_st, 2)
let q = floats(3)
m4_xform_point(q, vp, sh_probe_x, sh_probe_y + 12.0, sh_probe_z)
m4_xform_point(q, vp, render3d_st.sh_probe_x, render3d_st.sh_probe_y + 12.0, render3d_st.sh_probe_z)
let tx = int((q[0] * 0.5 + 0.5) * float(render3d_st.shadow_res))
let ty = int((q[1] * 0.5 + 0.5) * float(render3d_st.shadow_res))
let want = q[2] * 0.5 + 0.5