1 ray tracing lecture 10 © jeff parker, nov 2009

Download 1 Ray Tracing Lecture 10 © Jeff Parker, Nov 2009

If you can't read please download the document

Upload: arlene-bishop

Post on 06-Jan-2018

216 views

Category:

Documents


0 download

DESCRIPTION

3 Image Credits Ed Angel - University of New Mexico Allan Watt's text, 3D Computer Graphics Brian Salomon, UNC G. Scott Owen Paul Bourke Gilles Tran and others, as credited

TRANSCRIPT

1 Ray Tracing Lecture 10 Jeff Parker, Nov 2009 2 Introduction OpenGL is based on a pipeline model in which primitives are rendered one at time No shadows (except by tricks or multiple renderings) No reflections (though we can use multiple renderings) No refraction thus no caustics Global approaches Rendering equation Ray tracing Radiosity 3 Image Credits Ed Angel - University of New Mexico Allan Watt's text, 3D Computer Graphics Brian Salomon, UNC G. Scott Owen Paul Bourke Gilles Tran and others, as credited Currently We have rasterization with Phong lighting Strictly local illumination model: Ambient Diffuse Specular Shadows can be accomplished: Shadow maps Shadow volumes Can generate reflections using environment mapping but: Approximate Expensive with many reflective objects Hard to capture complex interreflections 5 Illumination Direct Illumination A surface point receives light from all visible lights Global Illumination Even if point is in shadow, Rays may pass through translucent material Light rays will bounce off other material in scene Want to sum all light that hits an object Beyond Radiosity: The Light of Mies van der Rohe 6 Example Eric Veach and Leonidas Guibas Image by Eric Veach and Leonidas Guibas Timeline [Appel 68] Some techniques for shading machine renderings of solids Basic Ray Casting designed for pen plotters: provides Perspective Accurate shadows [Whitted 80] An Improved Illumination Model for Shaded Display Reflection Refraction Shadows Hidden Surface Removal 8 Perspective Ray Tracing provides natural perspective The schemes used to develop perspective were tracing rays (Albrecht Durer) 9 Albrecht Durer Two alternatives 10 Ray Tracing Track the path of light between light source and the eye 11 Ray Tracing Track the path of light between light source and the eye Where do we start at light or at eye? 12 Steps in Ray Casting Shot a ray from the eye through each pixel of the screen Calculate which objects in the scene the ray hits If the ray misses all objects, display background color 13 Ray Casting Shot a ray from the eye through each pixel of the screen Calculate which objects in the scene the ray hits If it hits an object, we know basic color Now check to see if surface is illuminated or in shade 14 Shadow Ray Shoot a "shadow" ray from intersection point towards light If shadow ray hits object before it hits light, point is in shadow This is Appel's original Algorithm called Ray Casting today Only uses local illumination does not track light bouncing off intermediate surfaces 15 Ray Casting cast ray Intersect all objects: select minimal t Color = ambient term For every light Cast shadow ray color += local shading term 16 In practice Run the first few steps of the following appletrt_java/raytrace.html Whitted Raytracing (1980) Turner Witted An Improved Illumination Model for Shaded Display First global illumination model. An objects color is influenced by lights and other objects in the scene First to simulate specular reflection and refractive transmission 1986 Amiga Juggler home.comcast.net/~erniew/juggler.html#avi 19 Reflected Ray If the object is shiny, we send a third "reflection" ray If this hits an object, the color of the object will be reflected in the original screen point To see if the new point is in the shade, send shadow ray The new object may be shiny 20 Full Algorithm We have sketched the first steps. Will need to recurse Need to modify the path of refracted light May wish to add specular highlights What does it offer? Hidden Surface Removal Shading due to direct Illumination Global specular interaction effects Reflections Refraction of light Shadow Computation Shadows are hard-edged 22 Diffuse Surfaces Theoretically scattering at each point of intersection generates an infinite number of new rays that should be traced In practice, we only trace the transmitted and reflected rays but use the Phong model to compute shade at intersection Radiosity works best for perfectly diffuse (Lambertian) surfaces 23 POV Ray Persistence of Vision Raytracer POV Ray Images by Gilles Tran 24 POV Ray 25 POV Ray Match point in image with it's construction 27 Ray Tree 28 In practice Run the more steps of the following applet move objectsrt_java/raytrace.html 29 Raytracing trace ray Intersect all objects color = ambient term For every light cast shadow ray color += local shading term If mirror color += colorrefl * trace reflected ray If transparent color += colortrans * trace transmitted ray Raytracing Is Simple Paul Heckbert wrote a raytracer that fits on a business card Prints something like a 32x32 P3.ppm file to standard out. typedef struct{double x,y,z}vec;vec U,black,amb={.02,.02,.02};struct sphere{ vec cen,color;double rad,kd,ks,kt,kl,ir}*s,*best,sph[]={0.,6.,.5,1.,1.,1.,.9,.05,.2,.85,0.,1.7,-1.,8.,-.5,1.,.5,.2,1.,.7,.3,0.,.05,1.2,1.,8.,-.5,.1,.8,.8, 1.,.3,.7,0.,0.,1.2,3.,-6.,15.,1.,.8,1.,7.,0.,0.,0.,.6,1.5,-3.,- 3.,12.,.8,1., 1.,5.,0.,0.,0.,.5,1.5,};yx;double u,b,tmin,sqrt(),tan();double vdot(A,B)vec A,B;{return A.x*B.x+A.y*B.y+A.z*B.z;}vec vcomb(a,A,B)double a;vec A,B;{B.x+=a* A.x;B.y+=a*A.y;B.z+=a*A.z;return B;}vec vunit(A)vec A;{return vcomb(1./sqrt( vdot(A,A)),A,black);}struct sphere*intersect(P,D)vec P,D;{best=0;tmin=1e30;s= sph+5;while(s-- >sph)b=vdot(D,U=vcomb(-1.,P,s->cen)),u=b*b-vdot(U,U)+s->rad*s ->rad,u=u>0?sqrt(u):1e31,u=b- u>1e-7?b-u:b+u,tmin=u>=1e-7&&u ir;d= -vdot(D,N=vunit(vcomb(-1.,P=vcomb(tmin,D,P),s->cen )));if(d sph)if((e=l - >kl*vdot(N,U=vunit(vcomb(-1.,P,l->cen))))>0&&intersect(P,U)==l)color=vcomb(e,l- >color,color);U=s->color;color.x*=U.x;color.y*=U.y;color.z*=U.z;e=1-eta* eta*(1-d*d);return vcomb(s->kt,e>0?trace(level,P,vcomb(eta,D,vcomb(eta*d-sqrt (e),N,black))):black,vcomb(s- >ks,trace(level,P,vcomb(2*d,N,D)),vcomb(s->kd, color,vcomb(s->kl,U,black))));}main(){printf("%d %d\n",32,32);while(yx