summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/ShaderGenCommon.cpp
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2023-08-22 02:18:40 +0200
committerGitHub <noreply@github.com>2023-08-22 02:18:40 +0200
commitdbe6a5f7e4caca71de9d9ba86916f82c0bc21683 (patch)
tree84fd8c6f664f1df62350f9d7b5aa9d110b6aee02 /Source/Core/VideoCommon/ShaderGenCommon.cpp
parent3451cb1ca2583f9c2b02d0d216355047787c134b (diff)
parent55061216855af89f21eee1174fa81d927bc94991 (diff)
Merge pull request #11300 from iwubcode/custom-shaders
VideoCommon: add a graphics mod action that allows you to modify the game's base rendering
Diffstat (limited to 'Source/Core/VideoCommon/ShaderGenCommon.cpp')
-rw-r--r--Source/Core/VideoCommon/ShaderGenCommon.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/Source/Core/VideoCommon/ShaderGenCommon.cpp b/Source/Core/VideoCommon/ShaderGenCommon.cpp
index 234703d7d5..e4922f3e3e 100644
--- a/Source/Core/VideoCommon/ShaderGenCommon.cpp
+++ b/Source/Core/VideoCommon/ShaderGenCommon.cpp
@@ -10,6 +10,7 @@
#include "Core/ConfigManager.h"
#include "VideoCommon/VideoCommon.h"
#include "VideoCommon/VideoConfig.h"
+#include "VideoCommon/XFMemory.h"
ShaderHostConfig ShaderHostConfig::GetCurrent()
{
@@ -362,3 +363,90 @@ const char* GetInterpolationQualifier(bool msaa, bool ssaa, bool in_glsl_interfa
return "sample";
}
}
+
+void WriteCustomShaderStructDef(ShaderCode* out, u32 numtexgens)
+{
+ // Bump this when there are breaking changes to the API
+ out->Write("#define CUSTOM_SHADER_API_VERSION 1;\n");
+
+ // CUSTOM_SHADER_LIGHTING_ATTENUATION_TYPE "enum" values
+ out->Write("const uint CUSTOM_SHADER_LIGHTING_ATTENUATION_TYPE_NONE = {};\n",
+ static_cast<u32>(AttenuationFunc::None));
+ out->Write("const uint CUSTOM_SHADER_LIGHTING_ATTENUATION_TYPE_POINT = {};\n",
+ static_cast<u32>(AttenuationFunc::Spec));
+ out->Write("const uint CUSTOM_SHADER_LIGHTING_ATTENUATION_TYPE_DIR = {};\n",
+ static_cast<u32>(AttenuationFunc::Dir));
+ out->Write("const uint CUSTOM_SHADER_LIGHTING_ATTENUATION_TYPE_SPOT = {};\n",
+ static_cast<u32>(AttenuationFunc::Spot));
+
+ out->Write("struct CustomShaderLightData\n");
+ out->Write("{{\n");
+ out->Write("\tfloat3 position;\n");
+ out->Write("\tfloat3 direction;\n");
+ out->Write("\tfloat3 color;\n");
+ out->Write("\tuint attenuation_type;\n");
+ out->Write("\tfloat4 cosatt;\n");
+ out->Write("\tfloat4 distatt;\n");
+ out->Write("}};\n\n");
+
+ // CUSTOM_SHADER_TEV_STAGE_INPUT_TYPE "enum" values
+ out->Write("const uint CUSTOM_SHADER_TEV_STAGE_INPUT_TYPE_PREV = 0;\n");
+ out->Write("const uint CUSTOM_SHADER_TEV_STAGE_INPUT_TYPE_COLOR = 1;\n");
+ out->Write("const uint CUSTOM_SHADER_TEV_STAGE_INPUT_TYPE_TEX = 2;\n");
+ out->Write("const uint CUSTOM_SHADER_TEV_STAGE_INPUT_TYPE_RAS = 3;\n");
+ out->Write("const uint CUSTOM_SHADER_TEV_STAGE_INPUT_TYPE_KONST = 4;\n");
+ out->Write("const uint CUSTOM_SHADER_TEV_STAGE_INPUT_TYPE_NUMERIC = 5;\n");
+ out->Write("const uint CUSTOM_SHADER_TEV_STAGE_INPUT_TYPE_UNUSED = 6;\n");
+
+ out->Write("struct CustomShaderTevStageInputColor\n");
+ out->Write("{{\n");
+ out->Write("\tuint input_type;\n");
+ out->Write("\tfloat3 value;\n");
+ out->Write("}};\n\n");
+
+ out->Write("struct CustomShaderTevStageInputAlpha\n");
+ out->Write("{{\n");
+ out->Write("\tuint input_type;\n");
+ out->Write("\tfloat value;\n");
+ out->Write("}};\n\n");
+
+ out->Write("struct CustomShaderTevStage\n");
+ out->Write("{{\n");
+ out->Write("\tCustomShaderTevStageInputColor[4] input_color;\n");
+ out->Write("\tCustomShaderTevStageInputAlpha[4] input_alpha;\n");
+ out->Write("\tuint texmap;\n");
+ out->Write("\tfloat4 output_color;\n");
+ out->Write("}};\n\n");
+
+ // Custom structure for data we pass to custom shader hooks
+ out->Write("struct CustomShaderData\n");
+ out->Write("{{\n");
+ out->Write("\tfloat3 position;\n");
+ out->Write("\tfloat3 normal;\n");
+ if (numtexgens == 0)
+ {
+ // Cheat so shaders compile
+ out->Write("\tfloat3[1] texcoord;\n");
+ }
+ else
+ {
+ out->Write("\tfloat3[{}] texcoord;\n", numtexgens);
+ }
+ out->Write("\tuint texcoord_count;\n");
+ out->Write("\tuint[8] texmap_to_texcoord_index;\n");
+ out->Write("\tCustomShaderLightData[8] lights_chan0_color;\n");
+ out->Write("\tCustomShaderLightData[8] lights_chan0_alpha;\n");
+ out->Write("\tCustomShaderLightData[8] lights_chan1_color;\n");
+ out->Write("\tCustomShaderLightData[8] lights_chan1_alpha;\n");
+ out->Write("\tfloat4[2] ambient_lighting;\n");
+ out->Write("\tfloat4[2] base_material;\n");
+ out->Write("\tuint light_chan0_color_count;\n");
+ out->Write("\tuint light_chan0_alpha_count;\n");
+ out->Write("\tuint light_chan1_color_count;\n");
+ out->Write("\tuint light_chan1_alpha_count;\n");
+ out->Write("\tCustomShaderTevStage[16] tev_stages;\n");
+ out->Write("\tuint tev_stage_count;\n");
+ out->Write("\tfloat4 final_color;\n");
+ out->Write("\tuint time_ms;\n");
+ out->Write("}};\n\n");
+}