Jump to content
  • Advertisement
Sign in to follow this  

Depth buffer for D3DXSprite, smart, or just stupid?

This topic is 5045 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Two last questions, hope you can stand me ;) 1. Uhm, perhaps it isn't Z-buffer after all, "stencil depth buffer" I think is the term used in D3D for this, either way... that's what I'm talking about. I fiddeling with D3DXSprite, and all of a sudden I saw that it is possible to use a depth buffer when drawing sprites, and suddenly, I get this feeling, ... that would be just ... perfect! But then I come to think of the fact, that nothing is perfect when it is only a major setback when your work relies on something faulty. I mean, never having to worry about the order I'm drawing in anymore is great, and it seems to be at no visible cost. (drops about 1-2% in FPS) So my question is simple, using stencil depth buffers for D3DXSprites, are there any setbacks or possible bad outcomes with this method (presuming I do it right)? 2. This has a little connection to the previous question but I would like an answer regardless of the answer to the one above. This is very simple, and that is, RenderStates are used to control the way blending is done additive etc etc, but what if I want to use multiple RenderStates for the same scene. Do I have to flush everytime when I change (I don't want that, takes time and doesn't work with the above method)... So simply, can I specify a RenderState for a texture? Or can I "batch RenderStates" with the scene or something, some nifty trick which doesn't require me to flush/achieves the same purpose? (As I believe it is possible when working with 3D) Thanks in advance, and I thank you all for the previous help as well.

Share this post

Link to post
Share on other sites
Depth Stencil Buffer is a single buffer which can hold a ZBuffer and (optionally) a stencil buffer. The Z (Depth) part is what you're interested in. Technically a Z-Buffer is a specific method of implementing a Depth Buffer.

1. Sprites are 3D primitives (they're just really flat) so they should work fine with a ZBuffer. The important thing to note is that if you're drawing anything that needs to blend with what is behind it, what should be behind it needs to be already drawn.

2.D3D doesn't manage your scene for you. Using D3DXSprite you will need to flush between RenderState changes. The way to fix this is to organize your data so you can draw all of your additively blended objects together.

This ties in with the above because you're having to manage your batch drawing.

Essentially you want to draw in this order
1 - Opaque objects, including colour-keyed (alpha test, not alpha blend). Ideally drawing from front to back, this can save fill rate. Terrain tiles, HUD panels, etc

2 - Blended objects. Here you still need to draw from back to front to ensure proper blending. Additive blending is an exception since it's order independent.

And within those groups you may have subgroups, such as:
2a - AlphaBlended objects (SRCALPHA-INVSRCALPHA, or something similar). An example would be anti-aliased text. Sorted back to front.

2b - Additive Blended objects. Light particles, for example. No sorting needed.

This way you maximize the benefits of the Z-Buffer while minimizing your state changes and still get correct blending.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!