0% found this document useful (0 votes)
58 views27 pages

Visible Surface Detection

This document discusses various computer graphics algorithms for visible surface detection and ray tracing. It begins by describing back-face detection and depth-buffer methods for determining visibility. It then explains the z-buffer and a-buffer algorithms in more detail. The document also covers ray tracing techniques including calculating ray-surface intersections, reflections, refractions, shadows, and calculating pixel intensities. It discusses optimizations like space subdivision and bounding volumes to reduce computation costs.

Uploaded by

Thomas Cyriac
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views27 pages

Visible Surface Detection

This document discusses various computer graphics algorithms for visible surface detection and ray tracing. It begins by describing back-face detection and depth-buffer methods for determining visibility. It then explains the z-buffer and a-buffer algorithms in more detail. The document also covers ray tracing techniques including calculating ray-surface intersections, reflections, refractions, shadows, and calculating pixel intensities. It discusses optimizations like space subdivision and bounding volumes to reduce computation costs.

Uploaded by

Thomas Cyriac
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 27

Visible Surface Detection

Shmuel Wimer
Bar Ilan Univ., Eng. Faculty
Technion, EE Faculty

May 2012

Back-Face Detection
A point x, y, z is behind a polygon surface if Ax By Cz D 0,
where A, B, C and D are the plane parameters of the polygon. Test is
simplified by considering normal of face and viewing direction.
N A, B, C

Vview

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


viewing system viewing direction is along negative z axis,
Vview 0, 0, 1 . Then, a polygon is a back face if C 0.
May 2012

Depth-Buffer Methods
S3

S2

S1

view plane

yv

xv

x, y

zv

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


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

Z - Buffer Algorithm
Initialize each pixel ( x, y ) of depth buffer and frame buffer (color):
depthBuf x, y 1.0; // Z is normalized to [0,1.0]
frameBuf x, y background color; // initialize to background
for each polygon { // traverse all polygons
for each pixel x, y polygon { // rasterization
if (z x, y depthBuf x, y ) { // check closer pixel
get (compute) color x, y ; // compute color of pixel
depthBuf x, y z x, y ; frameBuf x, y color x, y ;
}}}
May 2012

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 z Ax By D C .
At rasterization x along scan-line changes by 1. Therefore,
z x 1 A x 1 By D C z A C , and the ratio A C
is constant for the entire polygon.

May 2012

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
May 2012

x`
6

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


depth at first pizel in new scan line is z z A m B C .
All values of 1 m can be stored in a lookup table (memory).

A m B

C is calculated once for the entire edge, and

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

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

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


or Bernsham-type algorithm.
May 2012

A-Buffer Method
background
opaque surface
foreground
transparent
surface

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.
May 2012

Ray Tracing
opaque
opaque

transparent
Projection
reference
point

May 2012

Highly realistic. It detects visibility, transparency, shadows,


illumination effects, and generates perspective views.
Computational intensive.

May 2012

10

Binary Ray-Tracing Tree


R4

S3 transparent
T3

Projection
reference
point

S 4 opaque

R3
R1

R2
T1

S 2 opaque

S1

R1

T1

S3

S1 transparent

R3

S2
T3

R2

S4
R4

May 2012

11

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.

May 2012

12

u incoming ray

R unit reflected ray


N unit surface normal
L unit vector pointing to light source
H unit vector half way between u and L
May 2012

13

The paths along the


direction of L is referred
as the shadow ray.
source.
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.

For reflection path there exists R u 2 u N N,


hence, R u 2u N N.
May 2012

14

In transparent surface light is transmitted through


material. The unit transmission vector T is obtained
from u and N and refraction indices.

i
i
T u cos r cos i N
r
r

T
u

May 2012

cos r 1 i r

1 cos 2 i

15

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 childs surface from the parents
surface. The intensity assigned to the pixel is the sum
of attenuated intensities at the root.
If the primary ray for a pixel doesnt intersect with an
object of the scene, the ray-tracing tree is empty and
the pixel is assigned the background intensity.
May 2012

16

Ray-Surface Intersection Calculations


projection
reference point

pixel point

y
P0

u
x

A point along the ray at distance s from P0 is given


by P P0 su.

Unit vector along initial ray path is u Ppixel P0 | Ppixel P0 |.

At each surface intersection P0 and u are updated acoording


to R and T.

May 2012

17

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.
P

Ray-Sphere
Intersections

P0

Pc

| P Pc |2 r 2 0 | P0 su Pc |2 r 2 0.
May 2012

18

Set Pc PP
0

, then s 2 u2 P

|
s P

|2 r 2 0.

At intersection there exists


s uP

u P

P
|
|2
r2 .

If the discriminant is negative then either the ray


doesnt intersect the sphere or the sphere is behind P0.
In either case the sphere is eliminated from further
consideration.

May 2012

19

s uP

u P

P
|
|2 r2 is susceptible to

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


2

since r =| P | .

This can be avoided in most cases by the


rearrangement s uP

r P
|
u P
u | ,
2

yielding two terms of same order of magnitude.


May 2012

20

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
doesnt intersect the sphere.

Front faces of the polyhedron are identified first by u N 0.


For those we find first the intersection point of the ray with
face's plane N P D N P0 su
May 2012

D N P0

D s
N u
21

To find whether the point is within the face an oddeven test is in order. Among all the faces intersected
by the ray, the one with the smallest s is chosen. If
theres no intersection with any face, the polyhedron is
excluded from further consideration.

May 2012

22

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.
May 2012

23

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.

May 2012

24

N2

u
Pin

N1

Pout

N1 1, 0, 0
N 2 0, 1, 0
N3 0, 0, 1

N3

Given a unit vector u of the ray and the entry point Pin , the
candidate faces of exit point are those satisfying u N k 0.
The exit point satisfies Pout,k Pin sk u, sk is the distance along
the ray from Pin to Pout,k . Exit point satisfies N k Pout,k Dk .
May 2012

25

Solving for sk yields sk Dk N k Pin

N k u .

The smallest value of sk defines the exit face.


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 u and start with
the face on the perpendicular plane.

May 2012

26

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

1
5
2

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

0
4

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


and 8 further test is required.

May 2012

7
3

27

You might also like