softgpu: Calc worldnormal a bit less often.

This is clearer anyway.
This commit is contained in:
Unknown W. Brackets committed 2023-04-16 10:16:32 -07:00
1 parent 59fb374c38
commit b5206df04f
3 files changed
+13 -9

No files matched your search

+7 -2
View File
@@ -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) {
+2
View File
@@ -60,6 +60,8 @@ struct State {
bool colorForSpecular : 1;
bool setColor1 : 1;
bool addColor1 : 1;
bool usesWorldPos : 1;
bool usesWorldNormal : 1;
};
};
+4 -7
View File
@@ -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<float> worldnormal;
if (state.enableLighting || state.uvGenMode == GE_TEXMAP_ENVIRONMENT_MAP) {
if (state.lightingState.usesWorldNormal) {
worldnormal = TransformUnit::ModelToWorldNormal(normal);
worldnormal.NormalizeOr001();
}