diff options
| author | qwasdrizzel <145519042+qwasdrizzel@users.noreply.github.com> | 2026-03-16 21:44:26 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-16 21:44:26 -0500 |
| commit | ce739f6045ec72127491286ea3f3f21e537c1b55 (patch) | |
| tree | f33bd42a47c1b4a7b2153a7fb77127ee3b407db9 /Minecraft.Client/Windows64/PostProcesser.cpp | |
| parent | 255a18fe8e9b57377975f82e2b227afe2a12eda0 (diff) | |
| parent | 5a59f5d146b43811dde6a5a0245ee9875d7b5cd1 (diff) | |
Merge branch 'smartcmd:main' into main
Diffstat (limited to 'Minecraft.Client/Windows64/PostProcesser.cpp')
| -rw-r--r-- | Minecraft.Client/Windows64/PostProcesser.cpp | 80 |
1 files changed, 49 insertions, 31 deletions
diff --git a/Minecraft.Client/Windows64/PostProcesser.cpp b/Minecraft.Client/Windows64/PostProcesser.cpp index 5abd83b4..aabb1f67 100644 --- a/Minecraft.Client/Windows64/PostProcesser.cpp +++ b/Minecraft.Client/Windows64/PostProcesser.cpp @@ -21,14 +21,22 @@ const char* PostProcesser::g_gammaPSCode = "cbuffer GammaCB : register(b0)\n" "{\n" " float gamma;\n" - " float3 pad;\n" + " float _pad;\n" + " float2 uvOffset;\n" + " float2 uvScale;\n" + " float2 _pad2;\n" "};\n" "Texture2D sceneTex : register(t0);\n" "SamplerState sceneSampler : register(s0);\n" "float4 main(float4 pos : SV_Position, float2 uv : TEXCOORD0) : SV_Target\n" "{\n" - " float4 color = sceneTex.Sample(sceneSampler, uv);\n" - " color.rgb = pow(max(color.rgb, 0.0), 1.0 / gamma);\n" + " float2 texUV = uvOffset + uv * uvScale;\n" + " float4 color = sceneTex.Sample(sceneSampler, texUV);\n" + "\n" + " color.rgb = max(color.rgb, 0.0);\n" + "\n" + " color.rgb = pow(color.rgb, 1.0 / gamma);\n" + "\n" " return color;\n" "}\n"; @@ -75,6 +83,9 @@ void PostProcesser::Init() pBackBuffer->GetDesc(&bbDesc); pBackBuffer->Release(); + m_gammaTexWidth = bbDesc.Width; + m_gammaTexHeight = bbDesc.Height; + DXGI_FORMAT texFormat = bbDesc.Format; if (m_wineMode) { @@ -151,7 +162,7 @@ void PostProcesser::Init() cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - GammaCBData initData = {1.0f, {0, 0, 0}}; + GammaCBData initData = {1.0f, 0, 0.0f, 0.0f, 1.0f, 1.0f, {0, 0}}; D3D11_SUBRESOURCE_DATA srData; srData.pSysMem = &initData; srData.SysMemPitch = 0; @@ -219,7 +230,9 @@ void PostProcesser::Apply() const if (FAILED(hr)) return; - ctx->CopyResource(m_pGammaOffscreenTex, pBackBuffer); + D3D11_BOX srcBox = { 0, 0, 0, m_gammaTexWidth, m_gammaTexHeight, 1 }; + ctx->CopySubresourceRegion(m_pGammaOffscreenTex, 0, 0, 0, 0, pBackBuffer, 0, &srcBox); + pBackBuffer->Release(); D3D11_MAPPED_SUBRESOURCE mapped; const D3D11_MAP mapType = m_wineMode ? D3D11_MAP_WRITE_NO_OVERWRITE : D3D11_MAP_WRITE_DISCARD; @@ -228,6 +241,10 @@ void PostProcesser::Apply() const { GammaCBData *cb = static_cast<GammaCBData *>(mapped.pData); cb->gamma = m_gamma; + cb->uvOffsetX = 0.0f; + cb->uvOffsetY = 0.0f; + cb->uvScaleX = 1.0f; + cb->uvScaleY = 1.0f; ctx->Unmap(m_pGammaCB, 0); } @@ -236,16 +253,12 @@ void PostProcesser::Apply() const ctx->OMGetRenderTargets(1, &oldRTV, &oldDSV); UINT numViewports = 1; - D3D11_VIEWPORT oldViewport; + D3D11_VIEWPORT oldViewport = {}; ctx->RSGetViewports(&numViewports, &oldViewport); ID3D11RenderTargetView* bbRTV = g_pRenderTargetView; ctx->OMSetRenderTargets(1, &bbRTV, nullptr); - D3D11_TEXTURE2D_DESC bbDesc; - pBackBuffer->GetDesc(&bbDesc); - pBackBuffer->Release(); - D3D11_VIEWPORT vp; if (m_useCustomViewport) { @@ -253,8 +266,8 @@ void PostProcesser::Apply() const } else { - vp.Width = static_cast<FLOAT>(bbDesc.Width); - vp.Height = static_cast<FLOAT>(bbDesc.Height); + vp.Width = static_cast<FLOAT>(m_gammaTexWidth); + vp.Height = static_cast<FLOAT>(m_gammaTexHeight); vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; vp.TopLeftX = 0; @@ -313,7 +326,8 @@ void PostProcesser::CopyBackbuffer() if (FAILED(hr)) return; - ctx->CopyResource(m_pGammaOffscreenTex, pBackBuffer); + D3D11_BOX srcBox = { 0, 0, 0, m_gammaTexWidth, m_gammaTexHeight, 1 }; + ctx->CopySubresourceRegion(m_pGammaOffscreenTex, 0, 0, 0, 0, pBackBuffer, 0, &srcBox); pBackBuffer->Release(); } @@ -327,6 +341,21 @@ void PostProcesser::ApplyFromCopied() const ID3D11DeviceContext* ctx = g_pImmediateContext; + D3D11_VIEWPORT vp; + if (m_useCustomViewport) + { + vp = m_customViewport; + } + else + { + vp.Width = static_cast<FLOAT>(m_gammaTexWidth); + vp.Height = static_cast<FLOAT>(m_gammaTexHeight); + vp.MinDepth = 0.0f; + vp.MaxDepth = 1.0f; + vp.TopLeftX = 0; + vp.TopLeftY = 0; + } + D3D11_MAPPED_SUBRESOURCE mapped; const D3D11_MAP mapType = m_wineMode ? D3D11_MAP_WRITE_NO_OVERWRITE : D3D11_MAP_WRITE_DISCARD; const HRESULT hr = ctx->Map(m_pGammaCB, 0, mapType, 0, &mapped); @@ -334,6 +363,12 @@ void PostProcesser::ApplyFromCopied() const { const auto cb = static_cast<GammaCBData*>(mapped.pData); cb->gamma = m_gamma; + const float texW = static_cast<float>(m_gammaTexWidth); + const float texH = static_cast<float>(m_gammaTexHeight); + cb->uvOffsetX = vp.TopLeftX / texW; + cb->uvOffsetY = vp.TopLeftY / texH; + cb->uvScaleX = vp.Width / texW; + cb->uvScaleY = vp.Height / texH; ctx->Unmap(m_pGammaCB, 0); } @@ -342,29 +377,12 @@ void PostProcesser::ApplyFromCopied() const ctx->OMGetRenderTargets(1, &oldRTV, &oldDSV); UINT numViewports = 1; - D3D11_VIEWPORT oldViewport; + D3D11_VIEWPORT oldViewport = {}; ctx->RSGetViewports(&numViewports, &oldViewport); ID3D11RenderTargetView* bbRTV = g_pRenderTargetView; ctx->OMSetRenderTargets(1, &bbRTV, nullptr); - D3D11_VIEWPORT vp; - if (m_useCustomViewport) - { - vp = m_customViewport; - } - else - { - D3D11_TEXTURE2D_DESC texDesc; - m_pGammaOffscreenTex->GetDesc(&texDesc); - vp.Width = static_cast<FLOAT>(texDesc.Width); - vp.Height = static_cast<FLOAT>(texDesc.Height); - vp.MinDepth = 0.0f; - vp.MaxDepth = 1.0f; - vp.TopLeftX = 0; - vp.TopLeftY = 0; - } - ctx->RSSetViewports(1, &vp); ctx->IASetInputLayout(nullptr); |
