Graphics Reference
In-Depth Information
float up = dot( vec2(u,v), vec2(cossin.x, -cossin.y) );
float vp = dot( vec2(u,v), cossin.yx) );
In fact, this is a good programming lesson in general. Don't ever call the
atan function and then turn around and use the resulting angle to compute a
sine or cosine. You already had the sine and cosine when you called the atan
function (albeit, possibly with a litle manipulation).
Generalized Bump Mapping
Height fields are a special, and simplified, case of bump-mapping. Now, let's
look at it in the general case. For this, we will define a surface local coordinate
system at each fragment with components N , T , B ( N ormal, T angent, and
B itangent B = T × N ). Figure 9.7 shows the pyramid map example, and the
vertex and fragment shaders used to create it are shown below.
The pyramid bump map example needs special vertex and fragment
shaders. The vertex shader sets up the surface coordinate system discussed
above, taking the tangent and normal from the geometric object and comput-
ing the varying variable vLightDir that is used in the fragment shader, along
with the computed normal, to determine the diffuse light component for the
pixel. In this example, we convert everything into the eye coordinate system.
It can also work to convert everything into the surface local coordinate system,
but the surface local coordinate system changes at each location in the geome-
try. By using a “universal” coordinate system, such as eye coordinates, we can
make surface coordinates, light positions and directions, reflection directions,
and refraction directions all interoperate.
Figure 9.7. A sphere with
pyramid bump map-
ping (left) and the right-
handed BTN coordinate
system for one particular
location (right).
Search WWH ::




Custom Search