+ All Categories
Home > Documents > Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf ·...

Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf ·...

Date post: 24-Oct-2019
Category:
Upload: others
View: 3 times
Download: 0 times
Share this document with a friend
61
C O M P U T E R G R A P H I C S Computer Graphics Computer Graphics Three-Dimensional Graphics IV Guoying Zhao 1 / 61
Transcript
Page 1: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Computer GraphicsComputer Graphics

Three-Dimensional Graphics IV

Guoying Zhao 1 / 61Guoying Zhao 1 / 61

Page 2: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

• Hidden Surface Removal• Hidden Surface Removal

• Polygon Clipping

Guoying Zhao 2 / 61Guoying Zhao 2 / 61

Page 3: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

S fHidden Surface Removal

Guoying Zhao 3 / 61Guoying Zhao 3 / 61

Page 4: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C S

Vi ibl S f D t i tiVisible Surface Determination

• DefinitionDefinition– Given a set of 3-D objects and a view

specification (camera) determine whichspecification (camera), determine which lines or surfaces of the object are visible

’ l d VSD t ti• you’ve already seen a VSD step…computing smallest non-negative depth value along a ray

• why might objects not be visible? occlusion vs• why might objects not be visible? occlusion vs. clipping

• clipping is one object at a time while occlusion• clipping is one object at a time while occlusion is global

– Also called Hidden Surface Removal (HSR)Guoying Zhao 4 / 61

– Also called Hidden Surface Removal (HSR)

Page 5: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C S

Photorealistic Image

Guoying Zhao 5 / 61

Page 6: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

GraphicsGraphics Pipeline

3D d l i ld di t

Visible surface detection and rendering process also take place in the pipeline

Geometric transformation in 3D space

3D model in world coordinates

Rasterization

P j i

3D model in world coordinates

2D i iProjection

2D graphics in projection coordinates

2D image in viewport coordinates

Window clipping

Clipped 2D graphics in window coordinates

Transformation from window to viewport

pp g p

Guoying Zhao 6 / 61Guoying Zhao 6 / 612D graphics in viewport coordinates

Page 7: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Visible Surface Determination

• Why to do it?• Why to do it?– Avoiding ambiguity– Improving rendering rates

Guoying Zhao 7 / 61Guoying Zhao 7 / 61

Page 8: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

A idi bi itAvoiding ambiguity

Guoying Zhao 8 / 61Guoying Zhao 8 / 61

Page 9: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

I i d i tImproving rendering rates

Guoying Zhao 9 / 61Guoying Zhao 9 / 61

Page 10: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Hidden Surface Removal Methods• Object space algorithms• Object-space algorithms

Area-Subdivision MethodDepth Sorting Method

• Image-space algorithmsRay Casting MethodZ-buffer

Guoying Zhao 10 / 61Guoying Zhao 10 / 61

Page 11: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Hidden Surface Removal

Obj t h i i t ti• Object-space approach: use pairwise testing between polygons (objects)

partially obscuring can draw independently

• Worst case complexity O(n2) for n polygons

p y obscu g c d w depe de y

Guoying Zhao 11 / 61Guoying Zhao 11 / 6111

Worst case complexity O(n ) for n polygons

Page 12: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Area-Subdivision Method

• It’s applied by successively dividing the total viewing area into smaller and smaller rectangles until each small area is the projection of part of a single visible

Guoying Zhao 12 / 61Guoying Zhao 12 / 61

small area is the projection of part of a single visible surface or no surface at all.

Page 13: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Area-Subdivision Method

Guoying Zhao 13 / 61Guoying Zhao 13 / 61

Page 14: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Possible relationships between polygon surfaces and a rectangular

areaarea– surrounding– overlapping– inside

t id– outside2

4

1

3

1

Guoying Zhao 14 / 61Guoying Zhao 14 / 61

Page 15: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Area-Subdivision Method

• No further subdivisions until:• No further subdivisions until:– All polygons are outside the area– Only one inside, overlapping, or

