Test program and files for Modified Noise Marc Olano, UMBC 2005 See also, Marc Olano, "Modified Noise for Evaluation on Graphics Hardware", Graphics Hardware 2005, Eurographics/ACM SIGGRAPH, July 2005. This package contains noise shaders, noise textures, and a (far from production quality) test program. The program uses OpenGL and GLUT, so in theory should be relatively portable. However, I offer no guarantees that it will work on any platform different from the one where I developed it (Mac OS X, with extra non-standard symlinks for the OpenGL and GLUT headers as described in the Makefile). If you want to actually use my test code, you're on your own. On the other hand, the shaders and texture should be quite portable and I welcome comments or suggestions to improve them. ********************************************************************** * Program: The program is a quick and dirty test program, evolved from other earlier quick and dirty test programs. As such, it's not that well written and does almost no error checking. It doesn't like it if you point it at shader or texture files that don't exist, though it's relatively resilient to shader errors. It periodically reloads the shader files, so you can leave it running while you debug. Note that it does handle window resizing, to more easily make it big or tuck it into a corner somewhere. Usage: noise [-v file.vs] [-f file.fs] [- file.png] -v file loads an OpenGL low-level vertex program -f file loads an OpenGL low-level fragment program -0 file loads a PNG format image into texture unit 0 -1 file loads a PNG format image into texture unit 1 - file loads a PNG format image into texture unit n Some sample commands in the run-* files Keys: models t switch to teapot model (default) s switch to sphere model d switch to donut model (a torus, but t was taken) p switch to plane model (a quad) shaders v/f force reload of shaders shader control these control the object 'color' -- I use it to control arbitrary aspects of the shaders for development. Each color channel has two keys, one to decrement that color channel value (clamped to 0), and one to increment the color channel value (clamped to 1). Multiple presses increase the speed of change. 1/2 decrement/increment red (used in my shaders for 4D noise w) 3/4 dec/inc green (used in my shaders for texture scale) 5/6 dec/inc blue (used in noise2 shader to select texture/computed) 7/8 dec/inc alpha (not used in current shaders) 9 reset RGBA to 0 0 stop changing, but don't reset color other i dump current image to a file named 'dump.png' ESC quit Mouse Motion: note that Mac GLUT automatically adds an application preference menu to set a mapping between a one-button mouse and left/middle/right. My setting (possibly the default) is middle=option-drag; right=control-drag left button rotate object middle button zoom in (changes perspective position) right button translate object Source: Makefile Build info (for Mac) noise.h/noise.cc Main program, GL & GLUT init, command line parsing pngtex.h/pngtex.cc Load a texture unit from a png file, save the current window (or part thereof) to a png file view.h/view.cc Adjust viewport & projection for window size changes motion.h/motion.cc Handle mouse motion (as defined above) key.h/key.cc Handle keys pressed (as defined above) draw.h/draw.cc Load shaders; adjust object color according to keys; Draw all objects ********************************************************************** * Shaders: The test program takes OpenGL low-level vertex and fragment programs, so most of the shading code is in the form of hand-coded low-level shaders. * n3v.glsl, n3f.glsl OK, so there is one 3D noise OpenGL high-level shader. This high-level code is probably more easily understood than the low-level versions, but so far I've only ported the 2D texture-based 3D noise. As of this writing, Mac OpenGL shader support is "lacking". They have a software renderer you can select that handles them, though the sample code that uses it doesn't use GLUT and figuring out if there's a GLUT incantation to select it didn't seem worth the effort for what, in the end, is a software renderer. I've used ATI's ashlicc to compile these shaders into low-level vertex and fragment shaders, then used the noise test app to run them. Like low-level shaders, if you make a change then compile, the test app will load the new shaders. Ashlicc will split complex shaders, into multiple segments, but the noise app can only deal with one. The ashlicc command I used (in the shaders directory): ashlicc -n GLSL -s n3v.glsl -p vertex -s n3f.glsl -p fragment -c GL With my version, the resulting code file names are ashli_0.vp and ashli_0.fp. To use them (back in the main directory): ./noise -v shaders/ashli_0.vp -f shaders/ashli_0.fp -0 textures/pzw.png * tex.vs, noise2.fs ** sample command line in run-noise2 Sample code 2D noise, both computed and from a texture. Use nzw.png as the texture. Code for both is in noise2.fs, but with each clearly indicated in the comments. To see the difference, zoom close to the noise texture and look for changes in the interpolation (due to linear texture reconstruction vs computed noise) The 'red' control isn't used. The 'green' control (3/4 keys) changes the noise scale (where only the starting 'green=0' value will wrap correctly across patches). The 'blue' control (5/6 keys) switches between texture-based and computed noise based. The blue controls are continuous, not just a binary switch, which makes it a bit quirky. It starts in texture mode when 'blue=0', and switches to computed for 'blue>.1'. * tex4d.vs, noise3.fs, noise4.fs ** sample command lines in run-noise3 and run-noise4 Sample code for 3D and 4D noise computed using a 2D texture. Use nzw.png as the texture. Both 3D and 4D noise share the same vertex shader. The 'red' control (1/2 keys) changes the 4D noise w coordinate (e.g. so you see changing slices of 3D noise). The 'green' control (3/4 keys) changes the noise scale. * turb3.vs, turb3.fs ** sample command line in run-turb3 Sample 4-octave 3D turbulence shader. 3D noise computation is rearranged slightly to take advantage of the ability to do many of the computations across two or four octaves at a time. Doesn't use any of the key/color controls. Uses texture nzw.png. * wood.vs, wood.fs; marble.vs, marble.fs ** sample command lines in run-wood and run-marble Sample very simple wood and marble shaders using 4-octave 3D turbulence. Use texture nzw.png. The 'red' control (1/2 keys) changes the amount of turbulence (starts at 0). The 'green' control (3/4) changes the wood ring scaling for the wood shader. * texgen.vs, texgen.fs ** sample command line in run-texgen Generates nzw.png if you don't resize the window and just dump the resulting image into a png file with the 'i' key. This is the only shader that's too big to run on my PowerBook (according to Mac System Profiler an ATI Mobility Radeon 9700). It overruns the 64(ish) instruction limit. The driver is actually smart enough to eliminate dead instructions if you switch to one of the alternate MAD or MOV instructions at the bottom of texgen.fs, so when I'm not sitting at a spiffier machine, I'll just generate the channels separately. ********************************************************************** * Textures All are png files. While the noise test program doesn't include any png error checking (sorry), it can create 1/2/3 or 4 channel textures from 1/2/3 or 4 channel images respectively. * n.png Grayscale 2D noise texture * z.png Grayscale 2D texture containing 3+D noise z gradient term as a function of x & y * w.png Grayscale 2D texture containing 4+D noise w gradient term as a function of x & y * nzw.png 2D texture merging the above (good for 1D-4D noise). n.png in red, z.png in green, and w.png in blue