3rd Party Effects

Introduction

This document describes the additional effects submitted to NVIDIA as part of the shader competition.  It includes details on how to run and use the effects, compiled from information supplied by the original developers.  If the developers have used extra commands to the standard Effects Browser controls, they are documented here.  All information on the shaders and their properties was provided by the creator of the effect, and only minor changes have been made to the text for readability.

All the effects live under the 'effects\xtra3rdparty' directory, and are designed to be built and run from there.

For information on how to build the effects, or any other NVEffectsBrowser issues, please consult the NVEffectsExplained document in the effects browser's root directory.

 

1. Bezier Patch

Creator:
Francesco Banterle

Description:
This effect shows how to generate a bezier patch inside the vertex shader.

Special Controls:
Up: Zoom In.
Down: Zoom Out.
b/B: Create new random control point.
+: Increase level detail of the patch.
-: Decrease level detail of the patch.


2. Bump Refraction

Creator:
Tomohide Kano

Description:
Does per-pixel refraction and reflection, with options to control refractive index of the material to simulate objects made from glass, diamond, etc..


3. Vortex

Creator:
Jim Bumgardner

Description:
This vertex shader produces a twisting vortex effect by remapping the texture coordinates. As a shortcut, the texture coordinates (tu, tv) are pre-computed as polar coordinates.  The vertex shader adds a twist rotation to the angular coordinate and then converts them back to Cartesian coordinates.  Since the center of the vortex contains the most detail, the mesh that is used has a correspondingly higher level of detail in the center.


4. Fresnel Refract and Reflect

Creator:
Kristian Olivero

Description:
This vertex shader implements a Fresnel reflection effect. Objects tend to be more reflective when the light is incident at a shallow angle. Good examples of Fresnel are a highway, which is non-reflective when looked at directly, but mirror-like at a distance, or a piece of glass, which you can look through with almost no reflection viewed directly, but is a perfect mirror when held at an angle. In the menu, alternate between the uniformly
blended reflect and refract, and the fresnel version, to see what a big difference this effect makes.

This shader generates the camera space reflection coordinates in T0, and a reasonable approximation of refraction coordinates in T1. The approximation for refraction is set up by shortening the vertex normal and passing it through the standard reflection calculation.

The dot product between the vector from the eye to the vertex, and the vertex normal vector is calculated and negated into the alpha channel of the diffuse vertex color. This is used to blend between the reflection and refraction stages for the Fresnel reflection effect.

Modified From Original NVIDIA source to include Fresnel Reflections, and to easily switch between different reflection and refraction combinations to illustrate differences.


5. Fur

Creator:
Sebastien St-Laurent

Description:
This effect is a Fur rendering shader. It simulates straight fur and by rendering multiple hulls around an object to create a 3D fur effect. A vertex shader is used in this renderer to facilitate the rendering of the hulls without having to maninupate the original mesh.

Special Controls:
M - Increases the number of hulls applied for fur.
L - Reduces the number of hulls applied for fur.
LEFT/RIGHT - Translates along X axis.
PGUP/PGDOWN - Translates along Y axis.
UP/DOWN - Translates along Z axis (equivalent to zooming).
+/- - Zoom in/out.


6. Grass

Creator:
Sebastien St-Laurent

Description:
This effect is a grass rendering shader. It simulates straight fur and by rendering multiple hulls around an object to create a 3D grass effect. A vertex shader is used in this renderer to facilitate the rendering of the hulls without having to manipulate the original mesh.

Special Controls:
M - Increases the number of hulls applied for grass.
L - Reduces the number of hulls applied for grass.
LEFT/RIGHT - Translates along X axis.
PGUP/PGDOWN - Translates along Y axis.
UP/DOWN - Translates along Z axis (equivalent to zooming).
+/- - Zoom in/out.


7. Height Field

Creator:
Steffen Bendel

