Low Level Shader Demos
These are some low level shaders I wrote
a couple of
ago when programmable GPUs were new(ish) and OpenGL 2.0 wasn't
available. All but one are written in low level assembler rather
than HLSL or GLSlang.
They're simple, but still worthwhile as examples of what being
"programmable" means in terms of being able to do new
and interesting things.
They're also useful as examples of how horrible it was before
high level shading languages became standard! In my day we didn't
use these fancy-dancy compilers. No, we had to hand code our
shaders while walking uphill through the snow ...
Mostly require nVidia FX5200 or better (PixelShader 2 in MS speak)
although some will run on older cards. Written on Linux, but all
using GLUT so should run on Windows as well.
Shader Demo Source Code
Very simple nVidia vertex and fragment shaders. Just
demonstrates low level code fragment and how C code is
written to create and use shaders.
The same, this time implemented in ARB dialect to
demonstrate the differences between the two.
The same program, this time in the high level Cg language.
Also shows difference between Cg matrix tracking and
nVidia/ARB state access: the teapot is not rendered properly
by the Cg vertex shader.
Implementation of standard OpenGL one directional light
with infinite viewer in nVidia. To replace the OpenGL in
your code, one must first understand it.
Also has a 'bomb' shader with infinite loop, just to
satisfy my curiosity. It will lock up your display for
seconds at a time!
Update Dec 2007: The 'bomb' shader no longer works
as a denial of service attack on recent nVidia systems.
Standard OpenGL lighting, this time using ARB vertex shader
assembly instead of nVidia. Shows how much more GL state
info is available to ARB shaders. (No bomb program: ARB
vertex shaders can't branch or loop.)
Simple nVidia vertex program that alters vertex values
within a (moving) bounding box. Shows that vertex progs
work even with other peoples binary libraries.
Same program, this time using ARB vertex shaders. Mostly
demonstrates why you shouldn't try to use ARB for anything
that needs conditionals.
Shows how to implement Phong shading with a fragment
shader program, with a bit of help from the vertex level.
Also has very crude benchmark to show impact of Phong
shading on frame rate.
Vertex shader that creates an underwater style fog effect
with objects fading as they get deeper (Y) as well as the
standard OpenGL fade with distance (Z).
Fragment shader that demonstrates how to modify pixels
within an area defined by window coordinates, not 3D,
and how fragment shaders can cull output pixels.
More complex example using vertex shader to do heightfield
scaling, surface normal, and vertical fogging. Shows the
difference in CPU load between standard OpenGL, using a
vertex buffer object, and using both buffer object and a
shader to do the calculations.
Complex example that shows how a vertex shader can generate
vertices and normals for a height field from the raw data.