Download presentation
Presentation is loading. Please wait.
Published byAnnice Hardy Modified over 8 years ago
1
Chapter 7. Three-Dimensional Viewing Sang Il Park Sejong University Lots of slides are stolen from Jehee Lee’s
2
OpenGL 3D Viewing Functions Viewing-transformation function –glMatrixMode(GL_MODELVIEW); –gluLookAt(x0,y0,z0,xref,yref,zref,vx,vy,vz); –Default: gluLookAt(0,0,0, 0,0,-1, 0,1,0); OpenGL orthogonal-projection function –glMatrixMode(GL_PROJECTION); –gluOrtho(xwmin,xwmax, ywmin,ywmax, dnear,dfar); –Default: gluOrtho(-1,1, -1,1, -1,1); –Note that dnear and dfar must be assigned positive values z near =-dnear and z far =-dfar The near clipping plane is the view plane
3
OpenGL 3D Viewing Functions OpenGL perspective-projection function –The projection reference point is the viewing-coordinate origin –The near clipping plane is the view plane –Symmetric: gluPerspective(theta,aspect,dnear,dfar) –General: glFrustum(xwmin,xwmax,ywmin,ywmax,dnear,dfar)
4
Chapter 9 Visible-Surface Detection Sang Il Park Sejong University
5
Visible-Surface Detection Methods Determine what is visible within a scene from a chosen viewing position Two approaches –Object-space methods: Decide which object, as a whole, is visible –Image-space methods: The visibility is decided point- by-point Most visible-surface algorithms use image- space methods Sometimes, these methods are referred to as hidden-surface elimination
6
Approaches Back-Face Removal Depth Buffer A-Buffer Scanline Depth Sorting BSP Tree Area Subdivision Octree Raycasting
7
Back-Face Removal (Culling) Used to remove unseen polygons from convex, closed polyhedron Does not completely solve hidden surface problem since one polyhedron may obscure another
8
Back-Face Removal (Culling) Compute the equation of the plane for each polygon –A point (x,y,z) is behind a polygon surface if Determine back-face –In projection coordinates, we need to consider only the z component of the normal vector N
9
Depth-Buffer (Z-Buffer) Z-Buffer has memory corresponding to each pixel location –Usually, 16 to 20 bits/location.
10
Review: Normalizing Transformation Transform an arbitrary perspective-projection view volume into the canonical view volume Step 1: from frustum to parallelepiped
11
Review: Normalizing Transformation Transform an arbitrary perspective-projection view volume into the canonical view volume Step 2: from parallelepiped to normalized
12
Depth-Buffer (Z-Buffer) Initialize –Each z-buffer location Max z value –Each frame buffer location background color For each polygon: –Compute z(x,y), polygon depth at the pixel (x,y) –If z(x,y) < z-buffer value at pixel (x,y), then z buffer(x,y) z(x,y) pixel(x,y) color of polygon at (x,y)
13
Depth Calculation Calculate the z-value on the plane Incremental calculation
14
Depth-Buffer (Z-Buffer) Advantages/Disadvantages –Lots of memory –Linear performance –Polygons may be processed in any order Modifications needed to implement antialiasing, transparency, translucency effects –Commonly implemented in hardware very fast
15
Depth-Buffer (Z-Buffer) Backface cullingZ-buffer algorithm
16
OPENGL Backface culling Using back face culling: –glEnable (GL_CULL_FACE); Selecting culling mode: –glCullFace (mode); –mode: GL_BACK, GL_FRONT, GL_FRONT_AND_BACK
17
OPENGL Depth Buffer Initialize (empty) depth buffer: –glClear (GL_DEPTH_BUFFER_BIT); Using depth buffer: –glEnable (GL_DEPTH_TEST); Not using depth buffer glDisable (GL_DEPTH_TEST);
18
연습 : 사면체를 그려보자 x y z
19
미리 해보는 3 차원 명암 나타내기
20
I. 조명과련 초기값 설정 : 1. 명암 계산을 사용함 glEnable(GL_LIGHTING); 2. 조명을 킴 glEnable(GL_LIGHT0); 3. 색을 이용하여 도형을 그림 glEnable(GL_COLOR_MATERIAL);
21
미리 해보는 3 차원 명암 나타내기 II. 면을 그릴 때 면의 방향 ( 법선 ) 을 주어 줌 –glNormal3f( nx, ny, nz); (nx, ny, nz) ex) glBegin(GL_TRIANGLES); glNormal3f(0,0,1); glVertex3f(0,0,0); glVertex3f(1,0,0); glVertex3f(0,1,0); glEnd(); ex) glBegin(GL_TRIANGLES); glNormal3f(0,0,1); glVertex3f(0,0,0); glVertex3f(1,0,0); glVertex3f(0,1,0); glEnd();
22
Programming Assignment #3 Obj Viewer 만들기 [stanford bunny]
23
Programming Assignment #3 Obj: 3 차원 도형을 표현하는 가장 간단한 형식 점 (vertex) 과 면 (face) 등의 정보를 저장 각 정보를 keyword 와 숫자의 조합으로 표현 –Keyword 의미 : v: vertex position vn: vertex normal f: face v: vertex position vn: vertex normal f: face
24
Programming Assignment #3 Obj example: CUBE f 1 7 5 f 1 3 7 f 1 4 3 f 1 2 4 f 3 8 7 f 3 4 8 f 5 7 8 f 5 8 6 f 1 5 6 f 1 6 2 f 2 6 8 f 2 8 4 f 1 7 5 f 1 3 7 f 1 4 3 f 1 2 4 f 3 8 7 f 3 4 8 f 5 7 8 f 5 8 6 f 1 5 6 f 1 6 2 f 2 6 8 f 2 8 4 # cube.obj : Comment v 0.0 0.0 0.0 v 0.0 0.0 1.0 v 0.0 1.0 0.0 v 0.0 1.0 1.0 v 1.0 0.0 0.0 v 1.0 0.0 1.0 v 1.0 1.0 0.0 v 1.0 1.0 1.0 # cube.obj : Comment v 0.0 0.0 0.0 v 0.0 0.0 1.0 v 0.0 1.0 0.0 v 0.0 1.0 1.0 v 1.0 0.0 0.0 v 1.0 0.0 1.0 v 1.0 1.0 0.0 v 1.0 1.0 1.0
25
Programming Assignment #3 채점 기준 : –Obj 읽기 관련 : Cube.obj 와 bunny.obj 를 읽고 화면에 표시됨 (20) 면들의 명암이 표시됨 (20) –Viewing 관련 : Perspective 가 느껴짐 (20) Cube 나 bunny 가 화면 가운데 최대한 가득히 나옴 (20) 물체가 물체의 중심을 기준으로 서서히 돌아감 (20) – 추가점수 : 면의 테두리를 검은 선으로 표시할 수 있음 (10) 마우스의 왼쪽 드래깅을 통해 물체의 중심을 기준으로 임의의 방향으로 돌릴 수 있음 (20)
26
Programming Assignment #3 Due Date: –5 월 27 일 ( 목요일 ) 저녁 23 시 59 분까지 리포트, 스크린샷 및 소스코드 제출
27
Accumulation Buffer (A-Buffer) An extension of the depth-buffer for dealing with anti-aliasing, area-averaging, transparency, and translucency The depth-buffer method identifies only one visible surface at each pixel position –Cannot accumulate color values for more than one transparent and translucent surfaces Even more memory intensive Widely used for high quality rendering
28
Accumulation Buffer (A-Buffer) Each position in the A-buffer has two fields –Depth field: Stores a depth value –Surface data field RGB intensity components Opacity parameter (percent of transparency) Depth Percent of area coverage Surface identifier
29
Scan Line Method Intersect each polygon with a particular scanline and solve hidden surface problem for just that scan line –Requires a depth buffer equal to only one scan line –Requires the entire scene data at the time of scan conversion Maintain an active polygon and active edge list Can implement antialiasing as part of the algorithm
30
Depth Sorting Painter’s algorithm –Draw polygons as an oil painters might do Sort polygons by depth and draw them from back to front Depth sorting is NOT simple
31
Depth Sorting We need a partial ordering (not a total ordering) of polygons –The ordering indicates which polygon obscures which polygon –Some polygons may not obscure each other Simple cases
32
Depth Sorting We make the following tests for each polygon that has a depth overlap with S If any one of these tests is true, no reordering is necessary for S and the polygon being tested –Polygon S is completely behind the overlapping surface relative to the viewing position –The overlapping polygon is completely in front of S relative to the viewing position –The boundary-edge projections of the two polygons onto the view plane do not overlap
33
Depth Sorting Example
34
Depth Sorting Cyclically overlapping surfaces that alternately obscure one another We can divide the surfaces to eliminate the cyclic overlaps
35
BSP Trees Binary space partitioning is an efficient method for determining object visibility Paint surfaces into the frame buffer from back to front Particularly useful when the view reference point changes, but the objects are at fixed positions
36
BSP Tree Construction 1.Choose a polygon T and compute the equation of the plane it defines 2.Test all the vertices of all the other polygons to determine if they are in front of, behind, or in the same plane as T. 3.If the plane intersects a polygon, divide the polygon at the plane 4.Polygons are placed into a binary search tree with T as the root 5.Call the procedure recursively on the left and right sub-tree
37
Traversing BSP Trees EYE 1 +X-X C B A D E1 +Z F2 E2 F1 EYE 2 A C F1D E2 F2 B E1
38
BSP Trees BST tree construction requires a number of polygons to be fractured It is possible for the number of triangles to increase exponentially but, in practice, it is found that the increase may be as small as two fold A heuristic to help minimize the number of fractures is to enter the polygons into the tree in order from largest to smallest
39
Area Subdivision Image-space method taking advantage of area coherence in a scene Recursively subdivide a square area into equal- sized quadrants if the area is too complex to analyze easily
40
Area Subdivision Four possible relationships between polygon surfaces and a rectangular section of the viewing plane Terminating criteria –Case 1: An area has no inside, overlapping, or surrounding surfaces (all surfaces are ourside the area) –Case 2: An area has only one inside, overlapping or surrounding surfaces –Case 3: An area has one surrounding surface that obscures all other surfaces within the area boundaries
41
Octrees Visible-surface identification is accomplished by searching octree nodes in a front-to-back order
42
Ray Casting We consider the line of sight from the a pixel position through the scene Useful for volume data Ray casting is a special case of ray tracing that we will study later
43
Ray Casting Examples
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.