0
\$\begingroup\$

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

asked May 14, 2014 at 8:59
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

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

answered May 14, 2014 at 9:25
\$\endgroup\$
4
  • \$\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\$ Commented May 14, 2014 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\$ Commented May 14, 2014 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\$ Commented May 14, 2014 at 12:51
  • \$\begingroup\$ ok, thanks, i think i will read something about sv_depth \$\endgroup\$ Commented May 14, 2014 at 13:06

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.