Inputs and outputs

As the rest of the shaders, fragment shaders can receive uniform variables as input. They work exactly as for vertex shaders, so there isn't much to say at this point except if we talk about textures. Textures are represented by an opaque variable type: a sampler (an opaque type is a special type that can only be used with built-in functions and cannot be used in mathematical operations). To make a texture available, you have to declare its uniform variable, using the right sampler type. Depending on the class of the texture you should use one sampler or other. A brief list is:

  • sampler1D (for 1D textures)
  • sampler2D (for 2D textures)
  • sampler3D (for 3D textures)
  • samplerCube (for cubemaps)
  • sampler2DArray (for arrays of 2D textures) ...

Get GLSL Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.