surrounding polygon is in the area– A surrounding polygon obscures all other

surfaces within the area boundariessu aces t t e a ea bou da es

Guoying Zhao 15 / 61Guoying Zhao 15 / 61

Page 16: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Area-Subdivision Method

F i d ith l ti 2N*2N ft N• For a window with resolution 2N*2N,after N divisions, the obtained sub-window is same to one pixel

Guoying Zhao 16 / 61Guoying Zhao 16 / 61

one pixel.

Page 17: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Depth Sorting Method

Guoying Zhao 17 / 61Guoying Zhao 17 / 61

Painter’s Method

Page 18: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Painter’s Algorithm

• Render polygons a back to front order so that• Render polygons a back to front order so that polygons behind others are simply painted overover

B behind A as seen by viewer Fill B then A

Guoying Zhao 18 / 61Guoying Zhao 18 / 6118

Page 19: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Depth Sort

• Requires ordering of polygons first• Requires ordering of polygons first – O(n log n) calculation for ordering– Not every polygon is either in front or

behind all other polygons

• Order polygons and deal withOrder polygons and deal with easy cases first, harder later

Polygons sorted by distance from COP

Guoying Zhao 19 / 61Guoying Zhao 19 / 6119

Page 20: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Easy Cases

• A lies behind all other polygons– Can render

• Polygons overlap in z but not in either x or y– Can render independently

Guoying Zhao 20 / 61Guoying Zhao 20 / 6120

Page 21: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Hard Cases

Overlap in all directionscyclic overlap

But one is fully on one side of the other

penetration

Guoying Zhao 21 / 61Guoying Zhao 21 / 6121

p

Page 22: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Back-Face Removal (Culling)Back Face Removal (Culling)

θ•face is visible iff 90 ≥ θ ≥ -90equivalently cos θ ≥ 0equivalently cos θ ≥ 0or v • n ≥ 0

I O GL i l bl lli•In OpenGL we can simply enable cullingbut may not work correctly if we have nonconvex objects

Guoying Zhao 22 / 61Guoying Zhao 22 / 6122

Page 23: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Image Space Approach

