Presentation is loading. Please wait.

Presentation is loading. Please wait.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 1/42 Raytracing Basics.

Similar presentations


Presentation on theme: "I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 1/42 Raytracing Basics."— Presentation transcript:

1 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 1/42 Raytracing Basics

2 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 2/42 Illumination Review (1/3) Key points Global, physically-based illumination models describe energy transport and radiation - subject to the properties of light and materials - subject to the geometry of light, objects and viewer For each surface, there is a distribution that characterizes its absorption and reflection at each wavelength -also some other properties that we will ignore for the sake of brevity All illumination models are, by definition, approximate -based on sampling geometry, light distribution and material properties, and taking rendering shortcuts

3 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 3/42 Illumination Review (2/3) Important illumination models Local (single-surface element) model -ambient approximates indirect global illumination as constant -Lambertian diffuse reflection (outgoing energy is proportional to the cosine of the angle between the vector to the light and the surface normal, due to geometry) -Phong approximation to specular reflection -these model part of the BRDF (itself an approx!): Global (multi-surface element) models shadows indirect illumination – from other objects specular and diffuse reflection, refraction ii rr ii rr LiLi LrLr Surface

4 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 4/42 Illumination Review (3/3) Important illumination models The illumination models most commonly in use today are tied to the particulars of scan-conversion and raytracing Z-buffered scan-conversion -highly specialized and parallelized hardware: fast -but more limited -eye rays, shadow rays, specular reflections (only from planar surfaces) Raytracing -targeted shooting of rays (more accurate, but slower) -shadows, recursive specular (but not diffuse) reflection, refractive transmission

5 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 5/42 Rendering with Raytracing (1/2) Generalizing from Durer’s painting showing perspective projection Durer: Put eye at center of projection on wall and record color of objects along each of those strings Raytracing: shoot rays from eye through sample point (e.g., a pixel center) of a virtual photo -compute what color/intensity you see at the corresponding sample point on the object out there; paint this on “photo” at the ray-photo intersection point “What you see out there” -combination of the color of the material of the surface element you hit first and the colors of light that hit it and reflect towards you Raytracing, a simple idea: instead of forward mapping an infinite number of rays from light source to object to viewer, backmap finite number of rays from viewer through each pixel to object to light source (or other object)

6 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 6/42 Rendering with Raytracing (2/2) Subproblems to solve Generate primary (‘eye’) ray Find closest object along ray path - find the first intersection of a ray that goes out from the eye through a pixel center (or any other sample point on image plane) into the scene Light sample -use illumination model to determine light at closest surface element -generate ‘secondary’ rays from object

7 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 7/42 Raycasting Raycasting versus scan conversion scan conversion raycasting for each triangle in scene… for each sample in pixel image…

8 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 8/42 Raycasting Raycasting versus scan conversion How is raycasting different from what you’ve been doing in your assignments? In shapes you did: for each object in scene for each triangular facet of object pass vertex geometry and colors to OpenGL, which paints all interior points of the triangle in the framebuffer This is fine if you’re just using the simple hardware lighting model, and just using triangles We’re trying to solve a different problem: for each sample in our image determine which object in scene database the ray through that sample intersects paint that sample the color of the object at that point

9 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 9/42 Generating Rays (1/4) Ray origin Let’s look at the geometry of the problem in untransformed world-space - we’ll see why later We start a ray from an “eye point”: P We send it out in some direction  d from your eye toward a typical point on the film plane whose color we want to know Points along the ray have the form P + td where -P is the base point of the ray: the camera’s “eye point” -d is the unit vector direction of the ray -t is a nonnegative real number The “eye point” is the center of projection in the perspective view volume (we use perspective coords to avoid having to deal with the inverse of a perspective transformation later)

10 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 10/42 Generating Rays (2/4) Ray direction We start raycasting with screen-space points (pixels). Need to find a point in 3-D that lies on the corresponding ray - we will use ray to intersect with the original objects in the original, untransformed world coordinate system Transform 2D screen-space points into points on the camera’s 3D film plane Any planes orthogonal to the look vector is a convenient film plane: constant z in canonical view volume Choose a plane to be the film plane and then create a function that maps screen-space points onto it -what’s a convenient plane? Try the far plane :-) -to convert, we just have to scale integer screen-space coordinates into floating point values between -1 and 1 canonical view volume Any plane z=k, -1<= k < 0 can be the film plane

11 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 11/42 Generating Rays (3/4) Ray direction(cont.) Transform film plane point into world-space point - we can make the direction vector between the eye and this world-space point -we need direction to be in world space so that we can intersect with the original object in the original, untransformed world coordinate system Normalizing transformation takes world-space points to points in the canonical view volume - translate to the origin, orient with the axes, scale x and y to adjust viewing angles, scale so that z: [-1, 0]; x,y: [-1, 1] Apply the inverse of the normalizing transformation: the Viewing Transformation

12 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 12/42 Generating Rays (4/4) Summary Start the ray at the center of projection (eye point) Transform 2D integer screen-space point onto the 3D film plane -use the far clip plane as the film plane -scale the points to fit between -1 and 1 -set their z to -1 so that they lie on the far clip plane Transform the 3D film plane point into the untransformed world coordinate system -need to undo the normalizing transformation (i.e., viewing transformation) Construct the direction vector -point minus point is a vector -world-space point minus eye point

13 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 13/42 Ray-Object Intersection (1/6) Implicit objects If an object is defined implicitly by a function f such that f(Q) = 0 if and only if Q is a point on the surface of the object, then ray-object intersection is comparatively easy -we can define many objects implicitly -implicit functions give you potentially infinite resolution -tessellating implicit functions is more difficult than using them directly For example, a circle of radius R is an implicit object in the plane, and its equation is points where f(x, y) = 0 are points on the circle An infinite plane is defined by the function: A sphere of radius R in 3-space: (A,B,C) (0,0,0) -D