Description:
This effect demonstrates how you can create a (massive parallel) stack engine in the pixel shader.  This is only possible if you can use the last computed value as input for the next pixel. Generally this is not implemented in current hardware, but you can use the render target as a source for the next step. The reference device can process a bitmap as source and render target at one time. So you can render current line X and use line X-1 as source.  To avoid problems with hardware rendering, this implementation uses 2 switching line-textures for 'line X' and 'line X-1'. So target and source texture are different and the result must be copied to the real target. This is a little bit slower than necessary, because there are a lot of state changes and a line is rendered by using 2 triangles instead of a real line primitive. Because the stack element has only a size of 4*8 bits, the demo uses only the red component for color, the alpha is used for current high and blue is used to hold the pointer to the next stack element.  Green is not explicitly used, but must be 1.0 for texture-lookup operation.

In the first pass, the height-map is rendered down (front) to top (back). The height-component (alpha) is scaled and added to the current line-height.  The next pointer is the last line.  If this is higher than the last, it is the result for the operation, else the last line is used.  After this pass, we have a list of stack top-down sorted elements (invisible ones are rejected), with the first being the stack pointer of the top line.  In the next pass, this list is drawn. The current stack element is used, until the render-height is lower than the height of this element, then the next is used.  This is retrieved using texture-lookup (the last-line stack pointer is an index into the lookup table created in the last first pass).

The effect is limited by color-resolution. The stack-pointer has only 8 bits, so the target picture has maximum 256 resolved lines. The x-resolution is maybe better, because an iterated value is used as coordinate for the lookup. This program is not well optimized, and maybe the visual quality can be better (higher precision by another implementation?, perspective view, etc..), but it does demonstrate that some complex stack-based operations are possible by using a pixel shader.


8. Matrix TexGen

Creator:
Kristian Olivero

Description:
This is the vertex shader implementation of the traditional shader, which allows you to rotate, scale, and translate, texture coordinates.
Texture coordinate transformation matrix is set up, then necessary components are passed in the vertex shader constants. Any number of effects beyond the given example are possible with the shader by generating and multiplying the  correct component matrixes and passing in the composite. This is a nice speedy effect, with only 4 instructions more than the simple quad shader dealing with the texture coordinate transformation.

A 4x4 texture coordinate transformation matrix is used to utilize D3DX helper functions easily, and to facilitate easy transition to a full 3D transformation for 3D textures. Matrix is transposed so only 2 vectors can be easily passed in and used, one to transform each texture coordinate.


9. Rain

Creator:
Sebastien St-Laurent

Description:
This renderer uses an accelerated vertex shader program to render a "rain splash" effect onto a mesh. The shader takes some time indexes as input and a rain direction vector.  From this information, the water splash sprite is scaled and alpha-blended properly for create an animating rain-splash effect.  In this sample, a separate vertex buffer is calculated (based on some random function and some triangle surface area calculation).  But if a mesh is sufficiently dense and non-uniform, the base mesh of a model could be used as the source of rain-splashes.


10. Bezier Spline

Creator:
Lee Baldwin

Description:
This shader does the bi-cubic Bezier spline computations, based on the 4 control points packed into the constant registers.  The input vertex stream consists of a single float, which are the iterated delta values, from 0.0 to 1.0, in which to interpolate the spline. The number of vertices is equal to the number of segments to tessellate, and the primitive is drawn as a line list.

Special Controls:
The + and - keys increase or decrease the number of segments, meaning the vertex buffer gets rebuilt with a new set of deltas.
You can also toggle some simple animation on the y-axis of the in/out vectors in the bezier basis.


11. Spyrorama

Creator:
Jim Bumgardner

Description:
The vertex texture coordinates (tu, tv) are precomputed during initialization as polar coordinates. These are used to generate a groovy psychadelic pattern.  Suitable for wild parties, and gas giant planets.

The color formula for each rgb component i is (range -1 to 1):

