Clip Space
Before rendering something all objects need to be projected to the screen ( a plane ). The first step, to project to the screen, is to project entities to clip space.
The mostly used projection type in games is perspective projection and therefore only this kind of projection will be explained. An other type of projection is parallel projection which is a projection that will keep parallel lines parallel. Perspective projection gives a field of view and objects appears to be smaller when further away which will feel realistic. The projection volume is set up as the following image shows.
You apply a projection to the entities that is in eye space to get them to clip space. This is the space that will soon decide if the vertex will be culled or not. Together with homogenization it can be thougt as a mapping from the projection volume to a cube with sizes 2 (in OpenGL) and with origin at 0,0,0. This mapping is showed in the image below.
In OpenGL you can access the projection matrix if you set the matrix mode to projection:
glMatrixMode(GL_PROJECTION); |
The following vertex shaders shows some ways to transform a vertex to clip space. The fastest way is the third shader that uses the highly optimized ftransform() function.
void main() { // vertex in clip space gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex; } |
void main() { // vertex in clip space gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; } |
void main() { // vertex in clip space gl_Position = ftransform(); } |
One side effect from applying perspective projection is that you end up with a non-linear z-buffer. The buffer will be more detailed closer to the screen which is often good. More about this in the z-buffer article.
After applying projection to a point p = (x,y,z,w) you will end up with a w value that is most probably not zero or one. This means you need to divide all components by this value to obtain normalized device coordinates. This will happen automatically between the vertex shader and fragment shader. Clipping will also be performed between these.
Information about different ways to transform vertices to clip space inside of a vertex shader:
http://www.lighthouse3d.com/opengl/glsl/index.php?minimal
Description of different 3D spaces:
http://vesta.astro.amu.edu.pl/Library/Linux/LinFocus/May1998/article6.html






















