• Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

VaW progress: Week 2

Sign in to follow this  


Welcome back!

I haven't had much time to work on Vegetables at War this week. I was in Ludum Dare #21 this weekend! I was busy making sure my game library was ready, then busy actually making my game, and then after the deadline, busy trying to compile the damn thing for Windows. I wasn't able to actually able to do it successfully until about an hour ago!

You can see the game here: http://www.ludumdare.com/compo/ludum-dare-21/?action=preview&uid=4920

I tried Visual Studio first, but it didn't like some of my (perfectly valid) code, so I spent ages rewriting a lot of it, only to spend even longer trying to get the program to link. Then, when I finally got it compiled, it just didn't run! So I thought, "Why don't I just use the Windows versions of Eclipse and G++, like I do in Linux?". So I downloaded Eclipse and Mingw which had the G++/GCC compiler. It didn't complain about my code, which was a good start! Long story short, I still spent a long time trying to get stuff to work, but eventually I got it working by compiling GLEW from source with the game and making sure I had the Mingw SDL libs instead of VS ones (doh!).

Oh, and I bought Super Meat Boy. That took up a lot of my time rolleyes.gif

So, screenie:

It's almost the same as last week. I've updated my shaders so that there is a fog effect which becomes more intense as objects move into the distance. Originally, I wanted to have a blur effect, (which, again, would become more intense as you move back), but I think this looks good and was a lot easier. To achieve a blur effect, I would've had to render to a texture the objects I wanted to blur, then render that texture with a blur effect implemented in the fragment shader which would smudge the each pixel with adjacent pixels. I did get the rendering to a texture working actually. Then I tried the fog effect to see what it would look like, and then proceeded to scrap the blur idea tongue.gif

Each asset of type Scenery has a 'depth', which is independent of the Z value in space. It's the Z value according to a grid, with positive Z going into the screen, negative coming out. A depth of 0 is where the action of the game takes place, as you can see by where the carrot is standing. I used this in my fragment shader to determine how much the colour of the object should be blended with the background colour to produce the fog effect. I also needed to make sure that anything that is not Scenery or anything that has a depth less than or equal to 0 has no fog effect added to it.

The code to implement this (in the fragment shader) looks like this:

//'depth' and 'maxDepth' are floats (but they may as well just be integers) passed in by a shader uniform, which are grid depths.
//'z' is the z coordinate in space calculated by the vertex shader, which takes into account transformations so that the fog shading doesn't get screwed up

fragColor.r += (backgroundColor.r-fragColor.r)*((depth-z)/maxDepth)*clamp(depth, 0.0, 1.0);
fragColor.g += (backgroundColor.g-fragColor.g)*((depth-z)/maxDepth)*clamp(depth, 0.0, 1.0);
fragColor.b += (backgroundColor.b-fragColor.b)*((depth-z)/maxDepth)*clamp(depth, 0.0, 1.0);

What this code does is it takes the difference between the background colour and the current fragment colour (taken after texturing, lighting, etc.) and multiplies it by the percentage of how far away it is from the depth where every fragment becomes the fragment colour. Then it's multiplied by whether the depth is greater than 0, which acts as an IF statement. GPUs aren't good at branching, remember! Then this value is added to the fragment colour.

I can change the maxDepth value and background colour via script, which is very handy and only took a minute to implement! Yay for the super easy to use Ruby extension API! laugh.gif

Thanks for reading! Hopefully I'll get a lot more done this week than in the past week.

I'll see you next time smile.gif

Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement