Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk [email protected]...
-
Upload
calvin-austin -
Category
Documents
-
view
228 -
download
1
Transcript of Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk [email protected]...
![Page 1: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/1.jpg)
Visible Surface DeVisible Surface Detectiontection
UBI 516 Advanced Computer Graphics
UBI 516 Advanced Computer Graphics
Aydın Öztürk
[email protected]://www.ube.ege.edu.tr/~ozturk
![Page 2: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/2.jpg)
Review: Rendering Pipeline
Almost finished with the rendering pipeline:– Modeling transformations– Viewing transformations– Projection transformations– Clipping– Scan conversion
We now know everything about how to draw a polygon on the screen, except visible surface detection.
![Page 3: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/3.jpg)
Invisible Primitives
Why might a polygon be invisible?– Polygon outside the field of view– Polygon is backfacing– Polygon is occluded by object(s) nearer the
viewpoint
For efficiency reasons, we want to avoid spending work on polygons outside field of view or backfacing
For efficiency and correctness reasons, we need to know when polygons are occluded
![Page 4: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/4.jpg)
View Frustum Clipping
Remove polygons entirely outside frustum– Note that this includes
polygons “behind” eye (actually behind near plane)
Pass through polygons entirely inside frustum
Modify remaining polygonsto pass through portions intersecting view frustum
![Page 5: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/5.jpg)
View Frustum Clipping
Canonical View Volumes– Remember how we defined cameras
Eye point, lookat point, v-up Orthographic | Perspective
– Remember how we define viewport Width, height (or field of view, aspect ratio)
– These two things define rendered volume of space
– Standardize the height, length, and width of view volumes
![Page 6: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/6.jpg)
View Frustum Clipping
Canonical View Volumes
![Page 7: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/7.jpg)
Review Rendering Pipeline
Clipping equations are simplified Perspective and Orthogonal (Parallel) projections have consistent representations
![Page 8: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/8.jpg)
Perspective Viewing Transformation
Remember the viewing transformation for perspective projection– Translate eye point to origin– Rotate such that projection vector matches –z axis– Rotate such that up vector matches y
Add to this a final step where we scale the volume
![Page 9: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/9.jpg)
Canonical Perspective Volume
Scaling
![Page 10: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/10.jpg)
Clipping
Because both camera types are represented by same viewing volume– Clipping is simplified even further
![Page 11: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/11.jpg)
Visible Surface DeVisible Surface Detectiontection
There are many algorithms developed for the visible surface detection
● Some methods involve more processing time.
● Some methods require more memory.
● Some others apply only to special types of objects.
![Page 12: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/12.jpg)
Classification of Visible-Surface Classification of Visible-Surface Detection AlgorithmsDetection Algorithms
They are classified according to whether they deal with object definitions or with their projected images.
● Object space methods.
● Image-space methods.
Most visible-surface algorithms use image space method.
![Page 13: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/13.jpg)
Back-Face Detection
Most objects in scene are typically “solid”
![Page 14: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/14.jpg)
Back-Face Detection (cont.)
On the surface of polygons whose normals point away from the camera are always occluded:
Note: backface detectionalone doesn’t solve the
hidden-surface problem!
![Page 15: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/15.jpg)
Back-Face Detection
This test is based on inside-outside test. A point (x,y,z) is inside if
0 DCzByAxzv
xv
yv
V
N=(A,B,C)
We can simplify this test by considering the normal vector vector N to a polygon surface, which has Cartesian components (A,B,C).
If V is a vector in the viewing direction from eye then this polygon is back face if V●N > 0.
If the object descriptions have been converted to projection coordinates and viewing direction is parallel to zv axis then V=(0, 0, Vz) and V●N=VzC so that we only need to consider the sign of C.
![Page 16: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/16.jpg)
Depth-Buffer (z-Buffer) Method
zv
xv
yv
S3
S1
S2
This method compares surface depths at each pixel position on the projection plane.
Each surface is processed separetly, one point at a time across the surface.
Surface S1 is closest to view plane, so its surface intensity value at (x,y) is saved.
(x,y)
![Page 17: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/17.jpg)
Steps for Depth-Buffer (z-Buffer) Method(Cont.)
1. Initialize the depth buffer and refresh buffer s.t. for all buffer positions (x,y)
depth(x, y) = 0, refresh(x, y) = Ibackground
![Page 18: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/18.jpg)
Steps for Depth-Buffer (z-Buffer) Method(Cont.)
2. For each position on each polygon surface, compare depth values to previously stored values in depth buffer to determine visibility.
● Calculate the depth z for each (x,y) position on the polygon.
● If z >depth(x,y), thendepth(x, y) = z, refresh(x, y) = Isurf(x,y).
where Ibackground is the value for the bacground intensity and Isurf(x,y), is the projected intensity value for the surface
at (x,y).
![Page 19: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/19.jpg)
Depth-Buffer (z-Buffer) Calculations.
Depth values for a surface position (x,y) are calculated from the plane equation
z-value for the horizontal next position
z-value down the edge(starting at top vertex)
CDByxAz
CDByAxz
/))1((
/)(
CAzz /'
CBmAzz /)/('
X X+1
Y
Y-1
Left edge
intersection
bottom scan line
top scan line
![Page 20: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/20.jpg)
Scan-Line Method
Scan Line 1
Scan Line 2
Scan Line 3
S1S1 S2
xv
yv
A
B
D
F
G
HC
E
![Page 21: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/21.jpg)
Depth-Sorting Algorithm (Painter’s Algorithm)
This method performs the following basic functions:
1. Surfaces are sorted in order of decreasing order.
2. Surfaces are scan converted in order, starting with the surface of greatest.
![Page 22: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/22.jpg)
Depth-Sorting Algorithm (Painter’s Algorithm)
Simple approach: render the polygons from back to front, “painting over” previous polygons:
![Page 23: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/23.jpg)
Depth-Sorting Algorithm (Painter’s Algorithm)
![Page 24: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/24.jpg)
Depth-Sorting Algorithm (Painter’s Algorithm)
![Page 25: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/25.jpg)
Painter’s Algorithm: Problems
Intersecting polygons present a problem Even non-intersecting polygons can form a cycle
with no valid visibility order:
![Page 26: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/26.jpg)
Analytic Visibility Algorithms
Early visibility algorithms computed the set of visible polygon fragments directly, then rendered the fragments to a display:
– Now known as analytic visibility algorithms
![Page 27: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/27.jpg)
Analytic Visibility Algorithms
What is the minimum worst-case cost of computing the fragments for a scene composed of n polygons?
Answer: O(n2)
![Page 28: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/28.jpg)
Analytic Visibility Algorithms
So, for about a decade (late 60s to late 70s) there was intense interest in finding efficient algorithms for hidden surface removal
We’ll talk about two: – Binary Space-Partition (BSP) Trees
![Page 29: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/29.jpg)
Binary Space Partition Trees (1979)
BSP tree: organize all of space (hence partition) into a binary tree– Preprocess: overlay a binary tree on objects in
the scene– Runtime: correctly traversing this tree
enumerates objects from back to front– Idea: divide space recursively into half-spaces
by choosing splitting planes Splitting planes can be arbitrarily oriented
![Page 30: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/30.jpg)
BSP Trees: Objects
![Page 31: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/31.jpg)
BSP Trees: Objects
![Page 32: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/32.jpg)
BSP Trees: Objects
![Page 33: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/33.jpg)
BSP Trees: Objects
![Page 34: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/34.jpg)
BSP Trees: Objects
![Page 35: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/35.jpg)
Rendering BSP Trees
renderBSP(BSPtree *T)
BSPtree *near, *far;
if (eye on left side of T->plane)
near = T->left; far = T->right;
else
near = T->right; far = T->left;
renderBSP(far);
if (T is a leaf node)
renderObject(T)
renderBSP(near);
![Page 36: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/36.jpg)
Rendering BSP Trees
![Page 37: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/37.jpg)
Polygons: BSP Tree Construction
Split along the plane containing any polygon
Classify all polygons into positive or negative half-space of the plane– If a polygon intersects plane, split it into two
Recurse down the negative half-space Recurse down the positive half-space
![Page 38: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/38.jpg)
No bunnies were harmed in our example. But what if a splitting plane passes through an
object?– Split the object; give half to each node:
Notes About BSP Trees
Ouch
![Page 39: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/39.jpg)
BSP Demo
Nice demo:http://symbolcraft.com/graphics/bsp/
![Page 40: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/40.jpg)
Summary: BSP Trees
Advantages:– Simple, elegant scheme– Only writes to framebuffer (i.e., painters algorithm)
Thus very popular for video games (but getting less so)
Disadvantages:– Computationally intense preprocess stage restricts
algorithm to static scenes– Worst-case time to construct tree: O(n3)– Splitting increases polygon count
Again, O(n3) worst case
![Page 41: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/41.jpg)
OpenGL Visibility Detection Functions OpenGL Visibility Detection Functions
UBI 516 Advanced Computer Graphics
UBI 516 Advanced Computer Graphics
![Page 42: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/42.jpg)
OpenGL Backface Culling
glEnable(GL_CULL_FACE);glCullFace(mode);// mode: GL_BACK,
GL_FRONT,GL_FRONT_AND_BACK :-o
glDisable(GL_CULL_FACE);
![Page 43: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/43.jpg)
OpenGL Depth Buffer Functions
Set display ModeglutDisplayMode( GLUT_DOUBLE | GLUT_RGB |
GLUT_DEPTHGLUT_DEPTH ); Clear screen and depth buffer every time in the
display functionglClear( GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BITGL_DEPTH_BUFFER_BIT ); Enable/disable depth buffer
glEnable( GL_DEPTH_TESTGL_DEPTH_TEST );
glDisable( GL_DEPTH_TESTGL_DEPTH_TEST );
![Page 44: Visible Surface Detection UBI 516 Advanced Computer Graphics Aydın Öztürk ozturk@ube.ege.edu.tr ozturk.](https://reader035.fdocuments.us/reader035/viewer/2022062320/56649d015503460f949d353f/html5/thumbnails/44.jpg)
OpenGL Depth-Cueing Function
We can vary the brigthness of an object
glEnable ( GL_FOG );glFogi ( GL_FOG_MODE, mode);// modes: GL_LINEAR, GL_EXP or GL_EXP2. . .glDisable ( GL_FOG );