diff --git a/GPU/Software/Lighting.cpp b/GPU/Software/Lighting.cpp index e970fc9696..64a906844a 100644 --- a/GPU/Software/Lighting.cpp +++ b/GPU/Software/Lighting.cpp @@ -86,6 +86,7 @@ void ComputeState(State *state, bool hasColor0) { bool anyAmbient = false; bool anyDiffuse = false; bool anySpecular = false; + bool anyDirectional = false; for (int light = 0; light < 4; ++light) { auto &lstate = state->lights[light]; lstate.enabled = gstate.isLightChanEnabled(light); @@ -112,10 +113,12 @@ void ComputeState(State *state, bool hasColor0) { } lstate.pos = GetLightVec(gstate.lpos, light); - if (lstate.directional) + if (lstate.directional) { lstate.pos.NormalizeOr001(); - else + anyDirectional = true; + } else { lstate.att = GetLightVec(gstate.latt, light); + } if (lstate.spot) { lstate.spotDir = GetLightVec(gstate.ldir, light); @@ -174,6 +177,8 @@ void ComputeState(State *state, bool hasColor0) { state->baseAmbientColorFactor = LightColorFactor(gstate.getAmbientRGBA(), ones); state->setColor1 = gstate.isUsingSecondaryColor() && anySpecular; state->addColor1 = !gstate.isUsingSecondaryColor() && anySpecular; + state->usesWorldPos = anyDirectional; + state->usesWorldNormal = gstate.getUVGenMode() == GE_TEXMAP_ENVIRONMENT_MAP || anyDiffuse || anySpecular; } static inline float GenerateLightCoord(VertexData &vertex, const WorldCoords &worldnormal, int light) { diff --git a/GPU/Software/Lighting.h b/GPU/Software/Lighting.h index 9a89d2fa9f..c875aae08b 100644 --- a/GPU/Software/Lighting.h +++ b/GPU/Software/Lighting.h @@ -60,6 +60,8 @@ struct State { bool colorForSpecular : 1; bool setColor1 : 1; bool addColor1 : 1; + bool usesWorldPos : 1; + bool usesWorldNormal : 1; }; }; diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index f17f12cf19..da8469779a 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -273,12 +273,9 @@ void ComputeTransformState(TransformState *state, const VertexReader &vreader) { bool canSkipWorldPos = true; if (state->enableLighting) { Lighting::ComputeState(&state->lightingState, vreader.hasColor0()); - for (int i = 0; i < 4; ++i) { - if (!state->lightingState.lights[i].enabled) - continue; - if (!state->lightingState.lights[i].directional) - canSkipWorldPos = false; - } + canSkipWorldPos = !state->lightingState.usesWorldPos; + } else { + state->lightingState.usesWorldNormal = state->uvGenMode == GE_TEXMAP_ENVIRONMENT_MAP; } float world[16]; @@ -412,7 +409,7 @@ ClipVertexData TransformUnit::ReadVertex(const VertexReader &vreader, const Tran vertex.v.clipw = vertex.clippos.w; Vec3 worldnormal; - if (state.enableLighting || state.uvGenMode == GE_TEXMAP_ENVIRONMENT_MAP) { + if (state.lightingState.usesWorldNormal) { worldnormal = TransformUnit::ModelToWorldNormal(normal); worldnormal.NormalizeOr001(); }