Procedural Planet Engine Status

December 30, 2009 by Dave · 2 Comments
Filed under: C#, Procedural Planet, XNA 

Previously I mentioned I was going to do a mulligan on my procedural planet engine. The few hours I’ve worked on it so far have lead to a beautiful new architecture that’s doing most of the same things as before, as well as some major new things, using about 25% of the code.

Here is where  things stand currently. I’ll go through some of these in more detail in a later post:

The planet consists of a cube, with the vertices mapped to a sphere. Each of the six cube faces is a quad tree which is used for subdividing the terrain as you move closer to the planet. Each node in the quad tree represents a patch of terrain with 33×33 vertices that are spread out evenly to cover the patch’s area.

In the previous version the quad tree nodes were subdivided synchronously, which resulted in jerkiness when moving slowly, and outright 5 second waits when moving quickly if a lot of nodes needed to be subdivided. That was good enough then since my priorities were elsewhere, but it’s not good enough for the new version. Now, when a node needs to be split the request is queued on a separate thread. The current node will continue to draw until the split is complete. The split requests can be cancelled as well if the camera has moved elsewhere before the split request reaches the head of the queue.

The nice thing about this design is that if you’re moving very fast you end up getting fewer node splits because they’re cancelled before they happen since they’re no longer necessary. Conversely, if you’re moving slowly the splits can easily keep up with your location so you get all of the required detail.  On the con side, if you’re moving quickly down to a low level, then stop, it can take a bit for the queue to catch up generating the terrain patches, so the detail can take awhile to show up.

Generating a patch currently happens on the CPU using Perlin as a noise basis and various fractal algorithms such as fBm, Turbulence, and Ridged Multifractal. I will be moving this to the GPU over the coming weeks which will vastly improve the “catching up” problem mentioned previously. This will also enable creating procedural normal maps and textures on the fly.

So, the current version of the app lets me start out in space and fly to an Earth-sized planet down to ground level with ever increasing detail, and absolutely no stalling. The entire planet can be explored, but there is no texturing yet, and lighting is using vertex normals so it’s fairly ugly, but it gets the job done at this stage.

I think the next thing I will do is work on moving the patch generation to the GPU. This seemed like a daunting task 8  months ago, but it should be pretty straightforward now. This is a requirement to allow generating higher resolution procedural normal maps, which will be a big step in improving the look of the terrain.

So, that’s it for now.  In future posts I’ll go through some of these features in more detail and discuss how I did things.

Guardian Playtest Release

November 7, 2009 by Dave · Leave a Comment
Filed under: Game Programming, XNA 

Just uploaded the next version of Guardian for playtesting (you’ll need to be an XNA Creators Club member and signed in to follow the link successfully).  There were lots of changes this time around.  Over 250 items checked off of the todo list, many of them polish type things, but also some very major changes and additions, including these:

  • Supports multiple control configurations. The “standard” set is default and uses suggestions received from the last playtest
  • 2-4 player cooperative play
  • Comprehensive tutorial
  • Cleaned up the help “wall of text” somewhat
  • Added “demo mode” to allow watching how the game is played – this will also function as “attract mode” in a later version
  • Added 4 difficulty levels: Easy, Normal, Hard, Legendary
  • High scores for each difficulty level
  • Cooperative high scores for each difficulty level
  • Global (peer-to-peer) high scores for each difficulty level
  • The background nebula is now animated in the menus
  • Background nebula regenerated for each new wave
  • Increased sprite sizes
  • Show ammo level on selected weapon, eliminated inventory display
  • Automatically switch back to laser canon if out of ammo

I have a couple more things to finish up and then I’ll probably release another version before the 7 day playtest is up.  If that all goes well I’ll be submitting it for review in a couple of weeks!

Sprite Sheet Creator

August 25, 2009 by Dave · 1 Comment
Filed under: C#, Game Programming, Tools, XNA 

When developing the iPhone version of Guardian I manually created my sprite sheets.  I used individual sprites up until the end so everything was pretty much set in stone by the time I created the the sprite sheet.  Even then I ended up having to recreate the sprite sheet two or three times, and let me tell you, manually figuring out the texture coordinates isn’t a particularly pleasant experience. In this case I believe I made the right choice.  There were few enough sprites that I would have spent more time creating the tool than I would have saved.

The XBox version has quite a few more sprites, so I decided that spending time creating a sprite sheet tool was going to be well worth the effort.  It didn’t take too long to get it working well enough to use, and not too much longer than that to make it solid enough for distribution.

Sprite Sheet Creator

The application is released as open source under the MIT License.

Download SpriteSheetCreator.zip

Dream Build Play 2009

August 7, 2009 by Dave · Leave a Comment
Filed under: Dream Build Play, XNA 

I managed to make the deadline for entering the Dream Build Play 2009 competition.  The results are expected to be announced by the end of the month.  Based on the quality of entries this year I’m not holding out a huge amount of hope of actually winning.  Regardless, it was a great experience and I learned quite a bit in the process.

As part of the contest submission we wrote up a game description including play instructions and some comments on the technical design, as well as a video trailer.  The video is below, and the documentation I submitted follows. Many of the other entries have posted videos in the Dream Build Play 2009 YouTube group.  And you can see all of the contest entries in the Dream Build Play Gallery.

