Archive for the 'Graphics Programming' Category

Procedural Terrain Generation

Tuesday, August 12th, 2008

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

Sunday, August 10th, 2008

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

Saturday, August 9th, 2008

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

Wednesday, August 6th, 2008

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!

Alpha of Screensaver Available

Saturday, March 1st, 2008

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.

GPU Particles

Thursday, February 28th, 2008

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?

HLSL is More Strict on the Xbox 360

Sunday, February 25th, 2007

I ran into this problem recently, and I thought it would be a good point to note, especially for anyone who doesn’t have access to an Xbox but would like their code to work on one.

When writing shaders, remember that the Xbox is more strict than a PC. Make sure your input parameters match the vertex definition (and likewise, the other way around). So if you’re using a VertexPositionColor, make sure you’re looking for something like this:

VertexToPixel myVertexShader(float4 inPos : POSITION, float4 inColor : COLOR0)

Likewise, if you’re looking for a texture coordinate, don’t use the COLOR semantic, even if that’s what you’re going to be using it for. e.g., if you’re passing a VertexPositionTexture3 (a 3D texture coordinate you may have defined) but your vertex shader looks like this:

VertexToPixel myVertexShader(float4 inPos : POSITION, float3 inColor : COLOR0)

It’s not going to work…and worse yet, it’s not going to tell you why. This can be particularly troublesome if you’re developing without an Xbox on hand. Make sure your shader takes the correct parameters instead:

VertexToPixel myVertexShader(float4 inPos : POSITION, float3 inTex : TEXCOORD0)

While the former may work on a PC, it won’t work on the Xbox 360.

Custom Vertex Formats on the Xbox 360

Thursday, February 22nd, 2007

In my current project, I needed to make my own vertex format so I could pass more information to the shader. Reimer has a wonderful tutorial on the subject (and the rest of his stuff is great, too). Unfortunately, the tutorial doesn’t implement a vertex format that will work on the Xbox 360.

After some searching, I found that Ziggyware has a great tutorial on custom vertex formats. The most important thing to remember is to implement the entire interface.

Video of my cloud

Monday, February 5th, 2007

I thought a video might be a little better for demonstrating my cloud.

Granted, it’s not the best quality, but it still shows what’s going on. You can see that the cloud maintains its shape as you move around and even through it. You can also see the subtle animation.

Look what I did!

Sunday, February 4th, 2007

It’s not quite amazing yet, but it’s getting there. This is a completely volumetric cloud, rendering in real-time. I’m still working out the lighting equations for it (which are kind of hard to do when your hand it broken and you can’t draw the situation on a piece of paper) and then I’ll work on making it prettier. However, I’m pretty happy with how this looks so far.

My work is loosely based on Schpok et. al,, along with some other information I’ve found scattered about the internet. Most of it is old though, and doesn’t consider the capabilities of current graphics hardware or multi-core machines. Also, Swell, the demo for the algorithm proposed by Schpok et. al, doesn’t work on my machine because of a versioning problem with OpenGL 2+. I’m getting pretty close to what they’ve done though, so I don’t think I’ll be needing it.

I’ve got to say, I’m very happy with C# and the XNA Framework. They take a lot of the low-level details away without seriously hurting performance. I’m still able to do some pretty intensive stuff using managed code. I’m sure it’d probably be a bit faster in C++, but since XNA doesn’t work with unmanaged code, I’m pretty happy using C#.