PDA

View Full Version : Knowing vertex position on after projection


raznitzan
05-19-2006, 12:44 AM
Hi,
I would like to know if games are using the vertex shader to change the location of an object,vertex in space.?
If they change the location is it small offest only or could it be a large offset?
Can I understand from the vertex location before the GPU and the transform matrics where will the vertex be in the 2d world?
Thanks,
Raz

juhnu
05-19-2006, 01:00 AM
Yes you have all the freedom to change vertex positions in the vertex-shader as you like.

Nick
05-19-2006, 02:50 AM
Practically every vertex shader uses at least one matrix transform for the position. So there's no direct correlation between the input and output vertex position. Also, it's almost impossible to know which matrix is being used.

Why do you need to know?

Reedbeta
05-19-2006, 07:17 AM
Can I understand from the vertex location before the GPU and the transform matrics where will the vertex be in the 2d world?

It sounds like you're asking how to perform all the vertex transformations yourself, mapping from the vertex in object space to its 2D position in screen space? If so that is certainly possible. You have to transform it first by the modelview matrix, then by the projection matrix, then divide out the w (4th component). The result of these is the vertex location in normalized device-coordinates (NDC), which range from -1 to +1 on each axis. Then you just have to map the [-1, +1] range onto [0, screen_width] for x, and [0, screen_height] for y (the z-coordinate you can forget for now). Then you have the vertex location in screen space :yes:

raznitzan
05-23-2006, 02:35 PM
Wouldn't the vertex shader changes the vertex location in 2d space

Reedbeta
05-23-2006, 02:42 PM
Well, the vertex shader is responsible for ALL the transformations that go from the vertex location you have put in your arrays to the location in eye space that is finally projected onto the screen. So you can move the vertices in 3D if you choose, or you can move them in 2D if you choose, or both.