Multi-pass texturing in OpenGL

James Bowman, Silicon Graphics Inc

Pass 1

Introduction

This short example demonstrates how you can use a combination of OpenGL blend modes and multiple passes to achieve some quite sophisticated texturing effects. It also shows how you can use multi-pass rendering to get more from a very small texture. The example uses a single channel 16 x 16 texture, so the total texture requirement is just 256 bytes, or (256 + 64 + 16 + 4 + 1) = 341 bytes with all mip-maps. Its speed depends on the machine you're using: if you've got the fill-rate, it will run fast.

The code also demonstrates:

Look at source.

Download sources (if you want to compile it, you'll also need GLUT).

Download Irix executable.

Download Windows 95/Windows NT executable, linked with Microsoft's excellent OpenGL.

How it works

Here's the process visually, using the default settings of 3 noise octaves and full lighting.
Pass 1 Pass 1: just draw the random texture at full scale, with brightness 0.5.
plus Pass 4 equals Pass 2 Pass 2: add the same texture at 2.0 scale, randomly rotated, with brightness 0.25.
plus Pass 4 equals Pass 3 Pass 3: add the same texture at 4.0 scale, randomly rotated, with brightness 0.125. The texturing stage is over.
plus Pass 4 equals Pass 4 Pass 4: Disable texturing, enable lighting, modulate the texture by the diffuse lighting
plus Pass 4 equals Pass 4 Pass 5: Enable dither, add specular highlights, and we're done!

User interface

Drag with the left mouse button to spin the cube; pressing shift and dragging up or down with the mouse lets you zoom in or out. The right button gives you a menu for switching the two lights on and off, and for going full-screen.

Various keys do interesting things:
  0-8   
set the number of noise 'octaves' - i.e. how many layers of texture to apply
   D    
drift - slides the texture slowly across the polygons
   F    
toggles trilinear filtering
   L    
toggles lighting (both diffuse and specular)
   O    
toggles the object between a cube and a torus
   S    
toggles specular highlights
   Z    
toggles use of depth buffer

Further reading

If you're interested in procedural texturing, you should check out Texturing and Modeling - A Procedural Approach Ed. David S. Ebert, AP Professional, 1994. ISBN 0-12-228760-6.

Possible extensions, applications

In roughly ascending order of ambitiousness: