4

I have a fire simulation, containing a large number of textured GL_POINTS. Each particle has a transparent background, and when facing the fire from certain angles, the blending works correctly. However, viewing it from other angles shows the backgrounds, which should be transparent, obscuring particles rendered behind others. See picture below.

enter image description here

As you can see, there appears to be a lot of black boxes in the way of the particle. How can I avoid this? The blend function I am using is GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA. Using GL_ONE as the second argument to glBlendFunc gives very similar results.

Fitzy
  • 1,871
  • 6
  • 23
  • 40
  • 2
    Similar to http://stackoverflow.com/q/23280692/3530129. There might be different considerations since this is about a particle system instead of just general rendering with transparent textures. So I'm not sure if it should be a duplicate. – Reto Koradi Sep 16 '14 at 12:44
  • disable depth buffer – BeyelerStudios Sep 16 '14 at 12:44
  • @BeyelerStudios simply disabling the depth test fixes the problem of overlapping backgrounds but creates issues with the transparency in other parts of the texture – Fitzy Sep 16 '14 at 12:50
  • 4
    You may have to sort the particles and render them in the correct order, i.e. back-to-front. – Gigo Sep 16 '14 at 13:50
  • for light-emitting particles try additive blending. there are several tricks you need to know for "nice" particle effects. I'm guessing you're going for a fire effect: check [here](http://gamedev.stackexchange.com/questions/22989/how-can-i-achieve-a-good-fire-effect-with-alpha-blending-and-particles) – BeyelerStudios Sep 16 '14 at 13:53
  • @BeyelerStudios what was done in that question seems like quite a lengthy process, it seems like there would be a simpler solution, particularly given that I'm only drawing points on to a black background. Simply using additive blending gives results similar to the picture I linked above. – Fitzy Sep 16 '14 at 14:28
  • sounds like a bug to me. start reducing your code to an [mcve](http://stackoverflow.com/help/mcve): clear background, draw two particles partially occluding each other. compare your current approach to drawing two quads using your texture. see which result you were expecting. – BeyelerStudios Sep 16 '14 at 14:39
  • Reto Koradi is correct, most of those methods can be used for particle systems too. Another approach not mentioned in that thread is premultiplied alpha, as explained here: http://blogs.msdn.com/b/shawnhar/archive/2009/11/06/premultiplied-alpha.aspx – StarShine Sep 16 '14 at 20:58

1 Answers1

0

http://www.opengl-tutorial.org/intermediate-tutorials/billboards-particles/particles-instancing/#The_main_simulation_loop

There you can find the exact same problem and its solution. You indeed have to sort the particles as Gigo suggested. The reason is that alpha blending only looks right if the colors are mixed from back to front.

You can, however avoid sorting if you really want to. There are algorithms for 3d transparency that are a bit more efficient. See: http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-10-transparency/#Order_Independent_Transparency

Joonazan
  • 1,408
  • 10
  • 18