Game Development Reference
In-Depth Information
Setting shader uniforms
Most shaders have uniforms as a method of controlling some of the properties of the
shader. A uniform is a variable inside the shader that can be set from outside the shader. We
can set these uniforms by the name Shader::setParameter() and the value of the
uniform's type. The name has to match the name of the uniform inside the shader. For ex-
ample, if we want to set a 2D vector uniform, we call:
The shader class has overloads of the Shader::setParameter() method for a num-
ber of uniform types. The supported types are: float , 2D vector, 3D vector, 4D vector,
Color , Transform (matrix), and Texture (sampler).
Suppose we want to make a simple ripple shader, which distorts the sprite for a period of
time. We will play with texture coordinates, rather than vertices, because it's simpler and
more efficient than actually using a lot of vertices. Here is our Vertex shader:
This is a common shader which doesn't do anything particularly interesting—it only sets a
few varying variables for the fragment shader. Varying variables are used when we want
Search WWH ::

Custom Search