Skip to main content
gamedev.net
🔒 Locked

efficiency question

Started by TreborZehn Mar 10, 2004 at 7:52 AM 4 replies 300+ views
Original Post
TreborZehn
TreborZehn
I have heard some people say that it is more efficient to draw front-to-back, but everyone draws back-to-front because how else can you ensure that you don''t get strange artifacts where far-field objects appear in front of near-field objects. Is it really more efficient to draw front-to-back? If so... why?
"Good code will come and go, but bad code sticks around."
SPatuel
SPatuel
Hmm... interesting, let''s see this:

Back to Front:
Vectors are draw on the screen with full texture

Pro: No extra calculation
Con: Your are blitting the entire texture when is not necessary to have it all if the object is overlapped with other one.

Front to back:
The first objects are draw complete but the Z-back objects are blitted only if the texture is shown

Pro: Less textures sent to the frontbuffer (less bytes)
Cont: You have some extra calculation to "cut" the texture, the blitting has to calculate if any objects obstructs the vector and generates a new "virtual" vector to store de texture.

Conclusion: You can perform a test, kill your video card drawing 10.000 vectors with textures and measure the speed. (no more than 15.000 vectors, is a lie what the cards says about millions of vector, the only way to get that is to draw vectors of one pixels!)

Hope this helps

Syco - Spatuel
Syco - Spatuel
Fruny
Fruny
because how else can you ensure that you don''t get strange artifacts where far-field objects appear in front of near-field objects.

Depth test.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Cypher19
Cypher19
For back to front drawing, you will be rendering virtually the entire scene, which can result in a lot of overdraw (if you want to see the implications of overdraw, go look at the StencilDepth demo in the pre-summer DX9SDK) for your objects.
Front to back draw will result in zero overdraw, so your scene can be rendered MUCH faster (but there is the addition depth check required for each pixel, but that one calc is better than having to calculate the colour value based on the texture).

Back to front could also allow you to have the Z-Buffer turned off, which I imagine would get rid of Z-fighting for faraway objects.
Also, back to front would be required at times for some pixel shaders which rely on a bit of a transparency, such as a cloaking effect or some funky shield.

In general however, front to back does its job very well, and for the Z-fighting and PS problems above, there are simple workarounds, such as rendering chunks of vertices that are within a certain depth range with different view matrices, and rendering items requiring that PS at certain times.
Yratelev
Yratelev
Is there anyway of drawing front to back with alpha blending, or does that still have to be drawn back to front like good ol'' days?

Yratelev
Yratelev
Fruny
Fruny
quote:
Original post by Yratelev
Is there anyway of drawing front to back with alpha blending, or does that still have to be drawn back to front like good ol'' days?



You can go front to back if you change the blending equation.


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan (C programming language co-inventor)
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.