CS 430/585 Computer Graphics I 3D Clipping Backface Culling, Z-buffering, Ray Casting, Ray Tracing Week 7, Lecture 14 - PowerPoint PPT Presentation

About This Presentation
Title:

CS 430/585 Computer Graphics I 3D Clipping Backface Culling, Z-buffering, Ray Casting, Ray Tracing Week 7, Lecture 14

Description:

Ray Casting, Ray Tracing. Week 7, Lecture 14. David Breen, William ... Snell's Law: i sin i = t sin. t Let = i / t =sin t / sin. i Let m = (cos i n - i) / sin ... – PowerPoint PPT presentation

Number of Views:324
Avg rating:3.0/5.0
Slides: 40
Provided by: willia69
Category:

less

Transcript and Presenter's Notes

Title: CS 430/585 Computer Graphics I 3D Clipping Backface Culling, Z-buffering, Ray Casting, Ray Tracing Week 7, Lecture 14


1
CS 430/585Computer Graphics I3D
ClippingBackface Culling,Z-buffering,Ray
Casting, Ray TracingWeek 7, Lecture 14
  • David Breen, William Regli and Maxim Peysakhov
  • Geometric and Intelligent Computing Laboratory
  • Department of Computer Science
  • Drexel University
  • http//gicl.cs.drexel.edu

2
Overview
  • 3D Clipping
  • Advanced topics
  • Z-buffering
  • Back-Face Culling
  • Ray Tracing (Ray Casting)

1994 Foley/VanDam/Finer/Huges/Phillips ICG
3
Simple Mesh Format (SMF)
  • Michael Garland http//graphics.cs.uiuc.edu/garla
    nd/
  • Triangle data
  • Vertex indices begin at 1

4
3D Clipping
  • Cohen-Sutherland and Cyrus-Beck can be trivially
    extended to 3D
  • We will cover
  • Cohen-Sutherland for 3D, (parallel projection)
  • Cohen-Sutherland for 3D, (perspective projection)

5
Recall Cohen-Sutherland
  • Line is completely visible iff both code values
    of endpoints are 0, i.e.
  • If line segments are completely outside the
    window, then

Pics/Math courtesy of Dave Mount _at_ UMD-CP
6
Cohen-Sutherland for 3D,Parallel Projection
  • Use 6 bits
  • Trivially accept if both end-codes are 0
  • Trivially reject if bit-by-bit AND of end-codes
    is not 0
  • Up to 6 intersections may have to be computed

7
Cohen-Sutherland for 3D computing intersection
points.
  • Use parametric representation of the line to
    compute intersections
  • So for y1 replace y with 1 and solve for t
  • If 1 ? t ? 0 use it to find x and z
  • Test if x and z are in valid range
  • Repeat for planes y-1, x1, x-1, z-1, z0

8
Cohen-Sutherland for 3D, Perspective Projection
  • Use 6 bits identical to parallel view volume
    clipping
  • Conditions on the codes are different
  • Trivially accept/reject lines using same roles
  • Intersection points computed differently

9
Cohen-Sutherland for 3D computing intersection
points.
  • Intersections with planes z-1, zzmin is the
    same.
  • Calculating intersections with a sloping plane
  • For plane yz these two equations are equal
  • Repeat for planes y-z, xz, x-z

10
Clipping in Homogeneous Coordinates
  • Same algorithm for clipping parallel and
    perspective view volumes
  • Avoid problems of clipping rational parametric
    splines
  • Transform canonical perspective view volume to
    canonical parallel view volume

11
Application of Matrix M
  • If using Nper we can always clip against the
    parallel projection View Volume
  • Nper M Sper SHpar T(-PRP) R T(-VRP)

Before
After
12
Homogeneous Clipping
  • 3D parallel view-volume defined by
  • -1 ? x ? 1, -1 ? y ? 1, -1 ? z ? 0
  • -1 ? X/W ? 1, -1 ? Y/W ? 1, -1 ? Z/W ? 0
  • We must change the inequalities for W lt0
  • W gt0 - W ? X ? W,
    - W ? Y ? W,
    - W ? Z/W ? 0
  • W lt0 - W ? X ? W,
    - W ? Y ? W,
    - W ? Z/W ? 0

1994 Foley/VanDam/Finer/Huges/Phillips ICG
13
Homogeneous Clipping
  • Clip once for W gt0 and once for W lt0
  • Too much work
  • For each point P with W lt0 find symmetric 1P
    and clip it

1994 Foley/VanDam/Finer/Huges/Phillips ICG
14
More Efficient Alternative?
  • Use Cohen-Sutherland to do trivial accept/reject
  • Project remaining edges onto view plane
  • Clip lines in 2D

15
end clipping
16
Mesh/Faceted Model
17
Back-Face Culling
  • Assumptions
  • Object approximated as closed polyhedron
  • Polyhedron interior is not exposed by the front
    cutting plane
  • Eye-point not inside object
  • Polygons not facing the viewer called Back-Facing
  • Right-hand vertex ordering defines outward normal
  • Back-Face Culling is a technique for eliminating
    these polygons
  • On average eliminates half of the polygons

18
Back-Face Culling
  • After projection, examine normal Nk (xk , yk, zk)
    to the face.
  • If zk lt 0, face is a Back-Face - dont draw it
  • More general test looks at NkV
  • V - View vector
  • The only test necessary for a single convex
    polyhedron

1994 Foley/VanDam/Finer/Huges/Phillips ICG
19
Back-Face Culled Wire-Frame
20
Z-buffering
  • Z-buffering (depth-buffering) is a visible
    surface detection algorithm
  • Implementable in hardware and software
  • Requires data structure (z-buffer) in addition to
    frame buffer.
  • Z-buffer stores values 0 .. ZMAX corresponding
    to depth of each point.
  • If the point is closer than one in the buffers,
    it will replace the buffered values

