ofFbo layering problem

Hi all

I’m making a 3D particle system that consists of (among other things) one ofBbo object drawn many times. Nothing complicated, I create the ofFbo in a ParticleSystem class, pass a reference of it to a bunch of Particle classes, sort the draw order based on z depth, calculate the new position, scale, colour etc, then draw it:

  
ofSetColor(colour.r * 255, colour.g * 255, colour.b * 255, alpha);  
ofPushMatrix();  
ofTranslate(position);  
ofScale(scale, scale, scale);  
orbFbo->draw(0, 0);  
ofPopMatrix();  

It’s all working fine and looking almost perfect apart from some strange visual effects (see image). These seem to be the result of the ofFbo objects being drawn too close together and overlapping. To create the effect I’m after I need lots of ofFbos drawn close to each other.

Any advice on how to fix this? Also, am I approaching this in the most efficient way? I’m looking to have around around 10k particles in the scene. At the moment the fps lowers from 60 - 25 when there are 5k active particles.

Thanks in advance.

Hi James,

Is there a reason you are using an ofFbo? If you are using the same image repeatedly, you should bind a single texture, instead of making the draw calls on the fbo.
Is glDepthTest enabled? Maybe that will fix the issue shown in the image.
For the most efficient, you will probably want to use textures, vbos, point sprites and a shader. Here is an old thread that goes through the process.
http://forum.openframeworks.cc/t/vbo-billboard-particle-system/2639/0

Hope that helps.

Thanks Nick, this seems the best way to go although I haven’t been able to get it working in OF 007. After some investigation I found Todd Vanderlin’s example for OF 0071:

https://github.com/openframeworks/openFrameworks/tree/master/apps/devApps/BillboardExample

I made a couple of changes to get it working with 007 (billboardColor[] to ofFloatColor and shader.setup to shader.load) but it crashes. After some investigation I found this is because of the uniform float pointSize in the vert shader. If I don’t use and it and hard-code gl_PointSize to 20 it runs but I can’t see any textures.

Any idea where I’m going wrong? Or does anyone have an example using point sprites and textures in 007?

I haven’t had the chance to test it, but do you call these enabling functions?

  
  
glEnable(GL_POINT_SPRITE);    
glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);    
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);  
  

It already has ofEnablePointSprites() which I suspect takes care of this. However I just tried your suggestion and it made no difference.

I managed to get the point sprites example running. I had another PC arrive for this project today so I tried to build the app on that and it worked perfectly. It’s so frustrating when one PC behaves differently to another like this.

Thanks for your suggestions Nick. You’ve definitely put me on the right path. Next stop OpenCL…

I may have spoken a little too soon. On my PC the textures are being rendered but this was because I hardcoded the gl_PointSize in the vert shader. I am not able to resize the points using the billboardSize array and setUniform1fv. The pointSize uniform does not appear to be assigned correctly.

As in Todd’s code, I’m doing the following:

  
billboardShader.setUniform1fv("pointSize", billboardSize, NUM_BILLBOARDS);  

It is possible to resize the point by doing something like this in the shader:

  
gl_PointSize  = ((gl_Position.x + 400.0) * 0.1);  

… so that’s not the problem. Any shader heads out there with a possible solution?

This isn’t a problem on the Mac but unfortunately I have to use PCs for this project.

EDIT:

Here’s my machine spec
64bit Win 7
Intel® Core™ i5-400 CPU @ 3.10 GHz
4 GB RAM
NVIDIA Quatro 600

I’m using Visual C++. I’ve also recreated the problem in Code::Blocks.

Im not too familiar with pcs. Can you hardcode the point size and change some other factor like color using the setUniform1fv vars? are you using the normals? could you pass the point sizes using the normals?

Brilliant, I’m all about the filthy hacks and that worked a treat. Thanks Nick, you’re a lifesaver. Been pulling my hair out for a couple of days over this one.

sweet. whatever gets the job done. glad to help.

Cheers!