Download presentation

1
**Image by Eric Veach and Leonidas Guibas**

Ray Tracing Lecture 10

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 Ray tracing – student project Rendering equation – many approaches, such as Radiosity – approach to solve rendering equation

3
**Currently We have rasterization with Phong lighting**

Strictly local illumination model: Ambient Diffuse Specular Shadows can be accomplished – we will discuss Shadow maps Shadow volumes Can generate reflections using environment mapping but: Approximate Expensive for scenes with many reflective objects Hard to capture complex inter-reflections

4
Example Gilles Tran

5
**Global 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

6
Timeline [Appel 68] “Some techniques for shading machine renderings of solids” Basic Ray Casting – designed for pen plotters: provides Perspective Accurate shadows Hidden Surface Removal [Whitted 80] “An Improved Illumination Model for Shaded Display” Reflection Refraction

7
**Perspective Ray Tracing provides natural perspective**

The schemes used to develop perspective were tracing rays Albrecht Durer

8
Two Alternatives Albrecht Durer Albrecht Durer

9
Ray Tracing Track the path of light between light source and the eye

10
**Ray Tracing Track the path of light between light source and the eye**

Where do we start – at light or at eye?

11
**Ray Casting Shot a ray from the eye through each pixel of the screen**

Can cast more than one ray through a pixel Calculate which objects in the scene the ray hits If it hits an object, we know basic color Images from SIGGRAPH Tutorial on Ray Tracing G. Scott Owens, 1999

12
**Ray Casting Shot a ray from the eye through each pixel of the screen**

Calculate which objects in the scene the ray hits Now check to see if surface is illuminated or in shade

13
**Shadow Ray Shoot a "shadow" ray from intersection point towards light**

If shadow ray hits an object before it hits light, point is in shadow This is Appel's original Algorithm – called Ray Casting today Only uses direct illumination – does not track light bouncing off intermediate surfaces

14
**Ray Casting cast ray Intersect all objects: select minimal t**

Color = ambient color of object For every light Cast shadow ray color += local shading term

15
**In practice Run the first few steps of the following applet**

16
Whitted Raytracing (1980) Turner Witted

17
Turner Witted “An Improved Illumination Model for Shaded Display” First global illumination model. An object’s color is influenced by lights and other objects in the scene First to simulate specular reflection and refractive transmission

18
Amiga Juggler Eric Graham – "In November 1966, a month after I learned to program, I had written a simple ray tracing program. I was then a grad student at Manchester…After getting the program to actually work, I only ran it once. "I used ray tracing because that was the simplest and most obvious way to render an image. I can't claim priority over Turner Whitted … because it was never published, but I suspect lots of other people also figured it out over the years. "In the fall of 1986, … I re-implemented the ray tracer. It took about a week to get running, and then another week or two to make a few models and put the compression scheme together. That was November and the Juggler was born. "The reaction amongst the Amiga community in Albuquerque encouraged me to send it to Commodore. Their legal department thought it was a hoax, and that I'd done the image generation on a mainframe..." 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
Ray Tree

21
**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 …

22
**What does Ray Tracing Offer?**

Hidden Surface Removal Shading due to direct Illumination Global specular interaction effects Reflections Refraction of light Shadow Computation Though the shadows are hard-edged

23
Diffuse Surfaces Theoretically scattering at each point of intersection generates an infinite number of new rays to trace We only trace the transmitted and reflected rays and use Phong model to compute shade at intersection To get full simulation of indirect lighting, we will need to turn to the Rendering Equations But first look at Ray Tracing in greater detail

24
Match point in image with its construction

25
**In practice Run more steps of the following applet Now move objects**

26
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<tmin?best=s,u: tmin;return best;}vec trace(level,P,D)vec P,D;{double d,eta,e;vec N,color; struct sphere*s,*l;if(!level--)return black;if(s=intersect(P,D));else return amb;color=amb;eta=s->ir;d= -vdot(D,N=vunit(vcomb(-1.,P=vcomb(tmin,D,P),s->cen )));if(d<0)N=vcomb(-1.,N,black),eta=1/eta,d= -d;l=sph+5;while(l-->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<32*32) U.x=yx%32-32/2,U.z=32/2-yx++/32,U.y=32/2/tan(25/ ),U=vcomb(255., trace(3,black,vunit(U)),black),printf("%.0f %.0f %.0f\n",U);}/*minray!*/ See Heckbert's work on ray tracing Jello

27
**Minimal Ray Tracing Contest**

Andrew Kensler's contribution Walkthrough…

28
**Minimal Ray Tracing Contest**

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

30
Examples Persistence of Vision Raytracer POV Ray Gilles Tran

31
POV Ray Gilles Tran

32
POV Ray Gilles Tran

33
POV Ray Steve Davis, CS 234

34
**POV Ray Start Steve Davis, CS 234 //Steve Davis POV Ray**

