VertexBlend
|
| |
VertexBlend shows how to perform matrix skinning and
bump mapping using DirectX(r) 9 High Level Shading language
and the D3DX Effects framework. Figure 1 shows a screenshot
of the sample application.
|
| |

|
| |
Figure 1 - More detail is added
to the final image as the
shader complexity increases. Effects are in order from Top Left to bottom
right: Per Pixel N dot L, Result of view Just the bump values, Bump mapping with
Specular highlights and a gloss map, Bump mapping with specular highlights +
gloss map + environment mapping.
|
| |
-
A word about the shader files:
The shaders that effect this model are stored in
the files:
- DefaultEffects.fx --
contains the techniques and shaders that perform
per vertex and per pixel lighting on the model.
- common_Functions.fxh -- contains
common routines that are called from the shaders
in DefaultEffects.fx.
- ViewingTangentSpace.fx -- contains
the shaders for viewing the tangent space.
- LightEffects.fx -- contains shaders
for viewing the light source.
- MiscEffects.fx -- contains miscellaneous
shaders. Currently only the menu shaders exist in
this file.
All the cool effects are in DefaultEffects.fx. The
techniques are at the bottom of the file. They
pass in uniform values into
the different shaders. These uniform values tell the compiler that these
parameters are constant for this technique. This allows the compiler to
perform dead code removal and optimize the shaders for us.
Feel free to add new shaders or new techniques. You
can add them without having to recompile the app. You
can write you shaders into DefaultEffects.fx and hit
the "r" key to reload the shader files. If
you add new techniques, you will see them automatically
added into the help menu. |
| |
Matrix Skinning:
Matrix Skinning is the act of animating a vertex
over time given a known set of matrices and a known set of blend weights
assigned to those matrices. The model shown here has 39 bones
and an animation cycle of 13 frames.
Each frame the application re-computes the blending
matrices for each vertex by linearly interpolating between the matrices
needed for the two frames the animation is currently between. So,
if, based on time, the app is asked to render the model as if it were
at frame 9.75 it would blend the matrices for frame 9 and frame 10
in the app before passing these matrices to the vertex shader.
The skinning happens as part of the vertex shader
and is defined in two functions in common_Functions.fxh.:
- SkinPoint(...) -- this
function skins a vertex (float 4) by the four skinning matrices.
- SkinVector( ... ) -- this
function skins a vector (float 3) by the four skinning matrices.
|
| |
|
Bump Mapping:
This application also shows how
to compute tangent space from a models vertex position,
normal, and texture coordinates. The tangent
space is passed into vertex shader as part of the vertex
stream. For more information on the form of tangent
space computation we used, see Game Programming
Gems, 2000, Charles River Media, ISBN-1-58450-049-2.
The vertex shader transforms the
tangent space vectors into world space and passes them
down to the pixel shader.
The pixel shader takes the tangent
space vectors and uses them as a basis to transform
the normal read in from the bump map into world space. This
allows us to perform our N dot L computation in world
space to achieve bump mapping.
|
| |
|
VertexBlend Controls:
-
- Left Drag to rotate object
- Right Drag to translate object in plane of
screen
- Middle Drag to translate object perpendicular
to screen
- [A] - Toggles animation.
- [W] - Toggles viewing wire frame.
- [T] - Toggles viewing tangent space.
- [D] - Dumps a screen shot.
- [R] - Reloads shaders.
- [+/-] - Increases or decreases animation speed.
- [I/M] - Increases or decreases Depth Bias (for
wire frame).
- [O/J] - Increases or decreases Z Slope Scale
(for wire frame).
- Up/Down Arrows - Previous/Next Shader.
- Alt+[ENTER] - Toggles between fullscreen and
windowed modes .
- [TAB] - Next Object.
- [SPACE] - Toggles help menu.
- [ESC] - Quit
|
| |
- Requirements
-
Download
VertexBlendD3D.zip
|
| |