Creating video effects with fragment shaders
In this section, we will extend the knowledge of shaders and will see how to pass parameters from your C++ code, how to use Perlin noise, and how to process several images. The examples will be about the fragment shaders, but all the principles extend to the vertex and geometry shaders.
Passing a float parameter to a shader
In order to make the shader interactive, we need a way to pass in it some parameters, such as time, mouse position, and some arrays. To add a parameter, you need to add its declaration in the shader's code using the uniform
keyword. For example, to declare the time
parameter, use the following line:
uniform float time;
To specify the parameter's value in openFrameworks, you need to add the following line after the shader.enable()
calling:
shader.setUniform1f( "time", time );
The 1f
suffix in the setUniform1f()
function name means that you pass one float value to the shader. The first parameter "time"
indicates the parameter name...