cos(log2(d)*x.i + a*y.i + z.i)*cos(a*w.i)

in which:

d is the distance polar coordinate (from v2.x)
a is the angle polar coordinate (from v2.y)
x is shader constant 10 (aka "twist")
- values from 0-10 are good. 0 = no twist
y is shader constant 11 (aka "rotate-direction")
- these should be integers - typically -1 or 1
z is shader constant 12 (aka "rotate phase")
- used to put r,g,b out of phase - values from 0-2pi
w is shader constant 13 (aka "pleats" (angular cos frequency))
- these should be integers - values from 0-6 are good

Shader constants x,y,z correspond to red,green,blue, respectively.
 


12. Twister

Creator:
Alain Bellec

Description:
This effect consists of a twisting which moves along the x-axis or the y-axis of the world coordinates system.
Sine and cosine are calculated by the vertex shader to create the matrix of rotation to be applied to every vertex.
The calculation of the angle of rotation makes intervene at the same moment the time (a simple counter which believes and which decreases) as well as the position x (or y) of the current vertex of the object.  The relation between the position x (or y) of the vertex and the angle depends on a "step" value. In other words, the more the "step" is small and the more the rotation is stressed for the same distance.  It is possible to make vary the maximum value of the loop, the "step" value, the offset of the start point as well as the "speed" of the effect.  When an unspecified value is modified, it is often necessary to also modify other values. For example the duration of the loop must be adapted to the new value of speed or "step".
The calculation of the lighting uses the same matrix of rotation.

This effect is based on a simple use of the sines and cosines and it is easy to create other effects with a small modification of the code of the vertex shader.
Thus " Twister.cpp " is reused to carry out the effects " Sine ", " Scaling " and " Manta ".

Special Controls:
+ or - to increase or decrease the "Step " of the effect.
(ALT gr +) or (ALT gr -) to increase or decrease the time of the loop
PageUp or PageDown keys to increase or decrease the speed of the effect (only 5 values)
Left Arrow key to decrease the offset of the start point
Right Arrow key to increase the offset of the start point


13. Flying Worlds

Creator:
Steffen Bendel

Description:
This effect demonstrates the possibility of emulating real geometry by using pixel shading. A billboard object is used to draw an illuminated sphere, that can viewed in all directions. This is similar to the principle of reflected bump-mapping. But here the normal-map is more macroscopic (because there is no basic geometry) and no reflection is calculated.

For this effect we need a normal-map and cube map texture.  The processing is here separated in two steps: lighting/border culling and texturing.

1. Pass:
Vertex Shader:
-transformation for billboard object
-calculate the intensity-scaled light-vector in eye-space

PixelShader:
- get normal-vector by texture
- calculate dp3 with light-vector for brightness
(more than one light should be not problem here)
- add ambient color to get result brightness
- use normal map alpha to clip the border of the sphere

Blending:
-alpha>=0.5 compare to clip the non-sphere-parts
(the normal map has a smooth alpha-gradient to get after
texture interpolation a 0.5-alpha-contour that is really
round.)

2. Pass:
Vertex Shader:
-transformation for billboard object
-creating the transformation matrix for the cube map lookup

PixelShader:
- get normal-vector by texture
- transform vector by matrix
- look in cube map to get the result color

Blending:
-multiply the result and the backbuffer color
-use z-equal compare to write only the sphere


14. Shinning Flare

Creator:
Jarno Heikkinen

Description:
This is a quickie for the NVidia shader competition. Rotate the flare to change the orientation.  Displays a texture mapped triangle fan that is radially distorted. Vertex shader is used for interpolation. Radial distortion and flare gradients are loaded from files.


15. Pencil Sketch

Creator:
David E. Tin Nyo

Description:
This shader effect was designed to simulate a hand drawn pencil sketch. Shaded areas of the 3D model appear to have a crosshatch pattern drawn on them. These lines are in screen-space and are not affected by the rotation of the camera or object, to simulate the way a real human would render a pencil drawing.

