The bubble sample demonstrates the use of vertex and
pixel shaders to procedurally generate a pulsating soap
bubble.
Rendering bubbles is an excellent candidate for vertex
and pixel shaders because they are dynamic, reflective
and partially transparent.
The Bubble sample creates a soap bubble effect by rendering
a dynamically deforming sphere with a base texture and
cubic environment map.
The vertex shader uses four sine waves traveling in
different directions over the surface of the bubble
to perturb the vertex position in the direction of the
normal. In order to perturb the normal, cosine waves
traveling in the same four directions are used. In order
to provide a consistent looking warping across vertices,
the tangent and bi-normal are used to guide the direction
of the sinusoidal warp.
The pixel shader uses the brightly colored rainbow
film map as a base texture. This texture map is meant
to simulate the soap film appearance of a bubble. The
environment map is modulated with this texture. The
white highlights are stored in the alpha of the environment
map as a glow map, and are linearly interpolated into
the result. The final alpha value used for blending
with the frame buffer is the fresnel term plus the glow
map.
|