Procedural Planetary Nebula


I’ve got a video on youtube from the nebula:


Some of us (including me, of course) are working on space shooter type of games.
And I’ve taken some time (together with the guys on Pandas IRC channel) to create one effect a good space shooter game can’t afford to miss…
…a planetary nebula!

Of yourse, you could just render some great looking nebulae on your skybox, but what we wanted (Treeform and myself) was a volumetric nebula that you could actually fly through.

So after some internet research I found some equations that could help with generating such nebulae.

Based on those “strange attractors” I created some code, that generates a nebula as a set of GeomParticles…

The code(with enough comments I hope):

And some screenshots with different angles and particle densities:

The last two are with 1000000 particles, obviously too much fro the frame rate, the first one is with 100000 particles…
so enjoy…

yes Legion is da man! I already put the nebulas into my game and they look awesome! I will let screen shots speak for them selfs!

and with more game elements:

Thanks alot for sharing Legion!!!

Have you tried using a significantly smaller number of particles, but with each individual particle larger?

Yes I did, but that just looks bad…
But you could try that for yourself (just takes a minute to adjust the number of particles and the thickness with setRenderModeThickness() )
And don’t ask about using textured sprite particles, that won’t even let me go up to 1000 particles with a reasonable frame-rate.

Though, I want to experiment with shaders, to achieve a denser look with less particles. But right now shaders won’t work (somehow my system is a little bit messed up)…

i changed the code structure a bit and added 2 other algorithms to play around with.

The used function can now be defined at the end of the file “a = nebula(func)”

  • where func may be:
    • default : the previous one
    • lorenz
    • ifsLorenz

to see the full capabilities i recommend playing around with the ‘changeable variables’ in the classes default, lorenz and ifsLorenz. Try little changes on separate numbers, as it often exceeds the number range of python.

Thanks Hypnos…
I already had the feeling, that the nebula class should provide more flexibility, so one could render different shapes…

it looks…beautiful…

I added a interactive environment to change the parameters on the fly. Get the latest version of my modification from: …

It also allows you to save the files into .bam
Because it recalculates the whole nebula when pressing a button the number of particles during modifying should be kept low. Once you found something nice you can increase the number of particles easily.

The only thing that has to be changed manually is the attractortype at the end of the file.


I’ve updated the code again and added a galaxy generator if have found lying around on my harddisk (though i did not write it), it’s currently the default when starting up.

I hope this helps someone.

this version is not integrated into the editing (however the names of the variables are more meaningful)

this version can be edited using the keys in the editor (the variable names are just useless), note that not all parameters can be changed (like the thickness of the arms and the depth of the arms, the other fixed vars are relative to other variables (like radius of the core/ radius of the arms)):

anyone happens to have the 4 or 4_1 version available somewhere?

on a side note: has anyone considered bringing all these examples together, including these small experiments, into a wiki or something, so they don’t get lost as times goes by?

radu: serach the forum for “demomaster” . aside from that we have the code-snippset and showcase corner here on the forum. then we have panda3dprojects which can host larger examples. only very few things are lost. you’r also free to write samples to be included into panda.

here’s a updated link, containing all versions i’ve worked on: …