summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeoBrainX <NeoBrainX@googlemail.com>2011-09-29 21:21:09 +0200
committerNeoBrainX <NeoBrainX@googlemail.com>2011-09-29 23:32:39 +0200
commitca7e8a9e88aeb2271ed04af4ff3994286c00a90c (patch)
tree6a1ae3e724863d0abdd933a6492af23edfb8a2ec
parent1f8a8268c66b3349c7b0d7ba0e5e2e8c9bd2dd2e (diff)
Fix pixel lighting.
-rw-r--r--Source/Core/VideoCommon/Src/LightingShaderGen.cpp15
-rw-r--r--Source/Core/VideoCommon/Src/LightingShaderGen.h3
-rw-r--r--Source/Core/VideoCommon/Src/PixelShaderGen.cpp18
-rw-r--r--Source/Core/VideoCommon/Src/PixelShaderGen.h4
-rw-r--r--Source/Core/VideoCommon/Src/VertexShaderGen.cpp14
5 files changed, 36 insertions, 18 deletions
diff --git a/Source/Core/VideoCommon/Src/LightingShaderGen.cpp b/Source/Core/VideoCommon/Src/LightingShaderGen.cpp
index 6824fbd2fc..a506acadfc 100644
--- a/Source/Core/VideoCommon/Src/LightingShaderGen.cpp
+++ b/Source/Core/VideoCommon/Src/LightingShaderGen.cpp
@@ -21,6 +21,21 @@
#define WRITE p+=sprintf
+int GetLightingShaderId(u32* out)
+{
+ for (int i = 0; i < xfregs.numChan.numColorChans; ++i)
+ {
+ out[i] = xfregs.color[i].enablelighting ?
+ (u32)xfregs.color[i].hex :
+ (u32)xfregs.color[i].matsource;
+ out[i] |= (xfregs.alpha[i].enablelighting ?
+ (u32)xfregs.alpha[i].hex :
+ (u32)xfregs.alpha[i].matsource) << 15;
+ }
+ _assert_(xfregs.numChan.numColorChans <= 2);
+ return xfregs.numChan.numColorChans;
+}
+
// coloralpha - 1 if color, 2 if alpha
char *GenerateLightShader(char *p, int index, const LitChannel& chan, const char* lightsName, int coloralpha)
{
diff --git a/Source/Core/VideoCommon/Src/LightingShaderGen.h b/Source/Core/VideoCommon/Src/LightingShaderGen.h
index 21da8ca01a..e72623a4d2 100644
--- a/Source/Core/VideoCommon/Src/LightingShaderGen.h
+++ b/Source/Core/VideoCommon/Src/LightingShaderGen.h
@@ -18,6 +18,9 @@
#ifndef _LIGHTINGSHADERGEN_H_
#define _LIGHTINGSHADERGEN_H_
+#include "CommonTypes.h"
+
+int GetLightingShaderId(u32* out);
char *GenerateLightingShader(char *p, int components, const char* materialsName, const char* lightsName, const char* inColorName, const char* dest);
#endif // _LIGHTINGSHADERGEN_H_
diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
index 7937c695ce..52a4477390 100644
--- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
+++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
@@ -125,16 +125,11 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode)
if (alphaPreTest == 1 || (alphaPreTest && !DepthTextureEnable && dstAlphaMode == DSTALPHA_ALPHA_PASS))
{
// Courtesy of PreAlphaTest, we're done already ;)
- // TODO: There's a comment including bpmem.genmode.numindstages.. shouldnt really bother about that though.
+ // NOTE: The comment header of generated shaders depends on the value of bpmem.genmode.numindstages.. shouldnt really bother about that though.
uid->num_values = 1;
return;
}
- if (enablePL)
- {
- // TODO: Include register states for lighting shader
- }
-
for (unsigned int i = 0; i < bpmem.genMode.numtexgens; ++i)
{
if (18+i < 32)
@@ -194,7 +189,12 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode)
ptr[0] |= bpmem.fogRange.Base.Enabled << 17; // 1
}
}
- uid->num_values = (ptr+1) - uid->values;
+
+ ++ptr;
+ if (enablePL)
+ ptr += GetLightingShaderId(ptr);
+
+ uid->num_values = ptr - uid->values;
}
void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode)
@@ -212,6 +212,10 @@ void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode)
if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
{
// TODO: Include register states for lighting shader
+ *ptr++ = xfregs.color[0].hex;
+ *ptr++ = xfregs.alpha[0].hex;
+ *ptr++ = xfregs.color[1].hex;
+ *ptr++ = xfregs.alpha[1].hex;
}
for (unsigned int i = 0; i < 8; ++i)
diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.h b/Source/Core/VideoCommon/Src/PixelShaderGen.h
index 8031fdfbb2..b24b656784 100644
--- a/Source/Core/VideoCommon/Src/PixelShaderGen.h
+++ b/Source/Core/VideoCommon/Src/PixelShaderGen.h
@@ -44,8 +44,8 @@
#define C_PLIGHTS (C_FOG + 3)
#define C_PMATERIALS (C_PLIGHTS + 40)
#define C_PENVCONST_END (C_PMATERIALS + 4)
-#define PIXELSHADERUID_MAX_VALUES 67
-#define PIXELSHADERUID_MAX_VALUES_SAFE 115
+#define PIXELSHADERUID_MAX_VALUES 69
+#define PIXELSHADERUID_MAX_VALUES_SAFE 117
// DO NOT make anything in this class virtual.
template<bool safe>
diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp
index 5c6c12887a..a492d5a201 100644
--- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp
+++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp
@@ -37,14 +37,9 @@ void GetVertexShaderId(VERTEXSHADERUID *uid, u32 components)
(xfregs.numChan.numColorChans << 27) |
(xfregs.dualTexTrans.enabled << 29);
- for (int i = 0; i < xfregs.numChan.numColorChans; ++i) {
- uid->values[1+i] = xfregs.color[i].enablelighting ?
- (u32)xfregs.color[i].hex :
- (u32)xfregs.color[i].matsource;
- uid->values[1+i] |= (xfregs.alpha[i].enablelighting ?
- (u32)xfregs.alpha[i].hex :
- (u32)xfregs.alpha[i].matsource) << 15;
- }
+ // TODO: If pixel lighting is enabled, do we even have to bother about storing lighting related registers here?
+ GetLightingShaderId(&uid->values[1]);
+
uid->values[2] |= (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) << 31;
u32 *pcurvalue = &uid->values[3];
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) {
@@ -306,7 +301,8 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type)
else
WRITE(p, "o.colors_0 = float4(1.0f, 1.0f, 1.0f, 1.0f);\n");
}
-
+
+ // TODO: This probably isn't necessary if pixel lighting is enabled.
p = GenerateLightingShader(p, components, I_MATERIALS, I_LIGHTS, "color", "o.colors_");
if(xfregs.numChan.numColorChans < 2)