- apply present shader on screenshots

This commit is contained in:
Magnus Norddahl 2019-05-20 12:36:45 +02:00
parent 61ead74492
commit 2a15f65065
3 changed files with 26 additions and 8 deletions

View file

@ -169,7 +169,7 @@ void VkPostprocess::BlitCurrentToImage(VkTextureImage *dstimage, VkImageLayout f
imageTransition1.execute(cmdbuffer);
}
void VkPostprocess::DrawPresentTexture(const IntRect &box, bool applyGamma, bool clearBorders)
void VkPostprocess::DrawPresentTexture(const IntRect &box, bool applyGamma, bool screenshot)
{
auto fb = GetVulkanFrameBuffer();
@ -193,10 +193,19 @@ void VkPostprocess::DrawPresentTexture(const IntRect &box, bool applyGamma, bool
uniforms.GrayFormula = static_cast<int>(gl_satformula);
}
uniforms.ColorScale = (gl_dither_bpc == -1) ? 255.0f : (float)((1 << gl_dither_bpc) - 1);
uniforms.Scale = { screen->mScreenViewport.width / (float)fb->GetBuffers()->GetWidth(), -screen->mScreenViewport.height / (float)fb->GetBuffers()->GetHeight() };
uniforms.Offset = { 0.0f, 1.0f };
if (applyGamma && fb->swapChain->swapChainFormat.colorSpace == VK_COLOR_SPACE_HDR10_ST2084_EXT)
if (screenshot)
{
uniforms.Scale = { screen->mScreenViewport.width / (float)fb->GetBuffers()->GetWidth(), screen->mScreenViewport.height / (float)fb->GetBuffers()->GetHeight() };
uniforms.Offset = { 0.0f, 0.0f };
}
else
{
uniforms.Scale = { screen->mScreenViewport.width / (float)fb->GetBuffers()->GetWidth(), -screen->mScreenViewport.height / (float)fb->GetBuffers()->GetHeight() };
uniforms.Offset = { 0.0f, 1.0f };
}
if (applyGamma && fb->swapChain->swapChainFormat.colorSpace == VK_COLOR_SPACE_HDR10_ST2084_EXT && !screenshot)
{
uniforms.HdrMode = 1;
}
@ -211,9 +220,11 @@ void VkPostprocess::DrawPresentTexture(const IntRect &box, bool applyGamma, bool
renderstate.Viewport = box;
renderstate.SetInputCurrent(0, ViewportLinearScale() ? PPFilterMode::Linear : PPFilterMode::Nearest);
renderstate.SetInputTexture(1, &hw_postprocess.present.Dither, PPFilterMode::Nearest, PPWrapMode::Repeat);
renderstate.SetOutputSwapChain();
if (screenshot)
renderstate.SetOutputNext();
else
renderstate.SetOutputSwapChain();
renderstate.SetNoBlend();
//if (clearBorders) renderstate.SetClearBorders();
renderstate.Draw();
}

View file

@ -56,7 +56,7 @@ public:
void BlitSceneToPostprocess();
void BlitCurrentToImage(VkTextureImage *image, VkImageLayout finallayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
void DrawPresentTexture(const IntRect &box, bool applyGamma, bool clearBorders);
void DrawPresentTexture(const IntRect &box, bool applyGamma, bool screenshot);
private:
void NextEye(int eyeCount);

View file

@ -272,7 +272,7 @@ void VulkanFrameBuffer::WaitForCommands(bool finish)
presentImageIndex = swapChain->AcquireImage(GetClientWidth(), GetClientHeight(), mSwapChainImageAvailableSemaphore.get());
if (presentImageIndex != 0xffffffff)
mPostprocess->DrawPresentTexture(mOutputLetterbox, true, true);
mPostprocess->DrawPresentTexture(mOutputLetterbox, true, false);
}
FlushCommands(finish, true);
@ -787,6 +787,13 @@ TArray<uint8_t> VulkanFrameBuffer::GetScreenshotBuffer(int &pitch, ESSType &colo
int w = SCREENWIDTH;
int h = SCREENHEIGHT;
IntRect box;
box.left = 0;
box.top = 0;
box.width = w;
box.height = h;
mPostprocess->DrawPresentTexture(box, true, true);
TArray<uint8_t> ScreenshotBuffer(w * h * 3, true);
CopyScreenToBuffer(w, h, ScreenshotBuffer.Data());