Page 6: More Procedural Textures

CS559 Spring 2021 Sample Solution - Workbook 11

Written by CS559 course staff

You can try out the example solutions here. The interesting code is on page 6, page 7 and page 9.

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 shaders/11-06-01.vs and shaders/11-06-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 11-06-01.js (11-06-01.html)). You shouldn’t have to modify the JavaScript file, but you can if you want to.

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.

Exercise: Some Other Pattern

This time, you pick what pattern/texture you want to make! Something more complicated than a checkerboard. Try to make wood grain, or plaid, or some wallpaper pattern - as long as its more complicated than a checkerboard. You can look at various resources to get ideas. For example, OpenGL Shading Language (3e) Chapter 6 gives a simple example of a brick texture, and many of the online tools provide galleries of cool examples. See Page  10  (Shader Tools and Examples).

Transferring a shader from one of these websites to our framework can be tricky. Page  10  (Shader Tools and Examples) will discuss it (and ask you to do it). For this page, please write the shader yourself. But, be sure to give attribution (in the text file below) if your shader is based on some example (even if you are just inspired by something). For this exercise, do not use image-based textures or animation.

Again, we’ve given you files to get started. If you need uniform variables, you’ll need to make them yourself. The files are shaders/11-06-02.vs and shaders/11-06-02.fs as well as 11-06-02.js (11-06-02.html). Once you’ve implemented the shader, explain your work in 11-06-02.txt

Summary: Procedural Textures

Procedural textures are one of the cooler things we can do with shaders. Let’s look at a detail of using them on Next: Aliasing .

Page 6 Rubric (18 points total)
Points (18):
Box 11-06-01
7 pt
looks like a checkerboard
Box 11-06-01
3 pt
responds to slider
Box 11-06-02
8 pt
some other pattern