| 160 | // const char *const s_caString = "Chromatic Aberration"; |
| 161 | |
| 162 | bool caOnDraw(ID3D11DeviceContext *context, ID3D11PixelShader *currentPs, std::function<void()> origDrawFn) |
| 163 | { |
| 164 | ZoneScopedN(__FUNCTION__); |
| 165 | |
| 166 | // Insert chromatic aberration after the sharpening pass |
| 167 | if (g_sharpenPsHandle.isValid() && ShaderRegistry::getPs(g_sharpenPsHandle) == currentPs && currentPs != nullptr) |
| 168 | { |
| 169 | if (g_settings.chromaticAberrationEnabled) |
| 170 | { |
| 171 | TracyD3D11Zone(g_tracyD3D11Ctx, "Chromatic Aberration (ON)"); |
| 172 | // FrameMarkStart(s_caString); |
| 173 | |
| 174 | static ShaderHandle chromaticAberrationPsHandle; |
| 175 | static bool resourcesCreated = false; |
| 176 | static glm::uvec2 resourcesResolution; |
| 177 | static ID3D11Texture2D *tempTex; |
| 178 | static ID3D11Buffer *constantBuffer; |
| 179 | |
| 180 | const uint screenWidth = g_frameConstants.screenWidth; |
| 181 | const uint screenHeight = g_frameConstants.screenHeight; |
| 182 | |
| 183 | struct Constants |
| 184 | { |
| 185 | float caAmount; |
| 186 | float pad[3]; |
| 187 | } constants = {g_settings.chromaticAberration}; |
| 188 | |
| 189 | if (!resourcesCreated || resourcesResolution != glm::uvec2(screenWidth, screenHeight)) |
| 190 | { |
| 191 | resourcesCreated = true; |
| 192 | resourcesResolution = glm::uvec2(screenWidth, screenHeight); |
| 193 | |
| 194 | chromaticAberrationPsHandle = ShaderRegistry::addPixelShader("chromaticAberration_ps.cso"); |
| 195 | |
| 196 | { |
| 197 | D3D11_TEXTURE2D_DESC texDesc; |
| 198 | ZeroMemory(&texDesc, sizeof(texDesc)); |
| 199 | texDesc.Width = screenWidth; |
| 200 | texDesc.Height = screenHeight; |
| 201 | texDesc.MipLevels = 1; |
| 202 | texDesc.ArraySize = 1; |
| 203 | texDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; |
| 204 | texDesc.SampleDesc.Count = 1; |
| 205 | texDesc.SampleDesc.Quality = 0; |
| 206 | texDesc.Usage = D3D11_USAGE_DEFAULT; |
| 207 | texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; |
| 208 | |
| 209 | DX_CHECK(g_device->CreateTexture2D(&texDesc, nullptr, &tempTex)); |
| 210 | } |
| 211 | |
| 212 | constantBuffer = createConstantBuffer(sizeof(Constants)); |
| 213 | } |
| 214 | |
| 215 | updateConstantBuffer(context, constantBuffer, &constants, sizeof(constants)); |
| 216 | |
| 217 | CComPtr<ID3D11RenderTargetView> targetRtv = nullptr; |
| 218 | context->OMGetRenderTargets(1, &targetRtv.p, nullptr); |
| 219 |
no test coverage detected