Game Development Reference
In-Depth Information
Working with shaders in LibGDX
Let's now turn our attention to the topic of shaders. This is a feature that is available
in OpenGL (ES) 2.0 and above as it makes use of the so-called Programmable
Pipeline . Shaders are usually small programs, which allow us to take over control of
certain stages in the rendering process to define the way a scene should be rendered
by the graphics processor. In consequence, shaders are an important building block
in today's computer graphics and are also an extremely powerful tool to create all
sorts of (special) effects that would be very hard to realize otherwise. For the sake of
simplicity, we will only discuss vertex and fragment shaders here.
Fragment shaders are also called pixel shaders. Unfortunately,
this is a bit misleading as this type of shader actually operates
on fragments instead of pixels.
Consider the following list of reasons as to why shaders are generally useful and
highly recommended to be in the toolkit of every (graphics) programmer:
• Programmability of the GPU rendering pipeline via shaders to create
arbitrary complex effects. This means a high degree of flexibility for all sorts
of special effects expressible through mathematical formulas.
• Shaders are run on the GPU, which saves the CPU time that can be spent
on other tasks, such as doing physics and general game logic.
• Heavy mathematical computations are usually done faster on GPUs than
on CPUs.
• GPUs are able to parallelize the processing of vertices and fragments.
Vertex shaders operate on each vertex given to the GPU. A vertex is a point in 3D
space with attributes, such as a position, a color, and texture coordinates. These
values can then be manipulated through the shader to achieve effects, for example,
the deformation of an object. The output for each vertex computed by the vertex
shader is then passed along in the rendering pipeline as the input for the next
rendering stage.
Fragment shaders compute the color of a pixel for each fragment. For this, many
factors may be taken into account to simulate different kinds of materials. Some of
them are values for lighting, translucency, shadows, and so on.
 
Search WWH ::




Custom Search