45
Einführung in Visual Computing Einführung in Visual Computing 186.822 Visible Surface Detection Visible Surface Detection W P hf Werner Purgathofer

Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Einführung in Visual ComputingEinführung in Visual Computing186.822

Visible Surface DetectionVisible Surface Detection

W P h fWerner Purgathofer

Page 2: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Visibility in the Rendering PipelineVisibility in the Rendering Pipelinebj t t / tiobject capture/creation

bj t i bj tmodeling

scene objects in object spacemodelingviewing vertex stageviewing

projection

g(„vertex shader“)

projectiont f d ti i li

clipping + homogenizationtransformed vertices in clip space

clipping + homogenizationi li d d i di t

viewport transformationscene in normalized device coordinates

t i tiviewport transformation

rasterizationh di pixel stageshading pixel stage

(„fragment shader“)2raster image in pixel coordinates

(„fragment shader )

Page 3: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

3D Display: Wireframe Display3D Display: Wireframe Display

© ZwCAD Software Co.,Ltd

Werner Purgathofer 3

Page 4: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

3D Display: Depth Cueing3D Display: Depth Cueing

= or ??

depth cueing = intensity decreasesdepth cueing = intensity decreases with increasing distancewith increasing distance

Werner Purgathofer 4

Page 5: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

3D Display: Visibility3D Display: Visibility

visible line and surface identificationvisible line and surface identification

= or != or !

© ZwCAD Software Co.,Ltd,

Werner Purgathofer  5

Page 6: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

3D Display: Visibility3D Display: Visibility

© Snaptu© Snaptu

Werner Purgathofer 6

Page 7: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

3D Display: Depth Cueing + Visibility3D Display: Depth Cueing + Visibility

only visible linesonly visible linesi t it dintensity decreases ith i i di twith increasing distance

© Gerschon Elber

Werner Purgathofer 7

Page 8: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

3D Display: Shaded Display3D Display: Shaded Display

© ZwCAD Software Co.,Ltdshading + depth cueing: ,shading + depth cueing:

8© Ansgar Philippsen

Page 9: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Visible‐Surface DetectionVisible Surface Detectionidentifying visible parts of a scene (also hidden surface elimination)(also hidden‐surface elimination)type of algorithm depends on:type of algorithm depends on: 

complexity of scenecomplexity of scenetype of objectstype of objectsavailable equipmentavailable equipmentstatic or animated displaysstatic or animated displays

object‐spacemethodsobject spacemethodsobjects compared to each otherobjects compared to each other

image spacemethodsimage spacemethodspoint by point at each pixel locationp y p p

often sorting and coherence usedWerner Purgathofer 9

g

Page 10: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Visible‐Surface Detection MethodsVisible Surface Detection Methods

the following algorithms are examples for different classes of methods

back‐face detectiondepth buffer methoddepth buffer methodscan‐line methodscan line methoddepth sorting methoddepth‐sorting method

bdi i i th darea‐subdivision methodh doctree methods

ray‐casting method

Werner Purgathofer 10

Page 11: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Back‐Face Detection (1)Back Face Detection (1)

surfaces (polygons) with a surface normal pointing away from the eye (p yg ) p g y ycannot be visible (back faces)( )

eliminate them before visibility algorithm ! eliminate them before visibility algorithm !

viewingviewing direction

direction

b li i t dcan be eliminated:Werner Purgathofer 11

Page 12: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Back‐Face Detection (2)Back Face Detection (2)eliminating back faces of closed polyhedraview point (x,y,z) “inside” a polygon surface if

Ax + By + Cz + D < 0or polygon with normal N=(A B C) is a back face if

yor polygon with normal N=(A, B, C) is a back face if

0NV 0 NVviewN = (A, B, C)

VVview

Werner Purgathofer 12

Page 13: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Back‐Face Detection (3)Back Face Detection (3)

object description in viewing coordinates  Vview = (0,0,Vz)view z

CVNV i s ffi ient ondition if C 0 then ba k fa e

CVNVview z

sufficient condition: if C 0 then back‐face negative !

yvz N = (A, B, C)zv

x Vxv Vview

Werner Purgathofer 13

Page 14: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Back‐Face Detection (4)Back Face Detection (4)

complete visibility test for non‐overlapping convex polyhedra

