Implementing an infinite grid GLSL shader
In the previous recipes of this chapter, we learned how to organize geometry storage in a more systematic way. To debug our applications, it is useful to have a visible representation of the coordinate system so that a viewer can quickly infer the camera orientation and position just by looking at a rendered image. A natural way to represent a coordinate system in an image is to render an infinite grid where the grid plane is aligned with one of the coordinate planes. Let's learn how to implement a decent-looking grid in GLSL.
Getting ready
The full C++ source code for this recipe can be found in Chapter5/GL01_Grid
. The corresponding GLSL shaders are located in the data/shaders/chapter05/GL01_grid.frag
and data/shaders/chapter05/GL01_grid.vert
files.
How to do it...
To parametrize our grid, we should introduce some parameters. They can be found and tweaked in the data/shaders/chapter05/GridParameters.h
GLSL include file: