Skip to content

Commit

Permalink
idk
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBarii committed Aug 4, 2024
1 parent 4ca2d4e commit 0fe9003
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 172 deletions.
37 changes: 25 additions & 12 deletions src/Client/GUI/Engine/Effects/Blur/blur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ ID3D11PixelShader *dbgShader;

void Blur::InitializePipeline()
{

HRESULT hr;
ID3D11DeviceContext* pContext;
SwapchainHook::d3d11Device->GetImmediateContext(&pContext);
Expand Down Expand Up @@ -211,8 +212,9 @@ void Blur::InitializePipeline()
sd.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
SwapchainHook::d3d11Device->CreateSamplerState(&sd, &pSampler);

}
pContext->Release();

}
void Blur::RenderToRTV(ID3D11RenderTargetView *pRenderTargetView, ID3D11ShaderResourceView *pShaderResourceView, XMFLOAT2 rtvSize)
{
HRESULT hr;
Expand All @@ -222,7 +224,8 @@ void Blur::RenderToRTV(ID3D11RenderTargetView *pRenderTargetView, ID3D11ShaderRe
dsd.DepthEnable = false;
dsd.StencilEnable = false;
ID3D11DepthStencilState *pDepthStencilState;
SwapchainHook::d3d11Device->CreateDepthStencilState(&dsd, &pDepthStencilState);
hr = SwapchainHook::d3d11Device->CreateDepthStencilState(&dsd, &pDepthStencilState);
if (FAILED(hr)) { pContext->Release(); return; }
pContext->OMSetDepthStencilState(pDepthStencilState, 0);

void *null = nullptr;
Expand All @@ -243,7 +246,7 @@ void Blur::RenderToRTV(ID3D11RenderTargetView *pRenderTargetView, ID3D11ShaderRe
pContext->VSSetShader(pVertexShader, nullptr, 0);
pContext->PSSetSamplers(0, 1, &pSampler);
pContext->PSSetConstantBuffers(0, 1, &pConstantBuffer);
D3D11_BLEND_DESC bd;
D3D11_BLEND_DESC bd{};
ZeroMemory(&bd, sizeof(bd));
bd.AlphaToCoverageEnable = false;
bd.RenderTarget[0].BlendEnable = true;
Expand All @@ -255,15 +258,17 @@ void Blur::RenderToRTV(ID3D11RenderTargetView *pRenderTargetView, ID3D11ShaderRe
bd.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
bd.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
ID3D11BlendState *pBlendState;
SwapchainHook::d3d11Device->CreateBlendState(&bd, &pBlendState);
hr = SwapchainHook::d3d11Device->CreateBlendState(&bd, &pBlendState);
if (FAILED(hr)) { pContext->Release(); pDepthStencilState->Release(); return; }
pContext->OMSetBlendState(pBlendState, NULL, 0xffffffff);
D3D11_RASTERIZER_DESC rd{};
rd.FillMode = D3D11_FILL_SOLID;
rd.CullMode = D3D11_CULL_NONE;
rd.DepthClipEnable = false;
rd.ScissorEnable = false;
ID3D11RasterizerState *pRasterizerState;
SwapchainHook::d3d11Device->CreateRasterizerState(&rd, &pRasterizerState);
hr = SwapchainHook::d3d11Device->CreateRasterizerState(&rd, &pRasterizerState);
if (FAILED(hr)) { pContext->Release(); pDepthStencilState->Release(); pBlendState->Release(); return; }
pContext->RSSetState(pRasterizerState);

pContext->PSSetShaderResources(0, 1, &pShaderResourceView);
Expand All @@ -280,26 +285,29 @@ void Blur::RenderToRTV(ID3D11RenderTargetView *pRenderTargetView, ID3D11ShaderRe
pContext->Draw(sizeof(quadVertices) / sizeof(quadVertices[0]), 0);
ID3D11RenderTargetView* kajgd = nullptr;
pContext->OMSetRenderTargets(1, &kajgd, nullptr);

pDepthStencilState->Release();
pBlendState->Release();
pRasterizerState->Release();
pContext->Release();
}

void Blur::RenderBlur(ID3D11RenderTargetView *pDstRenderTargetView, int iterations, float intensity)
{
ID3D11Texture2D* tex = MotionBlurListener::GetBackbuffer();
if(!tex) return;
if (!SwapchainHook::GetBackbuffer()) return;

ID3D11ShaderResourceView *pOrigShaderResourceView = MotionBlurListener::SaveBackbuffer();
if(!pOrigShaderResourceView) return;
ID3D11ShaderResourceView *pOrigShaderResourceView = MotionBlurListener::BackbufferToSRV();
if (!pOrigShaderResourceView) return;

ID3D11DeviceContext* pContext;
SwapchainHook::d3d11Device->GetImmediateContext(&pContext);

HRESULT hr;
std::vector<ID3D11Texture2D *> framebuffers;
std::vector<ID3D11RenderTargetView *> renderTargetViews;
std::vector<ID3D11ShaderResourceView *> shaderResourceViews;
std::vector<XMFLOAT2> fbSizes;
D3D11_TEXTURE2D_DESC desc;
tex->GetDesc(&desc);
SwapchainHook::GetBackbuffer()->GetDesc(&desc);

framebuffers.reserve((size_t)iterations);
renderTargetViews.reserve((size_t)iterations);
Expand Down Expand Up @@ -355,8 +363,13 @@ void Blur::RenderBlur(ID3D11RenderTargetView *pDstRenderTargetView, int iteratio
renderTargetViews[i]->Release();
framebuffers[i]->Release();
shaderResourceViews[i]->Release();

renderTargetViews.clear();
framebuffers.clear();
shaderResourceViews.clear();
fbSizes.clear();
}

tex->Release();
pContext->Release();
pOrigShaderResourceView->Release();
}
2 changes: 2 additions & 0 deletions src/Client/GUI/Engine/Elements/Control/Image/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ bool FlarialGUI::LoadImageFromResource(int resourceId, D3D12_CPU_DESCRIPTOR_HAND

void FlarialGUI::image(int resourceId, D2D1_RECT_F rect, LPCTSTR type, bool shouldadd) {

if(Client::settings.getSettingByName<bool>("noicons")->value) return;

if (isInScrollView and shouldadd) {
rect.top += scrollpos;
rect.bottom += scrollpos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,66 +1,48 @@
#include "../../../../Engine.hpp"
#include "../../../../../../Client.hpp"

inline float GetColorComponent(ImU32 color, int shift) {
return ((color >> shift) & 0xFF) / 255.0f;
}

void RoundedRectBorder(Vec2<float> Position, Vec2<float> Size, ImColor Colour, float Thickness, float Rounding, int Flags) {
ImGui::GetBackgroundDrawList()->AddRect(ImVec2(Position.x, Position.y), ImVec2(Position.x + Size.x, Position.y + Size.y), Colour, Rounding, Flags, Thickness);
}

void FlarialGUI::ShadowRect(Vec2<float> pos, Vec2<float> size, D2D_COLOR_F color, float rounding, int shadowSize)
{
if (isInScrollView) pos.y += scrollpos;

ImColor shadowColor = ImColor(color.r, color.g, color.b, color.a);
shadowColor.Value.w *= .5f;

for (int i = 0; i < shadowSize; i++)
{
float progress = (float)i / shadowSize;
float alphaFactor = (1.0f - progress) * (1.0f - progress); //took help from gpt for alpha factor

float shadowR = GetColorComponent(shadowColor, IM_COL32_R_SHIFT);
float shadowG = GetColorComponent(shadowColor, IM_COL32_G_SHIFT);
float shadowB = GetColorComponent(shadowColor, IM_COL32_B_SHIFT);
float shadowA = GetColorComponent(shadowColor, IM_COL32_A_SHIFT) * alphaFactor;

ImU32 fadedShadowColor = ImColor(shadowR, shadowG, shadowB, shadowA);

Vec2 offset = Vec2(progress * shadowSize, progress * shadowSize);

//ImGui::GetBackgroundDrawList()->AddRect(ImVec2(pos.x - offset.x, pos.y - offset.y), ImVec2(pos.x + size.x + (offset.x * 2), pos.y + size.y + (offset.y * 2)), fadedShadowColor, rounding + progress * shadowSize, 240, 2);

RoundedRectBorder(pos - offset, size + offset + offset, fadedShadowColor, 2.0f, rounding + progress * shadowSize, 240);
}
//ImGui::GetBackgroundDrawList()->AddRect(ImVec2(pos.x, pos.y), ImVec2(size.x + pos.y, size.y + pos.y), shadowColor, rounding, 240, 1);
RoundedRectBorder(pos, size, ImColor(color.r, color.g, color.b, color.a), 1, rounding, 240);

/*
color.a *= .5f;
for (int i = 0; i < shadowSize; i++)
{
float progress = (float)i / shadowSize;
float alphaFactor = (1.0f - progress) * (1.0f - progress); //took help from gpt for alpha factor
ImColor fadedShadowColor = ImColor(color.r, color.g, color.b, color.a * alphaFactor);
void FlarialGUI::ShadowRect(Vec2<float> pos, Vec2<float> size, D2D_COLOR_F color, float rounding, int shadowSize) {

Vec2 offset = Vec2(progress * shadowSize, progress * shadowSize);
if (Client::settings.getSettingByName<bool>("noshadows")->value) return;

ImGui::GetBackgroundDrawList()->AddRect(ImVec2(pos.x - (offset.x), pos.y - (offset.y)), ImVec2(pos.x + size.x + (offset.x * 2), pos.y + size.y + (offset.y * 2)), fadedShadowColor, rounding + progress * shadowSize, 0, 2);
if (isInScrollView) pos.y += scrollpos;

//FlarialGUI::RoundedHollowRect(pos.x - offset.x, pos.y - offset.y, 2.0f, fadedShadowColor, size.x + offset.x*2, size.y + offset.y*2, rounding + progress * shadowSize, rounding + progress * shadowSize);
//RoundedRectBorder(pos - offset, size + offset + offset, fadedShadowColor, 2.0f, rounding + progress * shadowSize);
ImColor shadowColor(color.r, color.g, color.b, color.a * 0.5f);

for (int i = 0; i < shadowSize; i++) {
float progress = static_cast<float>(i) / shadowSize;
float alphaFactor = (1.0f - progress) * (1.0f - progress);

ImColor fadedShadowColor = ImColor(
shadowColor.Value.x,
shadowColor.Value.y,
shadowColor.Value.z,
shadowColor.Value.w * alphaFactor
);

Vec2 offset(progress * shadowSize, progress * shadowSize);

RoundedRectBorder(
pos - offset,
size + offset + offset,
fadedShadowColor,
2.0f,
rounding + progress * shadowSize,
240
);
}

ImGui::GetBackgroundDrawList()->AddRect(ImVec2(pos.x, pos.y), ImVec2(pos.x + size.x, pos.y + size.y), D2DColorToImColor(color), rounding, 0, 2);
//FlarialGUI::RoundedHollowRect(pos.x, pos.y, shadowSize, color, size.x, size.y, rounding, rounding);
//RoundedRectBorder(pos, size, color, 1, rounding);
*/
}
RoundedRectBorder(
pos,
size,
ImColor(color.r, color.g, color.b, color.a),
1.0f,
rounding,
240
);
}
59 changes: 57 additions & 2 deletions src/Client/Hook/Hooks/Render/SwapchainHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ HRESULT SwapchainHook::swapchainCallback(IDXGISwapChain3 *pSwapChain, UINT syncI

} else {

SaveBackbuffer();

/* IMPORTANT FONT STUFF */
if (ImGui::GetCurrentContext()) {
Expand Down Expand Up @@ -419,8 +420,6 @@ HRESULT SwapchainHook::swapchainCallback(IDXGISwapChain3 *pSwapChain, UINT syncI
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();



RenderEvent event;
event.RTV = mainRenderTargetView;
EventHandler::onRender(event);
Expand Down Expand Up @@ -610,3 +609,59 @@ void SwapchainHook::DX12Init() {
init = true;
}
}

ID3D11Texture2D* SwapchainHook::GetBackbuffer()
{
return SavedD3D11BackBuffer;
}

void SwapchainHook::SaveBackbuffer()
{

Memory::SafeRelease(SavedD3D11BackBuffer);

ID3D11DeviceContext* deviceContext;
SwapchainHook::d3d11Device->GetImmediateContext(&deviceContext);
IDXGISurface1* backBuffer = nullptr;
HRESULT hr;
SwapchainHook::swapchain->GetBuffer(0, IID_PPV_ARGS(&backBuffer));

ID3D11Texture2D* buffer2D = nullptr;
if(FAILED(backBuffer->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&buffer2D)))) std::cout << "failed to get 2d" << std::endl;

D3D11_TEXTURE2D_DESC desc;
buffer2D->GetDesc(&desc);

ID3D11Texture2D* stageTex = nullptr;
D3D11_TEXTURE2D_DESC stageDesc = desc;
stageDesc.Usage = D3D11_USAGE_STAGING;
stageDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
stageDesc.BindFlags = 0;

//desc.Usage = DXGI_USAGE_SHADER_INPUT;
HRESULT r = SwapchainHook::d3d11Device->CreateTexture2D(&stageDesc, nullptr, &stageTex);
deviceContext->CopyResource(stageTex, buffer2D);

if (FAILED(r)) std::cout << "Failed to create stage texture: " << std::hex << r << std::endl;


D3D11_TEXTURE2D_DESC defaultDesc = desc;
defaultDesc.Usage = D3D11_USAGE_DEFAULT;
defaultDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
defaultDesc.CPUAccessFlags = 0;

ID3D11Texture2D* defaultTexture = nullptr;
hr = SwapchainHook::d3d11Device->CreateTexture2D(&defaultDesc, nullptr, &defaultTexture);
if (FAILED(hr)) {
std::cout << "Failed to create def texture: " << std::hex << r << std::endl;
}

deviceContext->CopyResource(defaultTexture, stageTex);

stageTex->Release();
Memory::SafeRelease(backBuffer);
Memory::SafeRelease(buffer2D);
Memory::SafeRelease(deviceContext);

SavedD3D11BackBuffer = defaultTexture;
}
5 changes: 4 additions & 1 deletion src/Client/Hook/Hooks/Render/SwapchainHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class SwapchainHook : public Hook {

static void DX12Init();

static ID3D11Texture2D* GetBackbuffer();
static void SaveBackbuffer();

typedef HRESULT(__thiscall *SwapchainOriginal)(IDXGISwapChain3 *, UINT, UINT);

static inline SwapchainOriginal funcOriginal = nullptr;
Expand All @@ -41,7 +44,7 @@ class SwapchainHook : public Hook {
SwapchainHook();

void enableHook() override;

static inline ID3D11Texture2D* SavedD3D11BackBuffer;
static ID3D12CommandQueue *queue;
static inline std::vector<IDXGISurface1 *> DXGISurfaces;
static inline std::vector<ID2D1Bitmap1 *> D2D1Bitmaps;
Expand Down
Loading

0 comments on commit 0fe9003

Please sign in to comment.