Further enhance lighting engine

This commit is contained in:
Agent X 2025-04-05 11:29:27 -04:00
parent 3bfa75e32b
commit 211ad82937
3 changed files with 28 additions and 4 deletions

View file

@ -1015,7 +1015,7 @@ ifeq ($(IS_DEV_OR_DEBUG),0)
ifeq ($(OSX_BUILD),0)
LDFLAGS += -Wl,--build-id=none
endif
else
# Stuff for showing the git hash and build time in dev builds
# Originally from https://stackoverflow.com/questions/44038428/include-git-commit-hash-and-or-branch-name-in-c-c-source
GIT_HASH=$(shell git rev-parse --short HEAD)

View file

@ -60,9 +60,16 @@ void le_calculate_vertex_lighting(Vtx_t* v, Color out) {
void le_calculate_lighting_color(Vec3f pos, Color out, f32 lightIntensityScalar) {
if (sLights == NULL) { return; }
#ifdef LE_TOTAL_WEIGHTED_LIGHTING
f32 r = sAmbientColor[0];
f32 g = sAmbientColor[1];
f32 b = sAmbientColor[2];
#else
f32 r = 0;
f32 g = 0;
f32 b = 0;
#endif
f32 weight = 1.0f;
for (struct LELight* light = hmap_begin(sLights); light != NULL; light = hmap_next(sLights)) {
f32 diffX = light->posX - pos[0];
f32 diffY = light->posY - pos[1];
@ -75,11 +82,18 @@ void le_calculate_lighting_color(Vec3f pos, Color out, f32 lightIntensityScalar)
r += light->colorR * brightness;
g += light->colorG * brightness;
b += light->colorB * brightness;
weight += brightness;
}
out[0] = min(r, 255);
out[1] = min(g, 255);
out[2] = min(b, 255);
#ifdef LE_TOTAL_WEIGHTED_LIGHTING
out[0] = min(r / weight, 255);
out[1] = min(g / weight, 255);
out[2] = min(b / weight, 255);
#else
out[0] = min(sAmbientColor[0] + (r / weight), 255);
out[1] = min(sAmbientColor[1] + (g / weight), 255);
out[2] = min(sAmbientColor[2] + (b / weight), 255);
#endif
}
void le_calculate_lighting_dir(Vec3f pos, Vec3f out) {

View file

@ -863,6 +863,16 @@ static void OPTIMIZE_O3 gfx_sp_vertex(size_t n_vertices, size_t dest_index, cons
U = (int32_t)((dotx / 127.0f + 1.0f) / 4.0f * rsp.texture_scaling_factor.s);
V = (int32_t)((doty / 127.0f + 1.0f) / 4.0f * rsp.texture_scaling_factor.t);
}
if (rsp.geometry_mode & G_LIGHTING_ENGINE_EXT) {
Color color;
CTX_BEGIN(CTX_LIGHTING);
le_calculate_lighting_color(((Vtx_t*)v)->ob, color, 1.0f);
CTX_END(CTX_LIGHTING);
d->color.r *= color[0] / 255.0f;
d->color.g *= color[1] / 255.0f;
d->color.b *= color[2] / 255.0f;
}
} else if (rsp.geometry_mode & G_LIGHTING_ENGINE_EXT) {
Color color;
CTX_BEGIN(CTX_LIGHTING);