Shaderey
A Beyond3D/ATi DX9 shader competition entry (2003 Sep, some additional tweaks for ShaderX3 during 2004 May); development info
General readme here: readme.html.
Description
Non-shader ingredients:
- A (relatively) high-poly terrain. Note that there's no LOD on it, just culling of chunks. For water reflections, the terrain is rendered with lower detail, though.
Whole terrain is half million triangles, split into chunks for culling. With a small amount of work, GeoMipMapping can be implemented.
- Single shadow map for trees/houses, received by terrain. Terrain samples it 4 times with rotated grid for some anti-aliasing. The shadow map isn't
cast on entire terrain, instead, just to some "nearby viewer" portion.
- Simple water reflections.
- And, of course, simple frustum culling for the objects :)
The flow:
- Render trees/houses into shadow map (1024x1024).
- Render all except lakes into reflection map (256x256). Lower detail for terrain.
- Render everything into two screen-sized rendertargets - one gets final color, another gets world space normals in RGB and eye-space
(kind-of) depth in A. This includes shadows, reflections and atmospheric light scattering for most of the objects (from Hoffman et al.,
SigGraph2002; get it at ATI's devrel site).
If there's no MRT support, or we haven't forced it (see notes in readme.html), then do separate passes to write into color RT and normals/depth
RT. So this is the default (no MRT use).
- Downsample color RT into smaller (512x512) texture ("smallrt").
- Convert smallrt from RGB into HSV space and quantize HSV components. This is done via dependant volume texture lookup.
Distort the HSV image at color boundaries; keep the hue channel undistorted. Convert from HSV back to RGB (another volume texture).
Now we have smaller texture distorted in a funky way :) All this is done in a single pass, see more comments in data/fx/imgBleed.fx
- Detect edges in original image, and apply hatch-like pattern to some places. This operates in image space on normals/depth rendertarget that
was produced earlier. Normals/depth detection is similar to ATI's at SigGraph 2002. Hatching texture gets applied based on dot product of
normal and light direction.
- Now, composite the edges/hatches and smaller-distorted into backbuffer. That's all!
Shaders/effects:
- Use D3DX Effects framework.
- Use HLSL.
- Vertex shaders are 1.1 everywhere (there was no need for 2.0 :))
- Pixel shaders are 2.0 mostly, with some simpler ones being 1.4 or 1.1.
"Biggest" shaders:
- Terrain pixel shader: data/fx/terrain.fx
- RGB->HSV, image distortion and back to RGB pixel shader: data/fx/imgBleed.fx
- Edge detection/hatching pixel shader: data/fx/imgEdgeDetect.fx
- Atmospheric scattering part of most vertex shaders: data/fx/_library.fx
The source
Needed:
- MSVC 6.0 SP5
- DirectX 9.0 SDK, at least Summer 2003 Update.
- boost 1.30.0 libraries (www.boost.org)
Caution: don't take as an example of good design or programming style!
Structure:
- Everything in sourcecode/ is the source -- you can safely delete it if you don't need it.
- VC project/workspace is in sourcecode/shaderey/shaderey.[dsp|dsw]
- Demo code is in sourcecode/shaderey/
- Other "utility" code is in sourcecode/dingus/ [no, not an engine! just a bunch of code :)]