Postproc: Scale pixel deltas and round off screen position. Fixes #8016

This commit is contained in:
Henrik Rydgard 2015-11-02 22:22:48 +01:00
parent 728d9e51bd
commit b411fc0455
3 changed files with 22 additions and 24 deletions

View file

@ -59,16 +59,16 @@ void CenterDisplayOutputRect(float *x, float *y, float *w, float *h, float origW
float smallDisplayW = origW * customZoom;
float smallDisplayH = origH * customZoom;
if (!rotated) {
*x = ((frameW - smallDisplayW) / 2.0f) + offsetX;
*y = ((frameH - smallDisplayH) / 2.0f) + offsetY;
*w = smallDisplayW;
*h = smallDisplayH;
*x = floorf(((frameW - smallDisplayW) / 2.0f) + offsetX);
*y = floorf(((frameH - smallDisplayH) / 2.0f) + offsetY);
*w = floorf(smallDisplayW);
*h = floorf(smallDisplayH);
return;
} else {
*x = ((frameW - smallDisplayH) / 2.0f) + offsetX;
*y = ((frameH - smallDisplayW) / 2.0f) + offsetY;
*w = smallDisplayH;
*h = smallDisplayW;
*x = floorf(((frameW - smallDisplayH) / 2.0f) + offsetX);
*y = floorf(((frameH - smallDisplayW) / 2.0f) + offsetY);
*w = floorf(smallDisplayH);
*h = floorf(smallDisplayW);
return;
}
} else {
@ -76,9 +76,9 @@ void CenterDisplayOutputRect(float *x, float *y, float *w, float *h, float origW
float resCommonWidescreen = pixelCrop - floor(pixelCrop);
if (!rotated && resCommonWidescreen == 0.0f) {
*x = 0;
*y = -pixelCrop;
*w = frameW;
*h = pixelCrop * 272.0f;
*y = floorf(-pixelCrop);
*w = floorf(frameW);
*h = floorf(pixelCrop * 272.0f);
return;
}
}
@ -102,10 +102,10 @@ void CenterDisplayOutputRect(float *x, float *y, float *w, float *h, float origW
}
}
*x = (frameW - outW) / 2.0f;
*y = (frameH - outH) / 2.0f;
*w = outW;
*h = outH;
*x = floorf((frameW - outW) / 2.0f);
*y = floorf((frameH - outH) / 2.0f);
*w = floorf(outW);
*h = floorf(outH);
}

View file

@ -210,8 +210,6 @@ void FramebufferManager::CompileDraw2DProgram() {
deltaLoc_ = glsl_uniform_loc(postShaderProgram_, "u_texelDelta");
pixelDeltaLoc_ = glsl_uniform_loc(postShaderProgram_, "u_pixelDelta");
timeLoc_ = glsl_uniform_loc(postShaderProgram_, "u_time");
UpdatePostShaderUniforms(renderWidth_, renderHeight_);
usePostShader_ = true;
}
} else {
@ -223,7 +221,7 @@ void FramebufferManager::CompileDraw2DProgram() {
}
}
void FramebufferManager::UpdatePostShaderUniforms(int renderWidth, int renderHeight) {
void FramebufferManager::UpdatePostShaderUniforms(int bufferWidth, int bufferHeight, int renderWidth, int renderHeight) {
float u_delta = 1.0f / renderWidth;
float v_delta = 1.0f / renderHeight;
float u_pixel_delta = u_delta;
@ -231,8 +229,8 @@ void FramebufferManager::UpdatePostShaderUniforms(int renderWidth, int renderHei
if (postShaderAtOutputResolution_) {
float x, y, w, h;
CenterDisplayOutputRect(&x, &y, &w, &h, 480.0f, 272.0f, (float)pixelWidth_, (float)pixelHeight_, ROTATION_LOCKED_HORIZONTAL, false);
u_pixel_delta = 1.0f / w;
v_pixel_delta = 1.0f / h;
u_pixel_delta = (1.0f / w) * (480.0f / bufferWidth);
v_pixel_delta = (1.0f / h) * (272.0f / bufferHeight);
}
if (deltaLoc_ != -1)
@ -427,7 +425,7 @@ void FramebufferManager::DrawFramebufferToOutput(const u8 *srcPixels, GEBufferFo
CenterDisplayOutputRect(&x, &y, &w, &h, 480.0f, 272.0f, (float)pixelWidth_, (float)pixelHeight_, uvRotation, true);
if (applyPostShader) {
glsl_bind(postShaderProgram_);
UpdatePostShaderUniforms(renderWidth_, renderHeight_);
UpdatePostShaderUniforms(480, 272, renderWidth_, renderHeight_);
}
float u0 = 0.0f, u1 = 480.0f / 512.0f;
float v0 = 0.0f, v1 = 1.0f;
@ -1089,7 +1087,7 @@ void FramebufferManager::CopyDisplayToOutput() {
glstate.viewport.set(0, 0, fbo_w, fbo_h);
shaderManager_->DirtyLastShader(); // dirty lastShader_
glsl_bind(postShaderProgram_);
UpdatePostShaderUniforms(renderWidth_, renderHeight_);
UpdatePostShaderUniforms(vfb->bufferWidth, vfb->bufferHeight, renderWidth_, renderHeight_);
DrawActiveTexture(colorTexture, 0, 0, fbo_w, fbo_h, fbo_w, fbo_h, 0.0f, 0.0f, 1.0f, 1.0f, postShaderProgram_, ROTATION_LOCKED_HORIZONTAL);
fbo_unbind();
@ -1132,7 +1130,7 @@ void FramebufferManager::CopyDisplayToOutput() {
shaderManager_->DirtyLastShader(); // dirty lastShader_
glsl_bind(postShaderProgram_);
UpdatePostShaderUniforms(vfb->renderWidth, vfb->renderHeight);
UpdatePostShaderUniforms(vfb->bufferWidth, vfb->bufferHeight, vfb->renderWidth, vfb->renderHeight);
if (g_Config.bEnableCardboard) {
// Left Eye Image
glstate.viewport.set(cardboardSettings.leftEyeXPosition, cardboardSettings.screenYPosition, cardboardSettings.screenWidth, cardboardSettings.screenHeight);

View file

@ -137,7 +137,7 @@ protected:
virtual void NotifyRenderFramebufferUpdated(VirtualFramebuffer *vfb, bool vfbFormatChanged) override;
private:
void UpdatePostShaderUniforms(int renderWidth, int renderHeight);
void UpdatePostShaderUniforms(int bufferWidth, int bufferHeight, int renderWidth, int renderHeight);
void CompileDraw2DProgram();
void DestroyDraw2DProgram();