f i ll hiddface partially hiddenb h fby other faces

preprocessing step for other objects:preprocessing step for other objects:b f f l dabout  50% of surfaces are eliminated

Werner Purgathofer 14

Page 15: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Depth‐Buffer Method (1)Depth Buffer Method (1)z‐buffer methodimage‐space methodhardware implementationno sorting!

Werner Purgathofer 15

Page 16: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Depth‐Buffer Method (2)Depth Buffer Method (2)two buffers

( )refresh buffer (intensity information)d h b ff (di i f i )depth buffer (distance information)

size corresponds to screen resolutionp(for every pixel: r, g, b, z)

d thidraw something =ith i b ff• compare z with z in buffer

if l t i• if z closer to viewerth d d d t i b ff• then draw and update z in bufferl thi !• else nothing! 

Werner Purgathofer 16

Page 17: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Depth‐Buffer Algorithm ExampleDepth Buffer Algorithm Example

polygons withp ygcorresponding

3 3.8 .7p g

z-values .3 .33 3

.7 .6 .6 .56 5

.44.3 .3 .6 .5 .4

backimage

back-groundimage ground

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1depth- 8 7 8 7

-1 -1 -1 -11 1 1 1

-1 -1 -1 -11 1 1 1

-1 -1 -1 -11 1

-1 -1 -1 -11 1depth

buffer 3 3.8 .77 6 3 7 66

.8 .73

-1 -1 -1 -1-1 -1 -1 -1

-1 -1 -1 -1-1 -1

-1 -1-1

-1 -1buffer .3 .3

.3 .3.7 .6 .3

.3 .3.7 .6.6

.6 .5 .4.3.3

1 1 1 1-1 -1 -1 -1

1 1-1 -1

1-1 -1

Werner Purgathofer 17

3 3 3 3 6 5 3

Page 18: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Depth‐Buffer AlgorithmDepth Buffer Algorithm

for all (x,y)frameBuff(x,y) = backgroundColor( ,y) gdepthBuff(x,y) = -1 p ( ,y)

for each polygon Pfor each polygon Pfor each position (x y) on polygon Pfor each position (x,y) on polygon Pcalculate depth zcalculate depth zif z > depthBuff(x y) thenif z > depthBuff(x,y) thend thB ff( )depthBuff(x,y) = zframeBuff(x,y) = surfColor(x,y)

Werner Purgathofer 18

Page 19: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Depth‐Buffer: Incremental z‐ValuesDepth Buffer: Incremental z Values

depth at (x,y): z = AxByDdepth at (x,y): z = C

d th t ( 1 ) A(x+1)ByD Adepth at (x+1,y): z' = A(x 1) By DC = z C

AC C

Ax B(y 1) D Bdepth at (x,y‐1): z" = AxB(y1)DC = z C

BC C

constants !y constants !y

y–1y 1

x x+1

Werner Purgathofer 19

Page 20: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Depth‐Buffer: y‐Coordinate IntervalsDepth Buffer: y Coordinate Intervals

determine y‐coordinate extents of polygon Pdetermine y coordinate extents of polygon P

top scan line

y scan linel ft d

yleft edge i t tiintersection

bottom scan linebotto sca e

Werner Purgathofer 20

Page 21: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Depth‐Buffer: Values down an EdgeA B D

Depth Buffer: Values down an Edge

z = AxByDCz C

z' A(x1/m)B(y1)Dy' = y 1 z' = ( ) (y )

Cx' = x 1/m

A/m + B= z Cli Cy scan line(y – 1) scan line constant !(y  1) scan line

x x'Werner Purgathofer 2121

x x

Page 22: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Scan‐Line MethodScan Line Method

image‐space methodextension of scan‐line algorithm for polygon filling

Werner Purgathofer 22

Page 23: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Scan‐Line Method: Edge & Polygon TablesScan Line Method: Edge & Polygon Tables

edge table (all edges y‐sorted)edge table (all edges, y sorted)coordinate endpointscoordinate endpointsinverse slopeinverse slopepointers into polygon tablep p yg

polygon table (all polygons)coefficients of plane equationintensity information( i i d bl )(pointers into edge table)

Werner Purgathofer 23

