Elsevier

Computers & Graphics

Volume 31, Issue 3, June 2007, Pages 524-531
Computers & Graphics

Education
Teaching OpenGL shaders: Hands-on, interactive, and immediate feedback

https://doi.org/10.1016/j.cag.2007.02.001Get rights and content

Abstract

This paper describes the teaching of OpenGL shaders with hands-on a program called glman. Hands-on education is at its best when the students’ experimental feedback loop is very fast. glman allows students to create a shader scene description file which not only creates the 3D scene, but creates an interactive user interface to adjust parameters. Our experience in an experimental class taught in Spring 2006 is that glman is flexible enough to demonstrate and experiment with many shader concepts and creates a fast learning curve for the students.

Introduction

GPU-programmable shaders are the most exciting development in computer graphics in a long time. For the first time, programmers can get both the flexibility to perform amazing vertex-by-vertex and pixel-by-pixel effects, combined with the performance to make it interactive. The emergence of shader programming will have profound effects on all areas of computer graphics including science, engineering, art, animation, and gaming. This is the good news. The bad news is that shaders are difficult to teach and learn. The effects of certain shader parameters in certain shader equations are not obvious. Converging on good values is difficult.

glman is a new program that was written to help teach the OpenGL Shading Language (GLSL) [1], [2], [3]. It uses an input file called GL Interface Bytestream (GLIB), which is modeled after the style of the RenderMan Interface Bytestream (RIB) [4], [5]. glman reads a GLIB file as well as one or more vertex and fragment shader files. It then creates the requested scene, activates the requested shaders, and creates sliders for user-defined global parameters. glman also provides a Perlin noise [6], [7] 3D texture for use in the shader. Our experience with using glman in a college class is that students get a maximum amount of quality learning in the minimum amount of time.

Section snippets

Shaders in the graphics pipeline

Fig. 1 shows a generic view of the computer graphics rendering process. There are two locations in this process into which an application developer can inject custom shader code: the vertex processor (VP) and the fragment processor (FP). The VP takes 3D coordinates in the modeling coordinate space. It transforms them into world coordinates using a modeling transform, then transforms them into eye-space coordinates using a viewing transform. When coordinates leave the vertex processing stage,

The course

This course, CS 519, is a multidisciplinary course, with students from Computer Science, Engineering, and Geosciences. The course teaches the theory behind how shaders work, enough graphics software and hardware to understand what is happening behind-the-scenes, the mathematics of shader effects, and shows their use in a variety of applications such as special effects, procedural texturing, image processing, visualization, bump-mapping, cube-mapping, and displacement-mapping.

The assignments

Introducing shaders to students

Our experience is that people (instructors included!) learn shaders very slowly if they must go through the full edit–compile–execute sequence for every little feature they want to try, shown in the left side of Fig. 2. We found that learning shaders works best when the students are in a very tight try-it-myself loop. With that in mind, we created a program called glman. The main glman user interfaces are shown in Fig. 3a.

glman is so named because its input looks a lot like the RIB files of

What do shaders look like?

The following code shows a vertex shader example, one of the first given to the students. This vertex shader computes diffuse light source shading based on the transformed surface normal. It sets up variables Color, X, and LightIntensity to be interpolated by the rasterizer into each instance of the fragment shader. It also multiplies this model–space coordinate by the full Model-View-Projection matrix and passes into the rest of the pipeline.

  • varying float LightIntensity;

  • varying vec4 Color;

Teaching noise as an integral part of shaders

Noise is a major component of shader-writing. Originally developed by Ken Perlin [6], [7], noise is used as a variation on surface properties to make the surfaces more interesting. But, noise is a difficult concept to explain to students. So, we have written another program, NoiseGraph, to give the students hands-on experience with creating and controlling noise functions.

Fig. 5a and b shows two scenarios from NoiseGraph. Fig. 5a shows positional noise, that is, random values are chosen at

Assignments and examples

The following figures show some of the demonstrations and assignments used in the class (Fig. 8, Fig. 9, Fig. 10, Fig. 11, Fig. 12, Fig. 13, Fig. 14).

Conclusions

The combination of glman and NoiseGraph has been used in our college class to teach GLSL shaders. We have found them to be excellent tools to explain how certain shader parameters work and to let students quickly explore on their own. Because students do not need to write full programs, and because glman creates a user interface automatically from user directives, it is fast and easy to get started, and encourages individual exploration. Because the uniform variables can so readily be

Acknowledgment

The Earth globe image (Fig. 13) was provided by Nick Gebbie. Thanks to Nvidia for their generosity and help in setting up our Computer Graphics Education Lab.

References (7)

  • R. Fernando

    GPU Gems

    (2004)
  • F. Pharr et al.

    GPU Gems 2

    (2005)
  • R. Rost

    OpenGL shading language

    (2006)
There are more references available in the full text version of this article.

Cited by (4)

  • Teaching a modern graphics pipeline using a shader-based software renderer

    2013, Computers and Graphics (Pergamon)
    Citation Excerpt :

    For example, Schweppe and Geigel used the context of theater [14,30] for teaching computer graphics. With the wide availability of programmable graphics hardware, approaches of teaching shaders in computer graphics courses have been increasingly investigated [15–17]. As shaders have become commonly used in graphics programming, a shader-based introductory computer graphics course has recently been proposed [18].

  • Teaching 3D modelling and visualization using VTK

    2008, Computers and Graphics (Pergamon)
  • Application of OpenGL in NC turning simulation

    2012, Advanced Materials Research
  • Tiled projector displays correction for dark scenes in railway simulators

    2011, Proceedings - UKSim 5th European Modelling Symposium on Computer Modelling and Simulation, EMS 2011
View full text