Microscopic physics visualization

I am relatively new to OpenGL but it has become clear that the OpenGL framework along with the GLUT package can be useful for me to create realistic microscopic physics visualization (nuclear interactions, molecules, particle physics etc).

I have written a very simple class built on OpenGL and GLUT functions for generalized management of these sorts of animations. There is simply a “particle class,” which contains all rendering information and a “world class” which is more-or-less a container for some number of particles. Each particle or object contains member functions noting how to render itself and the entire vector of particles is rendered by the world. (NB: I am sure something like this already exists but I am creating it not only for its use but also so that I gain experience and I can make it plug into several other physics libraries I have).

Anyway, I have recently completed a simulation beginning with N bodies all which can spawn 2 new bodies (nuclear decay). While I previously had no trouble rendering ~600 individual bodies my rendering now slows down very substantially and I have 2 Ideas why:

1. After the decay there are a 2 more moving bodies which need to be kept track of.  These often move out of the viewable area but I believe they are still being computed and rendered.  Is there any GL function I can use to test if they are in the visible area before calculating/rendering?

2. Since I want the simulation to be as realistic as possible I end up generating quite a few (3 per body per render) random numbers.  I also do several geometric calculations in each render which has a spawning of new objects.  Is there a straightforward way to buffer these or some kind of common practice that allows me to calculate them for the NEXT render without affecting the frame rate?

I suspect my simulation is slowed greatly do to these computations.


I don’t know what you mean for realistic microscopic visualization… light don’t interact with object smaller than it’s wavelenght. Can you post an image?

Said that:

Is there any GL function I can use to test if they are in the visible area before calculating/rendering?

You can compute frustum culling
but computing the culling for every particle can be slower then render them. Maybe if you organize them in some smart hierarchical structure you can save some time. But again updating the structure can be time consuming. :-S

How do you render each particle? Point sprite? Sphere?
How many particle do you have? How do you send them to openGL?
Render 1 or 2 millions point sprite particle is not a problem for a modern GPU if you use vertex buffer.

From your post I think you are doing something like that

for(unsigned int i = 0; i < nParticles; i++)

If you are using point sprite consider to use vertex buffer object and if you are using sphere you can try with instancing.

Also if you have a nVidia GPU consider to use CUDA for the computation:


Thanks for the reply.

i. For “realistic” microscopic visualization I simply mean that the lifetimes of the “particles” which I use are in proportion to their real lifetimes. And also interact on the appropriate time scales with respect to scattering…etc.

ii. Thanks, I guess it will be OK to keep track of them outside the viewable area, since I don’t think I would want to compute the frustum culling for every instance.

iii. I render each particle as a GLUT sphere (with lighting effects at the moment…it looks pretty…maybe that takes time?) and I typically have 300 or so initial particles, but with decay this can grow to 900 during the course of the simulation. I would like to be able to simulate easily in the neighborhood of 1,000 initial particles, depending on their properties this can turn into as many as 4-6K easily.

You are exactly correct for your guess on how I am rendering the whole scene.

Another point is that I would eventually like to do particles which are “composite,” and therefore made of several spheres in a cluster type configuration. I suspect this will slow my rendering even further.

I would like to produce a picture, but I am still working on getting an output that will work (is there an easy post-script output command?) for making a picture of my sim.

Thanks for the tip on vertex buffer objects and instancing…I’ll have to learn what those are.