OpenGL render setup problem
Hey guys, I am 99% of the way to supporting the Rift in my OpenGL C++ engine but have come across a fundamental problem in how I am rendering the final scene. I am having trouble understanding which part of the transformation process is producing my erroneous result.
I render my scene to a full size framebuffer, first the left side of the buffer, then the right using glViewport and glScissor to limit the influence of the drawing and clearing. So I have a full screen buffer divided in half width wise with two slightly different images in each half.
Then when drawing to the screen, I set the rift shader up as per the tiny room demo then draw a pair of triangles for the left side using texCoords from 0.0 to 0.5 and repeat the process with texCoords 0.5 to 1.0. Everything works great except the result looks like this:

Great! Except the right eye image is backwards... No problem, I can just reverse it using multiple methods (flip texcoords, or in vertex or frag shader). But then I end up with this:

So the render is correct but the shape of the barrel shader has been affected. Each side of the shader is not symmetrical and in my flipping I have also affected this. I KNOW I have made some error in one part of the process and there are also a few parts of the tiny room demo that I don't understand (like why does the vertex shader flip the y texture coordinate? why does it load a matrix with a 2.0 scale for the look and right vectors to render with?).
So any help appreciated, my shaders follow, apologies for the usage of gl_TexCoord[0] etc, I only just learned this was bad mojo.
Vertex shader is passthrough:
Pixel shader is pretty much identical to the example:
I render my scene to a full size framebuffer, first the left side of the buffer, then the right using glViewport and glScissor to limit the influence of the drawing and clearing. So I have a full screen buffer divided in half width wise with two slightly different images in each half.
Then when drawing to the screen, I set the rift shader up as per the tiny room demo then draw a pair of triangles for the left side using texCoords from 0.0 to 0.5 and repeat the process with texCoords 0.5 to 1.0. Everything works great except the result looks like this:

Great! Except the right eye image is backwards... No problem, I can just reverse it using multiple methods (flip texcoords, or in vertex or frag shader). But then I end up with this:

So the render is correct but the shape of the barrel shader has been affected. Each side of the shader is not symmetrical and in my flipping I have also affected this. I KNOW I have made some error in one part of the process and there are also a few parts of the tiny room demo that I don't understand (like why does the vertex shader flip the y texture coordinate? why does it load a matrix with a 2.0 scale for the look and right vectors to render with?).
So any help appreciated, my shaders follow, apologies for the usage of gl_TexCoord[0] etc, I only just learned this was bad mojo.
Vertex shader is passthrough:
void main(void)
{
gl_FrontColor = gl_Color;
gl_Position = gl_Vertex;
gl_TexCoord[0].st = gl_MultiTexCoord0.xy;
}
Pixel shader is pretty much identical to the example:
uniform vec2 LensCenter;
uniform vec2 ScreenCenter;
uniform vec2 Scale;
uniform vec2 ScaleIn;
uniform vec4 HmdWarpParam;
vec2 HmdWarp(vec2 texIn)
{
vec2 theta = (texIn - LensCenter) * ScaleIn;
float rSq= theta.x * theta.x + theta.y * theta.y;
vec2 theta1 = theta * (HmdWarpParam.x + HmdWarpParam.y * rSq +
HmdWarpParam.z * rSq * rSq + HmdWarpParam.w * rSq * rSq * rSq);
return LensCenter + Scale * theta1;
}
void main()
{
vec2 tc = HmdWarp(gl_TexCoord[0].xy);
if (any(notEqual(clamp(tc, ScreenCenter-vec2(0.25,0.5), ScreenCenter+vec2(0.25, 0.5)) - tc, vec2(0.0, 0.0))))
{
gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
}
else
{
gl_FragColor = texture2D(tex, tc);
}
}
