and yet more cleanup...

This commit is contained in:
asrael 2026-04-15 00:53:03 -05:00
parent 26e855369d
commit cf43538518
16 changed files with 80 additions and 107 deletions

View file

@ -458,13 +458,7 @@ u8 demo3d_bsp_light_at(const demo3d_bsp* bsp, f32 x, f32 y, f32 z, u8 ambient) {
}
}
if (best_idx >= bsp->num_vertex_lights) return 255;
u32 packed = bsp->vertex_lights[best_idx];
u8 direct = (packed >> 24) & 0xFF;
u8 ao = (packed >> 16) & 0xFF;
f32 combined = (f32)direct + ((f32)ambient / 255.0f) * (f32)ao;
return (u8)(combined > 255.0f ? 255.0f : combined);
return demo3d_bsp_vertex_light(bsp, best_idx, ambient);
}
demo3d_bsp_lightmap_sample demo3d_bsp_sample_lightmap(const demo3d_bsp* bsp, u32 face_idx, f32 u, f32 v) {

View file

@ -157,6 +157,15 @@ static inline bool demo3d_bsp_get_edge_vertex(const demo3d_bsp* bsp, i32 surfedg
return *out_vert_idx < bsp->num_vertices;
}
static inline u8 demo3d_bsp_vertex_light(const demo3d_bsp* bsp, u32 vert_idx, u8 ambient) {
if (!bsp->vertex_lights || vert_idx >= bsp->num_vertex_lights) return 255;
u32 packed = bsp->vertex_lights[vert_idx];
u8 direct = (packed >> 24) & 0xFF;
u8 ao = (packed >> 16) & 0xFF;
f32 combined = (f32)direct + ((f32)ambient / 255.0f) * (f32)ao;
return (u8)(combined > 255.0f ? 255.0f : combined);
}
static inline i32 demo3d_bsp_find_leaf(const demo3d_bsp* bsp, pxl8_vec3 pos) {
if (!bsp || bsp->num_nodes == 0) return -1;
i32 node_id = 0;

View file

@ -72,14 +72,7 @@ static void collect_face_to_mesh(const demo3d_bsp* bsp, const demo3d_bsp_render_
f32 u = (pxl8_vec3_dot(pos, u_axis) + u_offset) / tex_scale;
f32 v = (pxl8_vec3_dot(pos, v_axis) + v_offset) / tex_scale;
u8 light = 255;
if (bsp->vertex_lights && vert_idx < bsp->num_vertex_lights) {
u32 packed = bsp->vertex_lights[vert_idx];
u8 direct = (packed >> 24) & 0xFF;
u8 ao = (packed >> 16) & 0xFF;
f32 combined = (f32)direct + ((f32)ambient / 255.0f) * (f32)ao;
light = (u8)(combined > 255.0f ? 255.0f : combined);
}
u8 light = demo3d_bsp_vertex_light(bsp, vert_idx, ambient);
pxl8_vertex vtx = {
.position = pos,