I still have a few more things to do on the game before I put it up for sale on the XBox, but I’m going to take a bit of a break before continuing on. I should have more time to update this blog as well. Thanks for reading – hope you enjoy the video.

 

 

Guardian

Game Play

The overriding premise of the game is to keep asteroids from hitting your planet, and alien ships from shooting it. Your planet will be damaged as it’s hit, and when the damage reaches the planet center the game is over.  You’re competing for high score, with the top ten high scores are tracked locally.

You command a satellite that constantly orbits the planet.  Pressing A fires your selected primary weapon from the satellite towards the red target indicator that you move with the left thumbstick to aim your shots.  You have to be careful to time your shots so the planet isn’t in between the satellite and the target.  Your main weapon is the Laser Canon and has infinite shots available.  The Plasma Canon is more powerful and the shots move faster.  The Rail Gun is an instantaneous kill, and will destroy anything in its path, including taking out a large portion of your planet if it’s in the way.  You will receive large cumulative bonuses for killing multiple enemies with a single Rail Gun shot.  Each primary weapon has a different charge rate which limits how often you can fire.  As mentioned, the Laser Canon has infinite shots, but all other weapons require ammunition.

Pressing Y fires your selected secondary weapon.  These weapons fire from the surface of the planet.  Missiles will automatically target the asteroid or enemy ship closest to the red target – it takes a second or two for the missile to lock on.  Nuclear Missiles will target the actual red target location, so you can fire them at a point in space and use the large blast radius to take out multiple targets.  The BG4143 will destroy everything on the screen by sending out a shockwave with an ever increasing radius.

Alien ships will drop a powerup after destruction.  You grab the powerup by moving the target close by and using X to activate the planetary tractor beam.  The beam will slowly pull the powerup to the planet, after which it will be used or automatically added to your inventory.  Powerups can add energy to your shields or primary weapon, add maximum shield/weapon energy, and increase shield/weapon charge rate. Powerups will also make ammunition available for the various secondary weapons.

You cycle your primary weapon by pressing the Right trigger, and cycle the secondary weapon using the Left trigger.  The right shoulder button will generate a new background at any time, and the left shoulder button displays your current weapon inventory during game play.

Shields work on their own with no intervention.  They will protect your planet for awhile but have a slow charge rate which can be increased by powerups.  Once the shield power is used up asteroids or enemy fire will damage your planet.  However the shield will continue to recharge as long as nothing is hitting it.

There are 32 asteroids in each wave, and 0 to 3 enemy ships.  There are also bonus asteroids and comets that will move by your planet quickly.  These can be difficult to hit, but you’ll receive a bonus score for destroying them.  They will never hit your planet, but they do come in close enough to hit the satellite and destroy it.  The asteroids and ships start out fairly slowly, but they speed up over time until they’re moving quite rapidly.

Development and Design

A limited version of Guardian was originally created for the iPhone, but I wasn’t happy developing on that platform so I made the decision to port it to XNA and XBox and add much of the functionality I had originally planned for the iPhone.

Most of the game uses basic 2D technology: Sprite sheets, particle systems, state machines, and the like.  Collision detection is mostly accomplished through point-in-circle tests.  However the planetary collision detection uses pixel tests since the planet is eaten away throughout the game.

Some of the more interesting technicalities are described in the following sections.

Background Nebula

The background nebulae are generated using a pixel shader which uses fractal brownian motion and other procedural techniques to build a random cloud and star texture.  Each time you see a new background it was generated in real time.  The backgrounds can actually be animated at 60fps to get some very nice moving nebula effects, but combining it with the rest of the game dropped me down to 30fps.  At some point I plan to optimize it some more.

It is also interesting to note that the backgrounds are generated entirely on the GPU and exist entirely in video memory.

Planet Generation

The planets are also procedurally generated, and are actually 3D.  The basic spherical structure is a cube, and a mapping function is used to move each vertex out to the sphere’s radius, and then the noise functions are used to add the height value.  A second sphere is used for the ocean areas.  Each time the game is started you get a new planet.  In future versions I plan to allow regenerating the planet, as well as having different texture sets to allow for non-Earth type planets.

Generating the planet in 3D allowed me to show the planet rotating in the menu areas, with a seamless transition to the game play area by simply moving the camera out to the proper location using the SmoothStep function.  The planet displayed during game play is still 3D, and can actually be rotated, but it looks kind of strange since the craters don’t move with it.

Planet Craters

The craters are created by drawing one of several random crater sprites into a mask texture each time damage is done to the planet.  The mask texture holds the cumulative result of each crater application.  Before drawing the planet the mask is used to set the stencil buffer, then the planet is drawn with the craters masked out.

Yet Another Guardian Progress Video

July 19, 2009 by Dave · Leave a Comment
Filed under: Game Programming, XNA 

Things are coming along nicely with Guardian. The Dream Build Play entry deadline is fast approaching, but I think I’m in pretty good shape to get my entry completed. The video shows most of the functionality. Pretty much all that’s left now is fleshing out some of the graphics, and adding a few more weapons. Then I can start getting some sleep.

XNA Game Project

June 24, 2009 by Dave · Leave a Comment
Filed under: Game Programming, XNA 

Here’s a video of the XNA game I’ve been working on. It’s a port of the iPhone version with some additional functionality planned.

« Previous PageNext Page »