currently I have two different projection modes, orthogonal and perspectivic. The orthogonal matrix is pixel perfect, I.E if I have a Quad that has a dimension of 100x100 and it is not transformed, the rendered size of that quad will be 100x100 as well. Now I want that the perspective matrix is pixel perfect too (I need it for a 3D UI), how can I do this? Scaling seems not to be the right way :o
Ok, I’ll try to explain:-) Here’s an image of the perspectivc projection I want:
Now the special thing I need. Imagine the green quad has the size 100 x 100. The red quad should represent the screen and splits the projection in two parts, the near and the far part. The target is the follwing: I want to define all models in pixel dimensions. If the model is exactly in the red plane, it should be rendered 1:1 to the screen. The projection I’m looking for is nothing else than a mix between a orthogonal and a perspective matrix. Its strange to explain, to you know what I mean?
An here’s what that matrix is doing:
its a normal perspective projection, but near,far and focal are measured in pixels. When the distance from the point to the camera is 500 (focal), then the point will be rendered 1:1 to the screen. A plane that is 100 x 100 and is 500 away from the camera, the plane will be rendered exactly 100 x 100 pixels.
Here’s the function I use to build that kind of matrix. width and height defines the 2D space available at z=0, must be the same as the size of the viewport. z_near defines the z position of the near plane, must be greater than 0. z_far defines the z position of the far plane, must be lesser than 0. z_eye defines the position of the viewer, must be greater that z_near. All the vertices placed at z=0 will now perfectly map with the pixel grid of your screen.