Perspective projection question

Started by
1 comment, last by Erkokite 14 years ago
Hello, I've been working on an unconventional software rendering method, and I've having some trouble with perspective projection. Given a plane with the formula, z=x+y+1 and the perspective projection formulas: x' = x/z y' = y/z Where primed variables are screen space, and unprimed are world space. We can find a formula for the depth (z value): z = x'z+y'z+1 Iterating over the pixels on the screen, we find a z value for each point on the plane. If we then apply a greyscale coloring with the value of 1/(z+1)^2 (to simulate lighting or fog for example), we end up with something like this: http://infernalandroid.tripod.com/examplepic1.jpg This strikes me as very wrong, as the lower right corner should be the furthest point from the camera, and thus the darkest, but we see the opposite effect. However, using orthographic projection, which results in the equation: z = x'+y'+1 We find that the shading is quite different. It is, as one should expect, lighter near the area closest to the camera (the center line), and darker as you proceed toward the lower right corner. http://infernalandroid.tripod.com/example_pic2.jpg Does anyone know why this might be happening? Thanks much.
Advertisement
Are you interpolating z or 1/z values? Only 1/z is linear in screen space and this may be part of the problem.

I also noticed that while writing my software rasterizer, using the "poor man's projection", i.e., x' = x / z,y' = y / z, doesn't always work. If I moved a vertex just a tiny bit, the triangle wouldn't rasterize. The accepted method of doing perspective projection is using homogenized coordinates (x,y,z,w). Though I'm not entirely sure how they work yet.

[Edited by - maspeir on March 22, 2010 1:29:16 AM]

No, I am not a professional programmer. I'm just a hobbyist having fun...

I'm not actually interpolating anything per se. I'm just trying to get the depth value for a point on a plane, that has been projected to the screen via its screen coordinate. I loop over the entire framebuffer, finding a depth value for each point using the equations derived above. The problem is that using perspective projection, I find the opposite value of what should be expected for a depth- that is as x and y increase, my apparent depth (z) decreases, as opposed to increasing like it should.

This topic is closed to new replies.

Advertisement