softgpu: Separate calculation of S/T.

We could probably reuse, but we're not right now and it complicates the
logic.
This commit is contained in:
Unknown W. Brackets 2022-01-03 22:56:26 -08:00
parent 683289402c
commit cba2374abd
3 changed files with 22 additions and 22 deletions

View File

@ -43,6 +43,22 @@ static inline float pspLightPow(float v, float e) {
return v;
}
static inline float GenerateLightCoord(VertexData &vertex, int light) {
// TODO: Should specular lighting should affect this, too? Doesn't in GLES.
Vec3<float> L = GetLightVec(gstate.lpos, light);
// In other words, L.Length2() == 0.0f means Dot({0, 0, 1}, worldnormal).
float diffuse_factor = Dot(L.NormalizedOr001(cpu_info.bSSE4_1), vertex.worldnormal);
return (diffuse_factor + 1.0f) / 2.0f;
}
void GenerateLightST(VertexData &vertex) {
// Always calculate texture coords from lighting results if environment mapping is active
// This should be done even if lighting is disabled altogether.
vertex.texturecoords.s() = GenerateLightCoord(vertex, gstate.getUVLS0());
vertex.texturecoords.t() = GenerateLightCoord(vertex, gstate.getUVLS1());
}
void Process(VertexData& vertex, bool hasColor) {
const int materialupdate = gstate.materialupdate & (hasColor ? 7 : 0);
@ -53,26 +69,6 @@ void Process(VertexData& vertex, bool hasColor) {
Vec3<float> final_color = mec + mac * Vec3<float>::FromRGB(gstate.getAmbientRGBA());
Vec3<float> specular_color(0.0f, 0.0f, 0.0f);
for (unsigned int light = 0; light < 4; ++light) {
// Always calculate texture coords from lighting results if environment mapping is active
// TODO: Should specular lighting should affect this, too? Doesn't in GLES.
// This should be done even if lighting is disabled altogether.
if (gstate.getUVGenMode() == GE_TEXMAP_ENVIRONMENT_MAP) {
Vec3<float> L = GetLightVec(gstate.lpos, light);
// In other words, L.Length2() == 0.0f means Dot({0, 0, 1}, worldnormal).
float diffuse_factor = Dot(L.NormalizedOr001(cpu_info.bSSE4_1), vertex.worldnormal);
if (gstate.getUVLS0() == (int)light)
vertex.texturecoords.s() = (diffuse_factor + 1.f) / 2.f;
if (gstate.getUVLS1() == (int)light)
vertex.texturecoords.t() = (diffuse_factor + 1.f) / 2.f;
}
}
if (!gstate.isLightingEnabled())
return;
for (unsigned int light = 0; light < 4; ++light) {
if (!gstate.isLightChanEnabled(light))
continue;

View File

@ -21,6 +21,7 @@
namespace Lighting {
void GenerateLightST(VertexData &vertex);
void Process(VertexData& vertex, bool hasColor);
}

View File

@ -277,9 +277,12 @@ VertexData TransformUnit::ReadVertex(VertexReader &vreader, bool &outside_range_
Vec3<float> stq = tgen * source + Vec3<float>(gstate.tgenMatrix[9], gstate.tgenMatrix[10], gstate.tgenMatrix[11]);
float z_recip = 1.0f / stq.z;
vertex.texturecoords = Vec2f(stq.x * z_recip, stq.y * z_recip);
} else if (gstate.getUVGenMode() == GE_TEXMAP_ENVIRONMENT_MAP) {
Lighting::GenerateLightST(vertex);
}
PROFILE_THIS_SCOPE("light");
if (gstate.isLightingEnabled())
Lighting::Process(vertex, vreader.hasColor0());
} else {
vertex.screenpos.x = (int)(pos[0] * 16) + gstate.getOffsetX16();