Chapter 10. Using Compute Shaders
In this chapter, we will cover the following recipes:
- Implementing a particle simulation with the compute shader
- Using the compute shader for cloth simulation
- Implementing an edge detection filter with the compute shader
- Creating a fractal texture using the compute shader
Introduction
Compute shaders were introduced into OpenGL with Version 4.3. A compute shader is a shader stage that can be used for arbitrary computation. It provides the ability to leverage the GPU and its inherent parallelism for general computing tasks that might have previously been implemented in serial on the CPU. The compute shader is most useful for tasks that are not directly related to rendering, such as physical simulation.
Note
Although APIs such as OpenCL and CUDA are already available for general purpose computation on the GPU, they are completely separate from OpenGL. Compute shaders are integrated directly within OpenGL, and therefore are more suitable for general computing...