From 4ca2d4e50648a98ffa7f7e67f0aa9c7be1a8c05b Mon Sep 17 00:00:00 2001 From: oAnshull Date: Sun, 4 Aug 2024 16:06:02 +0530 Subject: [PATCH] blur (insane fps drops for me idk why) --- src/Client/Events/Render/RenderEvent.hpp | 6 + src/Client/GUI/Engine/Effects/Blur/blur.cpp | 113 +++++++++++------- src/Client/GUI/Engine/Engine.hpp | 2 +- .../Hook/Hooks/Render/SwapchainHook.cpp | 3 +- src/Client/Module/Manager.cpp | 6 +- .../Modules/ClickGUI/ClickGUIRenderer.hpp | 5 +- 6 files changed, 81 insertions(+), 54 deletions(-) diff --git a/src/Client/Events/Render/RenderEvent.hpp b/src/Client/Events/Render/RenderEvent.hpp index 76dc8f63..9a9e2894 100644 --- a/src/Client/Events/Render/RenderEvent.hpp +++ b/src/Client/Events/Render/RenderEvent.hpp @@ -3,6 +3,12 @@ #include "../Event.hpp" #include "../Cancellable.hpp" +#include +#include +#include +#include class RenderEvent : public Event { +public: + ID3D11RenderTargetView* RTV; }; \ No newline at end of file diff --git a/src/Client/GUI/Engine/Effects/Blur/blur.cpp b/src/Client/GUI/Engine/Effects/Blur/blur.cpp index 44ae6a66..67e540b9 100644 --- a/src/Client/GUI/Engine/Effects/Blur/blur.cpp +++ b/src/Client/GUI/Engine/Effects/Blur/blur.cpp @@ -7,7 +7,7 @@ // CREDITS @MR CHIPS (@chyves) -#define BLUR_OFFSET 0.5f +#define BLUR_OFFSET 10 static const XMFLOAT4 quadVertices[] = { @@ -31,75 +31,100 @@ cbuffer BlurInputBuffer : register(b0) { float2 resolution; float2 offset; - float2 halfpixel; + float2 halfPixel; }; + sampler sampler0 : register(s0); Texture2D texture0 : register(t0); float4 main(float4 screenSpace : SV_Position) : SV_TARGET { float2 uv = screenSpace.xy / resolution; - float4 sum = float4(0.0, 0.0, 0.0, 0.0); - float2 offsets[5] = { - -2.0 * halfpixel * offset, - -halfpixel * offset, - float2(0.0, 0.0), - halfpixel * offset, - 2.0 * halfpixel * offset + float4 colorSum = float4(0.0, 0.0, 0.0, 0.0); + + static const float2 offsets[9] = { + float2(-1.0, -1.0) * halfPixel * offset, + float2(0.0, -1.0) * halfPixel * offset, + float2(1.0, -1.0) * halfPixel * offset, + float2(-1.0, 0.0) * halfPixel * offset, + float2(0.0, 0.0) * halfPixel * offset, + float2(1.0, 0.0) * halfPixel * offset, + float2(-1.0, 1.0) * halfPixel * offset, + float2(0.0, 1.0) * halfPixel * offset, + float2(1.0, 1.0) * halfPixel * offset }; - float weights[5] = { - 0.06136, - 0.24477, - 0.38774, - 0.24477, - 0.06136 + + static const float weights[9] = { + 0.06136, 0.12245, 0.06136, + 0.12245, 0.24477, 0.12245, + 0.06136, 0.12245, 0.06136 }; - for (int i = 0; i < 5; i++) + + float weightSum = 0.0; + for (int i = 0; i < 9; i++) + { + weightSum += weights[i]; + } + + for (int i = 0; i < 9; i++) { - sum += texture0.Sample(sampler0, uv + offsets[i]) * weights[i]; + colorSum += texture0.Sample(sampler0, uv + offsets[i]) * (weights[i] / weightSum); } - return sum; -})"; + return colorSum; +} +)"; const char *upsampleShaderSrc = R"( cbuffer BlurInputBuffer : register(b0) { float2 resolution; float2 offset; - float2 halfpixel; -}; -struct PS_INPUT -{ - float4 pos : POSITION; + float2 halfPixel; }; + sampler sampler0 : register(s0); Texture2D texture0 : register(t0); -float4 main(PS_INPUT input, float4 screenSpace : SV_Position) : SV_TARGET +float4 main(float4 screenSpace : SV_Position) : SV_TARGET { float2 uv = screenSpace.xy / resolution; - float4 sum = float4(0.0, 0.0, 0.0, 0.0); - float2 offsets[5] = { - -2.0 * halfpixel * offset, - -halfpixel * offset, - float2(0.0, 0.0), - halfpixel * offset, - 2.0 * halfpixel * offset + float4 colorSum = float4(0.0, 0.0, 0.0, 0.0); + + static const float2 offsets[9] = { + float2(-1.0, -1.0) * halfPixel * offset, + float2(0.0, -1.0) * halfPixel * offset, + float2(1.0, -1.0) * halfPixel * offset, + float2(-1.0, 0.0) * halfPixel * offset, + float2(0.0, 0.0) * halfPixel * offset, + float2(1.0, 0.0) * halfPixel * offset, + float2(-1.0, 1.0) * halfPixel * offset, + float2(0.0, 1.0) * halfPixel * offset, + float2(1.0, 1.0) * halfPixel * offset }; - float weights[5] = { - 0.06136, - 0.24477, - 0.38774, - 0.24477, - 0.06136 + + static const float weights[9] = { + 0.06136, 0.12245, 0.06136, + 0.12245, 0.24477, 0.12245, + 0.06136, 0.12245, 0.06136 }; - for (int i = 0; i < 5; i++) + + float weightSum = 0.0; + for (int i = 0; i < 9; i++) + { + weightSum += weights[i]; + } + + for (int i = 0; i < 9; i++) { - sum += texture0.Sample(sampler0, uv + offsets[i]) * weights[i]; + colorSum += texture0.Sample(sampler0, uv + offsets[i]) * (weights[i] / weightSum); } - return sum; -})"; + + return colorSum; +} +)"; + + const char *dbgDrawTextureShaderSrc = "cbuffer BlurInputBuffer : register(b0)\ {\ @@ -257,7 +282,7 @@ void Blur::RenderToRTV(ID3D11RenderTargetView *pRenderTargetView, ID3D11ShaderRe pContext->OMSetRenderTargets(1, &kajgd, nullptr); } -void Blur::RenderBlur(ID3D11RenderTargetView *pDstRenderTargetView, int iterations) +void Blur::RenderBlur(ID3D11RenderTargetView *pDstRenderTargetView, int iterations, float intensity) { ID3D11Texture2D* tex = MotionBlurListener::GetBackbuffer(); if(!tex) return; @@ -308,7 +333,7 @@ void Blur::RenderBlur(ID3D11RenderTargetView *pDstRenderTargetView, int iteratio desc.Height /= 2; } - constantBuffer.offset = XMFLOAT2(BLUR_OFFSET, BLUR_OFFSET); + constantBuffer.offset = XMFLOAT2(intensity, intensity); pContext->PSSetShader(pDownsampleShader, nullptr, 0); RenderToRTV(renderTargetViews[1], pOrigShaderResourceView, fbSizes[1]); diff --git a/src/Client/GUI/Engine/Engine.hpp b/src/Client/GUI/Engine/Engine.hpp index 3354a9e7..4b44c7cd 100644 --- a/src/Client/GUI/Engine/Engine.hpp +++ b/src/Client/GUI/Engine/Engine.hpp @@ -53,7 +53,7 @@ class Blur //static void Cleanup(); static void RenderToRTV(ID3D11RenderTargetView *, ID3D11ShaderResourceView *, XMFLOAT2); - static void RenderBlur(ID3D11RenderTargetView *, int); + static void RenderBlur(ID3D11RenderTargetView *, int, float); }; class Dimension { diff --git a/src/Client/Hook/Hooks/Render/SwapchainHook.cpp b/src/Client/Hook/Hooks/Render/SwapchainHook.cpp index d68244c0..a964d083 100644 --- a/src/Client/Hook/Hooks/Render/SwapchainHook.cpp +++ b/src/Client/Hook/Hooks/Render/SwapchainHook.cpp @@ -419,9 +419,10 @@ HRESULT SwapchainHook::swapchainCallback(IDXGISwapChain3 *pSwapChain, UINT syncI ImGui_ImplWin32_NewFrame(); ImGui::NewFrame(); - Blur::RenderBlur(mainRenderTargetView, 3); + RenderEvent event; + event.RTV = mainRenderTargetView; EventHandler::onRender(event); D2D::context->EndDraw(); diff --git a/src/Client/Module/Manager.cpp b/src/Client/Module/Manager.cpp index da5cfc53..c7ed4024 100644 --- a/src/Client/Module/Manager.cpp +++ b/src/Client/Module/Manager.cpp @@ -198,10 +198,6 @@ bool ModuleManager::doesAnyModuleHave(const std::string& settingName) { Module* ModuleManager::getModule(const std::string& name) { size_t hash = std::hash{}(name); - auto it = moduleMap.find(hash); - if (it != moduleMap.end()) { - return it->second; - } + return moduleMap[hash]; - return nullptr; } diff --git a/src/Client/Module/Modules/ClickGUI/ClickGUIRenderer.hpp b/src/Client/Module/Modules/ClickGUI/ClickGUIRenderer.hpp index 51a2205f..4afee4ed 100644 --- a/src/Client/Module/Modules/ClickGUI/ClickGUIRenderer.hpp +++ b/src/Client/Module/Modules/ClickGUI/ClickGUIRenderer.hpp @@ -117,9 +117,6 @@ class ClickGUIRenderer : public Listener { } - //if (realBlurAmount > 0.1) FlarialGUI::AllahBlur(realBlurAmount); - - if (SwapchainHook::init && baseHeightActual > 0.1) { /* Base Rectangle Start */ @@ -132,6 +129,8 @@ class ClickGUIRenderer : public Listener { } + Blur::RenderBlur(event.RTV, 3, realBlurAmount/4); + float baseHeight = Constraints::RelativeConstraint(baseHeightReal); Vec2 center = Constraints::CenterConstraint(baseWidth,