Allegro.cc - Online Community

Allegro.cc Forums » Game Design & Concepts » Z-buffering vs. scan-line

This thread is locked; no one can reply to it. rss feed Print
Z-buffering vs. scan-line
Rash
Member #2,374
May 2002
avatar

Which one do you use and why? What are your experiences?

Thomas Harte
Member #33
April 2000
avatar

Well, most of the time I use z-buffering because it is all my hardware supports. However, reading into the spirit of the question for just a minute yields this more useful responce . . .

The scan-line related algorithms are more complicated but for scenes with a reasonable amount of overlap typically end up faster. This is obvious and is because genuine pixel-computations are certainly avoided for sections that end up unseen. Also, for many scenes with a suitably designed data structure, scan-line algorithms are easier on the processor cache.

However, if you can get even a reasonably bad front to back sort on your objects before drawing, often you can lose the majority of the speed benefit of scan-lining because you can still throw away large parts of the per-pixel computations without doing them. And in that case you are much nicer on the code cache and it is easier to be sure you are using the data cache the best way you can given the data you will use because a z-buffer is a static data structure.

Also z-buffer's are algorithmically and processing cost wise much easier to work with if you want to do anything involving only partial updates of your display, because they are so very easy to duplicate.

It really depends on what you intend to do, but in most cases I personally would probably still go with a scan-line approach.

HoopsMan
Member #1,943
February 2002

I personally use Z-Buffering because of the inherent benefits. Perfect Intersection of polygons and simpler coding. There are methods which can speed up z-buffering in Software such as Clear-Reduction. But these need changes in the rendering code itself. One extra floating-point addition per pixel ::).
Still, due to the fact that Hardware accelerators use ZBuffering at high speeds, the engine can be ported over to 3D API's in a straightforward manner.
My own engine gives me about 25-30 FPS at 640x480x16-bit color with zbuffering and minimal polygons. I guess with other Occlusion techniques, This can become faster. Thomas Harte suggested a sign-change clearing method in another post which sounded promising but I'm not inclined to figure it right now. ;D
I explored S-Buffers for a while, but came away with a coding headache. Scanline sorting is ,as far as I know, harder to code but faster in general.
Personal preference and Laziness figure into the picture too, I guess!
;)

Korval
Member #1,538
September 2001
avatar

First of all, what do you define as "scan-line"? By the phrasing of the question, I'll assume that, by "scan-line", you mean, "non-z-buffered scan conversion."

note: the following discussion assumes hardware acceleration. The days of software-based rendering for even modestly-performing games are over.

The z-buffer is good. Most modern hardware implements z-buffering virtually for free. Some of them even use special early-z-culling modes (GeForce3+ or Radeon) that will cull out entire groups of pixels at a time. You can even use the z-buffer to implement various effects.

The only time to turn off a z-buffer is when you have to. You turn it off for transparency. You turn it off for certain effects. Otherwise, there's really no reason to bother not using a z-buffer. It can only help.

Bruce Perry
Member #270
April 2000

Quote:

The days of software-based rendering for even modestly-performing games are over.

Set Up Us The Bomb !!! uses software rendering. It also uses palette tricks for the explosions; this would not be possible in non-paletted modes. The water textures change constantly. If you tried to do the same using hardware acceleration, you'd have a choice between uploading textures every frame and creating many more polygons than you'd like to in order to render the water.

Never let it be said that software rendering is old-hat. ;D

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

HoopsMan
Member #1,943
February 2002

