add colored lighting back in via the colormap
This commit is contained in:
parent
01e6059dd1
commit
5510497cc5
16 changed files with 136 additions and 446 deletions
|
|
@ -32,6 +32,8 @@ void pxl8_shader_lit(
|
|||
}
|
||||
|
||||
pxl8_f32_simd light = ctx->v_light;
|
||||
f32 max_strength[4] = {0, 0, 0, 0};
|
||||
u8 dominant_color[4] = {0, 0, 0, 0};
|
||||
|
||||
if (uniforms) {
|
||||
pxl8_f32_simd ambient = pxl8_f32_simd_set((f32)uniforms->ambient / 255.0f);
|
||||
|
|
@ -72,11 +74,32 @@ void pxl8_shader_lit(
|
|||
);
|
||||
falloff = pxl8_f32_simd_max(falloff, pxl8_f32_simd_zero());
|
||||
|
||||
if (uniforms->dither) {
|
||||
f32 falloff_arr[4];
|
||||
pxl8_f32_simd_store(falloff_arr, falloff);
|
||||
for (u32 j = 0; j < 4; j++) {
|
||||
if (falloff_arr[j] < 0.5f) {
|
||||
f32 threshold = (PXL8_BAYER_4X4[((u32)py[j] & 3) * 4 + ((u32)px[j] & 3)] + 0.5f) * (1.0f / 16.0f);
|
||||
if (falloff_arr[j] < threshold * 0.5f) falloff_arr[j] = 0.0f;
|
||||
}
|
||||
}
|
||||
falloff = pxl8_f32_simd_load(falloff_arr);
|
||||
}
|
||||
|
||||
pxl8_f32_simd strength = pxl8_f32_simd_mul(
|
||||
pxl8_f32_simd_mul(pxl8_f32_simd_set(l->intensity), falloff),
|
||||
ndotl
|
||||
);
|
||||
|
||||
f32 strength_arr[4];
|
||||
pxl8_f32_simd_store(strength_arr, strength);
|
||||
for (u32 j = 0; j < 4; j++) {
|
||||
if (strength_arr[j] > max_strength[j]) {
|
||||
max_strength[j] = strength_arr[j];
|
||||
dominant_color[j] = l->color;
|
||||
}
|
||||
}
|
||||
|
||||
light = pxl8_f32_simd_add(light, strength);
|
||||
}
|
||||
}
|
||||
|
|
@ -88,13 +111,12 @@ void pxl8_shader_lit(
|
|||
pxl8_f32_simd_store(light_arr, light_f);
|
||||
|
||||
for (u32 i = 0; i < ctx->color_count; i++) {
|
||||
u8 light_u8;
|
||||
u8 light_u8 = (u8)light_arr[i];
|
||||
if (uniforms && uniforms->dither) {
|
||||
light_u8 = pxl8_gfx_dither(light_arr[i], (u32)px[i], (u32)py[i]);
|
||||
colors_out[i] = pxl8_colormap_lookup_dithered(bindings, tex_idx[i], dominant_color[i], light_u8, (u32)px[i], (u32)py[i]);
|
||||
} else {
|
||||
light_u8 = (u8)light_arr[i];
|
||||
colors_out[i] = pxl8_colormap_lookup(bindings, tex_idx[i], dominant_color[i], light_u8);
|
||||
}
|
||||
colors_out[i] = pxl8_colormap_lookup(bindings, tex_idx[i], light_u8);
|
||||
}
|
||||
|
||||
#else
|
||||
|
|
@ -111,6 +133,8 @@ void pxl8_shader_lit(
|
|||
}
|
||||
|
||||
f32 light = ctx->v_light;
|
||||
f32 max_strength = 0;
|
||||
u8 dominant_color = 0;
|
||||
|
||||
if (uniforms) {
|
||||
f32 ambient = (f32)uniforms->ambient / 255.0f;
|
||||
|
|
@ -143,8 +167,16 @@ void pxl8_shader_lit(
|
|||
|
||||
f32 falloff = 1.0f - dist_sq * l->inv_radius_sq;
|
||||
if (falloff <= 0.0f) continue;
|
||||
if (uniforms->dither && falloff < 0.5f) {
|
||||
f32 threshold = (PXL8_BAYER_4X4[((u32)ctx->y & 3) * 4 + ((u32)ctx->x & 3)] + 0.5f) * (1.0f / 16.0f);
|
||||
if (falloff < threshold * 0.5f) continue;
|
||||
}
|
||||
|
||||
f32 strength = l->intensity * falloff * ndotl;
|
||||
if (strength > max_strength) {
|
||||
max_strength = strength;
|
||||
dominant_color = l->color;
|
||||
}
|
||||
light += strength;
|
||||
}
|
||||
}
|
||||
|
|
@ -155,9 +187,9 @@ void pxl8_shader_lit(
|
|||
f32 light_f = light * 255.0f;
|
||||
u8 light_u8 = (u8)light_f;
|
||||
if (uniforms && uniforms->dither) {
|
||||
light_u8 = pxl8_gfx_dither(light_f, (u32)ctx->x, (u32)ctx->y);
|
||||
colors_out[0] = pxl8_colormap_lookup_dithered(bindings, tex_idx, dominant_color, light_u8, (u32)ctx->x, (u32)ctx->y);
|
||||
} else {
|
||||
colors_out[0] = pxl8_colormap_lookup(bindings, tex_idx, dominant_color, light_u8);
|
||||
}
|
||||
|
||||
colors_out[0] = pxl8_colormap_lookup(bindings, tex_idx, light_u8);
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue