diff --git a/GPU/Common/SoftwareLighting.h b/GPU/Common/SoftwareLighting.h new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/GPU/Common/TransformCommon.cpp b/GPU/Common/TransformCommon.cpp new file mode 100644 index 000000000000..ee47dea1472d --- /dev/null +++ b/GPU/Common/TransformCommon.cpp @@ -0,0 +1,177 @@ + +// 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 + +#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) { + 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; + + // TODO: Easy SSE + for (int l = 0; l < 12; l++) { + lpos[l] = getFloat24(gstate.lpos[l]); + ldir[l] = getFloat24(gstate.ldir[l]); + latt[l] = getFloat24(gstate.latt[l]); + } + for (int l = 0; l < 4; l++) { + lcutoff[l] = getFloat24(gstate.lcutoff[l]); + lconv[l] = getFloat24(gstate.lconv[l]); + } + + for (int l = 0; l < 4; l++) { + 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 = ∈ + else + ambient = &materialAmbient; + + const Color4 *diffuse; + if (materialUpdate_ & 2) + diffuse = ∈ + else + diffuse = &materialDiffuse; + + const Color4 *specular; + if (materialUpdate_ & 4) + specular = ∈ + 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]; + } +} \ No newline at end of file diff --git a/GPU/Common/TransformCommon.h b/GPU/Common/TransformCommon.h new file mode 100644 index 000000000000..0c528133c51b --- /dev/null +++ b/GPU/Common/TransformCommon.h @@ -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 +#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]; +}; + diff --git a/GPU/Directx9/GPU_DX9.cpp b/GPU/Directx9/GPU_DX9.cpp index 724f543f43f4..685ea2b01612 100644 --- a/GPU/Directx9/GPU_DX9.cpp +++ b/GPU/Directx9/GPU_DX9.cpp @@ -953,89 +953,46 @@ void DIRECTX9_GPU::ExecuteOp(u32 op, u32 diff) { case GE_CMD_LIGHTTYPE2: case GE_CMD_LIGHTTYPE3: break; - 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_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_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); - } + 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_LKS0: + 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_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_LAC1: + case GE_CMD_LDC1: + case GE_CMD_LSC1: + shaderManager_->DirtyUniform(DIRTY_LIGHT1); + break; + case GE_CMD_LX2:case GE_CMD_LY2:case GE_CMD_LZ2: + case GE_CMD_LDX2:case GE_CMD_LDY2:case GE_CMD_LDZ2: + case GE_CMD_LKA2:case GE_CMD_LKB2:case GE_CMD_LKC2: + case GE_CMD_LKS2: case GE_CMD_LKO2: - case GE_CMD_LKO3: - { - int l = cmd - GE_CMD_LKO0; - gstate_c.lightangle[l] = getFloat24(data); - if (diff) - shaderManager_->DirtyUniform(DIRTY_LIGHT0 << l); - } + case GE_CMD_LAC2: + case GE_CMD_LDC2: + case GE_CMD_LSC2: + shaderManager_->DirtyUniform(DIRTY_LIGHT2); break; - - case GE_CMD_LAC0:case GE_CMD_LAC1:case GE_CMD_LAC2:case GE_CMD_LAC3: - case GE_CMD_LDC0:case GE_CMD_LDC1:case GE_CMD_LDC2:case GE_CMD_LDC3: - case GE_CMD_LSC0:case GE_CMD_LSC1:case GE_CMD_LSC2:case GE_CMD_LSC3: - { - float r = (float)(data & 0xff)/255.0f; - float g = (float)((data>>8) & 0xff)/255.0f; - float b = (float)(data>>16)/255.0f; - - int l = (cmd - GE_CMD_LAC0) / 3; - int t = (cmd - GE_CMD_LAC0) % 3; - gstate_c.lightColor[t][l][0] = r; - gstate_c.lightColor[t][l][1] = g; - gstate_c.lightColor[t][l][2] = b; - if (diff) - shaderManager_->DirtyUniform(DIRTY_LIGHT0 << l); - } + case GE_CMD_LX3:case GE_CMD_LY3:case GE_CMD_LZ3: + case GE_CMD_LDX3:case GE_CMD_LDY3:case GE_CMD_LDZ3: + case GE_CMD_LKA3:case GE_CMD_LKB3:case GE_CMD_LKC3: + case GE_CMD_LKS3: + case GE_CMD_LKO3: + case GE_CMD_LAC3: + case GE_CMD_LDC3: + case GE_CMD_LSC3: + shaderManager_->DirtyUniform(DIRTY_LIGHT3); break; case GE_CMD_VIEWPORTX1: diff --git a/GPU/Directx9/ShaderManagerDX9.cpp b/GPU/Directx9/ShaderManagerDX9.cpp index a11366f10b97..021fc118afb3 100644 --- a/GPU/Directx9/ShaderManagerDX9.cpp +++ b/GPU/Directx9/ShaderManagerDX9.cpp @@ -208,7 +208,7 @@ void LinkedShaderDX9::SetFloat(D3DXHANDLE uniform, float value) { // Utility void LinkedShaderDX9::SetColorUniform3(D3DXHANDLE uniform, u32 color) { - const float col[3] = { + const float col[4] = { ((color & 0xFF)) / 255.0f, ((color & 0xFF00) >> 8) / 255.0f, ((color & 0xFF0000) >> 16) / 255.0f @@ -216,6 +216,12 @@ void LinkedShaderDX9::SetColorUniform3(D3DXHANDLE uniform, u32 color) { 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) { const float col[4] = { @@ -452,42 +458,30 @@ void LinkedShaderDX9::updateUniforms() { } for (int i = 0; i < 4; i++) { if (dirtyUniforms & (DIRTY_LIGHT0 << i)) { - if (gstate.isDirectionalLight(i)) { - // Prenormalize - float x = gstate_c.lightpos[i][0]; - float y = gstate_c.lightpos[i][1]; - float z = gstate_c.lightpos[i][2]; - float len = sqrtf(x*x+y*y+z*z); - if (len == 0.0f) - len = 1.0f; - else - len = 1.0f / len; - float vec[3] = { x * len, y * len, z * len }; - if (u_lightpos[i] != 0) + if (u_lightpos[i] != 0) { + if (gstate.isDirectionalLight(i)) { + // Prenormalize + float x = getFloat24(gstate.lpos[i * 3 + 0]); + float y = getFloat24(gstate.lpos[i * 3 + 1]); + float z = getFloat24(gstate.lpos[i * 3 + 2]); + float len = sqrtf(x*x + y*y + z*z); + if (len == 0.0f) + len = 1.0f; + else + len = 1.0f / len; + float vec[3] = { x * len, y * len, z * len }; SetFloatArray(u_lightpos[i], vec, 3); - } else { - if (u_lightpos[i] != 0) - SetFloatArray(u_lightpos[i], gstate_c.lightpos[i], 3); + } else { + SetFloat24Uniform3(u_lightpos[i], &gstate.lpos[i * 3]); + } } - if (u_lightdir[i] != 0) - SetFloatArray(u_lightdir[i], gstate_c.lightdir[i], 3); - if (u_lightatt[i] != 0) - SetFloatArray(u_lightatt[i], gstate_c.lightatt[i], 3); - - if (u_lightangle[i] != 0) - SetFloat(u_lightangle[i], gstate_c.lightangle[i]); - - 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); + if (u_lightdir[i] != 0) SetFloat24Uniform3(u_lightdir[i], &gstate.ldir[i * 3]); + if (u_lightatt[i] != 0) SetFloat24Uniform3(u_lightatt[i], &gstate.latt[i * 3]); + if (u_lightangle[i] != 0) SetFloat(u_lightangle[i], getFloat24(gstate.lcutoff[i])); + 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_lightdiffuse[i] != 0) SetColorUniform3(u_lightdiffuse[i], gstate.lcolor[i * 3 + 1]); + if (u_lightspecular[i] != 0) SetColorUniform3(u_lightspecular[i], gstate.lcolor[i * 3 + 2]); } } diff --git a/GPU/Directx9/ShaderManagerDX9.h b/GPU/Directx9/ShaderManagerDX9.h index 17c8ef8b8488..8a4885cf315a 100644 --- a/GPU/Directx9/ShaderManagerDX9.h +++ b/GPU/Directx9/ShaderManagerDX9.h @@ -41,6 +41,8 @@ class LinkedShaderDX9 void SetMatrix(D3DXHANDLE uniform, const float* pMatrix); void SetFloatArray(D3DXHANDLE uniform, const float* pArray, int len); void SetFloat(D3DXHANDLE uniform, float value); + void SetFloat24Uniform3(D3DXHANDLE uniform, const u32 data[3]); + public: LinkedShaderDX9(VSShader *vs, PSShader *fs, u32 vertType, bool useHWTransform); ~LinkedShaderDX9(); diff --git a/GPU/Directx9/TransformPipelineDX9.cpp b/GPU/Directx9/TransformPipelineDX9.cpp index bdb75b002a5d..7c2c3c30c01c 100644 --- a/GPU/Directx9/TransformPipelineDX9.cpp +++ b/GPU/Directx9/TransformPipelineDX9.cpp @@ -32,6 +32,7 @@ #include "GPU/ge_constants.h" #include "GPU/Common/TextureDecoder.h" +#include "GPU/Common/TransformCommon.h" #include "GPU/Directx9/StateMappingDX9.h" #include "GPU/Directx9/TextureCacheDX9.h" #include "GPU/Directx9/TransformPipelineDX9.h" @@ -130,169 +131,6 @@ void TransformDrawEngineDX9::DestroyDeviceObjects() { 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 = ∈ - else - ambient = &materialAmbient; - - const Color4 *diffuse; - if (materialUpdate_ & 2) - diffuse = ∈ - else - diffuse = &materialDiffuse; - - const Color4 *specular; - if (materialUpdate_ & 4) - specular = ∈ - 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 { u32 type; const char * name; @@ -747,8 +585,8 @@ void TransformDrawEngineDX9::SoftwareTransformAndDraw( case GE_TEXMAP_ENVIRONMENT_MAP: // Shade mapping - use two light sources to generate U and V. { - Vec3f lightpos0 = Vec3f(gstate_c.lightpos[gstate.getUVLS0()]).Normalized(); - Vec3f lightpos1 = Vec3f(gstate_c.lightpos[gstate.getUVLS1()]).Normalized(); + Vec3f lightpos0 = Vec3f(&lighter.lpos[gstate.getUVLS0()]).Normalized(); + Vec3f lightpos1 = Vec3f(&lighter.lpos[gstate.getUVLS1()]).Normalized(); uv[0] = (1.0f + Dot(lightpos0, normal))/2.0f; uv[1] = (1.0f - Dot(lightpos1, normal))/2.0f; diff --git a/GPU/GLES/GLES_GPU.cpp b/GPU/GLES/GLES_GPU.cpp index 3ea6d88e6e6c..3f222e12b904 100644 --- a/GPU/GLES/GLES_GPU.cpp +++ b/GPU/GLES/GLES_GPU.cpp @@ -1498,81 +1498,45 @@ void GLES_GPU::ExecuteOpInternal(u32 op, u32 diff) { break; 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_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_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); - } + 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_LKS0: + 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_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_LAC1: + case GE_CMD_LDC1: + case GE_CMD_LSC1: + shaderManager_->DirtyUniform(DIRTY_LIGHT1); + break; + case GE_CMD_LX2:case GE_CMD_LY2:case GE_CMD_LZ2: + case GE_CMD_LDX2:case GE_CMD_LDY2:case GE_CMD_LDZ2: + case GE_CMD_LKA2:case GE_CMD_LKB2:case GE_CMD_LKC2: + case GE_CMD_LKS2: case GE_CMD_LKO2: - case GE_CMD_LKO3: - { - int l = cmd - GE_CMD_LKO0; - gstate_c.lightangle[l] = getFloat24(data); - shaderManager_->DirtyUniform(DIRTY_LIGHT0 << l); - } + case GE_CMD_LAC2: + case GE_CMD_LDC2: + case GE_CMD_LSC2: + shaderManager_->DirtyUniform(DIRTY_LIGHT2); break; - - case GE_CMD_LAC0:case GE_CMD_LAC1:case GE_CMD_LAC2:case GE_CMD_LAC3: - case GE_CMD_LDC0:case GE_CMD_LDC1:case GE_CMD_LDC2:case GE_CMD_LDC3: - case GE_CMD_LSC0:case GE_CMD_LSC1:case GE_CMD_LSC2:case GE_CMD_LSC3: - { - 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); - - int l = (cmd - GE_CMD_LAC0) / 3; - int t = (cmd - GE_CMD_LAC0) % 3; - gstate_c.lightColor[t][l][0] = r; - gstate_c.lightColor[t][l][1] = g; - gstate_c.lightColor[t][l][2] = b; - shaderManager_->DirtyUniform(DIRTY_LIGHT0 << l); - } + case GE_CMD_LX3:case GE_CMD_LY3:case GE_CMD_LZ3: + case GE_CMD_LDX3:case GE_CMD_LDY3:case GE_CMD_LDZ3: + case GE_CMD_LKA3:case GE_CMD_LKB3:case GE_CMD_LKC3: + case GE_CMD_LKS3: + case GE_CMD_LKO3: + case GE_CMD_LAC3: + case GE_CMD_LDC3: + case GE_CMD_LSC3: + shaderManager_->DirtyUniform(DIRTY_LIGHT3); break; case GE_CMD_VIEWPORTX1: diff --git a/GPU/GLES/ShaderManager.cpp b/GPU/GLES/ShaderManager.cpp index d6010ca4fc4f..6d9e894c2ca5 100644 --- a/GPU/GLES/ShaderManager.cpp +++ b/GPU/GLES/ShaderManager.cpp @@ -308,6 +308,13 @@ static void SetColorUniform3ExtraFloat(int uniform, u32 color, float extra) { 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) { float m4x4[16]; ConvertMatrix4x3To4x4(m4x4, m4x3); @@ -532,28 +539,30 @@ void LinkedShader::UpdateUniforms(u32 vertType) { for (int i = 0; i < 4; i++) { if (dirty & (DIRTY_LIGHT0 << i)) { - if (gstate.isDirectionalLight(i)) { - // Prenormalize - float x = gstate_c.lightpos[i][0]; - float y = gstate_c.lightpos[i][1]; - float z = gstate_c.lightpos[i][2]; - float len = sqrtf(x*x+y*y+z*z); - if (len == 0.0f) - len = 1.0f; - else - len = 1.0f / len; - float vec[3] = { x * len, y * len, z * len }; - if (u_lightpos[i] != -1) glUniform3fv(u_lightpos[i], 1, vec); - } else { - if (u_lightpos[i] != -1) glUniform3fv(u_lightpos[i], 1, gstate_c.lightpos[i]); + if (u_lightpos[i] != -1) { + if (gstate.isDirectionalLight(i)) { + // Prenormalize + float x = getFloat24(gstate.lpos[i * 3 + 0]); + float y = getFloat24(gstate.lpos[i * 3 + 1]); + float z = getFloat24(gstate.lpos[i * 3 + 2]); + float len = sqrtf(x*x + y*y + z*z); + if (len == 0.0f) + len = 1.0f; + else + len = 1.0f / len; + float vec[3] = { x * len, y * len, z * len }; + glUniform3fv(u_lightpos[i], 1, vec); + } 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_lightatt[i] != -1) glUniform3fv(u_lightatt[i], 1, gstate_c.lightatt[i]); - if (u_lightangle[i] != -1) glUniform1f(u_lightangle[i], gstate_c.lightangle[i]); - if (u_lightspotCoef[i] != -1) glUniform1f(u_lightspotCoef[i], gstate_c.lightspotCoef[i]); - if (u_lightambient[i] != -1) glUniform3fv(u_lightambient[i], 1, gstate_c.lightColor[0][i]); - if (u_lightdiffuse[i] != -1) glUniform3fv(u_lightdiffuse[i], 1, gstate_c.lightColor[1][i]); - if (u_lightspecular[i] != -1) glUniform3fv(u_lightspecular[i], 1, gstate_c.lightColor[2][i]); + if (u_lightdir[i] != -1) SetFloat24Uniform3(u_lightdir[i], &gstate.ldir[i * 3]); + if (u_lightatt[i] != -1) SetFloat24Uniform3(u_lightatt[i], &gstate.latt[i * 3]); + if (u_lightangle[i] != -1) glUniform1f(u_lightangle[i], getFloat24(gstate.lcutoff[i])); + if (u_lightspotCoef[i] != -1) glUniform1f(u_lightspotCoef[i], getFloat24(gstate.lconv[i])); + if (u_lightambient[i] != -1) SetColorUniform3(u_lightambient[i], gstate.lcolor[i * 3]); + if (u_lightdiffuse[i] != -1) SetColorUniform3(u_lightdiffuse[i], gstate.lcolor[i * 3 + 1]); + if (u_lightspecular[i] != -1) SetColorUniform3(u_lightspecular[i], gstate.lcolor[i * 3 + 2]); } } } diff --git a/GPU/GLES/SoftwareTransform.cpp b/GPU/GLES/SoftwareTransform.cpp index 8a783f37472b..62ab0e36ad8f 100644 --- a/GPU/GLES/SoftwareTransform.cpp +++ b/GPU/GLES/SoftwareTransform.cpp @@ -22,6 +22,7 @@ #include "GPU/GPUState.h" #include "GPU/Math3D.h" #include "GPU/Common/VertexDecoderCommon.h" +#include "GPU/Common/TransformCommon.h" #include "GPU/GLES/ShaderManager.h" #include "GPU/GLES/TransformPipeline.h" @@ -44,160 +45,6 @@ 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 = ∈ - else - ambient = &materialAmbient; - - const Color4 *diffuse; - if (materialUpdate_ & 2) - diffuse = ∈ - else - diffuse = &materialDiffuse; - - const Color4 *specular; - if (materialUpdate_ & 4) - specular = ∈ - 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 static void SwapUVs(TransformedVertex &a, TransformedVertex &b) { float tempu = a.u; @@ -498,8 +345,8 @@ void TransformDrawEngine::SoftwareTransformAndDraw( case GE_TEXMAP_ENVIRONMENT_MAP: // Shade mapping - use two light sources to generate U and V. { - Vec3f lightpos0 = Vec3f(gstate_c.lightpos[gstate.getUVLS0()]).Normalized(); - Vec3f lightpos1 = Vec3f(gstate_c.lightpos[gstate.getUVLS1()]).Normalized(); + Vec3f lightpos0 = Vec3f(&lighter.lpos[gstate.getUVLS0() * 3]).Normalized(); + Vec3f lightpos1 = Vec3f(&lighter.lpos[gstate.getUVLS1() * 3]).Normalized(); uv[0] = (1.0f + Dot(lightpos0, normal))/2.0f; uv[1] = (1.0f + Dot(lightpos1, normal))/2.0f; diff --git a/GPU/GLES/TransformPipeline.h b/GPU/GLES/TransformPipeline.h index 417616889046..8e23c78c5252 100644 --- a/GPU/GLES/TransformPipeline.h +++ b/GPU/GLES/TransformPipeline.h @@ -244,41 +244,3 @@ class TransformDrawEngine : public GfxResourceHolder { 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; - } -}; diff --git a/GPU/GPU.vcxproj b/GPU/GPU.vcxproj index a80b82a73b9f..46f94cb47b35 100644 --- a/GPU/GPU.vcxproj +++ b/GPU/GPU.vcxproj @@ -171,6 +171,7 @@ true true + @@ -222,6 +223,7 @@ true true + @@ -281,4 +283,4 @@ - \ No newline at end of file + diff --git a/GPU/GPU.vcxproj.filters b/GPU/GPU.vcxproj.filters index d383f5b21727..8c82c34f7220 100644 --- a/GPU/GPU.vcxproj.filters +++ b/GPU/GPU.vcxproj.filters @@ -162,6 +162,9 @@ Common + + Common + @@ -302,6 +305,9 @@ GLES + + Common + diff --git a/GPU/GPUState.cpp b/GPU/GPUState.cpp index 408c3b7cc4b8..9d6e046aaa8d 100644 --- a/GPU/GPUState.cpp +++ b/GPU/GPUState.cpp @@ -270,7 +270,7 @@ struct GPUStateCache_v0 }; void GPUStateCache::DoState(PointerWrap &p) { - auto s = p.Section("GPUStateCache", 0, 1); + auto s = p.Section("GPUStateCache", 0, 2); if (!s) { // Old state, this was not versioned. GPUStateCache_v0 old; @@ -302,12 +302,19 @@ void GPUStateCache::DoState(PointerWrap &p) { p.Do(flipTexture); } - p.Do(lightpos); - p.Do(lightdir); - p.Do(lightatt); - p.Do(lightColor); - p.Do(lightangle); - p.Do(lightspotCoef); + if (s < 2) { + float l12[12]; + float l4[3]; + p.Do(l12); // lightpos + p.Do(l12); // lightdir + 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(curTextureWidth); diff --git a/GPU/GPUState.h b/GPU/GPUState.h index 28a2a1d184af..c74f27076b28 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -458,12 +458,6 @@ struct GPUStateCache UVScale uv; 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]; u32 curTextureWidth; diff --git a/GPU/Null/NullGpu.cpp b/GPU/Null/NullGpu.cpp index 88e067f36952..bfb5f2167af7 100644 --- a/GPU/Null/NullGpu.cpp +++ b/GPU/Null/NullGpu.cpp @@ -385,7 +385,6 @@ void NullGPU::ExecuteOp(u32 op, u32 diff) { int c = n % 3; float val = getFloat24(data); DEBUG_LOG(G3D,"DL Light %i %c pos: %f", l, c+'X', val); - gstate_c.lightpos[l][c] = val; } break; @@ -399,7 +398,6 @@ void NullGPU::ExecuteOp(u32 op, u32 diff) { int c = n % 3; float val = getFloat24(data); DEBUG_LOG(G3D,"DL Light %i %c dir: %f", l, c+'X', val); - gstate_c.lightdir[l][c] = val; } break; @@ -413,7 +411,6 @@ void NullGPU::ExecuteOp(u32 op, u32 diff) { int c = n % 3; float val = getFloat24(data); DEBUG_LOG(G3D,"DL Light %i %c att: %f", l, c+'X', val); - gstate_c.lightatt[l][c] = val; } break; @@ -428,10 +425,8 @@ void NullGPU::ExecuteOp(u32 op, u32 diff) { int l = (cmd - GE_CMD_LAC0) / 3; int t = (cmd - GE_CMD_LAC0) % 3; - gstate_c.lightColor[t][l][0] = r; - gstate_c.lightColor[t][l][1] = g; - gstate_c.lightColor[t][l][2] = b; - } + // DEBUG_LOG(G3D, "DL Light color %i %c att: %f", l, c + 'X', val); + } break; case GE_CMD_VIEWPORTX1: