depth testing woes

Published October 16, 2008
Advertisement
The next step was to get depth testing up and running. I had briefly toyed with the idea of doing some sort of triangle sorting, but decided against it in the end for several reasons. First, it wouldn't be practical for my pipeline, which processes one triangle at a time and doesn't rely on having all triangles in memory at once (though this might change in the future if required). Secondly, there are quality issues when it comes to depth sorting (e.g. intersecting triangles). With that in mind, I decided that using a z-buffer would be the best way to go. I know that z-buffer depth testing is relatively slow in software, but it seems to have less quality issues than other algorithms i've read about. I'll worry about optimizations later on down the road :D.

Before incorporating a z-buffer into my rasterization routine, I needed a way to interpolate z-coordinate values. I read some articles online (Chris Hecker's perspective correct texture mapping was a good one). I ended up writing a general function that lets you calculate interpolants using gradiants. Gradiants in screenspace represent the change in an interpolants (such a z-value) that occurs when you move up and down the x or y axis. These remain constant across the triangle so you only have to calculate them once. Whats more, the method of generating a gradiant can be generalized to work with other interpolants (e.g. colour, texture coordinates).

This is a screenshot before depth testing...



After adding z-interpolation and adding the z-buffer, I get the following...



When seen in motion, there are some artifacts (sometimes very tiny cracks are visible between triangles and there is some minor flickering).
0 likes 2 comments

Comments

Jason Z
Looks good - now on to texture mapping?
October 17, 2008 06:02 AM
Clapfoot
I'm pretty excited about adding texture mapping, but I want to fix the tearing/overdraw problems first before moving to the next stage... wish I had more time to work on this stuff!
October 21, 2008 02:04 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement