Skip to Content

Procedural Terrain Generation

This is something I’ve had in a semi-finished state for a long time. It’s just had a bug I haven’t had time to really look at for a while, and the shader wasn’t that special. This is a terrain generator with a focus on RTS-style terrain. That means clearly walkable and non-walkable regions, and flattened walkable regions.

I may write an article on this, in which case I’ll release the source. There’s already a paper on this method, but it skips some of the important parts (like generating the noise) in favor of covering the more inventive algorithms, so I figure I could write something to cover it all (time allowing).

You can download the demo below. WASD and QE control the camera, clicking and dragging with the mouse rotates the camera, holding F will display walkable areas, and pressing G will generate a new terrain.

Download the Windows Installer

Wisp Source

Because Mykre couldn’t wait to see it, here’s the source code for the wisp demo I recently made. I cleaned up the code a bit and added pretty liberal comments so you can really tell what’s going on. Let me know what you think!

Download the Source Code

Wispy UI Background

The other day I had a chance to look at the PS3′s UI, and I just couldn’t get over the slowly-moving, wavy shape in the background. So I figured I’d make it in XNA. I was pretty close on my guess about how it worked.

It just uses a constantly deforming plane and a pretty simple shader. The variation is just a lot of math modulated by position on the plane, time, and a random “seed” value. That way, while it has some coherency in its movements, it still has plenty of variation to make it interesting.

Try it out.

FlatRedBall Animation Demo

I thought I’d post a quick note to post this, a demo of animation blending using FlatRedBall (along with some other nice tricks). This only took a day to put together, and most of that was finding the assets and debugging the movement code (since I wanted to show the blending).

The demo program can be downloaded from my portfolio page, and runs in 720p. The audio is a little weird, but it’s probably because I messed a lot with the sound processing in XACT. Enjoy!

Is this thing on?

I’m not dead! Really! I’ve just been very busy during the last few months. Turns out that once you decide to get married, your life is taken over by wedding planning until you’re married (well, at least if you decide to have a really short engagement). Oh, and yah, I’m getting married!

So, in an attempt to keep my life somewhat normal while everything runs around crazy, I’m going to try getting this blog back in order. If you’re still out there watching, you deserve at least something for your patience, eh? I’m probably going to start it off with some simple tutorials on the engine I work on, FlatRedBall. The engine has really grown out of the “2.5D” that it started in and into a decent 3D engine – with some of my help of course ;)

Aside from that, I might as well share some awesome stuff I’ve seen/played lately:

GemCraft: a tower defense game with a twist – your “towers” hold gems, which actually do the attacking. They can be upgraded and moved around, and as you level up later on you can use your new skills to go play old levels (without being bored to tears). You can also respec your skill point distribution at any time for free – which is really nice. I recommend it as a study of how to create a game where your character can get stronger without previous areas being any less boring to play (and without “leveling up” previous areas to match your new character).

Team Fortress 2: I know, I caught the boat late. If you haven’t played this yet, go get it off Steam! If you have, and you’re reading my site, you must be some sort of developer, in which case you should read about the rendering methods used in TF2 here and here.

Final Fantasy Tactics A2: Final Fantasy Tactics really drew me in back in the Playstation days, and I’ve played it quite a few times since. I also played all the way through FFTA (the first Final Fantasy I actually finished). So getting this was a no-brainer. Now that I have it, I really appreciate all the variety they’ve added to the game. I also really appreciate how the game is broken into “quests” which each take about 10 to 30 minutes to complete. With the amount of running around I’ve been doing lately, it’s really nice to be able to pull out a game that I can play for 15 minutes or so when I have to wait for something.

Rock Band: I always hated rhythm/music games – there was only ever one song on DDR I was good at, and it was in a very specific arcade version that was in a city I didn’t live in. Other than that, I was horrible. My first experience with Guitar Hero wasn’t that great either – they started me on Medium and I did horrible. However, my fiancée started talking about liking it (she played it with some of her friends), and always on the lookout for new games to play with her, I picked up both Guitar Hero 3 and Rock Band. That was it – we played all the way through Guitar Hero 3, and I still have groups of people over all the time to play Rock Band. It’s a lot of fun to play with friends – and it’s a game that a group of people can really enjoy playing (without having to really be any good at games). Just don’t make people feel bad if they start on easy – it’s not the hardest of hardcore games after all.

So that’s a pretty good list of games that’ve been holding my attention lately. There’s a few others, and I’m always on the lookout for good co-op games I can play with my fiancée (know of any?). Of course there’s also Shizoid – I tried the demo with my best man, then we played it all afternoon. I’ve also played it quite a bit with my fiancée – the one-stick controls are really easy for anyone to pick up. Unfortunately, the difficulty really ramps up around the checkerboard stages.

Oh, and look at my wrist, I’ve gotta go.

Edit: One final note: I’m going to try upgrading to the newest version of WordPress soon – I’ve used it on another site and it’s much nicer. So a little downtime in the next day or so is to be expected.

Edit(again): Alright, that was relatively painless – only lost the categories for a while. I’ve updated to the newest version of WordPress. Let me know if anything is broken.

Particle Life Source

Much later than anticipated, here is the source code for my screen saver, Particle Life – and a short discussion of some techniques used to make the screen saver. I used GPU processing, pre-rendered depth blurring, and some fun camera tricks.

Particle Life Source Code

GPU Processing

You’ll see this in PositionsEffect.fx. Basically, I pre-generate a velocities texture with random noise, and pre-generate a positions texture with incremental depths for particles (to ensure a good distribution of particles) and random x/y values (with the camera’s frustum). Then every frame I sample both position and velocity, add the two together (multiplying the velocity by the elapsed time) and write the new values to the positions texture.

Now, here’s where I could use vertex texture fetching, but I wanted something that’d work on shader model 2.0 (and my laptop), so I did something simpler. The position texture is stored as a HalfVector4. Every frame, I dump this straight into an array and then push it into a vertex buffer of HalfVector4 vertices. Since I’m using point sprites, that’s all I need to do. It’s not the most efficient piece of code (the dump sure isn’t nice), but it works.

Pre-rendered Depth Blurring

I wanted particles to look blurry as they became more distant. However, with alpha-blended particles, I can’t quite do this in a post-processing step. I’d have to basically blur the texture whenever I rendered particles by taking several sample taps on the texture for each pixel. The fill rate would become horrible.

Life Particles

So, I took the easier route. Instead of doing all that work on the GPU just to get particles to blur, I just built the mipmaps in the texture by hand. If you open up, you’ll notice that each successive mipmap is not only smaller, but blurrier. Since the mipmaps are automatically blended when I sample the texture, that does the blurring for me for free.

Camera Work

One of the important things to take from this sample is that sometimes there’s ways you can “cheat” without being caught by the end-user, and save a lot of processing power in the meantime. One more example of this is how the particles are “culled”. Nothing exists outside of the camera’s viewing frustum. There’s no reason for it to – it’s not visible to the user, and it’d just waste processing power if we dealt with it. So when a particle leaves the camera’s frustum, it’s wrapped around to the other side.

So how do I know if the particle has left the view? Well, I could do a bunch of nasty math involving rotation, tilt, field of view, etc. Or I can just align the camera straight down the Z axis. Then I know that there is a linear relationship between the particle’s Z position and the width and height of the camera plane at that Z. This is the tangent of the field of view. So I just set that as a variable in the shader (or variables in this case: FieldWidthFactor and FieldHeightFactor in PositionsEffect.fx). Now I don’t even have to do any transformations of the particle positions.

One final note

GTA IV Depth of Field

You might recognize this, it’s from Grand Theft Auto IV (image from If you’ve played the game, you’ll probably have noticed how short the full-detail draw-distance is. After a couple blocks, cars turn into headlight circles (a simple circle to show headlights) and everything becomes really blurry. My theory is that, to help with memory streaming and file sizes, a lot of the intermediate mip-maps in textures have been cut out. That way the full-detail texture maps only have to be loaded when you’re close to an object, but it can still have some definition if it’s in the background. However, due to either space or processing constraints, they couldn’t show too far away, so a post-processing effect adds some grainy blur for distant objects, helping to hide the low-resolution textures.

That’s in no way the official word on things, just my guess – but it’d be a good example of how you sometimes can make clever use of graphics tricks to keep your asset size and processing requirements low while still maintaining good visual quality.

XNA 3.0: MP3/WMA/WAV support!

So, I was a little disappointed about the XNA 3.0 CTP when I read about it. It looked like the only big feature was Zune support (being without a Zune, or any friends who have a Zune, I have quite the lack of interest in developing for it). However, after a little prodding, it looks like with Zune support comes much better media support, including the ability to import and process MP3, WMA and WAV files without going through XACT! They seem to be converted to WMA files, which is fine by me, though the options available for compression are pretty simple still.

I made an example project which shows how to process and load an MP3 song in your program:

Download the Example!

It’s pretty trivially easy, but there’s really no how-to that I could find that explains this. The big thing is the MediaPlayer class, which lets you do a lot of different things with Song classes. Check it out in the documentation for the XNA 3.0 CTP.

And of course, you’ll need the XNA 3.0 Community Technical Preview to compile and run this example.

Now, if they add FriendGamer.CurrentTitle by the next release, I’ll be happy!

Alpha of Screensaver Available

I’ve completed an alpha version of the screen saver I’ve been talking about, and it’s now available for download.

Get it here
Edit: The screen saver works! Just copy ParticleLife.scr and FlatRedBall.dll to your Windows/System32 directory, then right click ParticleLife.scr and select Install.

Giant Screenshot

To run this you’ll need to copy the .scr and .dll to the windows directory (I hear Windows\System32 is the place to put it, but you can just right click the .scr and choose install too). Then make sure you have the following prerequisites installed:

The .NET Framework 2.0
DirectX 9.0c (run this even if you have it already – you may be missing files required for XNA)
XNA Runtime 2.0

I know it’s a pain (and ironic that this screen saver is windows-only), but the alternative is…well, not using the screen saver!

The original inspiration was this piece by Hawk: Life. I saw it and thought, “that would make a nice screen saver, and a good test of some GPU programming.” So I went for it. It’s not as pretty as the flash version (the lines aren’t as clean), but I think it looks decent for programmer art, and it runs nicely (and almost all of the calculation is done on the GPU – which was my major focus when making this).

There aren’t any options in this version. Eventually I want it to support user-specified particle counts, but I can’t really do that without storing the value somewhere. The most popular place for screen saver parameters is the registry, and I can’t go writing all over that without an installer/uninstaller (so if you decide you don’t like this it doesn’t leave a bunch of dead information in your registry). So – if this screen saver is a hit (goodness knows smaller things I’ve made have been huge hits), I’ll probably clean it up a bit and add some settings.

You’ll also need a graphics card that supports Pixel Shader Model 2.0 – I created this primarily as a test of some graphics techniques – not necessarily just to make a screen saver (you can compile that flash as an exe with exit-on-input to use it as a screen saver). I’m not doing any detection at the moment – so if it doesn’t run

For the XNA programmers in the audience, I’ll be releasing the source code for this soon.

Feed Fixed!

Looks like when I switched some stuff on my server, I nuked the feed! I fixed it, and hopefully you’re all getting this post as well as my last one! (I’m not dead yet!)

Enjoy this screenshot of my in-development screen saver at huge resolution (not giant yet – haven’t got to test it on 1080p yet):

Giant Screenshot

GPU Particles

Check this out: 10,000 particles running on my new system (with no gfx card!) at a consistent 30fps, all with different velocities, distance blurring, etc.:

I had 65,000 running just fine, but it rendered as a big white blob, which didn’t look very presentable. I’ll cover the techniques behind this sample soon, along with providing full source. Most of this is actually done on the (motherboard-embedded) gpu though – I was surprised it ran well at all!

So stay tuned – I’ve got a couple graphics samples in the works that I’m hoping to start filling my website with soon. I’ll release this one once I clean up the presentation a little (it’s not quite what I want – yet). I’m hoping to make it a screensaver similar to Hawk’s recent flash sample entitled Life. Anyone see the irony?