Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OPENGL clip coordinate

Tags:

opengl

clip

I have a question for opengl clip coordinate. For example, a triangle, three vetices, now have transformed to camera coordinate, multiply with perspective projection matrix to clip coordinate, begin to clip, -w=<x<=w, -w=<y<=w, -w=<z<=w, does x,y,z,w mean to each vertex's clip coordinate? So w may not be same in these three vertices?

like image 746
yewei Avatar asked Sep 18 '13 14:09

yewei


1 Answers

Yes, that w will vary per vertex. Most people imagine the clip space as the cube [-1,1]^3. However, that is not the clip space, but the normalized device space (NDC). You get from clip space to NDC by doing the perspective divide, so dividing each vertex by it's w component. So, in NDC, that clip condition would transform to -1 <= x/w <= 1. However, the clipping cannot be done in NDC (withpout extra information).

The problem here is that points which lie behind the camera would appear in front of the camera in NDC space. Think about it: x/w is the same as -x/-w. With a typical GL projection matrix, w_clip == z_eye of the vertex. Also, a point that lies in the camera plane (the plane parallel to the projection plane, but going through the camera itself) will have w=0 and you can't do any clipping after that divide. The solution is to always do the clipping before the divide, hence the clip space is called "clip space"...

like image 74
derhass Avatar answered Sep 18 '22 15:09

derhass