I have create a 2D game with directx11 and i want to use a depth buffer instead of a painter's algorithm to draw the sprites but i have a problem since i'm not really good with directx 3d programming. I can create a depthstencilview and it works but look at the following image: screen-shot the darker circle is not a semi-circle, they use the same texture and the same mesh: a quad. First i render the light red circle( with 0.5 depth) and then the darker one(1.0f depth). the alpha pixels of the first subscribe the depth buffer so the second isn't displayed correctly. I need aplha pixels don't subscribe depth buffer I can i set depth stencil / alpha blend state to do this?

Sorry for the bad english


If you draw your upper circle first you are blending the quad with the background color not the other circle (because it was not drawn yet). For a 2D game you are most likely better off using painter's algorithm. Depth buffer is usually used with 3D geometry where we can't determine a correct sorting between polygons and this way one has to use some nasty tricks to display transparent geometry (which always result in either quality loss or impact the performance geatly). If you are convinced that you must use depth buffer refer to my answer in a previous question like this: QUESTION

  • \$\begingroup\$ so how can i tell directx something like: if(pixel.a <0.9){do not write the pixel onto the depth buffer (but just on the rendertargetview)?? \$\endgroup\$ – Liuka May 14 '14 at 10:53
  • \$\begingroup\$ I want to use depth buffer because i'm making a little 2d engine and i render sprite "by texture" so i can't use a painter's algorithm \$\endgroup\$ – Liuka May 14 '14 at 10:55
  • \$\begingroup\$ if(pixel.a<0.9f) discard; or clip(pixel.a<0.9?-1,1); in your pixel shader (if you can use shaders). \$\endgroup\$ – János Turánszki May 14 '14 at 12:51
  • \$\begingroup\$ ok, thanks, i think i will read something about sv_depth \$\endgroup\$ – Liuka May 14 '14 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.