I agree with Ben. Whatever Hardware can do Software can do just as well, but at lesser speeds. In fact, some of the best experimentation can take place only if you are using Software coz the effects are visible due to the code and not the amount of OpenGL extensions supported by your card :). Disregarding a whole way of creating realtime 3D in favour of the next-best-thing by NVIDIA or ATI is not required.
Too many people keep suggesting switching to Hardware as a solution to learning Rendering techniques. Thats just a speed issue. Good-looking games require speed, but learning requires more than card or API specific knowledge. Switching to Direct3D or OpenGL (which seems to Korval's suggestion for any of my threads ;D) is step two, and I agree that it is required for any top of the line game or for professional purposes.
Software will never be Dead (just like DOS isn't ;)) coz of programmers like me who can't afford the Radeon's and GeForce's of the world! ;)

Thomas Harte
Member #33
April 2000
avatar

A mish-mash of responses :

Quote:

First of all, what do you define as "scan-line"? By the phrasing of the question, I'll assume that, by "scan-line", you mean, "non-z-buffered scan conversion."

Just to clarify what I wrote a little : I assumed that by scan-line he meant what is sometimes referred to as s-buffering.

Quote:

In fact, some of the best experimentation can take place only if you are using Software coz the effects are visible due to the code and not the amount of OpenGL extensions supported by your card

With all due respect, this opinion is slightly out of date now. The whole point of vertex and pixel shaders is that you write the software that generates the pixels, it just so happens that you write it for a processing unit specifically optimised for the task and not the explicitly not optimised for the task CPU. Although this is all academic if you are :

Quote:

like me who can't afford the Radeon's and GeForce's of the world

Which, incidentally, I am.

Quote:

Still, due to the fact that Hardware accelerators use ZBuffering at high speeds, the engine can be ported over to 3D API's in a straightforward manner.

This isn't always true. My experience with glide (from ages ago) and OpenGL tells me that hardware usually additionally ties you into double buffering (in the pure English sense), or at the very least into using a flipping chain. A software implementation can have as many buffers as you want and can arbitrarily blit both colour and depth information between them. Therefore it is conceivable that your game will not be an easy port. My surprisingly aged game, Anarchy, is an example of such a game.

Quote:

Too many people keep suggesting switching to Hardware as a solution to learning Rendering techniques.

I think their point is simply that when you want to learn a technique you really want to focus on that technique and not anything else, so a solution that already provides 3d transform & lighting + polygon drawing gives you the flexibility to experiment with radiosity or whatever without spending a lot of time writing the 'underneath' stuff.

Quote:

Set Up Us The Bomb !!! uses software rendering. It also uses palette tricks for the explosions; this would not be possible in non-paletted modes

The OpenGL paletted texture extension is quite widely supported, but in this particular case where your explosions aren't in many colours, surely you could have tapped into the gamma ramps? Which I assume are available in some GL extension or another without really knowing, and I know for sure are available in DirectX.

Quote:

The water textures change constantly. If you tried to do the same using hardware acceleration, you'd have a choice between uploading textures every frame and creating many more polygons than you'd like to in order to render the water.

But we shouldn't avoid stating both sides of the argument : conversely you could easily afford many more polygons without a speed drop. The whole game actually goes substantially more slowly on my P200 than many games with, as far as I'm concerned, equivalently nice graphics which can use the 3dfx voodoo1 within that machine.

Quote:

The only time to turn off a z-buffer is when you have to. You turn it off for transparency.

I don't! But then I use a particular 'cheat' in that all my objects only bound convex shapes with the translucent parts of their geometry, so I can get away with a simple back to front draw of all objects including transparency, safe in the knowledge that each objects gets its transparency correct thanks to the correct sorting of opaque and translucent geometry and meaningful use of reverse face removal at the object level.

Korval
Member #1,538
September 2001
avatar

Quote:

It also uses palette tricks for the explosions; this would not be possible in non-paletted modes.

Thomas has already shown how this is possible on modern cards. I'd like to add that there are much more asthetically pleasing ways to do explosions than relying on palatte hacks.

Quote:

The water textures change constantly. If you tried to do the same using hardware acceleration, you'd have a choice between uploading textures every frame and creating many more polygons than you'd like to in order to render the water.

Not true. What you're talking about is an animated texture. I have 2 options:

1) Put all of the animation frames in one gigantic texture. Simply alter the texture coordinates (via the texture matrix) at run-time.

2) Actually swap the texture it is using each frame. Unless the card cannot store all of these textures in video memory, the upload doesn't actually happen. And, even if it does, it won't hurt much at all. It is, after all, an AGP copy, which is pretty cheap (unless the texture is huge).

This doesn't cover the case of a procedural texutre, where you're actually generating the texture every frame. That can be somewhat painful.

Here's a question about software rendering: are you actually using the advantage of software rendering? Are you actually doing something with per-vertex or per-pixel computations that modern (non-shader-equipped) hardware cannot handle? Are you employing bump-mapping, anisotropic lighting, 1D point sprites, volumetric fog, or any number of the other effects that requires specialized hardware that may not even exist yet? If you're just rendering some texture-mapped polygons, potentially with basic alpha blending, I just can't see the point of your arguments.

Bob
Free Market Evangelist
September 2000
avatar

Quote:

This doesn't cover the case of a procedural texutre, where you're actually generating the texture every frame. That can be somewhat painful.

It is a procedular texture though, and it can be arbitrarily large. Storing it as one huge texture is not practical (video cards don't come with TB of RAM yet). Uploading a new texture is much more than just an AGP copy (which isn't that fast anyway), and you will notice a significant performence degradation. Of course, if everyone had GeForce 4 Tis or Radeon 9700s, then my point would be moot, as those cards are more than fast enough to compensate for all those stalls.