#include "colors.inc" #include "textures.inc" #include "shapes.inc" #include "metals.inc" #include "glass.inc" #include "woods.inc" global_settings {max_trace_level 5} camera { location <-5, 5, -10> direction <0, 0, 2.25> right x*1.33 look_at <0,0,0> } Steve Davis, CS 234

35
**POV Ray Lighting Steve Davis, CS 234 //Lighting #declare Dist=80.0;**

light_source {< -50, 25, -50> color White fade_distance Dist fade_power 2 area_light <-40, 0, -40>, <40, 0, 40>, 3, 3 adaptive 1 jitter } light_source {< 50, 10, -4> color Gray30 area_light <-20, 0, -20>, <20, 0, 20>, 3, 3 ... Steve Davis, CS 234

36
**POV Ray Surface Steve Davis, CS 234 // Water Surface**

plane{<0,1,0>, 0 texture { pigment { rgbf <0.2, 0.2, 0.9, > } finish { ambient 0.1 diffuse 0.7 brilliance 6.0 reflection 0.6 phong 0.8 phong_size 120 } normal {bumps 0.2 scale <1,0.25,0.25>*1 turbulence 0.5 } Steve Davis, CS 234

37
**POV Ray Spheres Steve Davis, CS 234 //first row**

texture { Shadow_Clouds } finish { specular 0.25 roughness ambient 0.2 } normal { bumps 0.4 scale 0.2 } } //second row sphere { <-0.4, 0.0, -0.5>, 0.4 texture { T_Copper_4A } sphere { <0.4, 0.0, -0.5>, 0.4 texture { T_Glass4 } Steve Davis, CS 234

38
**Cover of Rendering with Radiance, Larson and Shakespeare**

39
**When does it end? Diffuse surface – will not transmit or bounce**

Recursion depth: Stop after a number of bounces Ray contribution: Stop if reflected / transmitted contribution becomes too small No reflection One reflection Two reflections

40
When does it end?

41
Depth one and two

42
Adding levels

43
Adding…

44
Hard Work One difficulty is computing the intersection of the ray and the object Need to do this quickly: to find closest object, we may have to compute many intersections

45
**Math: Ray-Plane Intersection**

Equations of Ray and Plane. Ray is parameterized Plug the values for P from parameterized ray into Plane, and solve for t

46
**Ray Plane Intersection**

Solve this again with explicit values.

47
**Example: Ray Casting a Sphere**

Sphere is quadric equation, and ray is parameterized again. Resulting equation is a scalar quadratic equation It gives entry and exit points of ray

48
**Ray intersects Sphere Equations of Sphere and Ray**

Plug the values for (x, y, z) from parameterized ray into Sphere, and solve for t

49
**What does it mean? There are three cases:**

Equations of Sphere and Ray There are three cases: no roots (discriminant is negative), 2 roots, one root What does each mean?

50
**Finer Points If we have a solution with a negative t, we reject it**

Why? What does a negative t mean? If we have a solution with a very small positive t, we reject it (why?)

51
**Finer Points If we have a solution with a negative t, we reject it**

Why? What does a negative t mean? If we have a solution with a very small positive t, we reject it (why?) Hint – this can arise with a reflection ray

52
Epsilon "Acne" - Move intersection by epsilon along surface normal

53
What does it mean? Intersections with general quadratic equation is similar

54
**Ray Tracing Quadrics Constructive Solid Geometry (CSG)**

Primitives are solids Build objects with set operations Union, Intersection, Set Difference Wikipedia

55
Tree of objects Wikipedia

56
**CSG Intersections Spheres Polygons Boxes Quadrics**

Parameteric patches – we will see some later on… Subdivision surfaces Surfaces of revolution Fractals …

57
Polyhedra Generally we will be intersecting with closed objects such as polygons and polyhedra rather than planes Hence we have to worry about inside/outside testing For convex objects such as polyhedra there are some fast tests

58
Ray Tracing Polyhedra Polyhedron is formed by intersection of half-planes If ray enters an object, it must enter a front facing polygon and leave a back facing polygon If entry is further away than exit, ray must miss the polyhedron

59
**Problems for Ray Tracing**

Aliasing Finding all the intersections The technique we outlined had you intersect ray with all objects – time consuming Generates Hard Shadows Ambient Light is not uniform in real life

60
Aliasing

61
Aliasing

62
**Aliasing Three types of solutions Super sampling Many samples**

Stochastic Sampling Random points Adaptive Sampling Stop if no change seen How to pick?

63
**Finding All Intersections**

The technique we outlined intersects each ray with all objects Time consuming Major alternatives Try to bundle rays Describe scene as collection of objects Carve space up into regions

64
**Intersections with Objects**

To reduce the number of computations, we may put bounding boxes (or spheres) around complex objects in the scene Easier to compute intersection with simpler object (box) If we miss the bounding box, we miss its contents Early Reject

65
**Dividing Space Alternatives**

Do we work perpendicular to axis or to objects or to ray? Carve space up into regions – two approaches Volumetric Pixels (voxels) Keep track of which voxels each object hits Split space via half planes: Two alternatives Binary Space Partitioning (BSP) Trees k-Dimensional (kd) Trees

66
Voxel Grid

67
**Voxel Grid Figure out which voxels the ray hits**

See which shapes are in those voxels

68
Grid Divide scene deltaX need not be deltaY

69
**Precompute In advance, figure out which grid boxes each object hits**

Each grid box keeps list of objects

70
**For each box along a ray Ray hits this box Box hits these objects**

Test ray against each object in boxes it hits Return the closest intersection, if any

71
**Multiple Visits An object may hit multiple boxes**

We may encounter the same object multiple times Twice here Only test for intersections once: mark the object

72
**Grid If intersection is not within the grid box boundaries, continue**

There may be a better intersection in a later box

73
**Grid Binary Space Partitioning (BSP) Trees**

Build a binary tree: each node tests against a plane – is point left or right?

74
**Grid Binary Space Partitioning (BSP) Trees**

In this example, we check almost all objects, but we always check in order This makes it much easier to find the first intersection

75
**KD Trees All planes are parallel to standard axes**

Use lines through points to decompose space Alternate dimensions. x, then y, then z, then x…

76
KD Trees

77
**Speed up Computation Would like to handle all physical interactions**

Most secondary rays do not affect what we see Scattering produces many (infinite) additional rays Alternative: Ray Casting Various techniques to speed up Ray Tracing

78
**Light Map One technique that was introduced in Quake was light map**

Precompute lighting: paste it on like a texture

79
**Global 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

80
Rendering Equation Ray tracing is best with many highly specular surfaces Not characteristic of real scenes Rendering equation describes general shading problem Radiosity solves rendering equation for perfectly diffuse surfaces

81
Rendering Equation

82
**Rendering Equation Based on Heat Equation. 1986 paper by James Kajiya**

As explained by Sir Paul McCartney in 1969 "The light you take is proportional to the light you make" Keep track of the light exchange between points A red wall should cause color to bleed into white floor Look at sides of the boxes in this figure Matt surface with lots of incident light will reflect lots of light

83
**Rendering Equation Does not have a general closed form solution**

Solved in practice by iterative methods

84
Problems We have replaced a difficult problem with one even more difficult Rather than trace rays from the eye, we need to trace rays from light to the eye Many techniques are used to address this Radiance models Finite element method: break world into patches Monte-Carlo Methods Metropolis Light Transport Photon Mapping Cornell Box is widely used as a benchmark

85
Cornell Box

86
Joseph Cornell Box

87
Radiosity E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

88
**Rendering Equation Cornell Box**

Cornell Box is a Sample Scene Compare output of algorithm with picture of the scene

89
**Split model into Patches**

E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

90
**Computing Form Factors**

Consider two flat patches E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

91
**Using Differential Patches**

Must take angles into account foreshortening E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

92
**Use illuminating hemisphere**

Center hemisphere on patch with normal pointing up Must shift hemisphere for each point on patch In practice, use hemicube

93
**Bidirectional Path Tracing**

Track the path of light between light source and the eye Start at both ends, and look at how they meet

94
**Example Metropolis Light Transport Eric Veach and Leonidas Guibas**

Image by Eric Veach and Leonidas Guibas

95
**Metropolis Light Transport**

Speeds up Monte-Carlo simulation Uses technique attributed to Metropolis et. al. Start with a sample path that may not be representative Using probability model, mutate path Track the contributions of representative paths

96
**Compare to Monte-Carlo**

Metropolis Light Transport

97
Photon Mapping

98
Photon Mapping

99
Voxel Based Solutions Recent paper just added: Thiedemann - Voxel Based Global Illumination Combination of techniques Textures to store global atlas of voxels Maps to hold direct illumination per pixel Integrate over the pixels you can see… Focus on near term effects: distant sources are dim

100
**The Cathedral Won award as Best Animated Short at Siggraph 2002**

101
**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 many others

102
Resources Persistence of Vision (POV-RAY) – free ray tracer. Descriptions in HLL Radiance – another package radsite.lbl.gov/radiance/HOME.html Internet Ray Tracing Competition – many winners used POV-RAY SIGGRAPH Educational Material Applet to Ray Trace a simple scene Efficiency Issues for Ray Tracing, Brian Smits,, 1999 Also see the series of papers "State of the Art in Ray Tracing…" Tutorials

103
**Links See Lecture Links page for more…**

Demo Applet Amiga Juggler Dark Ridge Twin Engine example Beyond Radiosity: The Light of Mies van der Rohe Metropolis Light Transport Photon Mapping Sample Programs The Cathedral See Lecture Links page for more…

104
**Summary Ray Tracing provides a way to generate rich images**

Was too expensive for many uses Faster machines Better Data Structures and algorithms Offline processing Much work has gone into speeding up Ray Tracing Machines are fast enough for us to consider the Rendering Equation for illumination Compute the background illumination in advance Much work underway to speed up the evaluation or RE

Similar presentations

© 2023 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google