Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 376 Introduction to Computer Graphics 04 / 18 / 2007 Instructor: Michael Eckmann.

Similar presentations


Presentation on theme: "CS 376 Introduction to Computer Graphics 04 / 18 / 2007 Instructor: Michael Eckmann."— Presentation transcript:

1 CS 376 Introduction to Computer Graphics 04 / 18 / 2007 Instructor: Michael Eckmann

2 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Today’s Topics Questions? bump mapping remark radiosity ray-sphere intersections using a geometric method which will result in tests that can be done in order reducing the computations done overall. review ray-polygon intersections

3 Bump mapping remark When calculating N', the perturbed normal: N' = P' u x P' v we do: N' = ( P u + B u n ) x ( P v + B v n ) which after we do the math is (P u x P v ) + B v (P u x n) + B u (n x P v ) + B u B v (n x n) The partial derivatives of P are computed to be vectors in the direction of slope (in the u direction and the v direction) The partial derivatives of B are computed to be scalars

4 RayTracing / Radiosity Ray Tracing is a type of direct llumination method in image space. Direct illumination in image space because the scene that we're rendering is made up of surfaces and lights and we compute the colors of the pixels one at a time. –If the view moves --- have to ray trace again –If the world moves --- have to ray trace again Ray tracing results in some realism but with a few drawbacks + Handles both diffuse and specular reflections as well as refractions –Compute intensive –Shadows are too crisp Radiosity is a type of global illumination method that works in object space. + If the view moves, we DO NOT have to rerun the radiosity algorithm = view independent –Only diffuse, no specular reflection (therefore no mirrorlike surfaces) + Shadows are softer, more realistic +/- Color bleeds from surfaces to nearby surfaces Radiosity and Ray tracing can be combined to produce a more realistic image than either one separately.

5 Radiosity What follows is an overview of radiosity We won't go into as much detail as ray tracing I can point you to some sources if you wish to learn more about radiosity

