summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon
diff options
context:
space:
mode:
authorNeoBrainX <NeoBrainX@gmail.com>2013-03-31 23:29:33 +0200
committerNeoBrainX <NeoBrainX@gmail.com>2013-03-31 23:29:33 +0200
commitf6d65a636ef9c8a75b410314b94384a2ae2d7e62 (patch)
tree60aa59142ac04bc6151d0e7e1105c63588999ea4 /Source/Core/VideoCommon
parent248d56d930d8d6f7cae04efc0c1521c83676c074 (diff)
ShaderGen: Fix per pixel lighting.
Diffstat (limited to 'Source/Core/VideoCommon')
-rw-r--r--Source/Core/VideoCommon/Src/LightingShaderGen.h19
-rw-r--r--Source/Core/VideoCommon/Src/PixelShaderGen.cpp10
-rw-r--r--Source/Core/VideoCommon/Src/PixelShaderGen.h2
-rw-r--r--Source/Core/VideoCommon/Src/ShaderGenCommon.h13
-rw-r--r--Source/Core/VideoCommon/Src/VertexShaderGen.cpp2
-rw-r--r--Source/Core/VideoCommon/Src/VertexShaderGen.h11
-rw-r--r--Source/Core/VideoCommon/Src/VideoConfig.h2
7 files changed, 32 insertions, 27 deletions
diff --git a/Source/Core/VideoCommon/Src/LightingShaderGen.h b/Source/Core/VideoCommon/Src/LightingShaderGen.h
index 40a8fb2732..ff19b737f4 100644
--- a/Source/Core/VideoCommon/Src/LightingShaderGen.h
+++ b/Source/Core/VideoCommon/Src/LightingShaderGen.h
@@ -18,15 +18,12 @@
#ifndef _LIGHTINGSHADERGEN_H_
#define _LIGHTINGSHADERGEN_H_
-#include <typeinfo>
-
#include "ShaderGenCommon.h"
#include "NativeVertexFormat.h"
#include "XFMemory.h"
-// uid_data needs to have a struct named lighting_uid
-template<class T,class UidDataT>
-static void GenerateLightShader(T& object, UidDataT& uid_data, int index, int litchan_index, const char* lightsName, int coloralpha)
+template<class T>
+static void GenerateLightShader(T& object, LightingUidData& uid_data, int index, int litchan_index, const char* lightsName, int coloralpha)
{
const LitChannel& chan = (litchan_index > 1) ? xfregs.alpha[litchan_index-2] : xfregs.color[litchan_index];
const char* swizzle = "xyzw";
@@ -93,8 +90,8 @@ static void GenerateLightShader(T& object, UidDataT& uid_data, int index, int li
// materials name is I_MATERIALS in vs and I_PMATERIALS in ps
// inColorName is color in vs and colors_ in ps
// dest is o.colors_ in vs and colors_ in ps
-template<class T, class UidDataT>
-static void GenerateLightingShader(T& object, UidDataT& uid_data, int components, const char* materialsName, const char* lightsName, const char* inColorName, const char* dest)
+template<class T>
+static void GenerateLightingShader(T& object, LightingUidData& uid_data, int components, const char* materialsName, const char* lightsName, const char* inColorName, const char* dest)
{
for (unsigned int j = 0; j < xfregs.numChan.numColorChans; j++)
{
@@ -187,7 +184,7 @@ static void GenerateLightingShader(T& object, UidDataT& uid_data, int components
{
if (mask & (1<<i))
{
- GenerateLightShader<T,UidDataT>(object, uid_data, i, j, lightsName, 3);
+ GenerateLightShader<T>(object, uid_data, i, j, lightsName, 3);
}
}
}
@@ -197,9 +194,9 @@ static void GenerateLightingShader(T& object, UidDataT& uid_data, int components
for (int i = 0; i < 8; ++i)
{
if (!(mask&(1<<i)) && (color.GetFullLightMask() & (1<<i)))
- GenerateLightShader<T,UidDataT>(object, uid_data, i, j, lightsName, 1);
+ GenerateLightShader<T>(object, uid_data, i, j, lightsName, 1);
if (!(mask&(1<<i)) && (alpha.GetFullLightMask() & (1<<i)))
- GenerateLightShader<T,UidDataT>(object, uid_data, i, j+2, lightsName, 2);
+ GenerateLightShader<T>(object, uid_data, i, j+2, lightsName, 2);
}
}
else if (color.enablelighting || alpha.enablelighting)
@@ -213,7 +210,7 @@ static void GenerateLightingShader(T& object, UidDataT& uid_data, int components
for (int i = 0; i < 8; ++i)
{
if (workingchannel.GetFullLightMask() & (1<<i))
- GenerateLightShader<T,UidDataT>(object, uid_data, i, lit_index, lightsName, coloralpha);
+ GenerateLightShader<T>(object, uid_data, i, lit_index, lightsName, coloralpha);
}
}
object.Write("%s%d = mat * saturate(lacc);\n", dest, j);
diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
index e534e2a6ca..ceb2230684 100644
--- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
+++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
@@ -341,12 +341,12 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u
out.Write("\t%sfloat4 " I_INDTEXSCALE"[2] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_INDTEXSCALE));
out.Write("\t%sfloat4 " I_INDTEXMTX"[6] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_INDTEXMTX));
out.Write("\t%sfloat4 " I_FOG"[3] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_FOG));
-
+
// For pixel lighting - TODO: Should only be defined when per pixel lighting is enabled!
out.Write("struct Light { float4 col; float4 cosatt; float4 distatt; float4 pos; float4 dir; };\n");
out.Write("\t%sLight " I_PLIGHTS"[8] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_PLIGHTS));
out.Write("\t%sfloat4 " I_PMATERIALS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_PMATERIALS));
-
+
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
out.Write("};\n");
@@ -366,7 +366,7 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u
out.Write("float4 colors_1 = colors_12;\n");
// compute window position if needed because binding semantic WPOS is not widely supported
- // Let's set up attributes
+ // Let's set up attributes
if (xfregs.numTexGen.numTexGens < 7)
{
for (int i = 0; i < 8; ++i)
@@ -479,10 +479,10 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u
out.Write("\tfloat4 mat, lacc;\n"
"\tfloat3 ldir, h;\n"
"\tfloat dist, dist2, attn;\n");
-/// TODO
+
out.SetConstantsUsed(C_PLIGHTS, C_PLIGHTS+39); // TODO: Can be optimized further
out.SetConstantsUsed(C_PMATERIALS, C_PMATERIALS+3);
-/// p = GenerateLightingShader(p, components, I_PMATERIALS, I_PLIGHTS, "colors_", "colors_");
+ GenerateLightingShader<T>(out, uid_data.lighting, components, I_PMATERIALS, I_PLIGHTS, "colors_", "colors_");
}
if (numTexgen < 7)
diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.h b/Source/Core/VideoCommon/Src/PixelShaderGen.h
index 4881999206..98afec2c5b 100644
--- a/Source/Core/VideoCommon/Src/PixelShaderGen.h
+++ b/Source/Core/VideoCommon/Src/PixelShaderGen.h
@@ -187,6 +187,8 @@ struct pixel_shader_uid_data
u32 bHasIndStage : 16;
u32 xfregs_numTexGen_numTexGens : 4;
+
+ LightingUidData lighting;
};
typedef ShaderUid<pixel_shader_uid_data> PixelShaderUid;
diff --git a/Source/Core/VideoCommon/Src/ShaderGenCommon.h b/Source/Core/VideoCommon/Src/ShaderGenCommon.h
index ef88d411ea..4d41cd62f1 100644
--- a/Source/Core/VideoCommon/Src/ShaderGenCommon.h
+++ b/Source/Core/VideoCommon/Src/ShaderGenCommon.h
@@ -153,4 +153,17 @@ static void DeclareUniform(T& object, API_TYPE api_type, bool using_ubos, const
object.Write(";\n");
}
+struct LightingUidData
+{
+ struct
+ {
+ u32 matsource : 1;
+ u32 enablelighting : 1;
+ u32 ambsource : 1;
+ u32 diffusefunc : 2;
+ u32 attnfunc : 2;
+ u32 light_mask : 8;
+ } lit_chans[4];
+};
+
#endif // _SHADERGENCOMMON_H
diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp
index 44bad82471..82e7a7fdce 100644
--- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp
+++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp
@@ -270,7 +270,7 @@ static void GenerateVertexShader(T& out, u32 components, API_TYPE api_type)
}
// TODO: This probably isn't necessary if pixel lighting is enabled.
- GenerateLightingShader<T,vertex_shader_uid_data>(out, uid_data, components, I_MATERIALS, I_LIGHTS, "color", "o.colors_");
+ GenerateLightingShader<T>(out, uid_data.lighting, components, I_MATERIALS, I_LIGHTS, "color", "o.colors_");
if (xfregs.numChan.numColorChans < 2)
{
diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.h b/Source/Core/VideoCommon/Src/VertexShaderGen.h
index ea81aba468..9c44ba0448 100644
--- a/Source/Core/VideoCommon/Src/VertexShaderGen.h
+++ b/Source/Core/VideoCommon/Src/VertexShaderGen.h
@@ -79,7 +79,6 @@ const s_svar VSVar_Loc[] = { {I_POSNORMALMATRIX, C_POSNORMALMATRIX, 6 },
#pragma pack(4)
struct vertex_shader_uid_data
-
{
u32 components;
u32 numColorChans : 2;
@@ -100,14 +99,8 @@ struct vertex_shader_uid_data
struct {
u32 enabled : 1;
} dualTexTrans;
- struct {
- u32 matsource : 1;
- u32 enablelighting : 1;
- u32 ambsource : 1;
- u32 diffusefunc : 2;
- u32 attnfunc : 2;
- u32 light_mask : 8;
- } lit_chans[4];
+
+ LightingUidData lighting;
};
#pragma pack()
diff --git a/Source/Core/VideoCommon/Src/VideoConfig.h b/Source/Core/VideoCommon/Src/VideoConfig.h
index 99fff0d167..442e95f9bf 100644
--- a/Source/Core/VideoCommon/Src/VideoConfig.h
+++ b/Source/Core/VideoCommon/Src/VideoConfig.h
@@ -135,7 +135,7 @@ struct VideoConfig
int iAdapter;
// Debugging
- bool bEnableShaderDebugging; // TODO: Obsolete?
+ bool bEnableShaderDebugging;
// Static config per API
// TODO: Move this out of VideoConfig