Laboration 1

Procedural images on CPU & GPU

We will here program procedural images, first in C, then in GLSL.

Lab material: We start from a very simple example program. It will render a set of concentric circles. The demo includes code both for generating this image from C and GLSL. The colorization is different fo the two cases, but is otherwise the same.


OR Stefans old lab modified by me


which includes code for Perlin noise, simplex noise and cellular noise. HYBRID OF THESE CONSIDERED.

My code generally uses a code package that I made for other courses. The package is written in C, but can be used from C++. It includes a shader loader, a texture loader for TGA files, an algebra package, the OBJ loader “LittleObjLoader”, and the window/event interface MicroGlut. The package supports Windows, Linux and MacOSX.

We have several additional examples that you can use as inspiration:

• Ingemar’s Psychedelic Teapot: Loads the Utah Teapot, renders a sin-based animated procedural texture over it.

• Stefan’s GLSL Primer: Based on Stefan’s old demo, switched some code to what I will be using elsewhere, but everything important (the shaders) are the same. Loads a sphere, renders with using the alpha channel for separating the texture, plus deforms the sphere with a sin wave.

• 2D Plasma. This is a port of a pretty impressive demo from It uses mixed sin functions to produce a complex animation.

1. Test the lab environment. Compile and run lab1.c. Change the existing pattern.

Colors, frequency, position…

2. Load texture and modify it

Random numbers -> noise ("irrational random numbers”?)

3. Brick-like pattern or other pattern

4. Use a noise function to produce something (what?)

BUT we should include noise, snoise and cellular!

5. Move to GLSL!

6. Animated texture in GLSL.

© Ingemar Ragnemalm 2021