# How to draw point sprites with transparency in OpenGL without depth sorting?

I am trying to render point sprites with alpha transparency and because I render millions of points depth sorting would kill performance. My issue as you can probably imagine is that artifacts appear in some of the borders when the draw order is not correct:

My code for drawing:

glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDrawArrays(GL_POINTS,0,nSamples);


In my shader I just specify a alpha value in the output color depending on how close to the point center we are.

Is there any way to get rid of the artifacts and get a correct transparency render?

If you can change your blendfunc to one that is order-indpendent you may get good results, but then again you may not; it depends on whether or not the output meets the requirements of what you're trying to do.

Another semi-trick I've used before - for a particle system - is to group particles by emitters, then depth-sort the emitters. It's not 100% accurate of course, but if it works well enough for you then it may be worth trying.

• What I'm trying to do is get a smooth surface from all the points, in that test a sphere. You mean an additive function or something like that? It's not a particle system, so I can't rely on emitters. @Krom Stern Could you provide a little example or some links?
– Luis
Sep 19 '13 at 7:06
• On a second thought - that was a bad idea (at least it's not practical). Removed. Sep 19 '13 at 8:27

Some things to consider:

Do you really need to draw millions of points? Perhaps you could get away with only drawing the points on the surface, in which case you check to see if point center > radius of the sphere - some threshold, and only draw it if it's true.

Secondly, depending on how you're generating the points, you could generate them at initialization and sort them once before any rendering is done. Ensure your vertex array is sorted back to front and the frontmost will overwrite the ones back further back.

• Yes, I need to draw a lot of points, this is just a test, I normally have much bigger datasets. The second observation could work, but would this order not depend on the camera position?
– Luis
Sep 18 '13 at 10:31
• @Luis Oh, I see. Yes, you'd need to recompute the order when the camera moves, but you could do that when it moves more than a certain angle (which might still kill performance). How spread out are you planning on drawing the points? You might be able to use impostors for large numbers of distant points.
– usm
Sep 18 '13 at 10:49
• The points are normally really close together, but I cannot predict beforehand, because it depends on the dataset that I am trying to visualize.
– Luis
Sep 18 '13 at 11:12