mirror of
https://github.com/libretro/ppsspp.git
synced 2025-01-27 11:41:49 +00:00
softgpu: Implement environment mapping.
This commit is contained in:
parent
d2f30961af
commit
1450157e09
@ -35,6 +35,20 @@ void Process(VertexData& vertex)
|
||||
Vec3<int> specular_color(0, 0, 0);
|
||||
|
||||
for (unsigned int light = 0; light < 4; ++light) {
|
||||
// Always calculate texture coords from lighting results if environment mapping is active
|
||||
// TODO: specular lighting should affect this, too!
|
||||
if (gstate.getUVGenMode() == GE_TEXMAP_ENVIRONMENT_MAP) {
|
||||
Vec3<float> L = Vec3<float>(getFloat24(gstate.lpos[3*light]&0xFFFFFF), getFloat24(gstate.lpos[3*light+1]&0xFFFFFF),getFloat24(gstate.lpos[3*light+2]&0xFFFFFF));
|
||||
float diffuse_factor = Dot(L,vertex.worldnormal) / L.Length() / vertex.worldnormal.Length();
|
||||
|
||||
if (gstate.getUVLS0() == light)
|
||||
vertex.texturecoords.s() = (diffuse_factor + 1.f) / 2.f;
|
||||
|
||||
if (gstate.getUVLS1() == light)
|
||||
vertex.texturecoords.t() = (diffuse_factor + 1.f) / 2.f;
|
||||
}
|
||||
|
||||
// Skip other calculations if light chan is disabled
|
||||
if (!gstate.isLightChanEnabled(light))
|
||||
continue;
|
||||
|
||||
|
@ -472,6 +472,15 @@ void DrawTriangle(const VertexData& v0, const VertexData& v1, const VertexData&
|
||||
Vec3<float> stq = tgen * source + Vec3<float>(gstate.tgenMatrix[9], gstate.tgenMatrix[10], gstate.tgenMatrix[11]);
|
||||
|
||||
uv_map(0, stq.x/stq.z, stq.y/stq.z, u, v);
|
||||
} else if (gstate.getUVGenMode() == GE_TEXMAP_ENVIRONMENT_MAP) {
|
||||
// environment mapping - ST coordinates are calculated during Lighting
|
||||
float q0 = 1.f / v0.clippos.w;
|
||||
float q1 = 1.f / v1.clippos.w;
|
||||
float q2 = 1.f / v2.clippos.w;
|
||||
float q = q0 * w0 + q1 * w1 + q2 * w2;
|
||||
float s = (v0.texturecoords.s() * q0 * w0 + v1.texturecoords.s() * q1 * w1 + v2.texturecoords.s() * q2 * w2) / q;
|
||||
float t = (v0.texturecoords.t() * q0 * w0 + v1.texturecoords.t() * q1 * w1 + v2.texturecoords.t() * q2 * w2) / q;
|
||||
uv_map(0, s, t, u, v);
|
||||
} else {
|
||||
ERROR_LOG(G3D, "Unsupported texture mapping mode %x!", gstate.getUVGenMode());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user