Shaders… The Last Frontier

I can’t remember the first time I promised myself to add shader support to the engine. I even bought a couple of books about it a some years ago. But for some reason it always ended up with the lowest priority. Now I have the chance to redeem myself once and for all. Sort of 🙂

First of all, I’m going with GLSL since I wanted something multi-platform that it can be used on the iPhone as well.

As for the engine, I made some changes to the Renderer class in order to work with shader programs. It’s pretty much the same thing I do for textures: load the program for the first time and then use it repeatedly during the frame update. The program is released automatically when it’s no longer used.

It is also possible to use uniform variables for our programs, although multi-pass rendering is not yet supported.

In order to handle shader programs, I use the ShaderEffect class. Just create a ShaderSource object for each of your shaders, indicating whether your creating a vertex or fragment shader. Then attach them to a ShaderProgram object. Here’s some code extracted from the GLSLSimple example:

And some screenshots:

Pretty simple, yes, but it’s a start. I’m planning on doing some interesting things during the next days like lighting and shadows. Stay tunned.