Merge remote-tracking branch 'upstream/no-light-cache'

This commit is contained in:
Unknown W. Brackets 2014-04-21 22:40:21 -07:00
commit 701171f75a
19 changed files with 436 additions and 581 deletions

View File

@ -1219,6 +1219,8 @@ add_library(GPU OBJECT
GPU/Common/GPUDebugInterface.h GPU/Common/GPUDebugInterface.h
GPU/Common/VertexDecoderCommon.cpp GPU/Common/VertexDecoderCommon.cpp
GPU/Common/VertexDecoderCommon.h GPU/Common/VertexDecoderCommon.h
GPU/Common/TransformCommon.cpp
GPU/Common/TransformCommon.h
GPU/Common/IndexGenerator.cpp GPU/Common/IndexGenerator.cpp
GPU/Common/IndexGenerator.h GPU/Common/IndexGenerator.h
GPU/Common/TextureDecoder.cpp GPU/Common/TextureDecoder.cpp

View File

View File

@ -0,0 +1,181 @@
// Copyright (c) 2013- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <stdio.h>
#include "GPU/GPUState.h"
#include "GPU/Common/TransformCommon.h"
// Check for max first as clamping to max is more common than min when lighting.
inline float clamp(float in, float min, float max) {
return in > max ? max : (in < min ? min : in);
}
Lighter::Lighter(int vertType) {
if (!gstate.isLightingEnabled())
return;
doShadeMapping_ = gstate.getUVGenMode() == GE_TEXMAP_ENVIRONMENT_MAP;
materialEmissive.GetFromRGB(gstate.materialemissive);
materialEmissive.a = 0.0f;
globalAmbient.GetFromRGB(gstate.ambientcolor);
globalAmbient.GetFromA(gstate.ambientalpha);
materialAmbient.GetFromRGB(gstate.materialambient);
materialAmbient.GetFromA(gstate.materialalpha);
materialDiffuse.GetFromRGB(gstate.materialdiffuse);
materialDiffuse.a = 1.0f;
materialSpecular.GetFromRGB(gstate.materialspecular);
materialSpecular.a = 1.0f;
specCoef_ = getFloat24(gstate.materialspecularcoef);
// viewer_ = Vec3f(-gstate.viewMatrix[9], -gstate.viewMatrix[10], -gstate.viewMatrix[11]);
bool hasColor = (vertType & GE_VTYPE_COL_MASK) != 0;
materialUpdate_ = hasColor ? (gstate.materialupdate & 7) : 0;
for (int l = 0; l < 4; l++) {
int i = l * 3;
if (gstate.isLightChanEnabled(l)) {
lpos[i] = getFloat24(gstate.lpos[i]);
lpos[i + 1] = getFloat24(gstate.lpos[i + 1]);
lpos[i + 2] = getFloat24(gstate.lpos[i + 2]);
ldir[i] = getFloat24(gstate.ldir[i]);
ldir[i + 1] = getFloat24(gstate.ldir[i + 1]);
ldir[i + 2] = getFloat24(gstate.ldir[i + 2]);
latt[i] = getFloat24(gstate.latt[i]);
latt[i + 1] = getFloat24(gstate.latt[i + 1]);
latt[i + 2] = getFloat24(gstate.latt[i + 2]);
for (int t = 0; t < 3; t++) {
u32 data = gstate.lcolor[l * 3 + t] & 0xFFFFFF;
float r = (float)(data & 0xff) * (1.0f / 255.0f);
float g = (float)((data >> 8) & 0xff) * (1.0f / 255.0f);
float b = (float)(data >> 16) * (1.0f / 255.0f);
lcolor[t][l][0] = r;
lcolor[t][l][1] = g;
lcolor[t][l][2] = b;
}
}
}
}
void Lighter::Light(float colorOut0[4], float colorOut1[4], const float colorIn[4], const Vec3f &pos, const Vec3f &norm) {
Color4 in(colorIn);
const Color4 *ambient;
if (materialUpdate_ & 1)
ambient = &in;
else
ambient = &materialAmbient;
const Color4 *diffuse;
if (materialUpdate_ & 2)
diffuse = &in;
else
diffuse = &materialDiffuse;
const Color4 *specular;
if (materialUpdate_ & 4)
specular = &in;
else
specular = &materialSpecular;
Color4 lightSum0 = globalAmbient * *ambient + materialEmissive;
Color4 lightSum1(0, 0, 0, 0);
for (int l = 0; l < 4; l++) {
// can we skip this light?
if (!gstate.isLightChanEnabled(l))
continue;
GELightType type = gstate.getLightType(l);
Vec3f toLight(0, 0, 0);
Vec3f lightDir(0, 0, 0);
if (type == GE_LIGHTTYPE_DIRECTIONAL)
toLight = Vec3f(&lpos[l * 3]); // lightdir is for spotlights
else
toLight = Vec3f(&lpos[l * 3]) - pos;
bool doSpecular = gstate.isUsingSpecularLight(l);
bool poweredDiffuse = gstate.isUsingPoweredDiffuseLight(l);
float distanceToLight = toLight.Length();
float dot = 0.0f;
float angle = 0.0f;
float lightScale = 0.0f;
if (distanceToLight > 0.0f) {
toLight /= distanceToLight;
dot = Dot(toLight, norm);
}
// Clamp dot to zero.
if (dot < 0.0f) dot = 0.0f;
if (poweredDiffuse)
dot = powf(dot, specCoef_);
// Attenuation
switch (type) {
case GE_LIGHTTYPE_DIRECTIONAL:
lightScale = 1.0f;
break;
case GE_LIGHTTYPE_POINT:
lightScale = clamp(1.0f / (latt[l * 3] + latt[l * 3 + 1] * distanceToLight + latt[l * 3 + 2] * distanceToLight*distanceToLight), 0.0f, 1.0f);
break;
case GE_LIGHTTYPE_SPOT:
case GE_LIGHTTYPE_UNKNOWN:
lightDir = Vec3f(&ldir[l * 3]);
angle = Dot(toLight.Normalized(), lightDir.Normalized());
if (angle >= lcutoff[l])
lightScale = clamp(1.0f / (latt[l * 3] + latt[l * 3 + 1] * distanceToLight + latt[l * 3 + 2] * distanceToLight*distanceToLight), 0.0f, 1.0f) * powf(angle, lconv[l]);
break;
default:
// ILLEGAL
break;
}
Color4 lightDiff(lcolor[1][l], 0.0f);
Color4 diff = (lightDiff * *diffuse) * dot;
// Real PSP specular
Vec3f toViewer(0, 0, 1);
// Better specular
// Vec3f toViewer = (viewer - pos).Normalized();
if (doSpecular) {
Vec3f halfVec = (toLight + toViewer);
halfVec.Normalize();
dot = Dot(halfVec, norm);
if (dot > 0.0f) {
Color4 lightSpec(lcolor[2][l], 0.0f);
lightSum1 += (lightSpec * *specular * (powf(dot, specCoef_) * lightScale));
}
}
if (gstate.isLightChanEnabled(l)) {
Color4 lightAmbient(lcolor[0][l], 0.0f);
lightSum0 += (lightAmbient * *ambient + diff) * lightScale;
}
}
// 4?
for (int i = 0; i < 4; i++) {
colorOut0[i] = lightSum0[i] > 1.0f ? 1.0f : lightSum0[i];
colorOut1[i] = lightSum1[i] > 1.0f ? 1.0f : lightSum1[i];
}
}

View File

@ -0,0 +1,93 @@
// Copyright (c) 2014- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#pragma once
#include <cstring>
#include "base/basictypes.h"
#include "Common/Log.h"
#include "Common/CommonTypes.h"
#include "Core/Reporting.h"
#include "GPU/ge_constants.h"
#include "GPU/Math3D.h"
struct Color4 {
float r, g, b, a;
Color4() : r(0), g(0), b(0), a(0) { }
Color4(float _r, float _g, float _b, float _a = 1.0f)
: r(_r), g(_g), b(_b), a(_a) {
}
Color4(const float in[4]) { r = in[0]; g = in[1]; b = in[2]; a = in[3]; }
Color4(const float in[3], float alpha) { r = in[0]; g = in[1]; b = in[2]; a = alpha; }
const float &operator [](int i) const { return *(&r + i); }
Color4 operator *(float f) const {
return Color4(f*r, f*g, f*b, f*a);
}
Color4 operator *(const Color4 &c) const {
return Color4(r*c.r, g*c.g, b*c.b, a*c.a);
}
Color4 operator +(const Color4 &c) const {
return Color4(r + c.r, g + c.g, b + c.b, a + c.a);
}
void operator +=(const Color4 &c) {
r += c.r;
g += c.g;
b += c.b;
a += c.a;
}
void GetFromRGB(u32 col) {
b = ((col >> 16) & 0xff) * (1.0f / 255.0f);
g = ((col >> 8) & 0xff) * (1.0f / 255.0f);
r = ((col >> 0) & 0xff) * (1.0f / 255.0f);
}
void GetFromA(u32 col) {
a = (col & 0xff) * (1.0f / 255.0f);
}
};
// Convenient way to do precomputation to save the parts of the lighting calculation
// that's common between the many vertices of a draw call.
class Lighter {
public:
Lighter(int vertType);
void Light(float colorOut0[4], float colorOut1[4], const float colorIn[4], const Vec3f &pos, const Vec3f &normal);
private:
Color4 globalAmbient;
Color4 materialEmissive;
Color4 materialAmbient;
Color4 materialDiffuse;
Color4 materialSpecular;
float specCoef_;
// Vec3f viewer_;
bool doShadeMapping_;
int materialUpdate_;
// Converted light parameters
public:
float lpos[12]; // Used by shade UV mapping
private:
float ldir[12];
float latt[12];
float lcutoff[4];
float lconv[4];
float lcolor[3][4][3];
};

View File

@ -953,89 +953,46 @@ void DIRECTX9_GPU::ExecuteOp(u32 op, u32 diff) {
case GE_CMD_LIGHTTYPE2: case GE_CMD_LIGHTTYPE2:
case GE_CMD_LIGHTTYPE3: case GE_CMD_LIGHTTYPE3:
break; break;
case GE_CMD_LX0:case GE_CMD_LY0:case GE_CMD_LZ0: case GE_CMD_LX0:case GE_CMD_LY0:case GE_CMD_LZ0:
case GE_CMD_LX1:case GE_CMD_LY1:case GE_CMD_LZ1:
case GE_CMD_LX2:case GE_CMD_LY2:case GE_CMD_LZ2:
case GE_CMD_LX3:case GE_CMD_LY3:case GE_CMD_LZ3:
{
int n = cmd - GE_CMD_LX0;
int l = n / 3;
int c = n % 3;
gstate_c.lightpos[l][c] = getFloat24(data);
if (diff)
shaderManager_->DirtyUniform(DIRTY_LIGHT0 << l);
}
break;
case GE_CMD_LDX0:case GE_CMD_LDY0:case GE_CMD_LDZ0: case GE_CMD_LDX0:case GE_CMD_LDY0:case GE_CMD_LDZ0:
case GE_CMD_LDX1:case GE_CMD_LDY1:case GE_CMD_LDZ1:
case GE_CMD_LDX2:case GE_CMD_LDY2:case GE_CMD_LDZ2:
case GE_CMD_LDX3:case GE_CMD_LDY3:case GE_CMD_LDZ3:
{
int n = cmd - GE_CMD_LDX0;
int l = n / 3;
int c = n % 3;
gstate_c.lightdir[l][c] = getFloat24(data);
if (diff)
shaderManager_->DirtyUniform(DIRTY_LIGHT0 << l);
}
break;
case GE_CMD_LKA0:case GE_CMD_LKB0:case GE_CMD_LKC0: case GE_CMD_LKA0:case GE_CMD_LKB0:case GE_CMD_LKC0:
case GE_CMD_LKS0: // spot coef ("conv")
case GE_CMD_LKO0: // light angle ("cutoff")
case GE_CMD_LAC0:
case GE_CMD_LDC0:
case GE_CMD_LSC0:
shaderManager_->DirtyUniform(DIRTY_LIGHT0);
break;
case GE_CMD_LX1:case GE_CMD_LY1:case GE_CMD_LZ1:
case GE_CMD_LDX1:case GE_CMD_LDY1:case GE_CMD_LDZ1:
case GE_CMD_LKA1:case GE_CMD_LKB1:case GE_CMD_LKC1: case GE_CMD_LKA1:case GE_CMD_LKB1:case GE_CMD_LKC1:
case GE_CMD_LKA2:case GE_CMD_LKB2:case GE_CMD_LKC2:
case GE_CMD_LKA3:case GE_CMD_LKB3:case GE_CMD_LKC3:
{
int n = cmd - GE_CMD_LKA0;
int l = n / 3;
int c = n % 3;
gstate_c.lightatt[l][c] = getFloat24(data);
if (diff)
shaderManager_->DirtyUniform(DIRTY_LIGHT0 << l);
}
break;
case GE_CMD_LKS0:
case GE_CMD_LKS1: case GE_CMD_LKS1:
case GE_CMD_LKS2:
case GE_CMD_LKS3:
{
int l = cmd - GE_CMD_LKS0;
gstate_c.lightspotCoef[l] = getFloat24(data);
if (diff)
shaderManager_->DirtyUniform(DIRTY_LIGHT0 << l);
}
break;
case GE_CMD_LKO0:
case GE_CMD_LKO1: case GE_CMD_LKO1:
case GE_CMD_LKO2: case GE_CMD_LAC1:
case GE_CMD_LKO3: case GE_CMD_LDC1:
{ case GE_CMD_LSC1:
int l = cmd - GE_CMD_LKO0; shaderManager_->DirtyUniform(DIRTY_LIGHT1);
gstate_c.lightangle[l] = getFloat24(data);
if (diff)
shaderManager_->DirtyUniform(DIRTY_LIGHT0 << l);
}
break; break;
case GE_CMD_LX2:case GE_CMD_LY2:case GE_CMD_LZ2:
case GE_CMD_LAC0:case GE_CMD_LAC1:case GE_CMD_LAC2:case GE_CMD_LAC3: case GE_CMD_LDX2:case GE_CMD_LDY2:case GE_CMD_LDZ2:
case GE_CMD_LDC0:case GE_CMD_LDC1:case GE_CMD_LDC2:case GE_CMD_LDC3: case GE_CMD_LKA2:case GE_CMD_LKB2:case GE_CMD_LKC2:
case GE_CMD_LSC0:case GE_CMD_LSC1:case GE_CMD_LSC2:case GE_CMD_LSC3: case GE_CMD_LKS2:
{ case GE_CMD_LKO2:
float r = (float)(data & 0xff)/255.0f; case GE_CMD_LAC2:
float g = (float)((data>>8) & 0xff)/255.0f; case GE_CMD_LDC2:
float b = (float)(data>>16)/255.0f; case GE_CMD_LSC2:
shaderManager_->DirtyUniform(DIRTY_LIGHT2);
int l = (cmd - GE_CMD_LAC0) / 3; break;
int t = (cmd - GE_CMD_LAC0) % 3; case GE_CMD_LX3:case GE_CMD_LY3:case GE_CMD_LZ3:
gstate_c.lightColor[t][l][0] = r; case GE_CMD_LDX3:case GE_CMD_LDY3:case GE_CMD_LDZ3:
gstate_c.lightColor[t][l][1] = g; case GE_CMD_LKA3:case GE_CMD_LKB3:case GE_CMD_LKC3:
gstate_c.lightColor[t][l][2] = b; case GE_CMD_LKS3:
if (diff) case GE_CMD_LKO3:
shaderManager_->DirtyUniform(DIRTY_LIGHT0 << l); case GE_CMD_LAC3:
} case GE_CMD_LDC3:
case GE_CMD_LSC3:
shaderManager_->DirtyUniform(DIRTY_LIGHT3);
break; break;
case GE_CMD_VIEWPORTX1: case GE_CMD_VIEWPORTX1:

View File

@ -208,7 +208,7 @@ void LinkedShaderDX9::SetFloat(D3DXHANDLE uniform, float value) {
// Utility // Utility
void LinkedShaderDX9::SetColorUniform3(D3DXHANDLE uniform, u32 color) { void LinkedShaderDX9::SetColorUniform3(D3DXHANDLE uniform, u32 color) {
const float col[3] = { const float col[4] = {
((color & 0xFF)) / 255.0f, ((color & 0xFF)) / 255.0f,
((color & 0xFF00) >> 8) / 255.0f, ((color & 0xFF00) >> 8) / 255.0f,
((color & 0xFF0000) >> 16) / 255.0f ((color & 0xFF0000) >> 16) / 255.0f
@ -216,6 +216,12 @@ void LinkedShaderDX9::SetColorUniform3(D3DXHANDLE uniform, u32 color) {
SetFloatArray(uniform, col, 4); SetFloatArray(uniform, col, 4);
} }
void LinkedShaderDX9::SetFloat24Uniform3(D3DXHANDLE uniform, const u32 data[3]) {
const u32 col[4] = {
data[0] >> 8, data[1] >> 8, data[2] >> 8,
};
SetFloatArray(uniform, (const float *)&col[0], 4);
}
void LinkedShaderDX9::SetColorUniform3Alpha(D3DXHANDLE uniform, u32 color, u8 alpha) { void LinkedShaderDX9::SetColorUniform3Alpha(D3DXHANDLE uniform, u32 color, u8 alpha) {
const float col[4] = { const float col[4] = {
@ -452,42 +458,30 @@ void LinkedShaderDX9::updateUniforms() {
} }
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (dirtyUniforms & (DIRTY_LIGHT0 << i)) { if (dirtyUniforms & (DIRTY_LIGHT0 << i)) {
if (gstate.isDirectionalLight(i)) { if (u_lightpos[i] != 0) {
// Prenormalize if (gstate.isDirectionalLight(i)) {
float x = gstate_c.lightpos[i][0]; // Prenormalize
float y = gstate_c.lightpos[i][1]; float x = getFloat24(gstate.lpos[i * 3 + 0]);
float z = gstate_c.lightpos[i][2]; float y = getFloat24(gstate.lpos[i * 3 + 1]);
float len = sqrtf(x*x+y*y+z*z); float z = getFloat24(gstate.lpos[i * 3 + 2]);
if (len == 0.0f) float len = sqrtf(x*x + y*y + z*z);
len = 1.0f; if (len == 0.0f)
else len = 1.0f;
len = 1.0f / len; else
float vec[3] = { x * len, y * len, z * len }; len = 1.0f / len;
if (u_lightpos[i] != 0) float vec[3] = { x * len, y * len, z * len };
SetFloatArray(u_lightpos[i], vec, 3); SetFloatArray(u_lightpos[i], vec, 3);
} else { } else {
if (u_lightpos[i] != 0) SetFloat24Uniform3(u_lightpos[i], &gstate.lpos[i * 3]);
SetFloatArray(u_lightpos[i], gstate_c.lightpos[i], 3); }
} }
if (u_lightdir[i] != 0) if (u_lightdir[i] != 0) SetFloat24Uniform3(u_lightdir[i], &gstate.ldir[i * 3]);
SetFloatArray(u_lightdir[i], gstate_c.lightdir[i], 3); if (u_lightatt[i] != 0) SetFloat24Uniform3(u_lightatt[i], &gstate.latt[i * 3]);
if (u_lightatt[i] != 0) if (u_lightangle[i] != 0) SetFloat(u_lightangle[i], getFloat24(gstate.lcutoff[i]));
SetFloatArray(u_lightatt[i], gstate_c.lightatt[i], 3); if (u_lightspotCoef[i] != 0) SetFloat(u_lightspotCoef[i], getFloat24(gstate.lconv[i]));
if (u_lightambient[i] != 0) SetColorUniform3(u_lightambient[i], gstate.lcolor[i * 3]);
if (u_lightangle[i] != 0) if (u_lightdiffuse[i] != 0) SetColorUniform3(u_lightdiffuse[i], gstate.lcolor[i * 3 + 1]);
SetFloat(u_lightangle[i], gstate_c.lightangle[i]); if (u_lightspecular[i] != 0) SetColorUniform3(u_lightspecular[i], gstate.lcolor[i * 3 + 2]);
if (u_lightspotCoef[i] != 0)
SetFloat(u_lightspotCoef[i], gstate_c.lightspotCoef[i]);
if (u_lightambient[i] != 0)
SetFloatArray(u_lightambient[i], gstate_c.lightColor[0][i], 3);
if (u_lightdiffuse[i] != 0)
SetFloatArray(u_lightdiffuse[i], gstate_c.lightColor[1][i], 3);
if (u_lightspecular[i] != 0)
SetFloatArray(u_lightspecular[i], gstate_c.lightColor[2][i], 3);
} }
} }

View File

@ -41,6 +41,8 @@ protected:
void SetMatrix(D3DXHANDLE uniform, const float* pMatrix); void SetMatrix(D3DXHANDLE uniform, const float* pMatrix);
void SetFloatArray(D3DXHANDLE uniform, const float* pArray, int len); void SetFloatArray(D3DXHANDLE uniform, const float* pArray, int len);
void SetFloat(D3DXHANDLE uniform, float value); void SetFloat(D3DXHANDLE uniform, float value);
void SetFloat24Uniform3(D3DXHANDLE uniform, const u32 data[3]);
public: public:
LinkedShaderDX9(VSShader *vs, PSShader *fs, u32 vertType, bool useHWTransform); LinkedShaderDX9(VSShader *vs, PSShader *fs, u32 vertType, bool useHWTransform);
~LinkedShaderDX9(); ~LinkedShaderDX9();

View File

@ -32,6 +32,7 @@
#include "GPU/ge_constants.h" #include "GPU/ge_constants.h"
#include "GPU/Common/TextureDecoder.h" #include "GPU/Common/TextureDecoder.h"
#include "GPU/Common/TransformCommon.h"
#include "GPU/Directx9/StateMappingDX9.h" #include "GPU/Directx9/StateMappingDX9.h"
#include "GPU/Directx9/TextureCacheDX9.h" #include "GPU/Directx9/TextureCacheDX9.h"
#include "GPU/Directx9/TransformPipelineDX9.h" #include "GPU/Directx9/TransformPipelineDX9.h"
@ -130,169 +131,6 @@ void TransformDrawEngineDX9::DestroyDeviceObjects() {
ClearTrackedVertexArrays(); ClearTrackedVertexArrays();
} }
namespace {
using namespace DX9;
// Convenient way to do precomputation to save the parts of the lighting calculation
// that's common between the many vertices of a draw call.
class Lighter {
public:
Lighter(int vertType);
void Light(float colorOut0[4], float colorOut1[4], const float colorIn[4], const Vec3f &pos, const Vec3f &normal);
private:
Color4 globalAmbient;
Color4 materialEmissive;
Color4 materialAmbient;
Color4 materialDiffuse;
Color4 materialSpecular;
float specCoef_;
// Vec3f viewer_;
bool doShadeMapping_;
int materialUpdate_;
};
Lighter::Lighter(int vertType) {
doShadeMapping_ = gstate.getUVGenMode() == GE_TEXMAP_ENVIRONMENT_MAP;
materialEmissive.GetFromRGB(gstate.materialemissive);
materialEmissive.a = 0.0f;
globalAmbient.GetFromRGB(gstate.ambientcolor);
globalAmbient.GetFromA(gstate.ambientalpha);
materialAmbient.GetFromRGB(gstate.materialambient);
materialAmbient.GetFromA(gstate.materialalpha);
materialDiffuse.GetFromRGB(gstate.materialdiffuse);
materialDiffuse.a = 1.0f;
materialSpecular.GetFromRGB(gstate.materialspecular);
materialSpecular.a = 1.0f;
specCoef_ = getFloat24(gstate.materialspecularcoef);
// viewer_ = Vec3f(-gstate.viewMatrix[9], -gstate.viewMatrix[10], -gstate.viewMatrix[11]);
bool hasColor = (vertType & GE_VTYPE_COL_MASK) != 0;
materialUpdate_ = hasColor ? gstate.materialupdate & 7 : 0;
}
void Lighter::Light(float colorOut0[4], float colorOut1[4], const float colorIn[4], const Vec3f &pos, const Vec3f &norm)
{
// Color are in dx format
Color4 in;
in.a = colorIn[0];
in.r = colorIn[1];
in.g = colorIn[2];
in.b = colorIn[3];
const Color4 *ambient;
if (materialUpdate_ & 1)
ambient = &in;
else
ambient = &materialAmbient;
const Color4 *diffuse;
if (materialUpdate_ & 2)
diffuse = &in;
else
diffuse = &materialDiffuse;
const Color4 *specular;
if (materialUpdate_ & 4)
specular = &in;
else
specular = &materialSpecular;
Color4 lightSum0 = globalAmbient * *ambient + materialEmissive;
Color4 lightSum1(0, 0, 0, 0);
for (int l = 0; l < 4; l++)
{
// can we skip this light?
if (!gstate.isLightChanEnabled(l))
continue;
GELightType type = gstate.getLightType(l);
Vec3f toLight(0,0,0);
Vec3f lightDir(0,0,0);
if (type == GE_LIGHTTYPE_DIRECTIONAL)
toLight = Vec3f(gstate_c.lightpos[l]); // lightdir is for spotlights
else
toLight = Vec3f(gstate_c.lightpos[l]) - pos;
bool doSpecular = gstate.isUsingSpecularLight(l);
bool poweredDiffuse = gstate.isUsingPoweredDiffuseLight(l);
float distanceToLight = toLight.Length();
float dot = 0.0f;
float angle = 0.0f;
float lightScale = 0.0f;
if (distanceToLight > 0.0f) {
toLight /= distanceToLight;
dot = Dot(toLight, norm);
}
// Clamp dot to zero.
if (dot < 0.0f) dot = 0.0f;
if (poweredDiffuse)
dot = powf(dot, specCoef_);
// Attenuation
switch (type) {
case GE_LIGHTTYPE_DIRECTIONAL:
lightScale = 1.0f;
break;
case GE_LIGHTTYPE_POINT:
lightScale = clamp(1.0f / (gstate_c.lightatt[l][0] + gstate_c.lightatt[l][1]*distanceToLight + gstate_c.lightatt[l][2]*distanceToLight*distanceToLight), 0.0f, 1.0f);
break;
case GE_LIGHTTYPE_SPOT:
case GE_LIGHTTYPE_UNKNOWN:
lightDir = gstate_c.lightdir[l];
angle = Dot(toLight.Normalized(), lightDir.Normalized());
if (angle >= gstate_c.lightangle[l])
lightScale = clamp(1.0f / (gstate_c.lightatt[l][0] + gstate_c.lightatt[l][1]*distanceToLight + gstate_c.lightatt[l][2]*distanceToLight*distanceToLight), 0.0f, 1.0f) * powf(angle, gstate_c.lightspotCoef[l]);
break;
default:
// ILLEGAL
break;
}
Color4 lightDiff(gstate_c.lightColor[1][l], 0.0f);
Color4 diff = (lightDiff * *diffuse) * dot;
// Real PSP specular
Vec3f toViewer(0,0,1);
// Better specular
// Vec3f toViewer = (viewer - pos).Normalized();
if (doSpecular)
{
Vec3f halfVec = (toLight + toViewer);
halfVec.Normalize();
dot = Dot(halfVec, norm);
if (dot > 0.0f)
{
Color4 lightSpec(gstate_c.lightColor[2][l], 0.0f);
lightSum1 += (lightSpec * *specular * (powf(dot, specCoef_) * lightScale));
}
}
if (gstate.isLightChanEnabled(l))
{
Color4 lightAmbient(gstate_c.lightColor[0][l], 0.0f);
lightSum0 += (lightAmbient * *ambient + diff) * lightScale;
}
}
// 4?
for (int i = 0; i < 4; i++) {
colorOut0[i] = lightSum0[i] > 1.0f ? 1.0f : lightSum0[i];
colorOut1[i] = lightSum1[i] > 1.0f ? 1.0f : lightSum1[i];
}
}
} // namespace
struct DeclTypeInfo { struct DeclTypeInfo {
u32 type; u32 type;
const char * name; const char * name;
@ -747,8 +585,8 @@ void TransformDrawEngineDX9::SoftwareTransformAndDraw(
case GE_TEXMAP_ENVIRONMENT_MAP: case GE_TEXMAP_ENVIRONMENT_MAP:
// Shade mapping - use two light sources to generate U and V. // Shade mapping - use two light sources to generate U and V.
{ {
Vec3f lightpos0 = Vec3f(gstate_c.lightpos[gstate.getUVLS0()]).Normalized(); Vec3f lightpos0 = Vec3f(&lighter.lpos[gstate.getUVLS0()]).Normalized();
Vec3f lightpos1 = Vec3f(gstate_c.lightpos[gstate.getUVLS1()]).Normalized(); Vec3f lightpos1 = Vec3f(&lighter.lpos[gstate.getUVLS1()]).Normalized();
uv[0] = (1.0f + Dot(lightpos0, normal))/2.0f; uv[0] = (1.0f + Dot(lightpos0, normal))/2.0f;
uv[1] = (1.0f - Dot(lightpos1, normal))/2.0f; uv[1] = (1.0f - Dot(lightpos1, normal))/2.0f;

View File

@ -1498,81 +1498,45 @@ void GLES_GPU::ExecuteOpInternal(u32 op, u32 diff) {
break; break;
case GE_CMD_LX0:case GE_CMD_LY0:case GE_CMD_LZ0: case GE_CMD_LX0:case GE_CMD_LY0:case GE_CMD_LZ0:
case GE_CMD_LX1:case GE_CMD_LY1:case GE_CMD_LZ1:
case GE_CMD_LX2:case GE_CMD_LY2:case GE_CMD_LZ2:
case GE_CMD_LX3:case GE_CMD_LY3:case GE_CMD_LZ3:
{
int n = cmd - GE_CMD_LX0;
int l = n / 3;
int c = n % 3;
gstate_c.lightpos[l][c] = getFloat24(data);
shaderManager_->DirtyUniform(DIRTY_LIGHT0 << l);
}
break;
case GE_CMD_LDX0:case GE_CMD_LDY0:case GE_CMD_LDZ0: case GE_CMD_LDX0:case GE_CMD_LDY0:case GE_CMD_LDZ0:
case GE_CMD_LDX1:case GE_CMD_LDY1:case GE_CMD_LDZ1:
case GE_CMD_LDX2:case GE_CMD_LDY2:case GE_CMD_LDZ2:
case GE_CMD_LDX3:case GE_CMD_LDY3:case GE_CMD_LDZ3:
{
int n = cmd - GE_CMD_LDX0;
int l = n / 3;
int c = n % 3;
gstate_c.lightdir[l][c] = getFloat24(data);
shaderManager_->DirtyUniform(DIRTY_LIGHT0 << l);
}
break;
case GE_CMD_LKA0:case GE_CMD_LKB0:case GE_CMD_LKC0: case GE_CMD_LKA0:case GE_CMD_LKB0:case GE_CMD_LKC0:
case GE_CMD_LKS0: // spot coef ("conv")
case GE_CMD_LKO0: // light angle ("cutoff")
case GE_CMD_LAC0:
case GE_CMD_LDC0:
case GE_CMD_LSC0:
shaderManager_->DirtyUniform(DIRTY_LIGHT0);
break;
case GE_CMD_LX1:case GE_CMD_LY1:case GE_CMD_LZ1:
case GE_CMD_LDX1:case GE_CMD_LDY1:case GE_CMD_LDZ1:
case GE_CMD_LKA1:case GE_CMD_LKB1:case GE_CMD_LKC1: case GE_CMD_LKA1:case GE_CMD_LKB1:case GE_CMD_LKC1:
case GE_CMD_LKA2:case GE_CMD_LKB2:case GE_CMD_LKC2:
case GE_CMD_LKA3:case GE_CMD_LKB3:case GE_CMD_LKC3:
{
int n = cmd - GE_CMD_LKA0;
int l = n / 3;
int c = n % 3;
gstate_c.lightatt[l][c] = getFloat24(data);
shaderManager_->DirtyUniform(DIRTY_LIGHT0 << l);
}
break;
case GE_CMD_LKS0:
case GE_CMD_LKS1: case GE_CMD_LKS1:
case GE_CMD_LKS2:
case GE_CMD_LKS3:
{
int l = cmd - GE_CMD_LKS0;
gstate_c.lightspotCoef[l] = getFloat24(data);
shaderManager_->DirtyUniform(DIRTY_LIGHT0 << l);
}
break;
case GE_CMD_LKO0:
case GE_CMD_LKO1: case GE_CMD_LKO1:
case GE_CMD_LKO2: case GE_CMD_LAC1:
case GE_CMD_LKO3: case GE_CMD_LDC1:
{ case GE_CMD_LSC1:
int l = cmd - GE_CMD_LKO0; shaderManager_->DirtyUniform(DIRTY_LIGHT1);
gstate_c.lightangle[l] = getFloat24(data);
shaderManager_->DirtyUniform(DIRTY_LIGHT0 << l);
}
break; break;
case GE_CMD_LX2:case GE_CMD_LY2:case GE_CMD_LZ2:
case GE_CMD_LAC0:case GE_CMD_LAC1:case GE_CMD_LAC2:case GE_CMD_LAC3: case GE_CMD_LDX2:case GE_CMD_LDY2:case GE_CMD_LDZ2:
case GE_CMD_LDC0:case GE_CMD_LDC1:case GE_CMD_LDC2:case GE_CMD_LDC3: case GE_CMD_LKA2:case GE_CMD_LKB2:case GE_CMD_LKC2:
case GE_CMD_LSC0:case GE_CMD_LSC1:case GE_CMD_LSC2:case GE_CMD_LSC3: case GE_CMD_LKS2:
{ case GE_CMD_LKO2:
float r = (float)(data & 0xff) * (1.0f / 255.0f); case GE_CMD_LAC2:
float g = (float)((data >> 8) & 0xff) * (1.0f / 255.0f); case GE_CMD_LDC2:
float b = (float)(data >> 16) * (1.0f / 255.0f); case GE_CMD_LSC2:
shaderManager_->DirtyUniform(DIRTY_LIGHT2);
int l = (cmd - GE_CMD_LAC0) / 3; break;
int t = (cmd - GE_CMD_LAC0) % 3; case GE_CMD_LX3:case GE_CMD_LY3:case GE_CMD_LZ3:
gstate_c.lightColor[t][l][0] = r; case GE_CMD_LDX3:case GE_CMD_LDY3:case GE_CMD_LDZ3:
gstate_c.lightColor[t][l][1] = g; case GE_CMD_LKA3:case GE_CMD_LKB3:case GE_CMD_LKC3:
gstate_c.lightColor[t][l][2] = b; case GE_CMD_LKS3:
shaderManager_->DirtyUniform(DIRTY_LIGHT0 << l); case GE_CMD_LKO3:
} case GE_CMD_LAC3:
case GE_CMD_LDC3:
case GE_CMD_LSC3:
shaderManager_->DirtyUniform(DIRTY_LIGHT3);
break; break;
case GE_CMD_VIEWPORTX1: case GE_CMD_VIEWPORTX1:

View File

@ -308,6 +308,13 @@ static void SetColorUniform3ExtraFloat(int uniform, u32 color, float extra) {
glUniform4fv(uniform, 1, col); glUniform4fv(uniform, 1, col);
} }
static void SetFloat24Uniform3(int uniform, const u32 data[3]) {
const u32 col[3] = {
data[0] << 8, data[1] << 8, data[2] << 8
};
glUniform3fv(uniform, 1, (const GLfloat *)&col[0]);
}
static void SetMatrix4x3(int uniform, const float *m4x3) { static void SetMatrix4x3(int uniform, const float *m4x3) {
float m4x4[16]; float m4x4[16];
ConvertMatrix4x3To4x4(m4x4, m4x3); ConvertMatrix4x3To4x4(m4x4, m4x3);
@ -532,28 +539,30 @@ void LinkedShader::UpdateUniforms(u32 vertType) {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (dirty & (DIRTY_LIGHT0 << i)) { if (dirty & (DIRTY_LIGHT0 << i)) {
if (gstate.isDirectionalLight(i)) { if (u_lightpos[i] != -1) {
// Prenormalize if (gstate.isDirectionalLight(i)) {
float x = gstate_c.lightpos[i][0]; // Prenormalize
float y = gstate_c.lightpos[i][1]; float x = getFloat24(gstate.lpos[i * 3 + 0]);
float z = gstate_c.lightpos[i][2]; float y = getFloat24(gstate.lpos[i * 3 + 1]);
float len = sqrtf(x*x+y*y+z*z); float z = getFloat24(gstate.lpos[i * 3 + 2]);
if (len == 0.0f) float len = sqrtf(x*x + y*y + z*z);
len = 1.0f; if (len == 0.0f)
else len = 1.0f;
len = 1.0f / len; else
float vec[3] = { x * len, y * len, z * len }; len = 1.0f / len;
if (u_lightpos[i] != -1) glUniform3fv(u_lightpos[i], 1, vec); float vec[3] = { x * len, y * len, z * len };
} else { glUniform3fv(u_lightpos[i], 1, vec);
if (u_lightpos[i] != -1) glUniform3fv(u_lightpos[i], 1, gstate_c.lightpos[i]); } else {
SetFloat24Uniform3(u_lightpos[i], &gstate.lpos[i * 3]);
}
} }
if (u_lightdir[i] != -1) glUniform3fv(u_lightdir[i], 1, gstate_c.lightdir[i]); if (u_lightdir[i] != -1) SetFloat24Uniform3(u_lightdir[i], &gstate.ldir[i * 3]);
if (u_lightatt[i] != -1) glUniform3fv(u_lightatt[i], 1, gstate_c.lightatt[i]); if (u_lightatt[i] != -1) SetFloat24Uniform3(u_lightatt[i], &gstate.latt[i * 3]);
if (u_lightangle[i] != -1) glUniform1f(u_lightangle[i], gstate_c.lightangle[i]); if (u_lightangle[i] != -1) glUniform1f(u_lightangle[i], getFloat24(gstate.lcutoff[i]));
if (u_lightspotCoef[i] != -1) glUniform1f(u_lightspotCoef[i], gstate_c.lightspotCoef[i]); if (u_lightspotCoef[i] != -1) glUniform1f(u_lightspotCoef[i], getFloat24(gstate.lconv[i]));
if (u_lightambient[i] != -1) glUniform3fv(u_lightambient[i], 1, gstate_c.lightColor[0][i]); if (u_lightambient[i] != -1) SetColorUniform3(u_lightambient[i], gstate.lcolor[i * 3]);
if (u_lightdiffuse[i] != -1) glUniform3fv(u_lightdiffuse[i], 1, gstate_c.lightColor[1][i]); if (u_lightdiffuse[i] != -1) SetColorUniform3(u_lightdiffuse[i], gstate.lcolor[i * 3 + 1]);
if (u_lightspecular[i] != -1) glUniform3fv(u_lightspecular[i], 1, gstate_c.lightColor[2][i]); if (u_lightspecular[i] != -1) SetColorUniform3(u_lightspecular[i], gstate.lcolor[i * 3 + 2]);
} }
} }
} }

View File

@ -22,6 +22,7 @@
#include "GPU/GPUState.h" #include "GPU/GPUState.h"
#include "GPU/Math3D.h" #include "GPU/Math3D.h"
#include "GPU/Common/VertexDecoderCommon.h" #include "GPU/Common/VertexDecoderCommon.h"
#include "GPU/Common/TransformCommon.h"
#include "GPU/GLES/ShaderManager.h" #include "GPU/GLES/ShaderManager.h"
#include "GPU/GLES/TransformPipeline.h" #include "GPU/GLES/TransformPipeline.h"
@ -44,160 +45,6 @@
extern const GLuint glprim[8]; extern const GLuint glprim[8];
// Check for max first as clamping to max is more common than min when lighting.
inline float clamp(float in, float min, float max) {
return in > max ? max : (in < min ? min : in);
}
// Convenient way to do precomputation to save the parts of the lighting calculation
// that's common between the many vertices of a draw call.
class Lighter {
public:
Lighter(int vertType);
void Light(float colorOut0[4], float colorOut1[4], const float colorIn[4], const Vec3f &pos, const Vec3f &normal);
private:
Color4 globalAmbient;
Color4 materialEmissive;
Color4 materialAmbient;
Color4 materialDiffuse;
Color4 materialSpecular;
float specCoef_;
// Vec3f viewer_;
bool doShadeMapping_;
int materialUpdate_;
};
Lighter::Lighter(int vertType) {
if (!gstate.isLightingEnabled())
return;
doShadeMapping_ = gstate.getUVGenMode() == GE_TEXMAP_ENVIRONMENT_MAP;
materialEmissive.GetFromRGB(gstate.materialemissive);
materialEmissive.a = 0.0f;
globalAmbient.GetFromRGB(gstate.ambientcolor);
globalAmbient.GetFromA(gstate.ambientalpha);
materialAmbient.GetFromRGB(gstate.materialambient);
materialAmbient.GetFromA(gstate.materialalpha);
materialDiffuse.GetFromRGB(gstate.materialdiffuse);
materialDiffuse.a = 1.0f;
materialSpecular.GetFromRGB(gstate.materialspecular);
materialSpecular.a = 1.0f;
specCoef_ = getFloat24(gstate.materialspecularcoef);
// viewer_ = Vec3f(-gstate.viewMatrix[9], -gstate.viewMatrix[10], -gstate.viewMatrix[11]);
bool hasColor = (vertType & GE_VTYPE_COL_MASK) != 0;
materialUpdate_ = hasColor ? gstate.materialupdate & 7 : 0;
}
void Lighter::Light(float colorOut0[4], float colorOut1[4], const float colorIn[4], const Vec3f &pos, const Vec3f &norm) {
Color4 in(colorIn);
const Color4 *ambient;
if (materialUpdate_ & 1)
ambient = &in;
else
ambient = &materialAmbient;
const Color4 *diffuse;
if (materialUpdate_ & 2)
diffuse = &in;
else
diffuse = &materialDiffuse;
const Color4 *specular;
if (materialUpdate_ & 4)
specular = &in;
else
specular = &materialSpecular;
Color4 lightSum0 = globalAmbient * *ambient + materialEmissive;
Color4 lightSum1(0, 0, 0, 0);
for (int l = 0; l < 4; l++) {
// can we skip this light?
if (!gstate.isLightChanEnabled(l))
continue;
GELightType type = gstate.getLightType(l);
Vec3f toLight(0,0,0);
Vec3f lightDir(0,0,0);
if (type == GE_LIGHTTYPE_DIRECTIONAL)
toLight = Vec3f(gstate_c.lightpos[l]); // lightdir is for spotlights
else
toLight = Vec3f(gstate_c.lightpos[l]) - pos;
bool doSpecular = gstate.isUsingSpecularLight(l);
bool poweredDiffuse = gstate.isUsingPoweredDiffuseLight(l);
float distanceToLight = toLight.Length();
float dot = 0.0f;
float angle = 0.0f;
float lightScale = 0.0f;
if (distanceToLight > 0.0f) {
toLight /= distanceToLight;
dot = Dot(toLight, norm);
}
// Clamp dot to zero.
if (dot < 0.0f) dot = 0.0f;
if (poweredDiffuse)
dot = powf(dot, specCoef_);
// Attenuation
switch (type) {
case GE_LIGHTTYPE_DIRECTIONAL:
lightScale = 1.0f;
break;
case GE_LIGHTTYPE_POINT:
lightScale = clamp(1.0f / (gstate_c.lightatt[l][0] + gstate_c.lightatt[l][1]*distanceToLight + gstate_c.lightatt[l][2]*distanceToLight*distanceToLight), 0.0f, 1.0f);
break;
case GE_LIGHTTYPE_SPOT:
case GE_LIGHTTYPE_UNKNOWN:
lightDir = gstate_c.lightdir[l];
angle = Dot(toLight.Normalized(), lightDir.Normalized());
if (angle >= gstate_c.lightangle[l])
lightScale = clamp(1.0f / (gstate_c.lightatt[l][0] + gstate_c.lightatt[l][1]*distanceToLight + gstate_c.lightatt[l][2]*distanceToLight*distanceToLight), 0.0f, 1.0f) * powf(angle, gstate_c.lightspotCoef[l]);
break;
default:
// ILLEGAL
break;
}
Color4 lightDiff(gstate_c.lightColor[1][l], 0.0f);
Color4 diff = (lightDiff * *diffuse) * dot;
// Real PSP specular
Vec3f toViewer(0,0,1);
// Better specular
// Vec3f toViewer = (viewer - pos).Normalized();
if (doSpecular) {
Vec3f halfVec = (toLight + toViewer);
halfVec.Normalize();
dot = Dot(halfVec, norm);
if (dot > 0.0f) {
Color4 lightSpec(gstate_c.lightColor[2][l], 0.0f);
lightSum1 += (lightSpec * *specular * (powf(dot, specCoef_) * lightScale));
}
}
if (gstate.isLightChanEnabled(l)) {
Color4 lightAmbient(gstate_c.lightColor[0][l], 0.0f);
lightSum0 += (lightAmbient * *ambient + diff) * lightScale;
}
}
// 4?
for (int i = 0; i < 4; i++) {
colorOut0[i] = lightSum0[i] > 1.0f ? 1.0f : lightSum0[i];
colorOut1[i] = lightSum1[i] > 1.0f ? 1.0f : lightSum1[i];
}
}
// The verts are in the order: BR BL TL TR // The verts are in the order: BR BL TL TR
static void SwapUVs(TransformedVertex &a, TransformedVertex &b) { static void SwapUVs(TransformedVertex &a, TransformedVertex &b) {
float tempu = a.u; float tempu = a.u;
@ -498,8 +345,8 @@ void TransformDrawEngine::SoftwareTransformAndDraw(
case GE_TEXMAP_ENVIRONMENT_MAP: case GE_TEXMAP_ENVIRONMENT_MAP:
// Shade mapping - use two light sources to generate U and V. // Shade mapping - use two light sources to generate U and V.
{ {
Vec3f lightpos0 = Vec3f(gstate_c.lightpos[gstate.getUVLS0()]).Normalized(); Vec3f lightpos0 = Vec3f(&lighter.lpos[gstate.getUVLS0() * 3]).Normalized();
Vec3f lightpos1 = Vec3f(gstate_c.lightpos[gstate.getUVLS1()]).Normalized(); Vec3f lightpos1 = Vec3f(&lighter.lpos[gstate.getUVLS1() * 3]).Normalized();
uv[0] = (1.0f + Dot(lightpos0, normal))/2.0f; uv[0] = (1.0f + Dot(lightpos0, normal))/2.0f;
uv[1] = (1.0f + Dot(lightpos1, normal))/2.0f; uv[1] = (1.0f + Dot(lightpos1, normal))/2.0f;

View File

@ -244,41 +244,3 @@ private:
UVScale *uvScale; UVScale *uvScale;
}; };
// Only used by SW transform
struct Color4 {
float r, g, b, a;
Color4() : r(0), g(0), b(0), a(0) { }
Color4(float _r, float _g, float _b, float _a=1.0f)
: r(_r), g(_g), b(_b), a(_a) {
}
Color4(const float in[4]) {r=in[0];g=in[1];b=in[2];a=in[3];}
Color4(const float in[3], float alpha) {r=in[0];g=in[1];b=in[2];a=alpha;}
const float &operator [](int i) const {return *(&r + i);}
Color4 operator *(float f) const {
return Color4(f*r,f*g,f*b,f*a);
}
Color4 operator *(const Color4 &c) const {
return Color4(r*c.r,g*c.g,b*c.b,a*c.a);
}
Color4 operator +(const Color4 &c) const {
return Color4(r+c.r,g+c.g,b+c.b,a+c.a);
}
void operator +=(const Color4 &c) {
r+=c.r;
g+=c.g;
b+=c.b;
a+=c.a;
}
void GetFromRGB(u32 col) {
b = ((col>>16) & 0xff)/255.0f;
g = ((col>>8) & 0xff)/255.0f;
r = ((col>>0) & 0xff)/255.0f;
}
void GetFromA(u32 col) {
a = (col&0xff)/255.0f;
}
};

View File

@ -171,6 +171,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClInclude> </ClInclude>
<ClInclude Include="Common\TransformCommon.h" />
<ClInclude Include="Common\VertexDecoderCommon.h" /> <ClInclude Include="Common\VertexDecoderCommon.h" />
<ClInclude Include="Debugger\Breakpoints.h" /> <ClInclude Include="Debugger\Breakpoints.h" />
<ClInclude Include="Debugger\Stepping.h" /> <ClInclude Include="Debugger\Stepping.h" />
@ -222,6 +223,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="Common\TransformCommon.cpp" />
<ClCompile Include="Common\VertexDecoderCommon.cpp" /> <ClCompile Include="Common\VertexDecoderCommon.cpp" />
<ClCompile Include="Debugger\Breakpoints.cpp" /> <ClCompile Include="Debugger\Breakpoints.cpp" />
<ClCompile Include="Debugger\Stepping.cpp" /> <ClCompile Include="Debugger\Stepping.cpp" />
@ -281,4 +283,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@ -162,6 +162,9 @@
<ClInclude Include="Common\TextureDecoderNEON.h"> <ClInclude Include="Common\TextureDecoderNEON.h">
<Filter>Common</Filter> <Filter>Common</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Common\TransformCommon.h">
<Filter>Common</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Math3D.cpp"> <ClCompile Include="Math3D.cpp">
@ -302,6 +305,9 @@
<ClCompile Include="GLES\VertexDecoderX86.cpp"> <ClCompile Include="GLES\VertexDecoderX86.cpp">
<Filter>GLES</Filter> <Filter>GLES</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Common\TransformCommon.cpp">
<Filter>Common</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="CMakeLists.txt" /> <None Include="CMakeLists.txt" />

View File

@ -270,7 +270,7 @@ struct GPUStateCache_v0
}; };
void GPUStateCache::DoState(PointerWrap &p) { void GPUStateCache::DoState(PointerWrap &p) {
auto s = p.Section("GPUStateCache", 0, 1); auto s = p.Section("GPUStateCache", 0, 2);
if (!s) { if (!s) {
// Old state, this was not versioned. // Old state, this was not versioned.
GPUStateCache_v0 old; GPUStateCache_v0 old;
@ -302,12 +302,19 @@ void GPUStateCache::DoState(PointerWrap &p) {
p.Do(flipTexture); p.Do(flipTexture);
} }
p.Do(lightpos); if (s < 2) {
p.Do(lightdir); float l12[12];
p.Do(lightatt); float l4[3];
p.Do(lightColor); p.Do(l12); // lightpos
p.Do(lightangle); p.Do(l12); // lightdir
p.Do(lightspotCoef); p.Do(l12); // lightattr
p.Do(l12); // lightcol0
p.Do(l12); // lightcol1
p.Do(l12); // lightcol2
p.Do(l4); // lightangle
p.Do(l4); // lightspot
}
p.Do(morphWeights); p.Do(morphWeights);
p.Do(curTextureWidth); p.Do(curTextureWidth);

View File

@ -458,12 +458,6 @@ struct GPUStateCache
UVScale uv; UVScale uv;
bool flipTexture; bool flipTexture;
float lightpos[4][3];
float lightdir[4][3];
float lightatt[4][3];
float lightColor[3][4][3]; // Ambient Diffuse Specular
float lightangle[4]; // spotlight cone angle (cosine)
float lightspotCoef[4]; // spotlight dropoff
float morphWeights[8]; float morphWeights[8];
u32 curTextureWidth; u32 curTextureWidth;

View File

@ -385,7 +385,6 @@ void NullGPU::ExecuteOp(u32 op, u32 diff) {
int c = n % 3; int c = n % 3;
float val = getFloat24(data); float val = getFloat24(data);
DEBUG_LOG(G3D,"DL Light %i %c pos: %f", l, c+'X', val); DEBUG_LOG(G3D,"DL Light %i %c pos: %f", l, c+'X', val);
gstate_c.lightpos[l][c] = val;
} }
break; break;
@ -399,7 +398,6 @@ void NullGPU::ExecuteOp(u32 op, u32 diff) {
int c = n % 3; int c = n % 3;
float val = getFloat24(data); float val = getFloat24(data);
DEBUG_LOG(G3D,"DL Light %i %c dir: %f", l, c+'X', val); DEBUG_LOG(G3D,"DL Light %i %c dir: %f", l, c+'X', val);
gstate_c.lightdir[l][c] = val;
} }
break; break;
@ -413,7 +411,6 @@ void NullGPU::ExecuteOp(u32 op, u32 diff) {
int c = n % 3; int c = n % 3;
float val = getFloat24(data); float val = getFloat24(data);
DEBUG_LOG(G3D,"DL Light %i %c att: %f", l, c+'X', val); DEBUG_LOG(G3D,"DL Light %i %c att: %f", l, c+'X', val);
gstate_c.lightatt[l][c] = val;
} }
break; break;
@ -428,10 +425,8 @@ void NullGPU::ExecuteOp(u32 op, u32 diff) {
int l = (cmd - GE_CMD_LAC0) / 3; int l = (cmd - GE_CMD_LAC0) / 3;
int t = (cmd - GE_CMD_LAC0) % 3; int t = (cmd - GE_CMD_LAC0) % 3;
gstate_c.lightColor[t][l][0] = r; // DEBUG_LOG(G3D, "DL Light color %i %c att: %f", l, c + 'X', val);
gstate_c.lightColor[t][l][1] = g; }
gstate_c.lightColor[t][l][2] = b;
}
break; break;
case GE_CMD_VIEWPORTX1: case GE_CMD_VIEWPORTX1:

View File

@ -62,6 +62,7 @@ SOURCES += $$P/Core/*.cpp \ # Core
$$P/GPU/Common/IndexGenerator.cpp \ $$P/GPU/Common/IndexGenerator.cpp \
$$P/GPU/Common/TextureDecoder.cpp \ $$P/GPU/Common/TextureDecoder.cpp \
$$P/GPU/Common/VertexDecoderCommon.cpp \ $$P/GPU/Common/VertexDecoderCommon.cpp \
$$P/GPU/Common/TransformCommon.cpp \
$$P/GPU/Common/PostShader.cpp \ $$P/GPU/Common/PostShader.cpp \
$$P/ext/libkirk/*.c \ # Kirk $$P/ext/libkirk/*.c \ # Kirk
$$P/ext/xxhash.c \ # xxHash $$P/ext/xxhash.c \ # xxHash

View File

@ -137,6 +137,7 @@ EXEC_AND_LIB_FILES := \
$(SRC)/GPU/GeDisasm.cpp \ $(SRC)/GPU/GeDisasm.cpp \
$(SRC)/GPU/Common/IndexGenerator.cpp.arm \ $(SRC)/GPU/Common/IndexGenerator.cpp.arm \
$(SRC)/GPU/Common/VertexDecoderCommon.cpp.arm \ $(SRC)/GPU/Common/VertexDecoderCommon.cpp.arm \
$(SRC)/GPU/Common/TransformCommon.cpp.arm \
$(SRC)/GPU/Common/TextureDecoder.cpp \ $(SRC)/GPU/Common/TextureDecoder.cpp \
$(SRC)/GPU/Common/PostShader.cpp \ $(SRC)/GPU/Common/PostShader.cpp \
$(SRC)/GPU/Debugger/Breakpoints.cpp \ $(SRC)/GPU/Debugger/Breakpoints.cpp \