Page 24: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Scan‐Line Method: Active Edge ListScan Line Method: Active Edge List

active edge list (all edges crossing current scanline, x‐sorted, flag)

Werner Purgathofer 24

Page 25: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Scan‐Line Method ExampleScan Line Method ExampleEdge Table: 2,3,1,5,1,1,2,2,5,4,3,3,4,4 Polygon Table:  , ,

active edges active polygons2 3,2

31 51 2 1 3 1

1 11 5

1,5,2,1,3,1 , , 1

2 122 4 2,2,5,3,1,5 , ,

533

533,3,1,5 , 3 3,3,1,5 ,

4 3,1 Werner Purgathofer / Computergraphik 1 254

Page 26: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Scan‐Line Method ‐ CoherenceScan Line Method  Coherencecoherence between adjacent scan lines

incremental calculationsi d li i ilactive edge lists very similar

(easy sorting avoid depth calculations)(easy sorting, avoid depth calculations)

26Werner Purgathofer / Einführung in Visual Computing

Page 27: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Depth‐Sorting Method: OverviewDepth Sorting Method: Overview

surfaces sorted in order of decreasing depth (viewing in z‐direction)

“approximate”‐sorting using smallest z‐value (greatest depth)pp g g (g p )fine‐tuning to get correct depth orderfine tuning to get correct depth order

surfaces scan converted in ordersurfaces scan converted in orderti b th i i d bj tsorting both in image and object space

scan conversion in image spacealso called “painter’s algorithm”

Werner Purgathofer 27

Page 28: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Depth‐Sorting Method: Sorting (1)Depth Sorting Method: Sorting (1)

surface S with greatest depth is compared to all other surfaces S'

no depth overlap  ordering correctp p gdepth overlap z idepth overlap do further tests in 

zminS

increasing order gof complexity zmax

z'min S'min S

2 surfaces with no depth overlap z'maxf p pviewing x

Werner Purgathofer 28

viewing direction

xz

Page 29: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Depth‐Sorting Method: Sorting (2)Depth Sorting Method: Sorting (2)

ordering correct ifbounding rectangles in xy‐plane do not overlapg g y p pcheck x‐,y‐direction separatelycheck x ,y direction separately

viewing2 surfaces with depth

viewingdirection S'2 surfaces with depth 

overlap but no overlap SS

overlap but no overlap in the x‐direction

Sin the x‐direction

x x x' x' xzWerner Purgathofer 29

xmin xmax x min x max xz

Page 30: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Depth‐Sorting Method: Sorting (3)Depth Sorting Method: Sorting (3)

ordering correct ifS completely behind S'p ysubstitute vertices of S into equation of S'substitute vertices of S into equation of S

overlap in z‐directionoverlap in x‐directionS

viewing directionS is completely directionp y

behind (“inside”) S'( )the overlapping S'pp g

xzWerner Purgathofer 30

z

Page 31: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Depth‐Sorting Method: Sorting (4)Depth Sorting Method: Sorting (4)

ordering correct ifS' completely in front of Sp ysubstitute vertices of S' into equation of Ssubstitute vertices of S  into equation of S

overlap in x‐ and z‐direction

l i S' i l t l i Soverlapping S' is completely in f t (“ t id ”) f S b t S i viewing 

directionfront (“outside”) of S, but S is 

t l t l b hi d S’ directionnot completely behind S’S'

xzWerner Purgathofer 31

z

Page 32: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Depth‐Sorting Method: Sorting (4)Depth Sorting Method: Sorting (4)

ordering correct ifS' completely in front of Sp ysubstitute vertices of S' into equation of Ssubstitute vertices of S  into equation of S

SS is not completely behind

viewing direction

S is not completely behind (“inside”) the overlapping S' direction( inside ) the overlapping S

S'

xzWerner Purgathofer 32

z

Page 33: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Depth‐Sorting Method: Sorting (5)Depth Sorting Method: Sorting (5)

ordering correct ifprojections of S, S' in xy‐plane don’t overlapp j , y p p

surfaces with overlapping bounding rectanglesWerner Purgathofer 33

Page 34: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Depth‐Sorting Method: Sorting (6)Depth Sorting Method: Sorting (6)all five tests fail 

ordering probably wrongi h f S S'interchange surfaces S, S'

t f d d frepeat process for reordered surfaces

SSS'

viewingS

S'S

viewing direction

SS"

xz xzxz

sorted surface list: S, S', S" should be surface S has greater depth Werner Purgathofer / Computergraphik 1 34 reordered: S', S", Sbut obscures S'

Page 35: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Depth‐Sorting: Special CasesDepth Sorting: Special Cases

avoiding infinite loops due to cyclic overlapreordered surfaces S' are flaggedggif S' would have to be reordered again divide S' into two partsif S  would have to be reordered again  divide S  into two parts 

intersecting or cyclically overlapping surfaces!

35Werner Purgathofer / Einführung in Visual Computing

Page 36: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Area‐Subdivision Method (1)Area Subdivision Method (1)

image‐space methodarea coherence exploitedviewing area subdivided until visibility decision very easyg y y y

Werner Purgathofer 36

Page 37: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Area‐Subdivision Method (2)Area Subdivision Method (2)

relationship polygon  rectangular view area

inside outside  surrounding overlapping surfacesurface surfacesurface

only these four possibilitiesonly these four possibilities

Werner Purgathofer 37

Page 38: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Area‐Subdivision Method (3)

th i ibilit d i iArea Subdivision Method (3)three easy visibility decisions

ll f t id f i iall surfaces are outside of viewing area

only one inside, overlapping, or surrounding surface is in y , pp g, gthe area

one surrounding surface obscures all other surfaces withinone surrounding surface obscures all other surfaces within the viewing areathe viewing area

Werner Purgathofer 38

Page 39: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Area‐Subdivision Method (4)Area Subdivision Method (4)

a surrounding obscuring surfacesurfaces ordered according to minimum depthg pmaximum depth of surrounding surface closest to view plane?maximum depth of surrounding surface closest to view plane?test is conservativetest is conservative

viewingzmax

viewing direction

dizmin

surroundingsurface

xz area

Werner Purgathofer 39

Page 40: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Area‐Subdivision Method (5)Area Subdivision Method (5)

if all three tests fail  do subdivisionsubdivide area into four equal subareasqoutside and surrounding surfaces will remain in this status for alloutside and surrounding surfaces will remain in this status for all subareassome inside and overlapping surfaces will be eliminatedsome inside and overlapping surfaces will be eliminated

if no further subdivision possible (pixel resolution reached)if no further subdivision possible (pixel resolution reached)t f d t k i t it f t fsort surfaces and take intensity of nearest surface

Werner Purgathofer 40

Page 41: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Area‐Subdivision Method ExampleArea Subdivision Method Example

1 21 23 43 4

finishedfinished

Werner Purgathofer

Page 42: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Octree MethodsOctree Methods

recursive traversal of octreetraversal order depends on processing direction p p g

front‐to‐back:front to back: pixel(x y) written oncepixel(x,y) written oncecompletely obscuredcompletely obscured nodes are not traversednodes are not traversed

b k t f tback‐to‐front:i ipainter’s algorithm viewing

direction

Werner Purgathofer 42

Page 43: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Octree MethodsOctree Methods

recursive traversal of octreetraversal order depends on processing direction p p g

front‐to‐back:front to back: pixel(x y) written oncepixel(x,y) written oncecompletely obscured

viewing directioncompletely obscured 

nodes are not traverseddirection

nodes are not traversedb k t f tback‐to‐front:

painter’s algorithm

Werner Purgathofer 43

Page 44: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Ray‐Casting Method (1)Ray Casting Method (1)

line‐of‐sight of each pixel is intersected with all surfacestake closest intersected surface

closestclosest intersectionviewing 

di ti intersectionpointdirection

Werner Purgathofer 44

p

Page 45: Visible Surface Detection · 2015. 5. 12. · Ray‐Casting Method (2) based on geometric optics, tracing paths of light rays backward tracing of light rays suitable for complex,

Ray‐Casting Method (2)Ray Casting Method (2)

based on geometric optics, tracing paths of light raysbackward tracing of light raysg g ysuitable for complex curved surfacessuitable for complex, curved surfacesspecial case of ray tracing algorithmsspecial case of ray‐tracing algorithmsff f hefficient ray‐surface intersection techniques necessaryintersection pointnormal vector

Werner Purgathofer 45