27
May 2012 1 Visible Surface Detection Shmuel Wimer Bar Ilan Univ., Eng. Faculty Technion, EE Faculty

Visible Surface Detection

  • Upload
    zinna

  • View
    39

  • Download
    0

Embed Size (px)

DESCRIPTION

Visible Surface Detection. Shmuel Wimer Bar Ilan Univ., Eng. Faculty Technion, EE Faculty. Back-Face Detection. view plane. Depth-Buffer Methods. Three surfaces overlapping pixel position (x,y) on the view plane. The visible surface, S 1 , has the smallest depth value. - PowerPoint PPT Presentation

Citation preview

Page 1: Visible Surface Detection

May 2012 1

Visible Surface Detection

Shmuel WimerBar Ilan Univ., Eng. Faculty

Technion, EE Faculty

Page 2: Visible Surface Detection

May 2012 2

Back-Face Detection

A point , , is behind a polygon surface if 0,

where , , and are the plane parameters of the polygon. Test is

simplified by considering normal of face and viewing direction.

x y z Ax By Cz D

A B C D

, ,A B CN

viewV

view

view

A polygon is back face if 0. In a right-handed

viewing system viewing direction is along negative axis,

0,0, 1 . Then, a polygon is a back face if 0.

z

C

V N

V

Page 3: Visible Surface Detection

May 2012 3

Depth-Buffer Methods

Three surfaces overlapping pixel position (x,y) on the view

plane. The visible surface, S1, has the smallest depth value.

vxvy

vz

3S2S

1S

,x y

view plane

Page 4: Visible Surface Detection

May 2012 4

Initialize each pixel ( , ) of depth buffer and frame buffer (color):

, 1. // Z is normalized to [0,1.0]

//

0;

, background color; initialize

for ea

to backgroun

h

d

c p

x y

depthBuf x y

frameBuf x y

Z - Buffer Algorithm

olygon {

for each pixel , polygon {

if

// traverse all polygons

// rasterization

//( , , ) {

get (compute) , ;

check closer pixel

// compute color of pix

el

x y

z x y depthBuf x y

color x y

d

, , ; , , ;

}}}

epthBuf x y z x y frameBuf x y color x y

Page 5: Visible Surface Detection

May 2012 5

Efficient Depth Calculation

Given the depth value in a vertex of a polygon, the depth

of any other point in the plane containing the polygon can

be calculated efficiently (additions only).

Depth is calculated from plane equatuion .

At rasterization along scan-line changes by 1. Therefore,

1 1 , and the ratio

is constant for the entire polygon.

z Ax By D C

x

z x A x By D C z A C A C

Page 6: Visible Surface Detection

May 2012 6

Scanning can start at the top vertex of polygon and

obtain the first depth value. Progressing from scan line

to next one y is decreased by 1, which eases the depth

calculation of first pixel along the scan line.

top scan line

y scan line

y+1 scan line

