   Z-Buffering and Optimisation
  I was thinking about this the other day, and as I couldn''t come to a decent conclusion myself, I decided to post this here.If a graphics engine has a Z-Buffer that is always on, then it compares every pixel it trys draw to the screen and only draws the pixel if it passes the test. Therefore, would it be possible to save some time each frame by rendering the scene from front-to-back instead of back-to-front because then, it would minimise the amount of "redrawing pixels" and keep the same amount of pixel comparisons.This theory is probably flawed, but if someone does know whether this would be faster or has any other useful comments, then please post them below...Cheers,James Bird[Edited by - birdjames on December 5, 2007 2:10:24 PM]
  i would expect that to depend on how long it takes to sort your scene front to back and how much overdraw you would actually have without. ;  You theory is 100% correct. Most modern (Good) engines sort the geometry so that the nearest stuff is drawn first, ala BSP-Tree style for example. This does reduce overdraw and can significantly increase speeds since Todays hardware is optimized to quickly test for this kind of situation, and skip some calculations like Texture-Lookup for example. Sorting the geometry also helps when trying to do some occlusion testing.    One by one, the peguins steal my sanity. ;  A rough per-object front-to-back sort (such as a bucket sort or a single pass of a bubble sort each frame) will gain you a little bit of perfomance yes. If you spend too much time sorting accurately then of course you won''t gain anything  it''s all a tradeoff. ;  You can always render the geometry of the frame with no texturing lighting etc with colour buffer writing switched off but Z-buffer writing switched on and then render again but this time only read from the Z-buffer, enable colour buffer writes and switch on texturing lighting etc. ;  Monder:nice idea.But depend to what stupid card will do if z-test shows equality.So, you should draw with "polygon offset".Z-Buffer are just bruteforse method,for software rendering,much more intelligent methods are avaliable(say,if for each pixel of z-buffer we will store x-offset of nearest point where other polygon are,you could check visibility of each horisontal strip of polygon in several operations ). And back-to-front rendering aren't very good idea because if there's some slow pixelshaders...   [edited by - Dmytry on February 12, 2004 11:35:48 AM] [edited by - Dmytry on February 12, 2004 11:37:05 AM];  Nvidia actually recommend techniques like these (see their ChinaJoy2004 presentation).And as for what the ''stupid card'' will do if z-test shows equality?  It will do exactly what you tell it to do (OpenGL: glDepthFunc(GL_EQUAL)).Enigma 