Implementing an infinite grid GLSL shader
In the previous recipes of this chapter, we explored some approaches to geometry rendering. When debugging applications, it’s helpful to have a visible representation of the coordinate system, allowing viewers to quickly infer the camera’s orientation and position by examining the rendered image. A practical way to represent a coordinate system is by rendering an infinite grid aligned with one of the coordinate planes. Let’s learn how to implement a visually appealing grid in GLSL.
Getting ready
The complete C++ source code for this recipe is available in Chapter05/05_Grid
. The accompanying GLSL shaders, which will be reused in later recipes, are stored in the shared data folder under data/shaders/Grid.vert
and data/shaders/Grid.frag
.
How to do it...
To parameterize our grid, we should introduce some constants. These constants can be found and adjusted in the data/shaders/GridParameters.h
GLSL include file...