|Simple way to add 2D Filter|
To just GLSL shader on your objects you need to do a bit more:
|Use GLSL shader on object|
My code does it in a very simple way. I assume that my object is just one mesh. Therefore I put the code only on the first mesh. A mesh can have different materials. Because I don't care I put my code on all attached materials. Currently I can only set the vertex and fragment shader code. That can come from a string defined somewhere or loaded into a string from some file. Because I like to keep code separate I have put the shader code into own files and load those into strings at the beginning of the function. You can also push some variables, also known as uniforms, to the shader. In my case the are a texture, some matrices and some floats. (Read more about those here: http://www.blender.org/documentation/blender_python_api_2_66a_release/bge.types.BL_Shader.html?highlight=shader#bge.types.BL_Shader)
Recent development in the harmony branch (https://svn.blender.org/svnroot/bf-blender/branches/ge_harmony/ ) is making using shader much easier, and also brings support for geometry shader.
|Improvements inside the harmony branch|
A big problem remains:
Where do I get all those fancy shader from or do I have to code them all by myself?
Yes. And No.
For most things you don't need a custom shader. There are built-in post-processing shader and for materials and objects you can use the material nodes most of the time.
But there are cases where you need custom code. If you are lucky someone already posted the answer to your question on some forum, probably on http://blenderartists.org/ . Have fun searching…
There was a discussion about integrating more shader into Blender:
And because I had time and an idea I made a little addon:
GLSL Shader Repository
Basically there is a repository at https://bitbucket.org/Urfoex/bge-shader/
It has some shader sorted in folders.
The addon "GLSLShaderRepository.py" can be downloaded from the top directory. (Click on the file in the source view: https://bitbucket.org/Urfoex/bge-shader/src and select RAW from top right. Then save it e.g. via File → "Save page as …" or by pushing Ctrl + S ) Inside Blender go to
File → User Preferences… → Addons → Install from File…
and select the fresh downloaded file GLSLShaderRepository.py
You should get something that looks like this:
|Addon loaded and activated|
|Import shader from repository|
|Post Processing shader|
Click on one of the shader and it gets loaded as an internal file.
So currently the post-processing shader are easiest to use with the Filter 2D Actuator.
Most of those shader I found on http://blenderartists.org/
I haven't tried them so they might not work. Please post issues (best on the repository site) so they can be fixed.
It would be very nice if you could also give me more shader to put in the repository. There is also a reference folder in the repository containing lots of shader code that would need some revision to make it compatible with BGE.
Now have fun with shader!