In order to render a large amount of identical primitives, you probably want to 
use either instancing or geometry shaders. If your target hardware supports 
OpenGl 3.x features, then the latter is better. You can use arrays of 
per-vertex data to specify the differences between your spheres (radius, colour 
etc), create your osg::geometry as a list of points and have your geometry 
shader expand that into spheres.

For the spheres themselves, it's far quicker to create them as camera-facing 
impostors, and have your fragment shader just draw spheres for each of them 
(various examples are available on the web), which can be lit as needs be. The 
trouble is that they will be flat, which might not be ideal if many of your 
spheres intersect. You could at least save some triangles by generating 
camera-facing hemispheres. I'm not sure what the effect would be if you changed 
the z-values in the fragment shader, but I am advised that's not a good idea, 
because it means z-buffer-testing can't be done before your fragment shader is 
run.

If you're stuck with older or mobile hardware, then (extensions permitting) you 
can use shader instancing to do the same thing. Create a single sphere (or 
hemisphere or quad, for an impostor) , put your per-instance data into a 
texture, and sample that texture in your vertex shader (ensure you set your 
texture filtering modes appropriately).  There is an example osgdrawinstanced 
supplied with the OpenSceneGraph distribution that shows you basically how that 
is done.

If you don't have the instancing extension available (MESA software rendering, 
some older mobile OpenGLES 2 chipsets, VERY old desktop hardware) you need to 
just make sure you render them in large batches of vertices, which means making 
1, or only a few Geometries containing multiple spheres (or quads if you can 
still use a vertex shader to orient them).

Quite a lot of ideas there for things to try, I think, apologies if any of that 
is a bit confusing.


Alistair Baxter
Software Engineer
________________________________
Have you downloaded your FREE copy of FieldMove Clino?
Find out more about our app for iPhone and Android smartphones:  
http://news.mve.com/fieldmoveclino
Midland Valley Exploration Ltd.
144 West George Street
Glasgow G2 2HG
United Kingdom
Tel:     +44 (0) 141 332 2681
Fax:    +44 (0) 141 332 6792
The structural geology experts

From: [email protected] 
[mailto:[email protected]] On Behalf Of Trajce Nikolov 
NICK
Sent: 02 December 2013 13:50
To: OpenSceneGraph Users
Subject: [osg-users] rendering millions of spheres

Hi Community,

I remember someone has faced this problem and I think with some solution. 
Anyone knowing some pointers willing to share some hints, techniques?

Thanks a bunch

Nick

--
trajce nikolov nick
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to