14 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 14/42 Ray-Object Intersection (2/6) Implicit objects(cont.) At what points (if any) does the ray intersect the object? Points on the ray have the form P + td - t is any nonnegative real A point Q lying on the object has the property that f(Q) = 0 Combining, we want to know “For which values of t is f(P + td) = 0 ?” (if any) We are solving a system of simultaneous equations in x, y (in 2D) or x, y, z (in 3D)

15 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 15/42 An Explicit Example (1/3) 2D ray-circle intersection example Consider the eye-point P = (-3, 1), the direction vector d = (.8, -.6) and the unit circle given by: A typical point of the ray is: Plugging this into the equation of the circle: Expanding, we get: Setting this to zero, we get:

16 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 16/42 An Explicit Example (2/3) 2D ray-circle intersection example (cont.) Using the quadratic formula: We get: Because we have a root of multiplicity 2, our ray intersects the circle at one point (i.e., it’s tangent to the circle) We can use the discriminant D = b 2 - 4ac to quickly determine if a ray intersects a curve or not - if D < 0, imaginary roots; no intersection -if D = 0, double root; ray is tangent -if D > 0, two real roots; ray intersects circle at two points Smallest non-negative real t represents intersection nearest to eye-point

17 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 17/42 An Explicit Example (3/3) 2D ray-circle intersection example (cont.) Generalizing: our approach will be to take an arbitrary implicit surface with an equation f(Q) = 0 and a ray P + td, and plug the latter into the former: This results, after some algebra, in an equation with t as unknown We then solve for t, analytically or numerically

18 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 18/42 Ray-Object Intersection (3/6) Implicit objects-multiple conditions For objects like cylinders, the equation in 3-space defines an infinite cylinder of unit radius, running along the y-axis Usually, it’s more useful to work with finite objects, e.g. such a unit cylinder truncated with the limits But how do we do the “caps?” The cap is the inside of the cylinder at the y extrema of the cylinder

19 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Picture We want intersections satisfying the cylinder: or top cap: or bottom cap: Andries van Dam, John Alex October 28, 2003 Raytracing 19/42 Ray-Object Intersection (4/6) Multiple conditions (cont.)

20 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 20/42 Solve in a case-by-case approach Ray_inter_finite_cylinder: // Check for intersection with infinite cylinder ray_inter_infinite_cylinder(t1, t2) compute P + t1*d, P + t2*d // If intersection, is it between the “end caps”? if y > 1 or y < -1 for either t1 or t2, toss it // Check for intersection with top end cap Compute ray_inter_plane(t3, plane y = 1) Compute P + t3*d // If it intersects, is it within the “circle” on // the end? If x 2 + z 2 > 1, toss out t3 // Check intersection with other end cap Compute ray_inter_plane(t4, plane y = -1) Compute P + t4*d // If it intersects, is it within the “circle” on // the end? If x 2 + z 2 > 1, toss out t4 Among all the t’s that remain (1-4), select the smallest non-negative one Ray-Object Intersection (5/6) Multiple conditions-cylinder pseudocode

21 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 21/42 Ray-Object Intersection (6/6) Implicit surface strategy summary Turn an implicit surface equation into an equation for t and solve The thing you see “first” from eye point is at the smallest non-negative t-value For complicated objects (not defined by a single equation), write out a set of equalities and inequalities and then code as cases… Latter approach can be generalized cleverly to handle all sorts of complex combinations of objects -Constructive Solid Geometry (CSG), where objects are stored as a hierarchy of primitives and 3-D set operations (union, intersection, difference) -“blobby objects”, which are implicit surfaces defined by sums of implicit equations

22 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 22/42 World-Space Intersection One way to do intersection is to compute the equation of your object in world- space Example: a sphere translated to (3, 4, 5) after it was scaled by 2 in the x- direction has equation One can then take the ray P+td and plug it into the equation Solve the resulting equation for t Always start with the untransformed object definition in its own coordinate system We then try to derive what the transformed version should be, given the CTM (call it M) - this is not easy for general transformations, and furthermore, the transformed version of the equation is always more complicated and thus more expensive to compute -can we just work with the object in its own coordinate system? Yes, as follows: World space - a global view

23 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 23/42 Object-Space Intersection Express world-space point of intersection as MQ, where Q is some point in object- space: If is the equation of the untransformed object, we just have to solve -note d is probably not a unit vector -the parameter t along this vector and its world space counterpart always have the same value. Normalizing d would alter this relationship. Do NOT normalize d. Transform ray into object-space (0,0,0) MQ Q

24 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 24/42 World-Space vs. Object-Space To compute world-space intersections, you have to transform the implicit equation of your canonical object defined in object space - often difficult But to compute intersections in object-space, you need only apply a matrix (M -1 ) to P and d, which is much simpler. -does M -1 exist? -M was composed from two parts: the cumulative modeling transformation that positions the object in world-space, and the camera’s normalizing transformation -the modeling transformations are just translations, rotations, and scales (all invertible) -the normalizing transformation also consists of translations, rotations and scales (also invertible); no perspective! (Now you see why we used the “hinged” perspective view volume) When you’re done, you get a t-value This t can be used in two ways: -P + td is the world-space location of the intersection of the ray with the transformed object -P + td is the corresponding point on the untransformed object (in object space) Use object-space if objects defined there


Download ppt "I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 1/42 Raytracing Basics."

Similar presentations


Ads by Google