diff --git a/Source/Core/VideoCommon/ShaderGenCommon.cpp b/Source/Core/VideoCommon/ShaderGenCommon.cpp index 234703d7d5..5f2b2b224f 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,89 @@ 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(AttenuationFunc::None)); + out->Write("const uint CUSTOM_SHADER_LIGHTING_ATTENUATION_TYPE_POINT = {};\n", + static_cast(AttenuationFunc::Spec)); + out->Write("const uint CUSTOM_SHADER_LIGHTING_ATTENUATION_TYPE_DIR = {};\n", + static_cast(AttenuationFunc::Dir)); + out->Write("const uint CUSTOM_SHADER_LIGHTING_ATTENUATION_TYPE_SPOT = {};\n", + static_cast(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("}};\n\n"); +} diff --git a/Source/Core/VideoCommon/ShaderGenCommon.h b/Source/Core/VideoCommon/ShaderGenCommon.h index 7112dd4523..60e4b3cef9 100644 --- a/Source/Core/VideoCommon/ShaderGenCommon.h +++ b/Source/Core/VideoCommon/ShaderGenCommon.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -327,3 +328,21 @@ static const char s_geometry_shader_uniforms[] = "\tfloat4 " I_STEREOPARAMS ";\n "\tfloat4 " I_LINEPTPARAMS ";\n" "\tint4 " I_TEXOFFSET ";\n" "\tuint vs_expand;\n"; + +constexpr std::string_view CUSTOM_PIXELSHADER_COLOR_FUNC = "customShaderColor"; + +struct CustomPixelShader +{ + std::string custom_shader; + + bool operator==(const CustomPixelShader& other) const = default; +}; + +struct CustomPixelShaderContents +{ + std::vector shaders; + + bool operator==(const CustomPixelShaderContents& other) const = default; +}; + +void WriteCustomShaderStructDef(ShaderCode* out, u32 numtexgens);