Lecture 2 visible-surface determination Books Visible ... - Faculty
Lecture 2 visible-surface determination Books Visible ... - Faculty
Lecture 2 visible-surface determination Books Visible ... - Faculty
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>Lecture</strong> 2<br />
<strong>visible</strong>-<strong>surface</strong> <strong>determination</strong><br />
Prof. Marcelo Kallmann<br />
mkallmann@ucmerced.edu<br />
<strong>Visible</strong>-<strong>surface</strong> Determination<br />
M. Kallmann, Fall 2006, UCM<br />
M. Kallmann, Fall 2006, UCM<br />
<strong>Books</strong><br />
– 3-D Computer Graphics<br />
Samuel R. Buss<br />
– 3D Computer Graphics<br />
Alan H. Watt<br />
– Fundamentals of Computer Graphics<br />
Peter Shirley et al<br />
– Introduction to Computer Graphics<br />
Foley, van Dam et al<br />
– Computer Graphics: Principles<br />
and Practice (1990)<br />
Foley, van Dam et al<br />
– OpenGL red book<br />
http://www.rush3d.com/reference/opengl-redbook-1.1/<br />
The Rendering Pipeline<br />
Modeling<br />
Transformations<br />
Lighting<br />
Viewing/Camera<br />
Transformations<br />
Projection<br />
Transformation<br />
Clipping<br />
∀ Objects<br />
Scan Conversion Image<br />
M. Kallmann, Fall 2006, UCM<br />
M. Kallmann, Fall 2006, UCM
<strong>Visible</strong>-<strong>surface</strong> Determination<br />
• Which polygons go in front and which go<br />
behind during rasterization?<br />
– depth-sorting<br />
– BSP trees<br />
– z-buffer<br />
– there are others<br />
• scan line, area subdivision, etc<br />
• Back-face culling<br />
– only renders polygons facing camera<br />
– easy to determine with polygon normal<br />
Depth Sorting<br />
M. Kallmann, Fall 2006, UCM<br />
1. Sort polygons according to z coordinate<br />
2. Resolve ambiguities when polygon’s z<br />
extents overlap, split polygons if needed<br />
3. Start “painting” the polygons farther away<br />
from the camera<br />
z<br />
each polygon has to test<br />
all others intersecting its<br />
“z extent”<br />
z<br />
M. Kallmann, Fall 2006, UCM<br />
Depth Sorting<br />
• Also called the painters algorithm:<br />
1. Sort polygons according to z coordinate<br />
2. Start “painting” the polygons farther away<br />
from the camera<br />
Is that all?<br />
BSP trees<br />
z<br />
M. Kallmann, Fall 2006, UCM<br />
1. Build a tree “ordering” the polygons<br />
according to “half spaces separability”<br />
2. Traverse the tree according to view point<br />
M. Kallmann, Fall 2006, UCM
BSP tree construction 1/3<br />
5<br />
1<br />
4a<br />
2<br />
4<br />
3<br />
4b<br />
BSP tree construction 3/3<br />
5<br />
1<br />
4a<br />
2<br />
4<br />
3<br />
4b<br />
4a<br />
front<br />
front<br />
2 back<br />
1 3<br />
4a 4b<br />
5<br />
1<br />
M. Kallmann, Fall 2006, UCM<br />
2 back<br />
3<br />
5 4b<br />
M. Kallmann, Fall 2006, UCM<br />
BSP tree construction 2/3<br />
5<br />
1<br />
4a<br />
BSP tree traversal<br />
2<br />
4<br />
3<br />
4b<br />
front<br />
1<br />
4a<br />
5<br />
if viewer in root polygon’s front half-space<br />
else<br />
1. display polygons in root’s rear half-space<br />
2. display root<br />
3. display polygons in root’s front half-space<br />
1. display polygons in root’s front half-space<br />
2. display root<br />
3. display polygons in root’s rear half-space<br />
recursively process root’s children<br />
2 back<br />
3<br />
4b<br />
M. Kallmann, Fall 2006, UCM<br />
M. Kallmann, Fall 2006, UCM
BSP tree traversal<br />
5<br />
1<br />
Z-Buffer<br />
A<br />
4a<br />
A: 3, 4b, 2, 5, 1, 4a<br />
B: 5, 1, 4a, 2, 4b, 3<br />
2<br />
4<br />
3<br />
4b<br />
B<br />
4a<br />
front<br />
1<br />
2 back<br />
3<br />
5 4b<br />
M. Kallmann, Fall 2006, UCM<br />
• No sorting!<br />
– Rasterize polygons in any order<br />
• But maintain a buffer with same image size<br />
– each pixel in the buffer stores the z-value of the<br />
respective pixel in the image<br />
– new pixels are only displayed if their z-value are<br />
greater (closer to viewer) than previous value<br />
z<br />
z=4<br />
M. Kallmann, Fall 2006, UCM<br />
BSP tree traversal<br />
• Tree is constructed at pre-processing<br />
• Viewpoint can move but not polygons<br />
– Tree has to be reconstructed/updated every<br />
time a polygon moves<br />
• Need to know “front” and “back” of polygons<br />
– easy <strong>determination</strong> based on normals<br />
Z-Buffer<br />
4<br />
4 4 4 4 4 4<br />
4 4 4 4 4 4 4<br />
4 4 4 4 4 4 4<br />
4 4 4 4 4 4 4<br />
4 4 4 4 4 4 4<br />
4 4 4 4 4 4 4<br />
4 4 4 4 4 4 4<br />
M. Kallmann, Fall 2006, UCM<br />
M. Kallmann, Fall 2006, UCM
Z-Buffer<br />
Z-Buffer<br />
• Very fast!<br />
• Uses more memory<br />
– for ex, 1600x1200x1 ≅ 2MB<br />
– need to choose depth buffer resolution<br />
– graphics cards have lots of memory<br />
– memory is now cheap<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
• Most interactive graphics tools use z-buffer<br />
– OpenGL uses z-buffer<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
M. Kallmann, Fall 2006, UCM<br />
M. Kallmann, Fall 2006, UCM<br />
Z-Buffer<br />
Summary<br />
7<br />
7<br />
8<br />
8<br />
6<br />
6<br />
7<br />
7<br />
8<br />
8<br />
9<br />
9<br />
6<br />
6<br />
6<br />
6<br />
7<br />
7<br />
7<br />
8<br />
8<br />
9<br />
9<br />
9<br />
5<br />
5<br />
5<br />
6<br />
6<br />
7<br />
7<br />
7<br />
8<br />
8<br />
9<br />
• You need to know how the 3 algorithms<br />
explained today work<br />
– Depth-sorting, BSPs, depth buffer<br />
4<br />
5<br />
5<br />
5<br />
6<br />
6<br />
7<br />
7<br />
7<br />
8<br />
4<br />
4<br />
5<br />
5<br />
5<br />
6<br />
6<br />
6<br />
7<br />
• These same algorithms are also used for other<br />
purposes<br />
– Ex: desktop GUI management uses depth-sorting<br />
4<br />
4<br />
4<br />
5<br />
5<br />
5<br />
6<br />
6<br />
3<br />
4<br />
4<br />
4<br />
4<br />
5<br />
5<br />
5<br />
3<br />
4<br />
4<br />
4<br />
4<br />
4<br />
5<br />
4<br />
3<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
4<br />
3<br />
3<br />
3<br />
3<br />
3<br />
2<br />
2<br />
2<br />
2<br />
1<br />
1<br />
1<br />
1<br />
0<br />
0<br />
M. Kallmann, Fall 2006, UCM<br />
M. Kallmann, Fall 2006, UCM
Next <strong>Lecture</strong><br />
• Next <strong>Lecture</strong><br />
– Vector/Matrix algebra<br />
– Transformation matrices<br />
• Assignment 1<br />
– First assignment will be posted after that<br />
Notes: thanks to Fredo Durand for sharing some of his course notes<br />
M. Kallmann, Fall 2006, UCM<br />
Support Code<br />
• Get started with OpenGL<br />
– Support code is online<br />
– Demonstration now!<br />
• Which lab/platform is your preference?<br />
• At least while ucmcrops is being updated,<br />
CSE170 information will be posted at:<br />
http://faculty.ucmerced.edu/mkallmann/cse170/<br />
M. Kallmann, Fall 2006, UCM