add colored lighting back in via the colormap

This commit is contained in:
asrael 2026-02-05 03:27:35 -06:00
parent 01e6059dd1
commit a29a6018b8
16 changed files with 149 additions and 466 deletions

View file

@ -53,7 +53,6 @@ struct pxl8_gfx {
pxl8_renderer* renderer;
pxl8_gfx_texture color_target;
pxl8_gfx_texture depth_target;
pxl8_gfx_texture light_target;
pxl8_gfx_cmdbuf* cmdbuf;
pxl8_target_entry target_stack[PXL8_MAX_TARGET_STACK];
u32 target_stack_depth;
@ -115,11 +114,6 @@ i32 pxl8_gfx_get_height(const pxl8_gfx* gfx) {
return gfx ? gfx->framebuffer_height : 0;
}
u32* pxl8_gfx_get_light_accum(pxl8_gfx* gfx) {
if (!gfx) return NULL;
return (u32*)pxl8_texture_get_data(gfx->renderer, gfx->light_target);
}
u32* pxl8_gfx_get_output(pxl8_gfx* gfx) {
if (!gfx) return NULL;
return gfx->output;
@ -137,7 +131,6 @@ void pxl8_gfx_resolve(pxl8_gfx* gfx) {
pxl8_resolve_to_rgba(
gfx->renderer,
gfx->color_target,
gfx->light_target,
pal,
gfx->output
);
@ -246,14 +239,6 @@ pxl8_gfx* pxl8_gfx_create(
};
gfx->depth_target = pxl8_create_texture(gfx->renderer, &depth_desc);
pxl8_gfx_texture_desc light_desc = {
.width = (u32)gfx->framebuffer_width,
.height = (u32)gfx->framebuffer_height,
.format = PXL8_GFX_FORMAT_LIGHT_ACCUM,
.render_target = true,
};
gfx->light_target = pxl8_create_texture(gfx->renderer, &light_desc);
u32 pixel_count = (u32)gfx->framebuffer_width * (u32)gfx->framebuffer_height;
gfx->output = pxl8_calloc(pixel_count, sizeof(u32));
if (!gfx->output) {
@ -276,7 +261,6 @@ pxl8_gfx* pxl8_gfx_create(
gfx->target_stack[0] = (pxl8_target_entry){
.color = gfx->color_target,
.depth = gfx->depth_target,
.light = gfx->light_target,
};
gfx->target_stack_depth = 1;
@ -469,16 +453,6 @@ void pxl8_gfx_present(pxl8_gfx* gfx) {
gfx->hal->present(gfx->platform_data);
}
void pxl8_gfx_reset_stats(pxl8_gfx* gfx) {
if (!gfx || !gfx->renderer) return;
pxl8_renderer_reset_stats(gfx->renderer);
}
const pxl8_gfx_stats* pxl8_gfx_get_stats(pxl8_gfx* gfx) {
if (!gfx || !gfx->renderer) return NULL;
return pxl8_renderer_get_stats(gfx->renderer);
}
pxl8_viewport pxl8_gfx_viewport(pxl8_bounds bounds, i32 width, i32 height) {
pxl8_viewport vp = {0};
vp.scale = fminf(bounds.w / (f32)width, bounds.h / (f32)height);
@ -508,11 +482,6 @@ static pxl8_gfx_texture gfx_current_depth(pxl8_gfx* gfx) {
return gfx->target_stack[gfx->target_stack_depth - 1].depth;
}
static pxl8_gfx_texture gfx_current_light(pxl8_gfx* gfx) {
if (gfx->target_stack_depth == 0) return gfx->light_target;
return gfx->target_stack[gfx->target_stack_depth - 1].light;
}
static void gfx_composite_over(pxl8_gfx* gfx, const pxl8_target_entry* src, pxl8_target_entry* dst) {
if (!gfx || !src || !dst) return;
@ -546,7 +515,6 @@ static void gfx_composite_over(pxl8_gfx* gfx, const pxl8_target_entry* src, pxl8
void pxl8_2d_clear(pxl8_gfx* gfx, u32 color) {
if (!gfx) return;
pxl8_clear(gfx->renderer, gfx_current_color(gfx), (u8)color);
pxl8_clear_light(gfx->renderer, gfx_current_light(gfx));
}
void pxl8_2d_pixel(pxl8_gfx* gfx, i32 x, i32 y, u32 color) {
@ -745,7 +713,6 @@ void pxl8_3d_begin_frame(pxl8_gfx* gfx, const pxl8_3d_camera* camera, const pxl8
pxl8_gfx_pass_desc pass_desc = {
.color = { .texture = gfx_current_color(gfx), .load = PXL8_GFX_LOAD_CLEAR, .clear_value = 0 },
.depth = { .texture = gfx_current_depth(gfx), .load = PXL8_GFX_LOAD_CLEAR, .clear_value = 0xFFFF },
.light_accum = { .texture = gfx_current_light(gfx), .load = PXL8_GFX_LOAD_CLEAR },
};
gfx->frame_pass = pxl8_create_pass(gfx->renderer, &pass_desc);
pxl8_begin_pass(gfx->cmdbuf, gfx->frame_pass);
@ -791,7 +758,6 @@ u32 pxl8_3d_project_points(pxl8_gfx* gfx, const pxl8_vec3* in, pxl8_vec3* out, u
void pxl8_3d_clear(pxl8_gfx* gfx, u8 color) {
if (!gfx) return;
pxl8_clear(gfx->renderer, gfx_current_color(gfx), color);
pxl8_clear_light(gfx->renderer, gfx_current_light(gfx));
}
void pxl8_3d_clear_depth(pxl8_gfx* gfx) {
@ -1001,18 +967,9 @@ bool pxl8_gfx_push_target(pxl8_gfx* gfx) {
};
pxl8_gfx_texture new_depth = pxl8_create_texture(gfx->renderer, &depth_desc);
pxl8_gfx_texture_desc light_desc = {
.width = (u32)gfx->framebuffer_width,
.height = (u32)gfx->framebuffer_height,
.format = PXL8_GFX_FORMAT_LIGHT_ACCUM,
.render_target = true,
};
pxl8_gfx_texture new_light = pxl8_create_texture(gfx->renderer, &light_desc);
gfx->target_stack[gfx->target_stack_depth] = (pxl8_target_entry){
.color = new_color,
.depth = new_depth,
.light = new_light,
};
gfx->target_stack_depth++;