summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/LightingShaderGen.cpp
diff options
context:
space:
mode:
authoriwubcode <iwubcode@users.noreply.github.com>2025-02-12 20:18:20 -0600
committeriwubcode <iwubcode@users.noreply.github.com>2025-03-13 23:56:04 -0500
commit15372dc835a2c387f8f566fa86d6cc60b2534a7d (patch)
treede748ed185b1e3cf74c9509122b79fbb5432d9b7 /Source/Core/VideoCommon/LightingShaderGen.cpp
parentca9b34a6d1e7ad03c4879239e9c5b79a6c47522e (diff)
VideoCommon: move lighting shader logic to callable functions
Diffstat (limited to 'Source/Core/VideoCommon/LightingShaderGen.cpp')
-rw-r--r--Source/Core/VideoCommon/LightingShaderGen.cpp37
1 files changed, 20 insertions, 17 deletions
diff --git a/Source/Core/VideoCommon/LightingShaderGen.cpp b/Source/Core/VideoCommon/LightingShaderGen.cpp
index 4fb2c98ebd..130fb6f46d 100644
--- a/Source/Core/VideoCommon/LightingShaderGen.cpp
+++ b/Source/Core/VideoCommon/LightingShaderGen.cpp
@@ -79,31 +79,34 @@ static void GenerateLightShader(ShaderCode& object, const LightingUidData& uid_d
// vertex shader
// lights/colors
// 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,
- std::string_view in_color_name, std::string_view dest)
+void GenerateLightingShaderHeader(ShaderCode& object, const LightingUidData& uid_data)
{
for (u32 j = 0; j < NUM_XF_COLOR_CHANNELS; j++)
{
+ object.Write("vec4 dolphin_calculate_lighting_chn{}(vec4 base_color, vec3 pos, vec3 _normal)\n",
+ j);
object.Write("{{\n");
+ object.Write("\tint4 lacc;\n"
+ "\tvec3 ldir, h, cosAttn, distAttn;\n"
+ "\tfloat dist, dist2, attn;\n");
+
const bool colormatsource = !!(uid_data.matsource & (1 << j));
if (colormatsource) // from vertex
- object.Write("int4 mat = int4(round({}{} * 255.0));\n", in_color_name, j);
+ object.Write("\tint4 mat = int4(round(base_color * 255.0));\n");
else // from color
- object.Write("int4 mat = {}[{}];\n", I_MATERIALS, j + 2);
+ object.Write("\tint4 mat = {}[{}];\n", I_MATERIALS, j + 2);
if ((uid_data.enablelighting & (1 << j)) != 0)
{
if ((uid_data.ambsource & (1 << j)) != 0) // from vertex
- object.Write("lacc = int4(round({}{} * 255.0));\n", in_color_name, j);
+ object.Write("\tlacc = int4(round(base_color * 255.0));\n");
else // from color
- object.Write("lacc = {}[{}];\n", I_MATERIALS, j);
+ object.Write("\tlacc = {}[{}];\n", I_MATERIALS, j);
}
else
{
- object.Write("lacc = int4(255, 255, 255, 255);\n");
+ object.Write("\tlacc = int4(255, 255, 255, 255);\n");
}
// check if alpha is different
@@ -111,21 +114,21 @@ void GenerateLightingShaderCode(ShaderCode& object, const LightingUidData& uid_d
if (alphamatsource != colormatsource)
{
if (alphamatsource) // from vertex
- object.Write("mat.w = int(round({}{}.w * 255.0));\n", in_color_name, j);
+ object.Write("\tmat.w = int(round(base_color.w * 255.0));\n");
else // from color
- object.Write("mat.w = {}[{}].w;\n", I_MATERIALS, j + 2);
+ object.Write("\tmat.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
- object.Write("lacc.w = int(round({}{}.w * 255.0));\n", in_color_name, j);
+ object.Write("\tlacc.w = int(round(base_color.w * 255.0));\n");
else // from color
- object.Write("lacc.w = {}[{}].w;\n", I_MATERIALS, j);
+ object.Write("\tlacc.w = {}[{}].w;\n", I_MATERIALS, j);
}
else
{
- object.Write("lacc.w = 255;\n");
+ object.Write("\tlacc.w = 255;\n");
}
if ((uid_data.enablelighting & (1 << j)) != 0) // Color lights
@@ -144,9 +147,9 @@ void GenerateLightingShaderCode(ShaderCode& object, const LightingUidData& uid_d
GenerateLightShader(object, uid_data, i, j + 2, true);
}
}
- object.Write("lacc = clamp(lacc, 0, 255);\n");
- object.Write("{}{} = float4((mat * (lacc + (lacc >> 7))) >> 8) / 255.0;\n", dest, j);
- object.Write("}}\n");
+ object.Write("\tlacc = clamp(lacc, 0, 255);\n");
+ object.Write("\treturn vec4((mat * (lacc + (lacc >> 7))) >> 8) / 255.0;\n");
+ object.Write("}}\n\n");
}
}