--
- Bob
[ -- All my signature links are 404 -- ]

Korval
Member #1,538
September 2001
avatar

Actually, with a 9700, I'd probably encode the procedural program in the pixel shader.

Bob
Free Market Evangelist
September 2000
avatar

You'd still need to multi-pass and pipeline stall on each texture.

Of course, this is still much faster than all the other methods mentioned above :)

DX 8.1 is not capable of doing what we need (due to severely limited instruction set and program length imposed by MS).

DX 9 pixel shaders is a different story, but that's not out yet.

--
- Bob
[ -- All my signature links are 404 -- ]

HoopsMan
Member #1,943
February 2002

I thought Rash's question was about the VSD techniques and not the cutting-edge of EVERYTHING (DX8.1 pixel shaders!!??!). All I was saying was that why can't a question be answered just for itself? Z-buffering vs. scan-line! Simple, huh? Anyway, I guess my knowledge is too amateurish. ;D

white_door
Member #202
April 2000
avatar

I believe everyone knows that hardware rendering is better/faster/blah blah blah blah, but in all honesty mentioning hardware on this thread at all was quite silly, when you take in to account the nature of the original question.

In my own expements in to software rendering I found s-buffers can be really good provided you aren't using a large number of very small polygons. In one case like this, I was rendering a hieght field as a polygon mesh, and I found nice speed boost when changing from an sbuffer rendering method over to a software zbuffer.

Like all software methods, the complex methods aren't always the fastest you have to be care and pick a method based on what you will be doing.

Thomas Harte
Member #33
April 2000
avatar

But then, conversely, you can render a height map using the ROAM technique (an adaptive meshing approach) and be assured your polygons will never get very small.

white_door
Member #202
April 2000
avatar

Yes ROAM is quite cute, but it would not have worked in this case. I was drawing the height map in a isometric view with out any perspective, so it would have been impossible to merge together any of the polygons.

Korval
Member #1,538
September 2001
avatar

Quote:

mentioning hardware on this thread at all was quite silly, when you take in to account the nature of the original question.

I wouldn't have brought up the whole software/hardware issue if it had been immediately obvious what Rash was talking about.

A "scan-line" has a particular meaning. Rash, apparently, assumed that by putting it in the context of "z-buffer vs. scan-line" that this would obviously be refering to some alternative to z-buffering known as s-buffering. The assumption was valid only for those who had any knowledge of this technique. I freely admit I have no idea what an s-buffer is.

HoopsMan
Member #1,943
February 2002

Thomas Harte
Member #33
April 2000
avatar

Quote:

Yes ROAM is quite cute, but it would not have worked in this case. I was drawing the height map in a isometric view with out any perspective,

Well, it could very easily have worked in your case. As I'm sure you realise, even the implementations people use in perspective engines don't just think about perspective but also about variance, so even once you'd factored out perspective you'd almost certainly still end up with a more optimal meshing of your shape than the most basic heightmap implementation. The obvious case is an n by m grid where all height values are the same - even without perspective ROAM would come up with two triangles, whereas you would come up with something like 2*(n-1)*(m-1) triangles.

The moral of the story : even if ROAM can't make things better, it can't hurt!

Naturally I assume you're not stupid and discarded any idea of using ROAM because you knew it would not help regardless of whether you forget to mention whatever thoughts you had on here, but in a public forum I thought it was a good idea to make clear to casual readers not to dismiss ROAM out of hand purely because perspective is not involved.

P.s. if your map did not rotate, then why did you not pre-render it, not necessarily all of it but the sorts of quantities that would allow scrolling without much redraw, including depth information and simply do a blit (including depth information)? I'll assume because : it did rotate.

Quote:

A "scan-line" has a particular meaning. Rash, apparently, assumed that by putting it in the context of "z-buffer vs. scan-line" that this would obviously be refering to some alternative to z-buffering known as s-buffering.

I'm sorry, but I'm the sort of person who gets quite annoyed when other people feel they must religiously stick to some particular use of the language just because they've seen other people do so a few times. Yes, a scan-line has a particular meaning for graphics people, which is specifically the horizontal line along which an electron gun moves in a cathode ray tube. So, there you have it, every game I've ever written has used a scan-line approach. Assuming we are never allowed to expand the possibilities described by a particular set of words, then that is all scan-line can ever mean and there is no point arguing about it!

Go to: