From 75f839509e4ff3a1ef8e99e66e85f3dd2de2c200 Mon Sep 17 00:00:00 2001 From: offtkp Date: Sat, 20 Jul 2024 00:09:12 +0300 Subject: [PATCH] Nyom --- include/PICA/pica_frag_config.hpp | 27 ++++++++++----------------- include/PICA/regs.hpp | 5 +++++ src/core/PICA/shader_gen_glsl.cpp | 22 ++++++---------------- 3 files changed, 21 insertions(+), 33 deletions(-) diff --git a/include/PICA/pica_frag_config.hpp b/include/PICA/pica_frag_config.hpp index 3e736deb..39624432 100644 --- a/include/PICA/pica_frag_config.hpp +++ b/include/PICA/pica_frag_config.hpp @@ -73,18 +73,7 @@ namespace PICA { BitField<22, 2, u32> shadowSelector; }; - LightingLUTConfig d0{}; - LightingLUTConfig d1{}; - LightingLUTConfig sp{}; - LightingLUTConfig fr{}; - LightingLUTConfig rr{}; - LightingLUTConfig rg{}; - LightingLUTConfig rb{}; - - u32 config1; - u32 lutAbs; - u32 lutScale; - u32 lutSelect; + LightingLUTConfig luts[7]{}; std::array lights{}; @@ -95,13 +84,9 @@ namespace PICA { } const u32 config0 = regs[InternalRegs::LightConfig0]; + const u32 config1 = regs[InternalRegs::LightConfig1]; const u32 totalLightCount = Helpers::getBits<0, 3>(regs[InternalRegs::LightNumber]) + 1; - config1 = regs[InternalRegs::LightConfig1]; - lutAbs = regs[InternalRegs::LightLUTAbs]; - lutScale = regs[InternalRegs::LightLUTScale]; - lutSelect = regs[InternalRegs::LightLUTSelect]; - enable = 1; lightNum = totalLightCount; @@ -138,6 +123,14 @@ namespace PICA { light.distanceAttenuationEnable = ((config1 >> (24 + i)) & 1) ^ 1; // Of course same here } + LightingLUTConfig& d0 = luts[Lights::LUT_D0]; + LightingLUTConfig& d1 = luts[Lights::LUT_D1]; + LightingLUTConfig& sp = luts[spotlightLutIndex]; + LightingLUTConfig& fr = luts[Lights::LUT_FR]; + LightingLUTConfig& rb = luts[Lights::LUT_RB]; + LightingLUTConfig& rg = luts[Lights::LUT_RG]; + LightingLUTConfig& rr = luts[Lights::LUT_RR]; + d0.enable = Helpers::getBit<16>(config1) == 0; d1.enable = Helpers::getBit<17>(config1) == 0; fr.enable = Helpers::getBit<19>(config1) == 0; diff --git a/include/PICA/regs.hpp b/include/PICA/regs.hpp index 4518e16a..c4d6a5fb 100644 --- a/include/PICA/regs.hpp +++ b/include/PICA/regs.hpp @@ -278,6 +278,11 @@ namespace PICA { }; } + // There's actually 8 different LUTs (SP0-SP7), one for each light with different indices (8-15) + // We use an unused LUT value for "this light source's spotlight" instead and figure out which light source to use in compileLutLookup + // This is particularly intuitive in several places, such as checking if a LUT is enabled + static constexpr int spotlightLutIndex = 2; + enum class TextureFmt : u32 { RGBA8 = 0x0, RGB8 = 0x1, diff --git a/src/core/PICA/shader_gen_glsl.cpp b/src/core/PICA/shader_gen_glsl.cpp index 5fff34ae..0ab08d18 100644 --- a/src/core/PICA/shader_gen_glsl.cpp +++ b/src/core/PICA/shader_gen_glsl.cpp @@ -1,3 +1,4 @@ +#include "PICA/pica_frag_config.hpp" #include "PICA/regs.hpp" #include "PICA/shader_gen.hpp" using namespace PICA; @@ -30,11 +31,6 @@ static constexpr const char* uniformDefinition = R"( }; )"; -// There's actually 8 different LUTs (SP0-SP7), one for each light with different indices (8-15) -// We use an unused LUT value for "this light source's spotlight" instead and figure out which light source to use in compileLutLookup -// This is particularly intuitive in several places, such as checking if a LUT is enabled -static constexpr int spotlightLutIndex = 2; - std::string FragmentGenerator::getDefaultVertexShader() { std::string ret = ""; @@ -613,22 +609,16 @@ void FragmentGenerator::compileLUTLookup(std::string& shader, const PICA::Fragme } const bool samplerEnabled = isSamplerEnabled(config.lighting.config, lutID); - const u32 config1 = config.lighting.config1; + const LightingLUTConfig& lut = config.lighting.luts[lutID]; - if (!samplerEnabled || ((config1 >> bitInConfig1) & 1)) { + if (!samplerEnabled || !lut.enable) { shader += "lut_lookup_result = 1.0;\n"; return; } - static constexpr float scales[] = {1.0f, 2.0f, 4.0f, 8.0f, 0.0f, 0.0f, 0.25f, 0.5f}; - const u32 lutAbs = config.lighting.lutAbs; - const u32 lutSelect = config.lighting.lutSelect; - const u32 lutScale = config.lighting.lutScale; - - // The way these bitfields are encoded is so cursed - float scale = scales[(lutScale >> (4 * lutID)) & 0x7]; - uint inputID = (lutSelect >> (4 * lutID)) & 0x7; - bool absEnabled = ((lutAbs >> (4 * lutID + 1)) & 0x1) == 0; // 0 = enabled... + float scale = lut.scale; + uint inputID = lut.type; + bool absEnabled = lut.absInput; switch (inputID) { case 0: shader += "lut_lookup_delta = dot(normal, normalize(half_vector));\n"; break;