• Look at each projector (nm for an n x m• Look at each projector (nm for an n x mframe buffer) and find closest of k

lpolygons• Complexity O(nmk)Complexity O(nmk)• Ray tracing • z-buffer

Guoying Zhao 23 / 61Guoying Zhao 23 / 6123

Page 24: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Ray Casting Method

• Cast a ray along the line of sight from a y g gpixel position through a scene

PixelPixel

Guoying Zhao 24 / 61Guoying Zhao 24 / 61

Page 25: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

z-Buffer Algorithm

• Use a buffer called the z or depth buffer to• Use a buffer called the z or depth buffer to store the depth of the closest object at each pixel found so farpixel found so far

• As we render each polygon, compare the depth of each pixel to depth in z bufferof each pixel to depth in z buffer

• If less, place shade of pixel in color buffer and update z bufferupdate z buffer

Guoying Zhao 25 / 61Guoying Zhao 25 / 6125

Page 26: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Frame Buffer and Depth Buffer

Screen Frame buffer Depth Buffer

Color value Depth valueGuoying Zhao 26 / 61Guoying Zhao 26 / 61

Color value Depth value

Page 27: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Z-buffer Method

y

x

Guoying Zhao 27 / 61Guoying Zhao 27 / 61Z

Page 28: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Z-buffer Method

yy

x

x ZGuoying Zhao 28 / 61Guoying Zhao 28 / 61

x Z

Page 29: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Z-buffer Method

y

x

Guoying Zhao 29 / 61Guoying Zhao 29 / 61Z

Page 30: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Z b ff M h dZ-buffer Method

Framebuffer Depth Buffer

-5 -5 -5 -5 -5 -5 -5 -55 5 5 5 5 5 5 5-5 -5 -5 -5 -5 -5 -5 -5

-5 -5 -5 -5 -5 -5 -5 -5-5 -5 -5 -5 -5 -5 -5 -5-5 -5 -5 -5 -5 -5 -5 -55 5 5 5 5 5 5 5-5 -5 -5 -5 -5 -5 -5 -5

Guoying Zhao 30 / 61Guoying Zhao 30 / 61

Page 31: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Z b ff M h dZ-buffer Method

Framebuffer Depth Buffer

-5 -5 -5 -5 -5 -5 -5 -55 5 5 5 5 5 5 5-5 -5 -5 -5 -5 -5 -5 -5

-5 -5 -5 -5 -5 -5 -5 -5-5 -5 -5 -5 -5 -5 -5 -5-5 -5 -5 -5 -5 -5 -5 -55 5 5 5 5 5 5 5-5 -5 -5 -5 -5 -5 -5 -5

Guoying Zhao 31 / 61Guoying Zhao 31 / 61

Page 32: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Z b ff M h dZ-buffer Method

Framebuffer Depth Buffer

-5 -5 -5 -5 -5 -5 -5 -55 5 11 1 1 5 5-5 -5 -1-1 -1 -1 -5 -5

-5 -5 -1 -1 -1 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -55 5 1 1 1 1 5 5-5 -5 -5 -5 -5 -5 -5 -5

Guoying Zhao 32 / 61Guoying Zhao 32 / 61

Page 33: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Z-buffer Method

y

x

Guoying Zhao 33 / 61Guoying Zhao 33 / 61Z

Page 34: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Z-buffer Method

yy

x

x ZGuoying Zhao 34 / 61Guoying Zhao 34 / 61

x Zv

Page 35: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Z b ff M h dZ-buffer Method

Frame buffer Depth Buffer

-5 -5 -5 -5 -5 -5 -5 -55 5 11 1 1 5 5-5 -5 -1-1 -1 -1 -5 -5

-5 -5 -1 -1 -1 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -55 5 1 1 1 1 5 5-5 -5 -5 -5 -5 -5 -5 -5

Guoying Zhao 35 / 61Guoying Zhao 35 / 61

Page 36: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Z b ff M h dZ-buffer Method

Frame buffer Depth Buffer

-5 -5 -5 -5 -5 -5 -5 -55 5 11 1 1 5 5-5 -5 -1-1 -1 -1 -5 -5

-5 -5 2 -1 -1 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -55 5 1 1 1 1 5 5-5 -5 -5 -5 -5 -5 -5 -5

Guoying Zhao 36 / 61Guoying Zhao 36 / 61

Page 37: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Z b ff M h dZ-buffer Method

Frame buffer Depth Buffer

-5 -5 -5 -5 -5 -5 -5 -55 5 11 1 1 5 5-5 -5 -1-1 -1 -1 -5 -5

-5 -5 2 -1 -1 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -55 5 1 1 1 1 5 5-5 -5 -5 -5 -5 -5 -5 -5

Guoying Zhao 37 / 61Guoying Zhao 37 / 61

Page 38: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Z b ff M h dZ-buffer Method

Frame buffer Depth Buffer

-5 -5 -5 -5 -5 -5 -5 -55 5 11 1 1 5 5-5 -5 -1-1 -1 -1 -5 -5

-5 -5 2 1 -1 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -55 5 1 1 1 1 5 5-5 -5 -5 -5 -5 -5 -5 -5

Guoying Zhao 38 / 61Guoying Zhao 38 / 61

Page 39: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Z b ff M h dZ-buffer Method

Frame buffer Depth Buffer

-5 -5 -5 -5 -5 -5 -5 -55 5 11 1 1 5 5-5 -5 -1-1 -1 -1 -5 -5

-5 -5 2 1 -1 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -55 5 1 1 1 1 5 5-5 -5 -5 -5 -5 -5 -5 -5

Guoying Zhao 39 / 61Guoying Zhao 39 / 61

Page 40: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Z b ff M h dZ-buffer Method

Frame buffer Depth Buffer

-5 -5 -5 -5 -5 -5 -5 -55 5 11 1 1 5 5-5 -5 -1-1 -1 -1 -5 -5

-5 -5 2 1 0 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -55 5 1 1 1 1 5 5-5 -5 -5 -5 -5 -5 -5 -5

Guoying Zhao 40 / 61Guoying Zhao 40 / 61

Page 41: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Z b ff M h dZ-buffer Method

Frame buffer Depth Buffer

-5 -5 -5 -5 -5 -5 -5 -55 5 11 1 1 5 5-5 -5 -1-1 -1 -1 -5 -5

-5 -5 2 1 0 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -55 5 1 1 1 1 5 5-5 -5 -5 -5 -5 -5 -5 -5

Guoying Zhao 41 / 61Guoying Zhao 41 / 61

Page 42: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Z b ff M h dZ-buffer Method

Frame buffer Depth Buffer

-5 -5 -5 -5 -5 -5 -5 -55 5 11 1 1 5 5-5 -5 -1-1 -1 -1 -5 -5

-5 -5 2 1 0 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -55 5 1 1 1 1 5 5-5 -5 -5 -5 -5 -5 -5 -5

Guoying Zhao 42 / 61Guoying Zhao 42 / 61

Page 43: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Z b ff M h dZ-buffer Method

Frame buffer Depth Buffer

-5 -5 -5 -5 -5 -5 -5 -55 5 11 1 1 5 5-5 -5 -1-1 -1 -1 -5 -5

-5 -5 2 1 0 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -55 5 1 1 1 1 5 5-5 -5 -5 -5 -5 -5 -5 -5

Guoying Zhao 43 / 61Guoying Zhao 43 / 61

Page 44: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Z b ff M h dZ-buffer Method

Frame buffer Depth Buffer

-5 -5 -5 -5 -5 -5 -5 -55 5 11 1 1 5 5-5 -5 -1-1 -1 -1 -5 -5

-5 -5 2 1 0 -1 -2 -5-5 -5 -1 -1 -1 -1 -5 -5-5 -5 -1 -1 -1 -1 -5 -55 5 1 1 1 1 5 5-5 -5 -5 -5 -5 -5 -5 -5

Guoying Zhao 44 / 61Guoying Zhao 44 / 61

Page 45: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Z b ff M h dZ-buffer Method

Frame buffer Depth Buffer

-5 -5 -5 -5 -5 -5 -5 -55 5 11 1 1 5 5-5 -5 -1-1 -1 -1 -5 -5

-5 -5 2 1 0 -1 -2 -5-5 -5 -1 -5-5 -5 -1 -1 -1 -1 -5 -5

2 1 0 -25 5 1 1 1 1 5 5

-5 -5 -5 -5 -5 -5 -5 -5

Guoying Zhao 45 / 61Guoying Zhao 45 / 61

Page 46: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Z b ff M h dZ-buffer Method

y

x

Guoying Zhao 46 / 61Guoying Zhao 46 / 61Z

Page 47: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Efficiency

• If we work scan line by scan line as we• If we work scan line by scan line as we move across a scan line, the depth h i fchanges satisfy aΔx+bΔy+cΔz=0

Along scan line Δy = 0Δz = - Δxa

c

In screen space Δx = 1Guoying Zhao 47 / 61Guoying Zhao 47 / 61

47

p

Page 48: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Scan-Line Algorithm

• Can combine shading and hsr through• Can combine shading and hsr through scan line algorithm

scan line i: no need for depth information, can only be in noyor one polygon

scan line j: need depth information only when ininformation only when inmore than one polygon

Guoying Zhao 48 / 61Guoying Zhao 48 / 6148

Page 49: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Implementation

• Need a data structure to store• Need a data structure to store– Flag for each polygon (inside/outside)– Incremental structure for scan lines that

stores which edges are encountered – Parameters for planes

Guoying Zhao 49 / 61Guoying Zhao 49 / 6149

Page 50: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Visibility Testing

• In many realtime applications such as games we• In many realtime applications, such as games, we want to eliminate as many objects as possible within the applicationpp– Reduce burden on pipeline– Reduce traffic on bus

• Partition space with Binary Spatial Partition (BSP) Tree

Guoying Zhao 50 / 61Guoying Zhao 50 / 6150

Page 51: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Simple Example

consider 6 parallel polygons

top view

The plane of A separates B and C from D, E and F

Guoying Zhao 51 / 61Guoying Zhao 51 / 6151

Page 52: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

BSP Tree

• Can continue recursively• Can continue recursively – Plane of C separates B from A– Plane of D separates E and F

• Can put this information in a BSP treeCan put this information in a BSP tree– Use for visibility and occlusion testing

Guoying Zhao 52 / 61Guoying Zhao 52 / 6152

Page 53: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Clipping

Guoying Zhao 53 / 61Guoying Zhao 53 / 61

Page 54: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Polygon Clipping

• Not as simple as line segment clipping• Not as simple as line segment clipping– Clipping a line segment yields at most one

li tline segment– Clipping a polygon can yield multiple

polygons

• However, clipping a convex polygon can yield at most one other pol gon

Guoying Zhao 54 / 61Guoying Zhao 54 / 6154

at most one other polygon

Page 55: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Tessellation and ConvexityTessellation and Convexity

• One strategy is to replace nonconvex• One strategy is to replace nonconvex (concave) polygons with a set of triangular polygons (a tessellation)polygons (a tessellation)

• Also makes fill easierT ll ti d i GLU lib• Tessellation code in GLU library

Guoying Zhao 55 / 61Guoying Zhao 55 / 6155

Page 56: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Clipping as a Black Box

• Can consider line segment clipping as a• Can consider line segment clipping as a process that takes in two vertices and

d i h i hproduces either no vertices or the vertices of a clipped line segmentg

Guoying Zhao 56 / 61Guoying Zhao 56 / 6156

Page 57: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Pipeline Clipping of Line SegmentsPipeline Clipping of Line Segments

• Clipping against each side of window is• Clipping against each side of window is independent of other sides– Can use four independent clippers in a

pipeline

Guoying Zhao 57 / 61Guoying Zhao 57 / 6157

Page 58: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Pipeline Clipping of PolygonsPipeline Clipping of Polygons

• Three dimensions: add front and back clippersThree dimensions: add front and back clippers• Strategy used in SGI Geometry Engine• Small increase in latency• Small increase in latency

Guoying Zhao 58 / 61Guoying Zhao 58 / 6158

Page 59: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Bounding Boxes

• Rather than doing clipping on a complex• Rather than doing clipping on a complex polygon, we can use an axis-aligned bounding box or extentbox or extent– Smallest rectangle aligned with axes that

encloses the polygonencloses the polygon– Simple to compute: max and min of x and y

Guoying Zhao 59 / 61Guoying Zhao 59 / 6159

Page 60: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Bounding boxes

Can usually determine accept/rejectCan usually determine accept/reject based only on bounding box

reject

accept

requires detailedclipping

Guoying Zhao 60 / 61Guoying Zhao 60 / 6160

Page 61: Three-Dimensional Graphics IV - University of Oulujiechen/Course/Lecture9/CG_3d_4-C8.pdf · Pipeline 3D d l i ld di t Visible surface detection and rendering process also take place

C O M P U T E R G R A P H I C SC O M P U T E R G R A P H I C S

Clipping and Visibility

• Clipping has much in common with• Clipping has much in common with hidden-surface removal

• In both cases, we are trying to remove objects that are not visible to theobjects that are not visible to the cameraOft i ibilit l i• Often we can use visibility or occlusion testing early in the process to eliminate as many polygons as possible before going through the entire pipeline

Guoying Zhao 61 / 61Guoying Zhao 61 / 6161

g g g p p


Recommended