6 Radiosity Light reflects off of surfaces and onto other surfaces. The amount of reflected light that hits a surface is determined by –how much it is attenuated and –how much is absorbed before reflection. When some light is reflected off of surface S, the color of the surface S colors that reflected light to some extent. This reflected light then hits other surface(s). This effect causes color bleeding from one surface to another. Example image of radiosity “color bleeding”. Radiosity is a method of rendering a scene by considering the global illumination of the scene (as opposed to the way ray tracing does it) –scene is divided into patches (generally the smaller the better) –a patch will emit (if it's a light source) and reflect light uniformly over its surface

7 Radiosity Radiosity assumes –surfaces are diffuse emitters and diffuse reflectors –the emitting and reflecting is done uniformly over a “patch” –all light energy in the scene will be conserved --- either absorbed or reflected The radiosity of a surface is computed to be the sum of the light energy emitted (if a light source) and the (incident) light energy hitting the surface (coming from elsewhere). Attenuation is taken care of by –Form Factors (which represents the fraction of the light that is transferred from one surface to another) and –Reflectivity values (which represents the fraction of the light that is reflected from a surface)

8 Radiosity The Form Factor (the fraction of light that arrives at one surface from another) is computed based on –areas of the 2 surfaces involved –angles between the light travelling from one surface to the other and the surface normals –see text if you would like details A form factor is defined between all directed pairs of patches. F jk is the form factor from patch j to k it is the light energy incident on patch k divided by the total light energy leaving patch j

9 Radiosity The radiosity equation for a patch k, in a scene with n patches is: B k = E k + p k * Sum n j=1 [ B j F jk ] B k is the radiosity of patch k E k is the light emitted from patch k p k is the reflectivity fraction for patch k (the fraction of incident light that is reflected in all directions) F jk is the form factor from patch j to k

10 Radiosity For all n patches in the scene you have a radiosity equation that is based on the radiosity of all the n patches. To compute the radiosities you have to solve the n simultaneous equations. –Techniques exist to solve a system of simultaneous equations so not to worry, but it could be expensive The more patches we have the longer the radiosity calculations take, but the prettier our pictures will look (up to some point where reducing the size of our patches will not have any noticeable effect on the picture). Radiosity is compute intensive but the surfaces can have their radiosities precomputed if the world does not change. The radiosities are view independent. Therefore the radiosity of each patch can be precomputed and stored with the patch.

11 RayTracing / Radiosity Revisit the comparison Ray tracing results in some realism but with a few drawbacks + Handles both diffuse and specular reflections as well as refractions –Compute intensive –Shadows are too crisp –If the viewer moves --- have to ray trace again –If the world moves --- have to ray trace again Radiosity is a type of global illumination method that works in object space. + If the view moves, we DO NOT have to rerun the radiosity algorithm = view independent –Only diffuse, no specular reflection (therefore no mirrorlike surfaces) + Shadows are softer, more realistic + Color bleeds from surfaces to nearby surfaces (diffuse-diffuse reflections)

12 RayTracing / Radiosity Radiosity and Ray tracing can be combined to produce a more realistic image than either one separately. Radiosity algorithm would execute on the first pass and store the output with the surfaces. Then do Ray Tracing next based on viewer position. If the viewer position changes, but the world stays constant, radiosity does NOT need to be rerun (therefore we can precompute the radiosity of a scene.) However, radiosity would need to be rerun if the world changes in any way (e.g. lights move, objects move, etc.)

13 Ray / Sphere Intersection A ray is a “line” starting at some point and continuing out to infinity. P(s) = P 0 + R d s where P 0 is the starting point of the ray, R d is a unit directional vector and s is the parameter which represents the distance from P 0 Let's find the intersection of P(s) with a sphere with radius r and center point P c.

14 Ray / Sphere Intersection Earlier we saw an algebraic solution to the ray-sphere intersection. Here (with the accompanying drawings on the board) is a geometric solution that allows you to find out ealier in the computations if the ray and sphere do not intersect (thereby reducing unneeded computations.) 1. Determine if the ray's origin (P 0 ) is outside or inside of the sphere by: P 0 P c = P c – P 0. If the length squared of P 0 P c < r 2 then P 0 is inside sphere otherwise the it is outside the sphere and we continue onto step 2. 2. Find the length L, of the ray from P 0 to the point on the ray that is closest to the center of the sphere. L = | P 0 P c | cosA = |P 0 P c | |R d | cosA = P 0 P c R d If L < 0, then ray does not intersect with the sphere, done. Otherwise go to step 3.

15 Ray / Sphere Intersection 3. Find the square of the distance, E 2 from the point on the ray that is closest to the center of the sphere to the intersection of the the ray with the sphere. From pythagorean theorem, r 2 = E 2 + D 2 so E 2 = r 2 – D 2 Also from pythagorean theorem, D 2 = |P 0 P c | 2 – L 2 So, E 2 = r 2 – (|P 0 P c | 2 – L 2 ) If E 2 < 0, ray does not intersect the sphere, done. Otherwise go to step 4. 4. Find s, the parameter of the intersection to use for the ray equation P(s) = P 0 + R d s If ray originates outside the sphere then s = L – E If ray originates inside the sphere then s = L + E 5. Calculate the intersection using s from step 4, (x i, y i, z i ) = P 0 + R d s

16 Ray / Sphere Intersection 6. Calculate the normal vector at the intersection If ray's origin was outside the sphere, N = [(x i -x c )/r, (y i -y c )/r, (z i -z c )/r] If inside the sphere, N = [(x c -x i )/r, (y c -y i )/r, (z c -z i )/r] (this procedure is based on Drew Kessler's notes from Lehigh, 1999)

