summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/PixelShaderGen.cpp
diff options
context:
space:
mode:
authorTony Wasserka <neobrainx@gmail.com>2014-06-21 12:17:26 +0200
committerTony Wasserka <neobrainx@gmail.com>2014-06-21 12:17:26 +0200
commitfbca397c924e3906e9ab26ec3f967760385cc8d6 (patch)
treeb8c94b60ef5805ae0d36919d3183c6b122d59f36 /Source/Core/VideoCommon/PixelShaderGen.cpp
parentddadb4f29dc96b988a004bda43becb621fe2ac7d (diff)
parent924ad1ee9ff7bfa19163082ca203961d65788253 (diff)
Merge pull request #439 from degasus/lighting-fix
Lighting cleanup
Diffstat (limited to 'Source/Core/VideoCommon/PixelShaderGen.cpp')
-rw-r--r--Source/Core/VideoCommon/PixelShaderGen.cpp46
1 files changed, 36 insertions, 10 deletions
diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp
index b3db7ec6a5..0b4ed68892 100644
--- a/Source/Core/VideoCommon/PixelShaderGen.cpp
+++ b/Source/Core/VideoCommon/PixelShaderGen.cpp
@@ -11,6 +11,7 @@
#endif
#include "VideoCommon/BPMemory.h"
+#include "VideoCommon/ConstantManager.h"
#include "VideoCommon/LightingShaderGen.h"
#include "VideoCommon/NativeVertexFormat.h"
#include "VideoCommon/PixelShaderGen.h"
@@ -218,9 +219,13 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
out.Write("\n");
if (ApiType == API_OPENGL)
+ {
out.Write("layout(std140%s) uniform PSBlock {\n", g_ActiveConfig.backend_info.bSupportsBindingLayout ? ", binding = 1" : "");
+ }
else
- out.Write("cbuffer PSBlock {\n");
+ {
+ out.Write("cbuffer PSBlock : register(b0) {\n");
+ }
out.Write(
"\tint4 " I_COLORS"[4];\n"
"\tint4 " I_KCOLORS"[4];\n"
@@ -232,13 +237,32 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
"\tint4 " I_FOGCOLOR";\n"
"\tint4 " I_FOGI";\n"
"\tfloat4 " I_FOGF"[2];\n"
-
- // For pixel lighting - TODO: Should only be defined when per pixel lighting is enabled!
- "\tint4 " I_PLIGHT_COLORS"[8];\n"
- "\tfloat4 " I_PLIGHTS"[32];\n"
- "\tint4 " I_PMATERIALS"[4];\n"
"};\n");
+ if (g_ActiveConfig.bEnablePixelLighting)
+ {
+ out.Write("%s", s_lighting_struct);
+
+ if (ApiType == API_OPENGL)
+ {
+ out.Write("layout(std140%s) uniform VSBlock {\n", g_ActiveConfig.backend_info.bSupportsBindingLayout ? ", binding = 2" : "");
+ }
+ else
+ {
+ out.Write("cbuffer VSBlock : register(b1) {\n");
+ }
+ out.Write(
+ "\tfloat4 " I_POSNORMALMATRIX"[6];\n"
+ "\tfloat4 " I_PROJECTION"[4];\n"
+ "\tint4 " I_MATERIALS"[4];\n"
+ "\tLight " I_LIGHTS"[8];\n"
+ "\tfloat4 " I_TEXMATRICES"[24];\n"
+ "\tfloat4 " I_TRANSFORMMATRICES"[64];\n"
+ "\tfloat4 " I_NORMALMATRICES"[32];\n"
+ "\tfloat4 " I_POSTTRANSFORMMATRICES"[64];\n"
+ "\tfloat4 " I_DEPTHPARAMS";\n"
+ "};\n");
+ }
const bool forced_early_z = g_ActiveConfig.backend_info.bSupportsEarlyZ && bpmem.UseEarlyDepthTest() && (g_ActiveConfig.bFastDepthCalc || bpmem.alpha_test.TestResult() == AlphaTest::UNDETERMINED);
const bool per_pixel_depth = (bpmem.ztex2.op != ZTEXTURE_DISABLE && bpmem.UseLateDepthTest()) || (!g_ActiveConfig.bFastDepthCalc && bpmem.zmode.testenable && !forced_early_z);
@@ -351,11 +375,13 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
"\tfloat3 ldir, h;\n"
"\tfloat dist, dist2, attn;\n");
- out.SetConstantsUsed(C_PLIGHT_COLORS, C_PLIGHT_COLORS+7); // TODO: Can be optimized further
- out.SetConstantsUsed(C_PLIGHTS, C_PLIGHTS+31); // TODO: Can be optimized further
- out.SetConstantsUsed(C_PMATERIALS, C_PMATERIALS+3);
+ // TODO: Our current constant usage code isn't able to handle more than one buffer.
+ // So we can't mark the VS constant as used here. But keep them here as reference.
+ //out.SetConstantsUsed(C_PLIGHT_COLORS, C_PLIGHT_COLORS+7); // TODO: Can be optimized further
+ //out.SetConstantsUsed(C_PLIGHTS, C_PLIGHTS+31); // TODO: Can be optimized further
+ //out.SetConstantsUsed(C_PMATERIALS, C_PMATERIALS+3);
uid_data.components = components;
- GenerateLightingShader<T>(out, uid_data.lighting, components, I_PMATERIALS, I_PLIGHT_COLORS, I_PLIGHTS, "colors_", "colors_");
+ GenerateLightingShader<T>(out, uid_data.lighting, components, "colors_", "colors_");
}
// HACK to handle cases where the tex gen is not enabled