Reading data from textures
This section explores how animation data stored in textures can be retrieved in a shader. In this section, you will learn how to sample the texture and what sampler states should be used when sampling the texture.
Once the data is in the right format, sampling it becomes the next challenge. The glTexImage2D
function expects normalized uv
coordinates and returns a normalized value. On the other hand, the texelFetch
function can be used to sample a texture using pixel coordinates and return the raw data at those coordinates.
The texelFetch
glsl takes three arguments: a sampler, an ivec2
, and an integer. ivec2
is the x and y coordinates of the pixel being sampled, in pixel space. The last integer is the mip level to use, which, for this chapter, will always be 0
.
A mipmap is a chain of progressively lower resolution versions of the same image. When a mip level is scaled down, data is lost. This data loss alters the contents of the animation. Avoid...