21
Z-buffering




1994 Foley/VanDam/Finer/Huges/Phillips ICG
22
Z-buffering
  • for (y 0 y lt YMAX y)
  • for (x 0 x lt XMAX x)
  • Fxy BACKGROUND_VALUE
  • Zxy ZMIN
  • for (each polygon)
  • for (each pixel in polygons projection)
  • pz polygons z-value at pixel coordinates
    (x,y)
  • if (pz gt Zxy) / New point is closer /
  • Zxy pz
  • Fxy polygons color at pixel coordinates
    (x,y)

1994 Foley/VanDam/Finer/Huges/Phillips ICG
23
Z-buffering
  • We can simplify the calculation of z by
    exploiting the fact that triangle is planar.
  • Interpolate z values along the edges
  • Interpolate z values along scan line
  • Special cases vertices horizontal edge

1994 Foley/VanDam/Finer/Huges/Phillips ICG
24
Back-Face Culled Z-Buffered Wire-Frame
25
See the Difference
From HW of Andrew Mroczkowski
26
Depth Cueing
  • Objects that are closer are brighter
  • Objects farther away are darker
  • Color BaseColor?(z - far)/(near - far)

www.siggraph.org
www.dm.unibo.it/casciola
27
Important Reminder
  • Recall near and far planes are transformed by
    Nparand Nper
  • Parallel projection
  • Near z 0
  • Far z -1
  • Perspective projection
  • Near z
  • Far z -1

28
Ray Casting (Ray Tracing )
  • Determines visible surfaces by tracing rays of
    light from the viewers eye to the objects in the
    world.

29
Ray Casting
  • Determines visible surfaces by tracing rays of
    light from the viewers eye to the objects
  • View plane is divided on the pixel grid
  • The eye ray is fired from the center of
    projection through each pixel

1994 Foley/VanDam/Finer/Huges/Phillips ICG
30
Ray Casting
  • Select the center of projection and viewplane
    window
  • for (each scan line)
  • for (each pixel on the scan line)
  • Find ray from the center of projections through
    the pixel
  • for (each object in the scene)
  • if (object is intersected and
    intersection is closest considered
    so far)
  • Record the intersection and the object name
  • Set pixel color to that of the closest
    intersected object

1994 Foley/VanDam/Finer/Huges/Phillips ICG
31
Computing Intersections
  • Using parametric equation of the line
  • Simplifying for speed
  • Resulting ray

(x1,y1,z1)
(x0,y0,z0)
1994 Foley/VanDam/Finer/Huges/Phillips ICG
32
Computing Intersections with Sphere
  • Sphere with radius r and center (a,b,c) is
  • Intersection is found by substituting values for
    (x,y,z)
  • With some straightforward algebraic
    transformations
  • Equation is quadratic in terms of t
  • No real roots, No intersection
  • One real root, Ray grazes the sphere
  • Two roots, There are two points of intersection

1994 Foley/VanDam/Finer/Huges/Phillips ICG
33
Computing Intersections with Polygon
  • First intersect ray with plane
  • The substitution results in
  • If denominator is 0,
    ray is parallel to the
    plane
  • Project polygon and point orthographically on the
    coordinate plane
  • Polygon containment test can
    be performed in 2D

1994 Foley/VanDam/Finer/Huges/Phillips ICG
34
Polygon Containment Test
  • Jordan Curve Theorem
  • Point is inside if, for any ray, there is an odd
    number of crossings
  • Otherwise it is outside
  • Be careful with all the special cases
  • Wide variety of other techniques exist

35
Why Trace Rays?
  • More elegant
  • Testbed for techniques
  • modeling (reflectance, transport)
  • rendering (e.g. Monte Carlo)
  • texturing (e.g. hypertexture)
  • Easiest photorealistic renderer to implement

Boat reflected in wavy water rendered in
openGLusing an environment map
Compiled from Lecture notes of Dr. John C. Hart
_at_ University of Illinois
36
Ray Tracing
  • Extension of ray casting
  • Idea Continue to bounce the ray in the scene
  • Shoot rays to light sources
  • Simple and powerful
  • Reflections, shadows, transparency and multiple
    light sources
  • Can be used to produce highly realistic images

37
Ray Traced Image
Blessed State, by Ken Musgrave
38
To Ray Trace, We Need Refraction
  • Snells Law ?i sin ?i ?t sin ?t
  • Let ? ?i /?t sin ?t / sin ?i
  • Let m (cos ?i n - i) / sin ?i
  • Then
  • t sin ?t m - cos ?t n
  • (sin ?t / sin ?i) (cos ?i n - i) - cos ?t n
  • (? cos ?i - cos ?t )n - ? i

Can be negative for grazing angles when ? gt1, say
when going from glass to air, resulting in total
internal reflection (no refraction).
Compiled from Lecture notes of Dr. John C. Hart
_at_ University of Illinois
39
Refraction in Action
40
More Refractions
Photon Mapping!
Justin Hansen University of Utah
Henrik Wann Jensen UC, San Diego
41
Efficiency Considerations
  • Partition the bounding box on a regular grid with
    equal sized extents
  • Associate each partition with the list of objects
    contained in it

1994 Foley/VanDam/Finer/Huges/Phillips ICG
42
Efficiency Considerations
  • Ray only intersected with the objects contained
    in the partitions it passes through
  • If partitions are examined in the order ray
    travels, we can stop after first intersection is
    found
  • Need to check if intersection itself is in the
    partition

1994 Foley/VanDam/Finer/Huges/Phillips ICG
43
Computer Graphics II
Image produced by Horace Ip
Write a Comment
User Comments (0)
About PowerShow.com