Home | Lehre | Videos | Texte | Vorträge | Software | Person | Impressum, Datenschutzerklärung | Blog
Hidden Surface Elimination, Visible Surface Determination
A surface in the background that is occluded by a surface in the foreground
must not be visible in the rendering. So it has to be eliminated. Most
often, this is done in an indirect manner. Here are some typical methods
to solve the problem:
-
Ray casting, the first step of ray tracing: Follow a ray from the viewer's
eye through every screen pixel into the scene. Determine the ray's first
hit with an object of the scene.
-
Depth sorting: Sort surfaces according to their distance from the viewer;
paint them in this order, starting with the most distant. Problems: One
needs to store all surfaces; sorting is time-consuming; in some situations
the surfaces have to be split in order to cope with ambiguities.
-
Backface culling: Draw only the front-facing parts. Use the order of the
vertices (clockwise/counter-clockwise) to decide whether we see a triangle
from the front or from the back. Problems: Surfaces must not have holes;
furthermore, this is no solution for concave objects. Most typically, backface
culling is used for acceleration, not for hidden surface elimination. Demo
with Direct3D and Cinema 4D.
-
Z Buffer: Use an additional buffer (z buffer) of the same resolution as
the frame buffer (which contains the RGB values to be displayed). In this
additional buffer store the depth for each pixel. When painting a triangle,
fill the depth buffer pixel-wise with the corresponding depth data. But
do not draw a pixel (neither in the frame buffer nor in the z buffer),
when its existing depth in the z buffer would be nearer to the viewer than
its new depth. Advantages: We can draw the surfaces in arbitrary order;
the graphics cards does not need to store the surfaces itself. Demo with
Direct3D.
Screen Flicker, Double Buffering
If we clear the screen and then draw everything again, we generate screen
flicker. How can this be avoided?
-
Clipping: Restrict the drawing to a smaller region to diminish flicker,
but not avoid it completely. We may specify such a region in Invalidate().
-
Double buffering: Draw to a non-displayed buffer ("back buffer") first,
then copy this buffer to the real frame buffer ("front buffer").
In full-screen mode, no time-consuming copy ("blit": bit block transfer)
is needed for double-buffering; one can simply switch to a different position
in memory.
If the copying or switching is not sychronized to the display, "tearing"
will result.
Double-buffering is activated in Java Swing and Direct3D by default.
In Windows Forms it may be activated, too:
.NET 1.1:
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint
| ControlStyles.UserPaint, true);
.NET 2.0:
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint,
true);