Jump to content
  • Advertisement
Sign in to follow this  
noobnerd

asteroid generator

This topic is 2558 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

Hello!

I have been doing a 2D space game for quite a while now and i have stumbled upon a problem.
For graphical purposes, i would need huge amounts of asteroid images that are fairly low res ( 256x256 ) but still look quite good and different. also i would need different hues of asteroids for different systems and icy ones etc. I decided i should make an asteroid generator, but i´m not sure where to start? what would be a good way to do such a program?

I´m using DarkBasic Pro. It includes a lot of primitive 2D commands ( fillcircle, filltriangle etc ) and supports blendmodes ( additive subtractive etc. )

any advice ?

Share this post


Link to post
Share on other sites
Advertisement

Hello!

I have been doing a 2D space game for quite a while now and i have stumbled upon a problem.
For graphical purposes, i would need huge amounts of asteroid images that are fairly low res ( 256x256 ) but still look quite good and different. also i would need different hues of asteroids for different systems and icy ones etc. I decided i should make an asteroid generator, but i´m not sure where to start? what would be a good way to do such a program?

I´m using DarkBasic Pro. It includes a lot of primitive 2D commands ( fillcircle, filltriangle etc ) and supports blendmodes ( additive subtractive etc. )

any advice ?


I'd just get my digital camera out and take a whole bunch of photos of rocks and stones.

Share this post


Link to post
Share on other sites
There are two rather different typical classes of asteroids in videogames:
  • Starship-sized or smaller rocks that can be dodged or shot, usually with exaggeratedly irregular shapes. Usually drawn as flat sprites, with possible variation coming from random outlines (e.g. Asteroids, although the outlines aren't actually random) or from different tile assembly options (e.g. Tyrian)
  • Large ones that can be landed on, seen from very far or flown over just like a planet. Usually drawn perfectly round (maybe ellipsoidal or ovoidal) with some decorative texture of craters, rocks etc. that can be varied randomly before 3D rendering.

Share this post


Link to post
Share on other sites
I'm doing this right now with 3D asteroids and I've had a lot of success. First, asteroids are fundamentally ellipsoid in shape, so I start with an ellipsoid, which you would generate the same way as you would a sphere except you have a scalar that modifies the x, y, and z of the vectors (look up spherical coordinate systems, they aren't that complicated). The next thing, since asteroids aren't perfectly ellipsoidal, we have to deform the thing somehow. You could just do it randomly, but that's a bad idea since you'll get a really random looking jagged pointy mess of ugliness. You want some sort of coherent noise, something that's random but still has smooth transitions between randomness so that the overall appearance doesn't just look like static. Imagine you splatter some paint on something; the paint drops/splotches will be randomly places, but you'll get big droplets and small droplets and overall you'll get something that looks random and yet cohesive. The thing that does this mathematically is called Perlin noise (or simplex noise) and there are a variety of ways that you can generate it (I'm using simplex noise combined with fractional brownian motion) but there's a library called libnoise that will do the trick for you.

Anyway, once I have a noise map, I can do many wonderful things with it. First, I can use it as a scalar to deform my ellipsoid's vertices along their normals. Vary the persistence value in your noise map generation to get more smooth or lumpy asteroids. Next, this thing generally looks rocky anyway, so not too hard to apply a gradient to it and call it a texture. Surface is bumpy, so another noise map can be used as a height map (transformed on the fly to a normal map). I can generate spec maps and glow maps too if I want them, and some asteroids look interesting with various spec maps but generally I avoid this (and comets are a particle effect for me, not just a glow mapped asteroid). I can even use a noise map as a displacement map in theory, although I haven't actually implemented this yet. I've been pretty happy with the results so far of doing this and it's 1000x easier than having an artist individually craft each asteroid.

Now, how can you leverage this for 2D? Well, start with a circle or ellipse. Then generate a 2D noise map and sample it at each vertex on your circle/ellipse and deform that vertex by the amount you sampled it by, possibly applying some other effects as well. Now generate a texture by sampling the noise map and using the value you read to interpolate between two gradient colors, then apply it to your shape and you're done. If you generate 3D noise maps, you can get texture animations as well since you are guaranteed that the interpolations between textures are smooth (pro tip: go with quintic interpolation when you generate your noise map or you'll wish you had); can make a nice burning star effect with this.

So once you figure all of this out, to make an asteroid generator, just hook all of the parameters up to some buttons, checkboxes, and sliders, and then start generating asteroids and see what you like. Bonus points if you can create a genetic algorithm that will take your feedback and use it to render asteroids more to your preferences. Double bonus points if you crowdsource this.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!