From 8f1d724f4c0c9601bd5fd9c9343a1020e577d63b Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 5 Nov 2023 14:10:37 +1000 Subject: [PATCH] Postprocesing/FX: Add BUFFER_COLOR_BIT_DEPTH and random source --- src/util/postprocessing_shader_fx.cpp | 27 +++++++++++++++++++++++++++ src/util/postprocessing_shader_fx.h | 7 +++++++ 2 files changed, 34 insertions(+) diff --git a/src/util/postprocessing_shader_fx.cpp b/src/util/postprocessing_shader_fx.cpp index c3bddef5d..c5804217a 100644 --- a/src/util/postprocessing_shader_fx.cpp +++ b/src/util/postprocessing_shader_fx.cpp @@ -329,6 +329,7 @@ bool PostProcessing::ReShadeFXShader::CreateModule(s32 buffer_width, s32 buffer_ pp.add_macro_definition("BUFFER_HEIGHT", std::to_string(buffer_height)); pp.add_macro_definition("BUFFER_RCP_WIDTH", std::to_string(1.0f / static_cast(buffer_width))); pp.add_macro_definition("BUFFER_RCP_HEIGHT", std::to_string(1.0f / static_cast(buffer_height))); + pp.add_macro_definition("BUFFER_COLOR_BIT_DEPTH", "32"); switch (GetRenderAPI()) { @@ -683,6 +684,19 @@ bool PostProcessing::ReShadeFXShader::GetSourceOption(const reshadefx::uniform_i *si = SourceOptionType::MousePoint; return true; } + else if (source == "random") + { + if ((!ui.type.is_floating_point() && !ui.type.is_integral()) || ui.type.components() != 1) + { + Error::SetString(error, fmt::format("Unexpected type '{}' ({} components) for random source in uniform '{}'", + ui.type.description(), ui.type.components(), ui.name)); + return false; + } + + // TODO: This is missing min/max handling. + *si = (ui.type.base == reshadefx::type::t_float) ? SourceOptionType::RandomF : SourceOptionType::Random; + return true; + } else if (source == "overlay_active" || source == "has_depth") { *si = SourceOptionType::Zero; @@ -1241,6 +1255,19 @@ bool PostProcessing::ReShadeFXShader::Apply(GPUTexture* input, GPUFramebuffer* f } break; + case SourceOptionType::Random: + { + const s32 rv = m_random() % 32767; // reshade uses rand(), which on some platforms has a 0x7fff maximum. + std::memcpy(dst, &rv, sizeof(rv)); + } + break; + case SourceOptionType::RandomF: + { + const float rv = (m_random() - m_random.min()) / static_cast(m_random.max() - m_random.min()); + std::memcpy(dst, &rv, sizeof(rv)); + } + break; + case SourceOptionType::BufferWidth: case SourceOptionType::BufferHeight: { diff --git a/src/util/postprocessing_shader_fx.h b/src/util/postprocessing_shader_fx.h index cbbd8f06f..2d09e43ce 100644 --- a/src/util/postprocessing_shader_fx.h +++ b/src/util/postprocessing_shader_fx.h @@ -10,6 +10,8 @@ // reshadefx #include "effect_module.hpp" +#include + class Error; namespace PostProcessing { @@ -46,6 +48,8 @@ private: FrameCountF, PingPong, MousePoint, + Random, + RandomF, BufferWidth, BufferHeight, BufferWidthF, @@ -117,6 +121,9 @@ private: Common::Timer m_frame_timer; u32 m_frame_count = 0; + + // Specifically using a fixed seed, so that it's consistent from run-to-run. + std::mt19937 m_random{0x1337}; }; } // namespace PostProcessing \ No newline at end of file