Low Level Shader Demos
These are some low level shaders I wrote a couple of
many years
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.
Somewhat to my surprise, they still compile and run on Linux in
2017! 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 ...
Written in C on Linux, but all use GLUT so should run on Windows as well.
Shader Demo Source Code
Contents:
- 1-nv-tiny/
Very simple nVidia vertex and fragment shaders. Just
demonstrates low level code fragment and how C code is
written to create and use shaders.
- 1-arb-tiny/
The same, this time implemented in ARB dialect to
demonstrate the differences between the two.
- 1-cg-tiny/
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.
- 2-nv-light/
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.
- 2-arb-light/
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.)
- 3-nv-reshape/
Simple nVidia vertex program that alters vertex values
within a (moving) bounding box. Shows that vertex progs
work even with other peoples binary libraries.
- 3-arb-reshape/
Same program, this time using ARB vertex shaders. Mostly
demonstrates why you shouldn't try to use ARB for anything
that needs conditionals.
- 4-arb-phong/
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.
- 5-arb-fog/
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).
- 6-arb-lense/
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.
- 7-arb-height/
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.
- 8-arb-normals/
Complex example that shows how a vertex shader can generate
vertices and normals for a height field from the raw data.