XNA Creators Club Online
Page 1 of 1 (5 items)
Sort Posts: Previous Next

Particle on GPU - Draw Order

Last post 17/06/2009 19:07 by JimmyFo. 4 replies.
  • 17/06/2009 15:13

    Particle on GPU - Draw Order

    Hi, I have a question concerning the particle drawing example (http://creators.xna.com/en-US/sample/particle3d). The problem is that to draw the point sprites, they are added as game components, which sets their draw order. So when I modify it to add multiple columns of smoke, one is always drawn in front of the other no matter which is closer (and all vertices are set in 3D space, so it should know, right?). Is there a way around this?

    Thanks,
    James
  • 17/06/2009 16:18 In reply to

    Re: Particle on GPU - Draw Order

    The way around it would be for you to control the order of drawing (don't add the individual particle systems to the game's main component collection - just make another "parent" DrawableGameComponent that in turn calls your particle systems' Draw in the desired order).

  • 17/06/2009 16:31 In reply to

    Re: Particle on GPU - Draw Order

    Sorting particles can be as difficult or easy as you want to make it. It's a tradeoff between visual accuracy and performance. Do you want many particles with sorting errors, or fewer particles with more accurate sorting?

    At one end of the spectrum, our sample makes no attempt to sort anything, which is simple and fast.

    For more accuracy, you could use a separate particle system instance per emitter, and sort the list of particle systems by their depth (or at least the depth of their emitters, which isn't 100% as the particles move, but better than nothing) before you draw them.

    For perfect accuracy, you need to sort every individual particle. There are several ways of doing that, but all are rather complex and expensive so most people don't bother.
    XNA Framework Developer - blog - homepage
  • 17/06/2009 17:33 In reply to

    Re: Particle on GPU - Draw Order

    With vertex fetch, you can actually do this in the shader (although, as Shawn says, it's complex).

    You can also take advantage of the fact that pure additive, or pure multiplicative, blending is order independent. Thus, if you formulate your smoke as multiplication, order doesn't matter. Make a white texture with a vaguely grey cloud in the middle for your particle. Then set blending to DSTCOLOR, ZERO. This will make all smoke draw order independent.

    However: Once you add different kinds of particles (additive, or blended) to the same scene, you will get ordering problems between the two. Thus, in reality you have these options:
    1) Make all particle systems multiplicative (OK for military style games when it's mostly smoke and dust)
    2) Make all particle systems additive (OK for RPG style games where it's mostly magic effects)
    3) Sort each emitter by distance to camera (means higher render cost, but works better)

    In general, you almost never want particles to use alpha blending, though. You either want multiplication, or addition, or in some cases, pre-multiplied alpha (which is kind-of a mix of the two).

    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
  • 17/06/2009 19:07 In reply to

    Re: Particle on GPU - Draw Order

    Thanks guys, I figured it was something like that. The particle system is great (thanks for the helpful starting points!). I have a freely rotating camera (translate, zoom, etc) and I have begun running into some issues with the draw order. What you're basically saying is, before the particles/emitters are drawn, to sort by distance from the camera, and change the draw order based on that? Is there an easy way to place them at the end of the draw queue?

    Also, could you direct me towards some articles/books that describe the difference between additive/blended particles and what you mean by multiplicative? Are you referring to the shader language?

    I'm still learning XNA and HLSL is quite intimidating :)

    Thanks for all the help!
Page 1 of 1 (5 items) Previous Next