mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
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.
This commit is contained in:
@ -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
|
||||
{
|
||||
|
Reference in New Issue
Block a user