Wednesday 15 August 2012

Blender: 2D Filters

I recently started learning how to write 2D filters for the blender game engine.

Resources
As with python the amount of tutorials I used was fairly limited however if you are looking to start I recommend Solarlune's blog, it explains the basics very well and is a good stepping stone.


Next up is the hdr 2.0 .blend file from Martinsh.
Direct download

Whilst not a tutorial, I've found one of the best ways of learning coding is to read it! Take what has already been written and fiddle around with it so you can see how it all works together.

This site was useful as well
https://sites.google.com/site/blendergameengine/customfilter

Especially for clearly showing these variables:

  • bgl_RenderedTexture
    • usage: uniform sampler2D bgl_RenderedTexture;
  • bgl_TextureCoordinateOffset
    • usage: uniform vec2 bgl_TextureCoordinateOffset[9]; 
  • bgl_TextureWidth
    • usage: uniform float bgl_TextureWidth; 
  • bgl_TextureHeight
    • usage: uniform float bgl_TextureHeight; 

Application
As with anything the best way to learn and improve is to do it. My game needed a bloom filter so I started by writing one. The actual effect I wanted was a bloom filter crossed with  chromatic aberration (chromatic bloom?), not very photo-realistic, but it would look cool, and definitely befitting of a sci-fi game.

Here's some screenshots. Keep in mind this took me two days from knowing nothing about 2D filters, so if you're hesitant about learning how to write them, just jump straight in it seems a lot more difficult than it is.



I've also Included a second screenshot to better show the chromatic bloom, note the red and blue shifting effect on the top of the character's body and boots, as well as the colour bleeding effect in the top left, and on the bars on the right .



In the final game I will most likely include all the filters and allow the player to choose which bloom type to apply from the video settings in the options menu.

If you want the code for the filters here it is, this is my first attempt at creating 2d filters so I can't vouch for the accuracy or efficiency of the code, it seems to work though!

No comments:

Post a Comment