Skip to content

Commit

Permalink
blur (insane fps drops for me idk why)
Browse files Browse the repository at this point in the history
  • Loading branch information
oAnshull committed Aug 4, 2024
1 parent 24ee3c0 commit 4ca2d4e
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 54 deletions.
6 changes: 6 additions & 0 deletions src/Client/Events/Render/RenderEvent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

#include "../Event.hpp"
#include "../Cancellable.hpp"
#include <d2d1_3.h>
#include <d3d12.h>
#include <d3d11.h>
#include <d3d11on12.h>

class RenderEvent : public Event {
public:
ID3D11RenderTargetView* RTV;
};
113 changes: 69 additions & 44 deletions src/Client/GUI/Engine/Effects/Blur/blur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// CREDITS @MR CHIPS (@chyves)

#define BLUR_OFFSET 0.5f
#define BLUR_OFFSET 10

static const XMFLOAT4 quadVertices[] =
{
Expand All @@ -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)\
{\
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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]);

Expand Down
2 changes: 1 addition & 1 deletion src/Client/GUI/Engine/Engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/Client/Hook/Hooks/Render/SwapchainHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 1 addition & 5 deletions src/Client/Module/Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ bool ModuleManager::doesAnyModuleHave(const std::string& settingName) {
Module* ModuleManager::getModule(const std::string& name) {
size_t hash = std::hash<std::string>{}(name);

auto it = moduleMap.find(hash);
if (it != moduleMap.end()) {
return it->second;
}
return moduleMap[hash];

return nullptr;
}
5 changes: 2 additions & 3 deletions src/Client/Module/Modules/ClickGUI/ClickGUIRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ class ClickGUIRenderer : public Listener {

}

//if (realBlurAmount > 0.1) FlarialGUI::AllahBlur(realBlurAmount);


if (SwapchainHook::init && baseHeightActual > 0.1) {

/* Base Rectangle Start */
Expand All @@ -132,6 +129,8 @@ class ClickGUIRenderer : public Listener {

}

Blur::RenderBlur(event.RTV, 3, realBlurAmount/4);

float baseHeight = Constraints::RelativeConstraint(baseHeightReal);

Vec2<float> center = Constraints::CenterConstraint(baseWidth,
Expand Down

0 comments on commit 4ca2d4e

Please sign in to comment.