The shader is implemented by modulating pre-drawn 2D horizontal and vertical line maps with 1D grayscale ramps. The Vertex Shader for this plugin is used to scale the texture coordinates of the 2D bitmaps relative to the Z distance, which keeps the texture size constant in relation to the screen coordinates.

The vertex shader also computes the dot product of the surface normal and light direction and uses this as the texture coordinate of the grayscale texture, creating a transition from light to dark just like the toon texture.

A Pixel Shader is used to modulate the greyscale ramp with the 2D sketch texture, creating a sketch texture that appears white (no lines) in the direction of the light, but appears more distinct (darker lines) in areas of shade. The pixel shader is necessary because we need to combine the inverse of the textures, since the sketch textures are drawn as black lines on white background.  Additional interest is added by using two light sources and separate textures for horizontal and vertical lines. This creates areas of the drawing where the hatch lines "separate" from each other, adding to the authenticity of the hand drawn look.

The mouse can be used to rotate, pan, and zoom the view as with the other NVEffects. F1 or H can be used to view the help for the keyboard/mouse commands. The Pencil Sketch menu (or right-click in the view) allows the selection of three fixed light positions. The first, default, setting places the lights to the upper right, but slightly displaced from each other. The second setting places one light.

The crosshatch textures can be modified to give the shader a wide range of sketch styles. Also, since the greyscale texture is treated independently for each light, different textures can be supplied for different shading responses from each hatch texture.  Rotating the hatch textures using the Vertex Shader might provide some more interesting hatch behavior. For example, rotating the texture coordinates depending on the angle between the surface normal and the light.

This shader should have an option to automatically rotate the lights, similar to some of the samples (eg. the point-light sample), since there are a wide range of effects with varying light angles.


16. Cook-Torrance lighting

Creator:
Eric Duhon

Description:
My primary goal for this effect was the accurate rendering of metallic surfaces.  The Cook and Torrance lighting model was designed for just such a purpose. All of the real-time hardware implementations I have come across for bdrf lighting models all seem to rely on some form of pre-computation. This has many draw backs, namely the accuracy of pre-computation is limited by the size of the lut you create, and a different lut texture has to be generated for every type of material you wish to have in your program. However there is no question that these techniques are very fast.  Vertex shaders, however, allow for enough computational power that the cook and Torrance lighting model could be calculated real-time. This allows the programmer to change the material by just changing a few numbers in constant registers. The accuracy of the shader is not nearly as limited as a lut. Only the precision of the shader registers limits accuracy. There is no need with this shader to pre-calculate anything. The first part of my effect is this dynamic cook and Torrance vertex shader.  The second problem with most attempts at rendering metals is secondary reflections.  Usually an ambient term is added to the lighting model to approximate secondary reflections.  However, while an ambient term works fairly well for diffuse secondary reflections it can not accurately represent specular secondary reflections. Adding a cubemap to represent specular secondary reflections to an ambient term to represent diffuse secondary reflections provide a fairly good approximation. However this approach tends to give to much of a mirror appearance to the material.  For this effect I used a variation of the basic cubemap. The cubemap is treated as a light source and then inputted into the Torrance and cook lighting model to come upwith a final value for the specular secondary reflection. This gives the cubemap more of the color of the material at high angles of incidence and more of the color of the light source (cubemap) at low angles of incidence. This method also works extremely well for dull materials.  For dull materials, when looking at them straight on, the cubemap is barely visible, but at low angles of incidence the cubemap becomes more visible.  A good example of this type of behavior in the real world is semi-polished floors. If you look straight down at them you will not see much of a reflection, it is only when looking further away from you that you begin to see reflections in the floor. Traditional cubemaps don't exhibit this behavior. The Torrance and Cook cubemap makes up the second part of my effect.  The effect contains both a phong implementation and the  Torrance and Cook implementations for comparison. You can also compare the primary lighting models and secondary (i.e. cubemap) lighting models separately.

Effect options described
The first group of options allows you to select the lighting model you wish to use.
It defaults to Torrance and Cook lighting plus Torrance and Cook cubemap, which is the complete
shader. The other lighting models are for comparison. They are described below.

Phong Lighting:
primary diffuse light: Standard phong diffuse Lighting
primary specular light: Standard phong specular lighting
secondary diffuse light: Standard phong ambient term
secondary specular light: none

Torrance and Cook Lgihting:
primary diffuse light: Standard phong diffuse Lighting
primary specular light: Torrance and Cook specular lighting
secondary diffuse light: Standard phong ambient term
secondary specular light: none

Phong Cubemap:
primary diffuse light: none
primary specular light: none
secondary diffuse light: none
secondary specular light: standard cubemap

Torrance and Cook Cubemap:
primary diffuse light: none
primary specular light: none
secondary diffuse light: none
secondary specular light: Torrance and Cook cubemap

Phong Lgihting:
primary diffuse light: Standard phong diffuse Lighting
primary specular light: Standard phong specular lighting
secondary diffuse light: Standard phong ambient term
secondary specular light: standard cubemap

Torrance and Cook Lighting:
primary diffuse light: Standard phong diffuse Lighting
primary specular light: Torrance and Cook specular lighting
secondary diffuse light: Standard phong ambient term
secondary specular light: Torrance and Cook cubemap

The second set of options is used for choosing the type of material you wish to view
Shiny Gold (default): This represents highly polished gold
Dull Gold: This represents a duller gold than the previous
Dull blue material: This represents no particular material it is used to view the shaders
effectiveness at rendering dull materials.
Silver: Just another cool shiny material to look at.
Mirror: An example of a mirror surface rendered using the shader.

The third set of options allows you to control the brightness of the 2 lights. There meanings
are self explanatory.

The fourth option is to pause the motions of the 2 lights around the teapot.


Mathematical Theory for effect
Below are the mathematical formulas used in the shader. dot means the 3 component dot product
of 2 vectors.

Standard Phong ambient term:
A = Ka * Dc where
A = final color
Ka = amount of secondary diffuse light (ie from material properties)
Dc = Diffuse color of material

Standard Phong Diffuse Lighting:
D = Il * (Kd * (N dot L) * Dc) where
D = final color
Il = light intensity
Kd = amount of primary diffuse light
DC = diffuse color
N = normal vector
L = Light vector

Standard Phong Specular Lighting:
S = Il * (Ks * (N dot H)^n) where
S = final color
Il = Light intensity
Ks = amount of primary specular light
N = Normal Vector
H = Halfway Vector
n = Specular power

Standard Cubemap:
Start with previous phong specular equation S = Ks * (N dot H)^n
since the light vector is just the view vector reflected around the normal
vector in a cube map, the halfway vector by definition is equal to the normal
vector in a cube map so the equation reduces to:
S = Ks * Il where
S = final color
Ks = amount of secondary specular light
Il = Light intensity and color sampled from the cubemap

Cook and Torrance lighting
The original Cook and Torrance equation is, except for F which is from Schlick
S = dw * Ks * ((F * D * G)/(pi * (N dot V)) where
D = 1/(4 * m^2 * (N dot H)^4) * e^(-((tan(arccos(N dot H))^2) / m^2))
G = min(1,Gm,Gs)
Gm = (2 * (N dot H) * (N dot V)) / (V dot H)
Gs = (2 * (N dot H) * (N dot L)) / (V dot H)
F = F0 + (1-(N dot V)) * (1 - F0) from Schlick

this is not very practical so its best to rearrange and simplify the equation so it works better with
vertex shaders. All transcendentals have been removed exept the exponent in the equation below.

S = (B * F * D * G) / (N dot V)
B = (dw * ks) / (2 * m^2 * pi) can be calculated on a per object basis
D = (e^((1/m^2) * (1-(1/(N dot H)^2))) / (N dot H)^4
G = min(0.5,Gm,Gs)
Gm = ((N dot H) * (N dot V)) / (V dot H)
Gs = ((N dot H) * (N dot L)) / (V dot H)
F = F0 + (1-(N dot V))^5 * (1 - F0) from Schlick
N = Normal Vector
H = Halfway Vector
V = View vector
L = Light vector
m = Reflectivity
dw = .0001
Ks = amount of primary specular light
F0 = fresnel coefficient at 0 degrees angle of incidence

Cook and Torrance Cubemap:
Start with previous Cook and Torrance specular equation
since the light vector is just the view vector reflected around the normal
vector in a cube map, the halfway vector by definition is equal to the normal
vector in a cube map and N dot V is equal to N dot L so the equation reduces to:

S = (B * F) / (N dot V)
B = (dw * ks) / (4 * m^2 * pi) can be calculated on a per object basis
F = F0 + (1-(N dot V))^5 * (1 - F0) from Schlick
N = Normal Vector
V = View vector
m = Reflectivity
dw = .0001
Ks = amount of secondary specular light
F0 = fresnel coefficient at 0 degrees angle of incidence

References
Phong B. (1975) Illumination for computer-generated pictures. COMM. ACM, 18 (6), 311-17
Cook R.L. and Torrance K. E. (1982). A reflectance model for computer graphics. COMPUTER GRAPHICS, 15 (3), 307-16
Watt A. (2000) 3D Computer Graphics.


17. Hair

Creator:
Steffen Toksvig

Description:
This vertex shader takes a vertex stream:
D3DXVECTOR3 p; // position
D3DXVECTOR3 tx, ty; // tangents
D3DXVECTOR2 tex; // texture coordinate
D3DXVECTOR4 parm; // .x = u parameter value, .y = radius, .z = length
as input to render strips of triangles that that more or less resembles hair.

The animation and the rendering of the hairs are controlled by a number of constants.
Diffuse end specular colors
Specular reflection and sharpness
Transparency fade along the hair
Constant bending
Gravity point with distance attenuation
Dynamic bending is calculated from the object motion
Light source position
Bending shape polynomial

See ShaderConstants.h for a description of the constants.

In this version af the program fur can be grown on any parametric surface, that implements the ParameterSurface interface. However only a sphere and a torus is implemented.

Special Controls:
PgUP,PgDown Change number of hairs
+,- Change length
*,/ Change number of segments
R,E Change radius
P Change model


17. 1D Particles

Creator:
Martin Mittring

Description:
The work of the vertexshader is to project the particle (2 positions with 2 size values) and calculate the right texture coordinates (16 subpictures in one texture). I´m sure this calculation can be done with more precision - but I run out of time to prove it.  There is no special pixelshader used, this will work on most graphic cards.


18. Particle System

Creator:
Greg Snook

Description:
Particle System #1
The first shader runs a complete particle simulation within the shader. Trajectory, Wind Shear, Gravity and Magnetic forces can all be applied real-time in addition to particle scale and rotation. The shader also provides four-frame texture animation for the particles using creative UV mapping on a single texture. Each Vertex for this shader is only 16 bytes (a single vector). A huge Dialog box of sliders is presented to adjust the particle system in real-time. It's not exactly user-friendly, but it does allow for full control of the system and the ability to save/load particle system definitions.

Particle System #2 (Model Based particle system)
The second shader also runs a complete particle simulation within the shader just as above. The main difference is that in this case the particles are launched from the surface of a donor model instead of emitting from a single point in space. The vertex stride increases to 32 bytes (two vectors) but the end effect is really useful. As with the first shader, a full dialog of ugly slider controls is provided, plus you can right click on the particle system viewer to load a different donor model.


19. Plasma

Creator:
Laurent Mascherpa

Description:
A colourful procedural plasma effect.