From fcbf9342d69a04619042df12c88e857e7d41ee4e Mon Sep 17 00:00:00 2001 From: Christopher Bruns Date: Sun, 2 Oct 2016 13:11:07 -0400 Subject: [PATCH] Compute row location using gl_FragCoord. --- src/gl/shaders/gl_present3dRowshader.cpp | 1 + src/gl/shaders/gl_present3dRowshader.h | 1 + src/gl/stereo3d/gl_interleaved3d.cpp | 13 +++++-------- wadsrc/static/shaders/glsl/present_row3d.fp | 6 ++---- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/gl/shaders/gl_present3dRowshader.cpp b/src/gl/shaders/gl_present3dRowshader.cpp index 607e4ede6..931278aaa 100644 --- a/src/gl/shaders/gl_present3dRowshader.cpp +++ b/src/gl/shaders/gl_present3dRowshader.cpp @@ -54,6 +54,7 @@ void FPresent3DRowShader::Bind() Contrast.Init(mShader, "Contrast"); Brightness.Init(mShader, "Brightness"); Scale.Init(mShader, "UVScale"); + WindowHeight.Init(mShader, "WindowHeight"); VerticalPixelOffset.Init(mShader, "VerticalPixelOffset"); } mShader.Bind(); diff --git a/src/gl/shaders/gl_present3dRowshader.h b/src/gl/shaders/gl_present3dRowshader.h index 8e3bd772d..b7f0d87b2 100644 --- a/src/gl/shaders/gl_present3dRowshader.h +++ b/src/gl/shaders/gl_present3dRowshader.h @@ -41,6 +41,7 @@ public: FBufferedUniform1f Contrast; FBufferedUniform1f Brightness; FBufferedUniform2f Scale; + FBufferedUniform1i WindowHeight; FBufferedUniform1i VerticalPixelOffset; private: diff --git a/src/gl/stereo3d/gl_interleaved3d.cpp b/src/gl/stereo3d/gl_interleaved3d.cpp index 28b9c373e..5e0281ee6 100644 --- a/src/gl/stereo3d/gl_interleaved3d.cpp +++ b/src/gl/stereo3d/gl_interleaved3d.cpp @@ -61,14 +61,6 @@ void RowInterleaved3D::Present() const GLRenderer->mBuffers->BindOutputFB(); GLRenderer->ClearBorders(); - // Compute screen regions to use for left and right eye views - int topHeight = GLRenderer->mOutputLetterbox.height / 2; - GL_IRECT topHalfScreen = GLRenderer->mOutputLetterbox; - topHalfScreen.height = topHeight; - topHalfScreen.top = topHeight; - GL_IRECT bottomHalfScreen = GLRenderer->mOutputLetterbox; - bottomHalfScreen.height = topHeight; - bottomHalfScreen.top = 0; // Bind each eye texture, for composition in the shader GLRenderer->mBuffers->BindEyeTexture(0, 0); @@ -90,6 +82,7 @@ void RowInterleaved3D::Present() const GLRenderer->mPresent3dRowShader->Bind(); GLRenderer->mPresent3dRowShader->LeftEyeTexture.Set(0); GLRenderer->mPresent3dRowShader->RightEyeTexture.Set(1); + if (!applyGamma || GLRenderer->framebuffer->IsHWGammaActive()) { GLRenderer->mPresent3dRowShader->InvGamma.Set(1.0f); @@ -105,7 +98,11 @@ void RowInterleaved3D::Present() const GLRenderer->mPresent3dRowShader->Scale.Set( GLRenderer->mScreenViewport.width / (float)GLRenderer->mBuffers->GetWidth(), GLRenderer->mScreenViewport.height / (float)GLRenderer->mBuffers->GetHeight()); + + GLRenderer->mPresent3dRowShader->WindowHeight.Set(0); + GLRenderer->mPresent3dRowShader->VerticalPixelOffset.Set(0); // fixme: vary with window location + GLRenderer->RenderScreenQuad(); } diff --git a/wadsrc/static/shaders/glsl/present_row3d.fp b/wadsrc/static/shaders/glsl/present_row3d.fp index 18bd3cd11..73a01539b 100644 --- a/wadsrc/static/shaders/glsl/present_row3d.fp +++ b/wadsrc/static/shaders/glsl/present_row3d.fp @@ -7,6 +7,7 @@ uniform sampler2D RightEyeTexture; uniform float InvGamma; uniform float Contrast; uniform float Brightness; +uniform int WindowHeight; uniform int VerticalPixelOffset; // top-of-window might not be top-of-screen vec4 ApplyGamma(vec4 c) @@ -19,10 +20,7 @@ vec4 ApplyGamma(vec4 c) void main() { - // NOTE we assume here that the full screen height is the sum of the left - // and right eye view heights - int screenHeightInPixels = textureSize(LeftEyeTexture, 0).y + textureSize(RightEyeTexture, 0).y; - int thisVerticalPixel = int(TexCoord.y * screenHeightInPixels + 0.5); + int thisVerticalPixel = int(gl_FragCoord.y); bool isLeftEye = (thisVerticalPixel + VerticalPixelOffset) % 2 == 0; vec4 inputColor; if (isLeftEye) {