Draw many circles in 3d space, all facing ofCamera

I’m drawing thousands of circles with ofDrawCircle in 3d space, viewed by an ofEasyCam in perspective mode.

When I move the camera, I want all the circles to face the camera. Far away circles should still look smaller. Circles should still be repositioned according to the camera position and projection. I just don’t want to see any circles from the side.

Is there an efficient way to do this, short or writing my own camera implementation?

Thanks a lot for any advice!

The technique you are looking to implement is called billboarding. The circles will always face the camera. There are many different solutions. You can start with using ofNode and having it lookAt() the camera position. (it may have to be rotated 180 degrees around the y axis ). And then use ofNode.transformGL(), draw circle and ofNode.restoreTransformGL.
This will be a rather slow method. To speed things up, take a look at the textureBufferInstancedExample: https://github.com/openframeworks/openFrameworks/tree/patch-release/examples/gl/textureBufferInstancedExample

You should be able to use the matrices set from the nodes to feed to the shader.

1 Like

Thanks Nick! These are great leads. For my purposes it looks like using ofNode will be too slow. So I’ll take a look at the Texture Buffer Instance example.

Also if all you want to draw is circles (or anything else where the geometry is always the same) the fastest is to just use point textures, you just define a mesh with all the positions of each circle as vertex and calculate the look at to do the billboarding in a vertex shader. i think the billboardExample in the examples folder does just this