17 Ray / Polygon Intersection The first step in Ray/Polygon intersection is to compute the intersection of the ray with the plane that the polygon lives on. At this point we have –the plane equation Ax+By+Cz+D = 0 –the point of intersection P I = (x I, y I, z I ) of the ray and plane –the vertices V = (x j, y j, z j ) of the polygon on that plane A technique that makes computation easier at this point is to orthographically project the polygon onto either the x-y, y-z, or z-x plane. To do this we just have to ignore the same coordinate of all of the vertices of the polygon and we end up with 2d points. The best coordinate to ignore is the one whose corresponding coefficient in the plane equation is dominant (largest absolute value.)

18 Ray / Polygon Intersection The best coordinate to ignore is the one whose corresponding coefficient in the plane equation is dominant (largest absolute value.) It gives us a polygon in 2d with the largest area of the 3 choices.

19 Ray / Polygon Intersection Note: this technique is a combination of ideas from –Computer Graphics Principles and Practive by Foley, Van Dam, Feiner and Hughes, 1996 Addison-Wesley –Dr. G. Drew Kessler's csc313 course 1999, Lehigh Univ. and –Dr. Xiaoyu Zhang's Advanced Computer Graphics & Visualization page http://courses.csusm.edu/cs697exz/ray_polygon.htm Example: If the plane equation is –0.2 x +0.4 y –0.8945 z +5 = 0 we would orthographically project the polygon onto the x-y plane (ignore the z coordinate of each vertex) This will yield the largest (area) projection. Once we have done this projection, we can translate the intersection point P I to the origin of this new 2d space (call it u-v coordinates). Then determine whether the origin is inside or outside the polygon by counting the number of polygon edge crossings with the positive u axis.

20 Ray / Polygon Intersection The next algorithm distinguishes between several different situations to determine when to add 1 to the number of times the polygon's edges cross the positive u axis. For some edge –1) if the signs of the v coordinate in both vertices are the same, then that edge DOES NOT cross the positive u-axis –2) if the signs of the v coordinate in both vertices are different AND both u coordinates are positive then that edge DOES cross the positive u-axis. –3) if the signs of the v coordinate in both vertices are different AND one of the u coordinates is positive then compute the intersection of the line with v=0. If the u coordinate of this intersection is positive then that edge DOES cross the positive u-axis. –4) if the signs of the v coordinate in both vertices are different AND one of the u coordinates is positive then compute the intersection of the line with v=0. If the u coordinate of this intersection is not positive then that edge DOES NOT cross the positive u-axis. –For cases 2 and 3 above, add 1 to a counter. Do this for all edges in the polygon in order and then check the value of the counter --- if it is odd then the point is in the interior of the polygon and hence the ray intersects with the polygon.

21 Ray / Polygon Intersection The n vertices of the polygon are (u i, v i ) where i goes from 0 to n-1. Pseudocode to determine if the origin is inside the polygon initialize numCross to 0 if v 0 > 0 then signHold1 = +1 else signHold1 = -1 for each edge (u a, v a ) to (u b, v b ) { if v b > 0, signHold2 = +1, else signHold2 = -1 if signHold1 != signHold2 { if u a and u b are both > 0, then numCross++ if one of u a or u b is > 0, then { if (crossPosUAxis(u a, v a, u b, v b ) then numCross++ } } signHold1 = signHold2 } if numCross is odd, then the ray and polygon intersect

22 Ray / Polygon Intersection pseudocode for crossPosUAxis recall the parametric equations of a line: u = u b + (u a - u b )t v = v b + (v a - v b )t = 0 (because we're looking for intersection with u axis) so, use the second equation to solve for t then solve the first for u and get u = (u b + ( u a - u b ) * ( v b / (v b -v a ) ) ) crossPosUAxis(u a, v a, u b, v b ) if ( (u b + ( u a - u b ) * ( v b / (v b -v a ) ) ) > 0 ) return true else return false


Download ppt "CS 376 Introduction to Computer Graphics 04 / 18 / 2007 Instructor: Michael Eckmann."

Similar presentations


Ads by Google