x x`

Page 7: Visible Surface Detection

May 2012 7

If is the slope of the edge then 1 . Therefore the

depth at first pizel in new scan line is .

All values of 1 can be stored in a lookup table (memory).

is calculated once for the

m x x m

z z A m B C

m

A m B C

entire edge, and

and calculated once for the entire polygon.A C B C

The starting point of scan line can use mid-point method

or Bernsham-type algorithm.

If the edge is vertical the slope is infinite and .z z B C

Page 8: Visible Surface Detection

May 2012 8

A-Buffer Method

It is named so since z-buffer is used for depth semantics and

in some sense a-buffer has the nature of the other end of

alphabet. It is an extension using antialiasing, area-averaging

visibility detection method, supporting transparency.

background opaque surface

foreground transparent surface

Page 9: Visible Surface Detection

May 2012 9

Projection reference point

Ray Tracing

opaque

opaque

transparent

Page 10: Visible Surface Detection

May 2012 10

Highly realistic. It detects visibility, transparency, shadows,

illumination effects, and generates perspective views.

Computational intensive.

Page 11: Visible Surface Detection

May 2012 11

3S transparent

1S transparent

2S opaque

4S opaque

Projection reference point

Binary Ray-Tracing Tree

1R1T 1S

1R 1T

4S

4R

2S

2R

3R3T

3S

3R 3T

4R

2R

Page 12: Visible Surface Detection

May 2012 12

Left branches represent reflection paths, right

branches represent transmission paths.

A path is terminated if any of the following occurs:

The ray intersects no surface.

The ray intersects a light source that is not a reflecting surface.

The tree reached a depth limit.

Page 13: Visible Surface Detection

May 2012 13

u – incoming ray

R – unit reflected ray

L – unit vector pointing to light source

N – unit surface normal

u

R

L

ΝH

H – unit vector half way between –u and L

Page 14: Visible Surface Detection

May 2012 14

The paths along the

direction of L is referred

as the shadow ray.

source.

For reflection path there exists 2 ,

hence, 2 .

R u u N N

R u u N N

If any object intersects the shadow ray between the

surface and the point light source, the surface position

is in shadow with respect to that source.

Page 15: Visible Surface Detection

May 2012 15

r

iu

T

N

In transparent surface light is transmitted through

material. The unit transmission vector T is obtained

from u and N and refraction indices.

cos cosi ir i

r r

T u N

2 2cos 1 1 cosr i r i

Page 16: Visible Surface Detection

May 2012 16

Calculating Pixel Intensity

It works bottom up, where the intensity at a child node

is added to parent with an attenuation relative to the

distance of the child’s surface from the parent’s

surface. The intensity assigned to the pixel is the sum

of attenuated intensities at the root.

If the primary ray for a pixel doesn’t intersect with an

object of the scene, the ray-tracing tree is empty and

the pixel is assigned the background intensity.

Page 17: Visible Surface Detection

May 2012 17

Ray-Surface Intersection Calculations

projection reference point

pixel point

0P

x

y

z

u

0

0

A point along the ray at distance from is given

by .

s

s P

P P u

pixel 0 pixel 0Unit vector along initial ray path is | |. u P P P P

0At each surface intersection and are updated acoording

to and .

P u

R T

Page 18: Visible Surface Detection

May 2012 18

Ray-tracing is computations intensive, requiring root

finding to get the value of parameter s at ray-surface

incidence point. Efficient techniques exists for spherical,

planar and also spline surfaces.

xz

yP

cP0Pu

r

2 2 2 20| | 0 | | 0.c cr s r P P P u P

Ray-Sphere Intersections

Page 19: Visible Surface Detection

May 2012 19

2 2 20

2 2 2

Set , then 2 | | 0.

At intersection there exists

| | .

c s s r

s r

P P ΔP u ΔP ΔP

u ΔP u ΔP ΔP

If the discriminant is negative then either the ray

doesn’t intersect the sphere or the sphere is behind P0.

In either case the sphere is eliminated from further

consideration.

Page 20: Visible Surface Detection

May 2012 20

2 2 2

2 2

| | is susceptible to

round-off error if the sphere is small and very far,

since | | .

s r

r

u ΔP u ΔP ΔP

ΔP

2 2

This can be avoided in most cases by the

rearrangement | | ,

yielding two terms of same order of magnitude.

s r u ΔP ΔP u ΔP u

Page 21: Visible Surface Detection

May 2012 21

Ray-Polyhedron Intersections

Computing intersection with polyhedron is expensive. It is

useful to include polyhedron in the smallest enclosing

sphere and exclude any intersection calculation if the ray

doesn’t intersect the sphere.

00

Front faces of the polyhedron are identified first by 0.

For those we find first the intersection point of the ray with

face's plane D

D s D s

u N

N PN P N P u

N u

Page 22: Visible Surface Detection

May 2012 22

To find whether the point is within the face an odd-

even test is in order. Among all the faces intersected

by the ray, the one with the smallest s is chosen. If

there’s no intersection with any face, the polyhedron is

excluded from further consideration.

Page 23: Visible Surface Detection

May 2012 23

Reducing Intersection Calculations

Ray tracer consumes 95% time on intersection

calculations. It is possible to enclose groups of adjacent

objects in spheres, calculate intersection with enclosing

sphere first, and proceed to real objects only if intersection

exists.

Another approach is space-subdivision, where the entire

scene is enclosed with a cube. The cube is successively

divided into smaller cubes until the number of spaces

contained in a cube exceeds a predefined limit or the

size of cube reaches some threshold.

Page 24: Visible Surface Detection

May 2012 24

pixel ray

Cells are traced through the individual cells. intersection

tests are performed only for cells containing surfaces.

The first intersected surface is the visible for that ray.

Page 25: Visible Surface Detection

May 2012 25

1N

2N

3N

inP

outP

u

inGiven a unit vector of the ray and the entry point , the

candidate faces of exit point are those satisfying 0.k u P

u N

1

2

3

1,0,0

0, 1,0

0,0, 1

N

N

N

out, in

in out, out,

The exit point satisfies , is the distance along

the ray from to . Exit point satisfies .

k k k

k k k k

s s

D

P P u

P P N P

Page 26: Visible Surface Detection

May 2012 26

inSolving for yields .

The smallest value of defines the exit face. k k k k k

k

s s D

s

N P N u

Notice that other 2 intersection must occure outside

the cube since cube is convex. It is a good practice

to look at the largest component of and start with

the face on the perpendicular plane.

u

Page 27: Visible Surface Detection

May 2012 27

3

7

8

0

2

4

1

6

5

Consider the cube plane attempted

for exit point calculation. The cube

face divides the plane into nine

sectors. If the exit point is falling in

sector 0 we are done. If it is falling

in any of 1, 3, 2 or 4 we know the

face containing the exit point and

then can find it. In case of 5, 6, 7

and 8 further test is required.