Page 28: GLSL Exercises 1
Spring 2026 Sample Solution
On the next 2 pages, there are 5 exercises to practice GLSL programming.
For each, you should write the shaders in GLSL by modifying the fs and vs files.
So you can plan ahead (you have some choices), here are the exercises:
- Checkerboard (standard) - make a checkerboard pattern.
- Anti-Aliased Checkerboard (advanced) - make a checkerboard, but implement anti-aliasing.
- Some other pattern (standard/creative) - make some other pattern.
- Lighting and procedural (standard) - combine some simple lighting and a procedural texture (it’s OK if it’s one of the above).
- Student’s choice (standard/advanced/creative) - you decide what you want to make!
Note: you may use all the tricks you’ve learned about shaders. You can load images. You can use noise (if you use noise, you will need to put the noise function into your shader program). You can change the normals or positions. You shouldn’t make the same things I made (unless you do it differently).
Exercise: Checkerboard
It’s your turn to make a procedural texture. We’ll start with something simple: make a checkerboard pattern. I’ve started things for you in the files 06-28-01.vs and 06-28-01.fs . I’ve also done the JavaScript part for you, including a slider for the number of checks over the 0-1 range (see 06-28-01.js (06-28-01.html)). You shouldn’t have to modify the JavaScript file, but you can if you want to.
view - look at the box and experiment with it
examine - look at the code for the box
edit - change the box's content
rubric - several steps are suggested in the rubric page - form elements on page in rubric
06-28-01.html 06-28-01.js
| Kind
Kind of rubric items: standard - expected from all students advanced - used to get a better grade creative - an opportunity to do something creative levels - rubric item graded by selected achievement level optional - not required, but encouraged |
Description | |
| standard | Checkerboard | |
| standard | Respond to Slider |
A hint: on the next page, you will be asked to enhance your checkerboard. If you write your code to use the step and mix functions to compute the color (rather than using an if statement), the next page will be easier.
You should make this respond correctly to the checks uniform variable. Look at the dots for inspiration. The “number of checks” might mean either the number of squares (along an edge), or the number of dark/light pairs along an edge - whichever way you interpret it, it will be OK.
This should not have anti-aliasing, so you can compare with the next exercise.
Exercise: Anti-Aliased Checkerboard
This is a harder exercise. Make a version of your checkerboard shader that is anti-aliased!
You can figure out how to do it from the dots example. A hint: make a non-anti-aliased checkerboard using step and mix to switch between the colors. Then switching to smoothstep will be easy.
Warning: even with the hints, this can be a harder exercise. That’s why it is advanced.
You should not load an image and use a texture map - which is easy to anti-alias with mip-map filtering. For this exercise, write a procedural shader.
Note: it is OK if you make blurry edges (using a constant value instead of fwidth).
view - look at the box and experiment with it
examine - look at the code for the box
edit - change the box's content
rubric - several steps are suggested in the rubric page - form elements on page in rubric
06-28-02.html 06-28-02.js
| Kind
Kind of rubric items: standard - expected from all students advanced - used to get a better grade creative - an opportunity to do something creative levels - rubric item graded by selected achievement level optional - not required, but encouraged |
Description | |
| advanced | Anti-Aliased Checkerboard |
Exercise: Some Other Pattern
This time, you pick what pattern/texture you want to make! Something more complicated than a checkerboard. Try to make a brick pattern, plaid, or some wallpaper pattern - as long as it is more complicated than a checkerboard. You can look at various resources to get ideas.
Transferring a shader from some other website can be very tricky. It’s OK to be inspired by something else, but try to write this one yourself.
Again, we’ve given you files to get started. If you need uniform variables, you’ll need to make them yourself. The files are 06-28-03.vs and 06-28-03.fs as well as 06-28-03.js (06-28-03.html). Once you’ve implemented the shader, explain your work in the HTML file.
view - look at the box and experiment with it
examine - look at the code for the box
edit - change the box's content
rubric - several steps are suggested in the rubric page - form elements on page in rubric
06-28-03.html 06-28-03.js
| Kind
Kind of rubric items: standard - expected from all students advanced - used to get a better grade creative - an opportunity to do something creative levels - rubric item graded by selected achievement level optional - not required, but encouraged |
Description | |
| standard | some (new) pattern | |
| advanced | interesting pattern | |
| creative | exceptional pattern |
More on the next page…
Some more shader exercises on Next: Page 29 - GLSL Exercises 2.