简体   繁体   English

GLSL移动3D模型位置

[英]GLSL moving a 3D model position

I'm trying to move my 3D object using a GLSL vertex shader. 我正在尝试使用GLSL顶点着色器移动3D对象。 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. 这种方法可以在x和y轴上移动,但实际上并不能在z轴上移动,但是它可以做一些事情,因为如果我向前或向后移动得太远,它都会使对象消失。 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); 我用来发送坐标的行: 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). 就像glTranslatef一样(但是不建议使用,因此我尝试避免使用它)。 Thanks. 谢谢。

gl_Position is in the screen coordinates . gl_Position屏幕坐标中

  • Changing x or y will move the vertex (respectively) horizontally or vertically on the screen. 更改xy将分别在屏幕上水平或垂直移动顶点。
  • Changing z will change the depth value (used for depth check), and may move the vertex out of the box of the camera. 更改z会更改深度值(用于深度检查),并且可能会将顶点移出摄影机的框。 The visible part of the world, in the screen coordinates, is a box of [-1,1] x [-1,1] x [-1,1]. 在屏幕坐标中,世界的可见部分是[-1,1] x [-1,1] x [-1,1]的框。 So if z is out of this range, your vertex is no longer visible. 因此,如果z超出此范围,则不再可见您的顶点。 (replace 1 by position.w to be exact) (确切地说,将position.w替换为1)

You probably want to move the vertex in the world coordinates . 您可能想在世界坐标中移动顶点。 How to do so depends on the ftransform() function. 如何执行取决于ftransform()函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM