Home | Lehre | Videos | Texte | Vorträge | Software | Person | Impressum, Datenschutzerklärung | Blog
Index Buffer
Most surfaces consist of connected triangles, whoch means that most
vertices are shared between several triangles. It is not efficient to store
three vertices per triangle: Much more memory would be consumed and all
3D transformations would needlessly be computed for each identical copy
of a vertex. Instead, store each vertex only once and tell the graphics
card how to "connect the dots". This is done through an index buffer: an
array of integers giving the number of the vertices in the order in which
they are to be connected, i.e., three numbers per triangle. See demo.
Reflection Models
Real surfaces can display extraordinarily complex light reflection behavior:
Think for instance of perls or of holograms. In basic computer graphics,
the reflective behavior of a surface is approximated using four additive
components ("Phong model"), see demo:
-
Emission [Ausstrahlung]: The surface has a certain color, irrespective
of light sources
-
Ambient [Umgebungs-...]: The surface shows a base color irrespective of
direction or shadowing.
-
Diffuse [diffus]: The surface shows matte reflections.
-
Specular [glänzend] The surface shows glossy highlights. Highlights
on highly polished materials have a small diameter.
The diffuse component changes with the surface orientation towards the
light. Let n be the normal vector at a surface point, i.e., a vector
of length one (unit vector) perpendicular to the surface and pointing outside.
Let l be a unit vector pointing from this point to the light source.
If f is the angle between both vectors, then
the lighting will be proportional to cos(f),
which can be computed easily by forming the dot product of n and
l.
The specular component changes not only with light direction, but also
with viewing direction. Let v be the unit vector pointing from the
point on the surface to the viewer. The viewer looks straight into the
highlight if we have a mirror-like situation, i.e., n is half-way
between l and v. Thus, form the "half vector" h
:= (l+v)/|l+v|, another unit vector. If h
= n, the viewer looks at the center of the highlight. Thus, use
the dot product h.n to control the amount of light. However,
this expression decays too slowly as the viewer moves away from the center
of the highlight. We take the n-th power ("Phong exponent", n
= 10...100) to accelerate the decay: (h.n)n.
Note that the point of maximum brightness of the diffuse component does
not coincide with the center of the specular highlight. The latter depends
on the position of the viewer, whereas the former does not.
According to physics, the effect of a point light source should decay
with the square of the distance between light source and surface. However,
this leads to overly dark images because we do not yet take indirect illumination
into account in a reasonable manner. Typically, one sticks to linear decay
or no decay at all.
Smooth Shading
On standard graphics cards, these lighting computations [Vorsicht: nicht
"lightning" = Blitz] happen per vertex. The resulting colors are
interpolated across the triangular faces to yield quite smooth shading
("Gouraud interpolation"; demo in DirectX and Cinema 4D). However, any
small highlight in the center of a face will be missed; furthermore, sharp
highlights reveal the underlying triangular structure. Thus, standard offline
renderers use the more expensive "Phong interpolation", in which the normals
instead of the colors are interpolated across the faces and the lighting
model is evaluated per pixel (demo in DirectX). Using pixel shaders, this
can be done on current graphics hardware, too.
Determining the Vertex Normal
Typically, normal vectors for vertices are computed by averaging the normals
of the surrounding polygonal faces. The latter normals can easily be found
through a vector product. Actually, the Mesh calls of DirectX already contains
several helper functions for such computations.
Sometimes, however, we want sharp edges in an otherwise smooth object.
Typical 3D software allows you to define such sharp edges for instance
through a threshold angle. (Demo) In realtime graphics, this means to duplicate
the vertices of the sharp edge: Every vertex may have only one vertex normal,
but along sharp edges we need two or more normals. Thus, when smooth shading
is switched on, a cube has to be formed from six squares = twelve triangles
with 6*4 = 24 Vertices. Here, every geometric vertex is present three times
because it belongs to three different faces with different normals.