I need help with matrix transformations
Hey guys, I've been trying to get this to work for over an hour now, but I need a glsl vertex shader that will simulate the camera sliding along the relative x axis so i can create separate images for the left and right eye.
Here's where I'm at
as you can see i'm subtracting from new_position.x to move the vertexes on the screen to the left, the problem is i need to move them more the closer they are to the viewer, which is why I implemented *new_position.z. However that's not working. all vertexes are moving to the left evenly, created a flat 2d image that just appears farther away. Not really what i want.
Has anybody else used a shader for camera offsets before? Can anybody tell me what i'm doing wrong?
Here's where I'm at
//
// Simple passthrough vertex shader
//
attribute vec3 in_Position; // (x,y,z)
attribute vec4 in_Colour; // (r,g,b,a)
attribute vec2 in_TextureCoord; // (u,v)
//attribute vec3 in_Normal; // (x,y,z) unused in this shader.
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
void main()
{
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
vec4 new_position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
new_position.x -= 0.005*new_position.z;
gl_Position = new_position;
v_vColour = in_Colour;
v_vTexcoord = in_TextureCoord;
}
as you can see i'm subtracting from new_position.x to move the vertexes on the screen to the left, the problem is i need to move them more the closer they are to the viewer, which is why I implemented *new_position.z. However that's not working. all vertexes are moving to the left evenly, created a flat 2d image that just appears farther away. Not really what i want.
Has anybody else used a shader for camera offsets before? Can anybody tell me what i'm doing wrong?
