user2513924
user2513924

Reputation: 2250

GLSL moving a 3D model position

I'm trying to move my 3D object using a GLSL vertex shader. It kind of works and it moves fines on the x and y axis however it doesn't really move on the z axis but it does do something as it makes the object disappear if I go too far forward or back. I think I might be using the wrong method.

My vertex shader file:

uniform vec3 offset;

void main(){
    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_Position = ftransform() + vec4(offset, 0);
}

The line I use to send the coordinates: GL20.glUniform3f(offsetUniformLocation, x, y, z);

I just want to move the object. Like glTranslatef would (however that's deprecated so I'm trying to avoid using it). Thanks.

Upvotes: 0

Views: 333

Answers (1)

Volune
Volune

Reputation: 4339

gl_Position is in the screen coordinates.

  • Changing x or y will move the vertex (respectively) horizontally or vertically on the screen.
  • Changing z will change the depth value (used for depth check), and may move the vertex out of the box of the camera. The visible part of the world, in the screen coordinates, is a box of [-1,1] x [-1,1] x [-1,1]. So if z is out of this range, your vertex is no longer visible. (replace 1 by position.w to be exact)

You probably want to move the vertex in the world coordinates. How to do so depends on the ftransform() function.

Upvotes: 1

Related Questions