summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/LightingShaderGen.cpp
diff options
context:
space:
mode:
authorStenzek <stenzek@gmail.com>2017-01-29 22:38:48 +1000
committerPokechu22 <Pokechu022@gmail.com>2020-11-20 15:54:04 -0800
commit51724c1ccdbc141b1aed67a2efc952e884cadd35 (patch)
tree5dfc0c64dc693141ed34291e714c448dbf4a6c6b /Source/Core/VideoCommon/LightingShaderGen.cpp
parentfa73b1a23f9b0c5104909de410f9ae533cbf8af4 (diff)
LightingShaderGen: Always calculate lighting for both color channels
Cel-damage depends on lighting being calculated for the first channel even though there is no color in the vertex format (defaults to the material color). If lighting for the channel is not enabled, the vertex will use the default color as before. The default value of the color is determined by the number of elements in the vertex format. This fixes the grey cubes in Super Mario Sunshine. If the color channel count is zero, we set the color to black before the end of the vertex shader. It's possible that this would be undefined behavior on hardware if a vertex color index that was greater than the channel count was used within TEV.
Diffstat (limited to 'Source/Core/VideoCommon/LightingShaderGen.cpp')
-rw-r--r--Source/Core/VideoCommon/LightingShaderGen.cpp62
1 files changed, 5 insertions, 57 deletions
diff --git a/Source/Core/VideoCommon/LightingShaderGen.cpp b/Source/Core/VideoCommon/LightingShaderGen.cpp
index e4b8f16716..d84ff49e4d 100644
--- a/Source/Core/VideoCommon/LightingShaderGen.cpp
+++ b/Source/Core/VideoCommon/LightingShaderGen.cpp
@@ -78,7 +78,7 @@ static void GenerateLightShader(ShaderCode& object, const LightingUidData& uid_d
// 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
-void GenerateLightingShaderCode(ShaderCode& object, const LightingUidData& uid_data, int components,
+void GenerateLightingShaderCode(ShaderCode& object, const LightingUidData& uid_data,
std::string_view in_color_name, std::string_view dest)
{
for (u32 j = 0; j < NUM_XF_COLOR_CHANNELS; j++)
@@ -87,43 +87,16 @@ void GenerateLightingShaderCode(ShaderCode& object, const LightingUidData& uid_d
const bool colormatsource = !!(uid_data.matsource & (1 << j));
if (colormatsource) // from vertex
- {
- if ((components & (VB_HAS_COL0 << j)) != 0)
- object.Write("int4 mat = int4(round({}{} * 255.0));\n", in_color_name, j);
- else if ((components & VB_HAS_COL0) != 0)
- object.Write("int4 mat = int4(round({}0 * 255.0));\n", in_color_name);
- else
- object.Write("int4 mat = int4(255, 255, 255, 255);\n");
- }
+ object.Write("int4 mat = int4(round({}{} * 255.0));\n", in_color_name, j);
else // from color
- {
object.Write("int4 mat = {}[{}];\n", I_MATERIALS, j + 2);
- }
if ((uid_data.enablelighting & (1 << j)) != 0)
{
if ((uid_data.ambsource & (1 << j)) != 0) // from vertex
- {
- if ((components & (VB_HAS_COL0 << j)) != 0)
- {
- object.Write("lacc = int4(round({}{} * 255.0));\n", in_color_name, j);
- }
- else if ((components & VB_HAS_COL0) != 0)
- {
- object.Write("lacc = int4(round({}0 * 255.0));\n", in_color_name);
- }
- else
- {
- // TODO: this isn't verified. Here we want to read the ambient from the vertex,
- // but the vertex itself has no color. So we don't know which value to read.
- // Returning 1.0 is the same as disabled lightning, so this could be fine
- object.Write("lacc = int4(255, 255, 255, 255);\n");
- }
- }
+ object.Write("lacc = int4(round({}{} * 255.0));\n", in_color_name, j);
else // from color
- {
object.Write("lacc = {}[{}];\n", I_MATERIALS, j);
- }
}
else
{
@@ -135,42 +108,17 @@ void GenerateLightingShaderCode(ShaderCode& object, const LightingUidData& uid_d
if (alphamatsource != colormatsource)
{
if (alphamatsource) // from vertex
- {
- if ((components & (VB_HAS_COL0 << j)) != 0)
- object.Write("mat.w = int(round({}{}.w * 255.0));\n", in_color_name, j);
- else if ((components & VB_HAS_COL0) != 0)
- object.Write("mat.w = int(round({}0.w * 255.0));\n", in_color_name);
- else
- object.Write("mat.w = 255;\n");
- }
+ object.Write("mat.w = int(round({}{}.w * 255.0));\n", in_color_name, j);
else // from color
- {
object.Write("mat.w = {}[{}].w;\n", I_MATERIALS, j + 2);
- }
}
if ((uid_data.enablelighting & (1 << (j + 2))) != 0)
{
if ((uid_data.ambsource & (1 << (j + 2))) != 0) // from vertex
- {
- if ((components & (VB_HAS_COL0 << j)) != 0)
- {
- object.Write("lacc.w = int(round({}{}.w * 255.0));\n", in_color_name, j);
- }
- else if ((components & VB_HAS_COL0) != 0)
- {
- object.Write("lacc.w = int(round({}0.w * 255.0));\n", in_color_name);
- }
- else
- {
- // TODO: The same for alpha: We want to read from vertex, but the vertex has no color
- object.Write("lacc.w = 255;\n");
- }
- }
+ object.Write("lacc.w = int(round({}{}.w * 255.0));\n", in_color_name, j);
else // from color
- {
object.Write("lacc.w = {}[{}].w;\n", I_MATERIALS, j);
- }
}
else
{