2
\$\begingroup\$

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:

Alpha transparency problem

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?

\$\endgroup\$
3
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ 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? \$\endgroup\$
    – Luis
    Sep 19 '13 at 7:06
  • \$\begingroup\$ On a second thought - that was a bad idea (at least it's not practical). Removed. \$\endgroup\$
    – Kromster
    Sep 19 '13 at 8:27
2
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ 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? \$\endgroup\$
    – Luis
    Sep 18 '13 at 10:31
  • \$\begingroup\$ @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. \$\endgroup\$
    – usm
    Sep 18 '13 at 10:49
  • \$\begingroup\$ The points are normally really close together, but I cannot predict beforehand, because it depends on the dataset that I am trying to visualize. \$\endgroup\$
    – Luis
    Sep 18 '13 at 11:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .