Jump to content
  • Advertisement
Sign in to follow this  

Defining a "nebula"

This topic is 3122 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The problem: For my 2D space game, I need to be able to define nebulae that will have both display and real game play effects (such as altering visibility). The goals/requirements: I need to be able to define the origin, radius and various parameters for each nebula. Nebulae are constant (the state of all nebulae are defined once at the start of the game and do not change). I need to quickly calculate the nebula's "density" at any point in space. Nebulae should be, well, nebulous. As in not appearing too well defined or regular, and smoothly varying in density. Example implementation: A nebula has a single x,y origin and the nebula density at any given point is defined as the inverse distance to origin. This solution is simple and easy to calculate. The problem is that it's too regular, producing basically a gradient circle. What other algorithms could I try?

Share this post


Link to post
Share on other sites
Advertisement
In this thread there's a downloadable 2d solar system with procedurally generated nebulae and planets. It's written in a basic dialect, be warned :-)

http://www.freebasic.net/forum/viewtopic.php?t=13696

cheers,
Mike

Share this post


Link to post
Share on other sites
Your example implementation produces a fuzzy sphere that can be used as a building block for nebulae although you may want to modify the attenuation function so that the center isn't a sharp point.

To build a nebula you start by making one such "node" and then add more in random locations around it. Reject locations that are too close to an existing node (unnecessary to add density there) or too far from the nearest neighbor (you want the gradients around the nodes to "merge"). The nebular density at a point in space is the sum of the influence of all nodes that overlap the point.

In a 2D game you may be able to just "draw" all the nodes into a density map that'll make it very easy to use in-game. My old game "Strange Adventures in Infinite Space" (now available for free) did just that. I used several different image-based density maps for the nebula nodes to make interesting features like swirls and bubbles in the nebula. It's rather like a 2D "metaballs" system.

In the sequel "Weird Worlds: Return to Infinite Space" I computed a lower-resolution density map on the fly because the player can modify the nebula and the world size is variable.

Share this post


Link to post
Share on other sites
The approach I use in my game is to start with a single splotch and a number of empty textures. Then I randomly draw splotches into the empty textures. Then I randomly draw all of the textures into each other. At the end I assign each texture a color and overlay them all to create a colorful nebula. It's fairly efficient in that the amount of time taken is logarithmic with regard to the number of splotches. I use them for backgrounds in my shooter, but I spent alot of time on it and have a jar available that does nothing but generate nebulas. http://www.alrecenk.com/nebula.jar . Left and right changes nebula seed, up and down changes resolution. I can give you more information if it looks like what you're trying to do.

Share this post


Link to post
Share on other sites
Haven't tried this, maybe it's overengineered, but here's an idea:

1) Create nebula based on your parameters using Simplex noise (experiment a bit to see what gives reasonable results).

2) Combine result with one of any number of pre-generated "stencil" textures that define the outlines of your nebula. You can use airbrush or similar tool in GIMP/Photoshop for making the stencil, or even overlapping circles in Paint/Paint.net. Using alpha creatively could make for some fade out effects to prevent hard edges.

3) Because the noise function can be expensive, you can optionally pre-generate, say, 100 of these nebulae and include them with the game.

4) Density of nebula at given point can be extrapolated from the color of the nebula texture at the corresponding point.

5) Simplex noise could be used for a 3D texture, too. For instance, an animated nebula.

Share this post


Link to post
Share on other sites
I suspected that just adding more nebula cores with my implementation would produce just a lot of gradient circles, but perhaps I should actually try it before I give up on it.

Another option I considered was a plasma fractal.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!