diff --git a/src/pc/debug_context.h b/src/pc/debug_context.h index 27048a91f..013f1e469 100644 --- a/src/pc/debug_context.h +++ b/src/pc/debug_context.h @@ -20,6 +20,7 @@ enum DebugContext { CTX_RENDER, CTX_LEVEL_SCRIPT, CTX_HOOK, + CTX_LIGHTING, CTX_MAX, // MUST BE KEPT IN SYNC WITH sDebugContextNames }; diff --git a/src/pc/djui/djui_ctx_display.c b/src/pc/djui/djui_ctx_display.c index b485f76a4..08359ec32 100644 --- a/src/pc/djui/djui_ctx_display.c +++ b/src/pc/djui/djui_ctx_display.c @@ -17,6 +17,7 @@ static char* sDebugContextNames[] = { "RENDER", "LEVEL", "HOOK", + "LIGHTING", "OTHER", "MAX", }; diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index 340a4205b..e5ea2384b 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -892,17 +892,21 @@ static void OPTIMIZE_O3 gfx_sp_vertex(size_t n_vertices, size_t dest_index, cons } // if lighting engine is enabled and either we want to affect all shaded surfaces or the lighting engine geometry mode is on - if (le_is_enabled() && ((le_get_mode() != LE_MODE_AFFECT_ONLY_GEOMETRY_MODE) || (rsp.geometry_mode & G_LIGHTING_ENGINE_EXT))) { + if (le_is_enabled() && luaVertexColor && ((le_get_mode() != LE_MODE_AFFECT_ONLY_GEOMETRY_MODE) || (rsp.geometry_mode & G_LIGHTING_ENGINE_EXT))) { Color color = { gLEAmbientColor[0], gLEAmbientColor[1], gLEAmbientColor[2] }; Vec3f vpos = { v->ob[0], v->ob[1], v->ob[2] }; Vec3f vnormal = { nx, ny, nz }; + CTX_BEGIN(CTX_LIGHTING); + // transform vpos and vnormal to world space gfx_local_to_world_space(vpos, vnormal); le_calculate_lighting_color_with_normal(vpos, vnormal, 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; @@ -913,6 +917,8 @@ static void OPTIMIZE_O3 gfx_sp_vertex(size_t n_vertices, size_t dest_index, cons Vec3f vpos = { v->ob[0], v->ob[1], v->ob[2] }; + CTX_BEGIN(CTX_LIGHTING); + // transform vpos to world space gfx_local_to_world_space(vpos, NULL); @@ -926,6 +932,8 @@ static void OPTIMIZE_O3 gfx_sp_vertex(size_t n_vertices, size_t dest_index, cons le_calculate_vertex_lighting((Vtx_t*)v, vpos, color); } + CTX_END(CTX_LIGHTING); + // combine the colors if (affectAllVertexColored && !(rsp.geometry_mode & G_LIGHTING_ENGINE_EXT)) { d->color.r = (v->cn[0] * color[0] / 255.0f) * vertexColorCached[0];