Depth of Field Shader

June 13th, 2011 2 comments

I’m still working on Cargo, an adventure game made using the Blender Game Engine. I recently finished a big refactor of the code, allowing the player to move from one level to the next (this was blocked by a bad design decision early on). After many months, I can finally work on new features.

Screenshot of game play

That should mean expanding the story into a fully-playable game. But sometimes you need to take a break and have some fun, right? So for the last week, I have been working on a depth of field shader in GLSL. A few of these already existed for Blender games, but none were released with compatible licences. Also, I have been meaning to try my hand at some GLSL for a while.

It turns out that DoF shaders are remarkably easy to write: it’s just like a normal blur filter, but you vary the filter radius depending on the depth of the pixel from the camera. To stop colour from close objects from bleeding into the background, the weight of nearer samples should be modulated by how “in focus” they are, as described on page 10 in the paper Real-Time Depth of Field Simulation. The hardest part was working out how the depth buffer is scaled; the discussion determining depth of z-buffer on the WebGL mailing list was very helpful.

Screenshot of DoF shader

The results are great! With 32 samples you get a nice, smooth blur, with only a few artefacts along the edge of an in-focus object. The performance hit is acceptable for small screen sizes and my laptop graphics card, and barely noticeable with faster graphics cards. Note that the samples are evenly spaced and weighted (except as modulated by the depth) – no Gaussian-like smoothing is applied. This makes it easy to get shaped bokeh, as shown below.

Screenshot of DoF shader

Unfortunately you need a very bright object to show shaped bokeh, and maxing-out the brightness using Blender’s materials doesn’t quite cut it. The right-side of the image above has had its contrast increased to show the bokeh more clearly. The filter could apply its own brightness curve to enhance the bokeh, but the lights in the scene might need to be dimmed to account for that.

There is still some tweaking to do, but I’m really happy with these results. It makes the game look more three-dimensional, and emphasises the small scale of the scene.

Update: I have released this shader under the 2-clause (simplified) BSD licence. Download it as text, or integrated in a demo .blend file.

Categories: Games, Technical Tags:

The DOGSTRUCTOR

March 8th, 2011 1 comment

Last time it was the jacaranda; this time the banana plant copped it. Along with the rest of the yard – as shown below!

Categories: Uncategorized Tags:

String Tripod

February 27th, 2011 No comments

I finally got around to making a string tripod, like the one described here.

Photo of me, in a mirror, using my string tripod.

It wasn’t easy getting the right bolt, but I eventually found one at Bunnings that fit. Unfortunately the local hardware store didn’t have stainless steel bolts; only galvanised. Bunnings didn’t have imperial bolts, but I found that a 6mm one fit fairly well. It’s a bit loose, but when the nut is done up it holds tightly.

I bought 10m of string, but only used about half of it. I melted the cut ends with a match to stop them fraying. The free end is tied in a rolling hitch (like you would use for a guy rope on a tent), so I can adjust the length quickly.

From my quick tests it looks like it holds the camera more steady, but I couldn’t take this shot indoors without the flash. I’m looking forward to using it on a hike – after all, it fits in my camera bag!

Categories: Uncategorized Tags:

Dog-proofing Trees

February 27th, 2011 No comments

We arrived home on Thursday to find that Jessie had dug to the bottom of the roots of our new jacaranda tree – and had eaten some of the roots too! I don’t know if it will survive. But today I spent some time dog-proofing it:Wire meshing under the tree.That should keep her out. Actually most of the time was spent at the hardware shop buying the chicken wire and sand (I made her a sand pit too).

Categories: Uncategorized Tags:

Whip Frog: Our 48-hour Open Game Project

January 31st, 2011 No comments

That was one of the best weekends ever. I’m just back from the Global Game Jam in Melbourne. 48 hours of freezing half to death with 70 or so nerds and art-nerds, and it was such good fun.

I had four awesome team mates, and we produced a massive amount of work over the weekend. You can read about the game on our profile page, and download the game here or there. You need Blender 2.56 to play it – but don’t stress, it’s only about 20MB (that’s smaller than the game)!

The basic premise is that you are the last frog of your kind, and you need to rescue your tadpoles and return them to the water. You use your tongue as a whip to climb walls and swing up branches to reach them – but you have to return to the water regularly, or you’ll dry out!

The game plays fairly well, but there are a few things that I would like to fix. We may do another release soon – stay tuned!

Edit: another screenshot:

Categories: Animation, Games Tags: