Here are a couple of shader examples that people might find useful. I thought this thread could be used as a place to post shader example projects.
Both these examples are fragment shaders, ie shaders that operate on texture/pixel data.
They both use FBOs to render something to a texture which then has the shader applied.
**Note: these both use the non-power-of-2 arb textures that OF uses by default. This means that tex coordinates are in pixels not 0-1.0 range. **
1) Blur Shader
The first is a blur shader. It does the blur in two passes as described here:
It also ping pongs the shader - which is another way of saying that it runs the shader multiple times rendering from FBO1 → FBO2 → FBO1 etc. By ping ponging the shader you get much nicer results.
To use it, it is as simple as:
blur.setBlurParams(4, (float)mouseX / 100.0); blur.beginRender(); //DRAW SOME STUFF HERE blur.endRender(); blur.draw(0, 0, 640, 480, true);
To get a sort of glow effect try playing with the averaging of the pixel values in the .frag files
changing color /= 25.0; → color /= 23.0; for example gives things a slight bloom / glow effect
2) Zoom / Magnify shader
This one is a little less involved. You render some graphics into an FBO and then specify a circle somewhere on the screen with some zoom parameters. The shader then operates only on the area in the circle and transforms those pixels with a magnifying glass sort of effect.
Here are 006 xcode projects for both examples. Should be easy to hookup for CB or VS too.