Shading Chapter 6 CS 480680 Chapter 6 Shading

  • Slides: 72
Download presentation
Shading Chapter 6 CS 480/680 Chapter 6 -- Shading

Shading Chapter 6 CS 480/680 Chapter 6 -- Shading

n Introduction: - We have learned to build three-dimensional models and to display them.

n Introduction: - We have learned to build three-dimensional models and to display them. - However, if you render one of our models, you might be disappointed to see images that look flat. • This appearance is a consequence of our unnatural assumption that each surface is lit such that it appears to the viewer in a single color. - We have left out the interaction between light and the surfaces in our models • So, we will begin by developing models of light sources and the most common light-material interactions. CS 480/680 Chapter 6 -- Shading 2

- We then will investigate how we can apply shading to a polygonal model.

- We then will investigate how we can apply shading to a polygonal model. • We then develop a recursive approximation to a sphere to test our shading algorithms. - We then discuss how light and material properties are specified in Open. GL • and can be added to our sphere approximating program. - We conclude the chapter with a short discussion of the two most important methods for handling global lighting effects: • Ray Tracing and Radiosity CS 480/680 Chapter 6 -- Shading 3

1. Light and Matter - From a physical perspective, a surface can either •

1. Light and Matter - From a physical perspective, a surface can either • emit light by self-emission (as a light bulb does) • or reflect light from other surfaces that illuminate it. • Figure 6. 1 CS 480/680 Chapter 6 -- Shading 4

- The equation for solving this shading is called the rendering equation. • This

- The equation for solving this shading is called the rendering equation. • This cannot be solved in general, so we use approximations. – Radiosity and ray-tracing are approximations to this. • Unfortunately these approximations cannot yet be used to render scenes at the rate we can pass polygons through the modeling-projection pipeline. • Therefore, we will focus on a simpler rendering model – This model is based upon the Phong reflection model CS 480/680 Chapter 6 -- Shading 5

- To get an overview of the process, we can start following rays of

- To get an overview of the process, we can start following rays of light from a point-light-source - Figure 6. 2 CS 480/680 Chapter 6 -- Shading 6

- In terms of Computer graphics, we replace the viewer with the projection plane

- In terms of Computer graphics, we replace the viewer with the projection plane - Figure 6. 3 - Note that most rays leaving a source do not contribute to the image and are thus of no interest to us. CS 480/680 Chapter 6 -- Shading 7

- The interaction between light and materials can be classified into three groups •

- The interaction between light and materials can be classified into three groups • • • (a) specular (b) diffuse (c) translucent • Figure 6. 4 CS 480/680 Chapter 6 -- Shading 8

- Specular Surfaces • appear shiny because most of the light that is reflected

- Specular Surfaces • appear shiny because most of the light that is reflected in a narrow range of angles close to the angle of reflection. • Angle of Incidence is equal to the angle of reflection. - Diffuse Surfaces • reflected light is scattered in all directions. - Translucent Surfaces • allow some light to penetrate the surface and to emerge from another location on the object. • Refraction CS 480/680 Chapter 6 -- Shading 9

2. Light Sources - Light can leave a surface through • self-emission and reflection.

2. Light Sources - Light can leave a surface through • self-emission and reflection. - When we discuss Open. GL lighting in section 7 we shall see that we can easily simulate a selfemission term. CS 480/680 Chapter 6 -- Shading 10

- If we consider a source such as: - Figure 6. 5 - each

- If we consider a source such as: - Figure 6. 5 - each point on the surface can emit light that is characterized by • the direction of emission (q, f) ( • the intensity of energy emitted at each wavelength l - Thus, a general light source can be characterized by an illumination function • I(x, y, z, q, f, l) CS 480/680 Chapter 6 -- Shading 11

- From the perspective of the surface that is being illuminated, we can obtain

- From the perspective of the surface that is being illuminated, we can obtain the total contribution of the source by integrating over the surface of the source. - Figure 6. 6 - This can be difficult, so we will consider four basic types of sources: • ambient lighting, point sources, spotlights, and distant lights • These four are sufficient for rendering most simple scenes. CS 480/680 Chapter 6 -- Shading 12

n 2. 1 Color Sources - Not only do light sources emit different amounts

n 2. 1 Color Sources - Not only do light sources emit different amounts of light at different frequencies, but also their directional properties can very with frequency. • Consequently, a physically correct model can be complex. - However, since our visual system is based upon three colors, • for most applications, we can use each of the three colors to obtain what the human observer sees. CS 480/680 Chapter 6 -- Shading 13

n 2. 2 Ambient Light - In some rooms, such as certain classrooms or

n 2. 2 Ambient Light - In some rooms, such as certain classrooms or kitchens, the lights have been designed and positioned to provide uniform illumination throughout the room. - Often this is achieved with light sources that have diffusers whose purpose is to scatter light in all directions. • Florescent lights have covers designed to do this. CS 480/680 Chapter 6 -- Shading 14

- Making such a model and rendering the scene with it would be a

- Making such a model and rendering the scene with it would be a daunting task for a graphics system. - Alternatively, we can look at the desired effect: • to achieve a uniform light level in the room - This uniform lighting is called Ambient Light. • This is typically denoted Ia CS 480/680 Chapter 6 -- Shading 15

n 2. 3 Point Sources - An ideal point source emits light equally in

n 2. 3 Point Sources - An ideal point source emits light equally in all directions. • We can characterize a point light source by a three-component color matrix. - The intensity of illumination received from a point source is proportional to the inverse square of the distance from the source to the surface. - Figure 6. 7 CS 480/680 Chapter 6 -- Shading 16

- Scenes rendered with only point sources tend to have high contrast • (objects

- Scenes rendered with only point sources tend to have high contrast • (objects appear either bright or dark) - In the real world, it is the large size of most light sources that contributes to softer scenes. - Figure 6. 8 • • CS 480/680 Umbra Penumbra Chapter 6 -- Shading 17

n 2. 4 Spotlights - spotlights are characterized by a narrow range of angles

n 2. 4 Spotlights - spotlights are characterized by a narrow range of angles through which light is emitted. • We can construct a spotlight from a point source by limiting the angles. • For example, we can use a cone • Figure 6. 9 CS 480/680 Chapter 6 -- Shading 18

- More realistic spotlights are characterized by the distribution of light in the cone.

- More realistic spotlights are characterized by the distribution of light in the cone. • Usually most of the light is concentrated at the center of the cone. • The intensity is a function of the angle f • Figure 6. 10 • As we will see throughout this chapter, cosines are convenient functions for lighting calculations. CS 480/680 Chapter 6 -- Shading 19

n 2. 5 Distant Light Sources - Most shading calculations require the direction from

n 2. 5 Distant Light Sources - Most shading calculations require the direction from the point on the surface to the light source - As we move across a surface, calculating the intensity at each point, we should recompute this vector repeatedly. • This is very expensive and is a significant part of the shading calculation. • However, if the light source is far from the surface, the vector does not change much • Figure 6. 12 CS 480/680 Chapter 6 -- Shading 20

- In this case, we are effectively replacing a point light source with a

- In this case, we are effectively replacing a point light source with a source that illuminates objects with parallel rays of light. - Figure 6. 12 - Graphics systems can carry out rendering calculations more efficiently for distant light sources than for near ones. • Open. GL allows both CS 480/680 Chapter 6 -- Shading 21

3. The Phong Reflection Model - Although we could approach light-material interactions through physical

3. The Phong Reflection Model - Although we could approach light-material interactions through physical models, - we have chosen to use a model that leads to efficient computations and to be a close enough approximation to physical reality to produce good renderings under a variety of lighting conditions and material properties. CS 480/680 Chapter 6 -- Shading 22

- The model uses the four vectors shown here to calculate a color for

- The model uses the four vectors shown here to calculate a color for a point p on a surface. - Figure 6. 13 - n is the normal vector at p • We discuss its computation in section 6. 4 - v is the vector from p to the viewer or COP l is the vector from p to a light source r is in the direction that a perfectly reflected ray from l would take. • This is determined by n and l (calculated in 6. 4) CS 480/680 Chapter 6 -- Shading 23

- The Phong model supports three types of lightmaterial interactions • Ambient, Diffuse, and

- The Phong model supports three types of lightmaterial interactions • Ambient, Diffuse, and Specular. - For the total Intensity we write: • I = I a + I d + I s = L a R a + L d. R d + L s R s – where R is the reflection term • with the understanding that the computation will be done for each of the primaries and each source. CS 480/680 Chapter 6 -- Shading 24

n 3. 1 Ambient Reflection - The intensity of ambient light La is the

n 3. 1 Ambient Reflection - The intensity of ambient light La is the same at every point on the surface. - Some light is absorbed and some is reflected. • The amount reflected is given by the ambient reflection coefficient, Ra=ka (0 £ ka £ 1) • Thus Ia = ka La - A surface has of course, three ambient coefficients • kar, kag, and kab • and they can be different • Hence, a sphere appears yellow under white ambient light if its blue ambient coefficient is small and its red and green coefficients are large. CS 480/680 Chapter 6 -- Shading 25

n 3. 2 Diffuse Reflection - A perfectly diffuse reflector scatters the light that

n 3. 2 Diffuse Reflection - A perfectly diffuse reflector scatters the light that it reflects equally in all directions. - Perfectly diffuse surfaces are so rough that there is no preferred angle of reflection - Figure 6. 14 CS 480/680 Chapter 6 -- Shading 26

n 3. 3 Specular Reflection - If we employ only ambient and diffuse reflections,

n 3. 3 Specular Reflection - If we employ only ambient and diffuse reflections, our images will be shaded and will appear threedimensional, but all the surfaces will look dull, somewhat like chalk. - What is missing is the highlights - Figure 6. 17 CS 480/680 Chapter 6 -- Shading 27

- A specular surface is smooth. • A mirror is a perfectly specular surface.

- A specular surface is smooth. • A mirror is a perfectly specular surface. - Modeling specular surfaces realistically can be complex • This is because the pattern is not symmetric, it depends upon the wavelength and it changes with the reflection angle. - The Phong model adds a term for specular reflection. • The amount of light that the viewer sees depends upon the angle f between r and the reflector v CS 480/680 Chapter 6 -- Shading 28

- The Phong Model uses the equation • Is = ks. Lscosaf • ks

- The Phong Model uses the equation • Is = ks. Lscosaf • ks is the fraction of the incoming specular light that is reflected. • a is the shininess coefficient. – As a is increased, the reflected light is concentrated in a narrower region, centered on the perfect reflector. – Figure 6. 19 CS 480/680 Chapter 6 -- Shading 29

4. Computation of Vectors - The illumination and reflection models that we have derived

4. Computation of Vectors - The illumination and reflection models that we have derived are sufficiently general that they can be applied to either curved or flat surfaces, to parallel or perspective views, and to distant or near surfaces. • Most require vectors and dot products. - In this section we see what additional techniques can be applied when our objets are composed of flat polygons. CS 480/680 Chapter 6 -- Shading 30

n 4. 1 Normal Vectors - Plane • Typically the definition is given as

n 4. 1 Normal Vectors - Plane • Typically the definition is given as – ax+ by+ cz + d = 0 • It could also be given as – n. (p-p 0) = 0 • If we were given 3 noncollinear points, we could find the normal by – n = (p 2 -p 0) x (p 1 -p 0) – we must be careful about the order of the vectors. Reversing the order changes the surface from outward pointing to inward pointing. CS 480/680 Chapter 6 -- Shading 31

- Curved Surfaces • We could go through the math of how a sphere

- Curved Surfaces • We could go through the math of how a sphere is defined. • We could go through parametric equations of a sphere • But we are only interested in the direction of the normal, so if the sphere is centered at the origin, we can say the normal is p • Figure 6. 20 CS 480/680 Chapter 6 -- Shading 32

- In Open. GL we can associate a normal with a vertx through functions

- In Open. GL we can associate a normal with a vertx through functions such as • • gl. Normal 3 f(nx, ny, nz); gl. Normal 3 fv(pointer_to_normal); - Normals are modal variables. • If we define a normal before a sequence of vertices – this normal is associated with all the vertices – and is used for the lighting calculations at all the vertices • The problem remains, however, that we have to determine these normals ourselves. CS 480/680 Chapter 6 -- Shading 33

n 4. 2 Angle of Reflection - Once we have calculated the normal at

n 4. 2 Angle of Reflection - Once we have calculated the normal at a point, we can use this normal and the direction of light to compute the direction of a perfect reflection • angle of incidence is equal to the angle of reflection • Figure 6. 21 CS 480/680 Chapter 6 -- Shading 34

n 4. 3 Use of the Halfway Vector - If we use the Phong

n 4. 3 Use of the Halfway Vector - If we use the Phong model with specular reflections in our rendering, the dot product r. v should be recalculated at every point on the surface - We can obtain an interesting approximation by using the unit vector halfway between the viewer vector and the light-source vector: - Figure 6. 22 CS 480/680 Chapter 6 -- Shading 35

- If we replace r. v with n. h, we avoid calculation of r

- If we replace r. v with n. h, we avoid calculation of r - However, the halfway angle is smaller than the angle used for specular computation, so if we use the same exponent e in (n. h)e the specular highlights will be smaller, • so we use a different value of e to fix this. - Exercise 6. 8 helps you see how much work this saves. CS 480/680 Chapter 6 -- Shading 36

n 4. 4 Transmitted Light - Consider a surface that transmits all the light

n 4. 4 Transmitted Light - Consider a surface that transmits all the light that strikes it – Figure 6. 23 - If the speed of light differs in the two materials, the light is bent at the surface • Let hl and ht be the indices of refraction • Snell’s law states that CS 480/680 Chapter 6 -- Shading 37

- Therefore, we can calculate the direction of the transmitted light. - A more

- Therefore, we can calculate the direction of the transmitted light. - A more general expression for what happens at a transmitting surface corresponds to this figure – Figure 6. 24 • • • CS 480/680 some light is transmitted, some is reflected, and the rest is absorbed. Chapter 6 -- Shading 38

5. Polygonal Shading - Assuming that we can compute normal vectors, given a set

5. Polygonal Shading - Assuming that we can compute normal vectors, given a set of light sources and a viewer, both the lighting and illumination models that we have developed can be applied at every point on a surface. - Consider the polygon mesh shown here. We will consider three ways to shade the polygons: flat, interpolative or Gourand, and Phong sading - Figure 6. 25 CS 480/680 Chapter 6 -- Shading 39

n 5. 1 Flat Shading - The three vectors - l, n, and v

n 5. 1 Flat Shading - The three vectors - l, n, and v - can vary • • but for a flat polygon, n is constant if we assume the viewer does not change, v is constant • if the light source is distance, l is constant - If all three are constant, the shading calculations only need to be carried out once for each polygon. - In Open. GL we specify flat shading through • gl. Shade. Model(GL_FLAT); • This can be disappointing in its results • Figure 6. 27 CS 480/680 Chapter 6 -- Shading 40

n 5. 2 Interpolative and Gourand Shading - If we use: • gl. Shade.

n 5. 2 Interpolative and Gourand Shading - If we use: • gl. Shade. Model(GL_SMOOTH); – Then Open. GL interpolates colors for other primitives like lines - The normals are computed at each vertex. Colors and intensities of interior points are interpolated between vertices. - Problem: normals are discontinuous at the vertex • Figure 630 - Solution: average them - Color plates 3 -5 show flat shading up to interpolative. CS 480/680 Chapter 6 -- Shading 41

n 5. 3 Phong Shading - Even the smoothness introduced by Gourand shading may

n 5. 3 Phong Shading - Even the smoothness introduced by Gourand shading may not prevent bands. - Phong proposed that instead of interpolating the intensities, interpolate the normals – Figure 6. 32 – Figure 6. 33 • and then do calculation of intensities using the interpolated normal (typically at scan conversion) - This is much smoother, but at a greater computational cost. CS 480/680 Chapter 6 -- Shading 42

6. Approximation of a Sphere by Recursive Subdivision - We have used the sphere

6. Approximation of a Sphere by Recursive Subdivision - We have used the sphere as an example curved surface to illustrate shading clculations. - However, the sphere is not an object that is supported within Open. GL • Both the GL utility library (GLU) and the GL Utility Toolkit (GLUT) contain spheres – GLU via quadric surfaces • A topic discussed in Chapter 10 – GLUT via polygonal approximation CS 480/680 Chapter 6 -- Shading 43

n This section develops a polygonal approximation to a sphere. n This figure shows

n This section develops a polygonal approximation to a sphere. n This figure shows an approxiamtion to a sphere drawn with this code n Figure 6. 36 CS 480/680 Chapter 6 -- Shading 44

7. Light Sources in Open. GL - Open. GL supports the four types of

7. Light Sources in Open. GL - Open. GL supports the four types of light sources that we just described, and allows at least 8 light sources per program. - Each light source must be individually specified and enabled( – gl. Lightfv(source, parameter, pointer_to_array) – gl. Lightf(source, paramter, value); CS 480/680 Chapter 6 -- Shading 45

n There are four vector parameters that we can set - The position (or

n There are four vector parameters that we can set - The position (or direction) of the light, the amount of ambient, diffuse, and specular light associated with a source - For example: • • • gl. Enable(GL_LIGHTING); gl. Enable(GL_LIGHT 0); gl. Lightfv(GL_LIGHT 0, GL_POSITION, light 0_pos); gl. Lightfv(GL_LIGHT 0, GL_AMBIENT, ambinet 0); gl. Lightfv(GL_LIGHT 0, GL_DIFFUSE, diffuse 0); gl. Lightfv(GL_LIGHT 0, GL_SPECULAR, specular 0); - Note that we must enable both lighting and the particular source. CS 480/680 Chapter 6 -- Shading 46

- We can also set a global ambient term that is independent of any

- We can also set a global ambient term that is independent of any light • gl. Light. Model(GL_LIGHT_MODEL_AMIENT, global_ambient_data); - We can convert a source to a spotlight by choosing: • The spotlight direction (GL_SPOT_DIRECTION) • The exponent (GL_SPOT_EXPONENT) • And the angle (GL_SPOT_CUTOFF) - If we have objects that we need to have the light interact properly with both sides we may need to set • gl. Light. Model(GL_LIGHT_MODEL_TWO_SIDED, GL_TRUE); CS 480/680 Chapter 6 -- Shading 47

8. Specification of Materials in Open. GL - Material properties in. Open. GL match

8. Specification of Materials in Open. GL - Material properties in. Open. GL match up directly with the supported light sources and with the Phong reflection model. • We canalsospecify different material properties for the front and the back faces of a surface - All our reflection parameters are specified through the functions: • gl. Materialfv(face, type, pointer_to_array); • gl. Materialf(face, value); CS 480/680 Chapter 6 -- Shading 48

- For Example: • gl. Materialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient); - Note: • If both the

- For Example: • gl. Materialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient); - Note: • If both the specular and diffuse coefficients are the same (as is of the case), we can specify both by using GL_DIFFUSE_AND_SPECULAR - To specify different front- and back-face properties, • we use GL_FRONT and GL_BACK - The shininess of a surface (the exponent in the specular-reflection term) is specified as follows: • gl. Matrialg(GL_FRONT, GL_SHININESS, 100. 0); CS 480/680 Chapter 6 -- Shading 49

- Open. GL also allows us to define surfaces that have an emissive component

- Open. GL also allows us to define surfaces that have an emissive component • This characterizes self-luminous sources. • This is useful if you want a light source to appear in your image. – It is unaffected by any light source – And it does not affect any other surface. • For example this defines a small amount of blue-green emission: – Glfloat emission[ ] = {0. 0, 0. 3, 1. 0}; – gl. Materialfv(GL_FRONT_AND_BACK, GL_EMISSION, emission); CS 480/680 Chapter 6 -- Shading 50

9. Shading of the Sphere Model - We can now shade our spheres. -

9. Shading of the Sphere Model - We can now shade our spheres. - If we are to shade our approximate spheres with Open. GL’s shading model, we must assign normals. - Following our previous approach, we use the cross product, and then normalize the result CS 480/680 Chapter 6 -- Shading 51

- cross(point 3 a, point 3 b, point 3 c, point 3 d) {

- cross(point 3 a, point 3 b, point 3 c, point 3 d) { d[0]=(b[1]-a[1])*(c[2]-a[2])-(b[2]-a[2])*(c[1]-a[1]); d[0]=(b[2]-a[2])*(c[0]-a[0])-(b[0]-a[0])*(c[2]-a[2]); d[0]=(b[0]-a[0])*(c[1]-a[1])-(b[1]-a[1])*(c[0]-a[0]); normal(d); } - void normal(point 3 p) { float d = 0. 0; int i; for(i=0; i<3; i++) d += p[i]; d = sqrt(d); if(d>0. 0) for(i=0; i<3; i++) p[i]/=d; } CS 480/680 Chapter 6 -- Shading 52

- Assuming the light sources have been defined and enabled: • • • CS

- Assuming the light sources have been defined and enabled: • • • CS 480/680 void triangle(point 3 a, point 3 b, point 3 c) { point 3 n; cross(a, b, c, n); gl. Begin(GL_POLYGON); gl. Normal 3 fv(n); gl. Vertex 3 fv(a); gl. Vertex 3 fv(b); gl. Vertex 3 fv(c); gl. End(); } Chapter 6 -- Shading 53

- The results f flat shading the sphere done this way is shown here:

- The results f flat shading the sphere done this way is shown here: - Figure 6. 39 - Notice the silhouette edge of the sphere showing the polygons. - We can easily apply interpolative shading by setting the true normal at the vertex. CS 480/680 Chapter 6 -- Shading 54

 • • • • • CS 480/680 void triangle(point 3 a, point 3

• • • • • CS 480/680 void triangle(point 3 a, point 3 b, point 3 c) { point 3 n; int i; gl. Begin(GL_POLYGON); for(i=0; i<3; i++)n[i]=a[i]; normal(n); gl. Normal 3 fv(n); gl. Vertex 3 fv(a); for(i=0; i<3; i++)n[i]=a[i]; normal(n); gl. Normal 3 fv(n); gl. Vertex 3 fv(b); for(i=0; i<3; i++)n[i]=a[i]; normal(n); gl. Normal 3 fv(n); gl. Vertex 3 fv(c); gl. End(); } Chapter 6 -- Shading 55

- The results of this are shown here: • Figure 6. 40 - Although

- The results of this are shown here: • Figure 6. 40 - Although this produced a more realistic image, this method is not generalizable. • See exercises 6. 9 and 6. 10 to see where it falls apart. CS 480/680 Chapter 6 -- Shading 56

10. Global Rendering - There are limitations imposed by the local lighting model that

10. Global Rendering - There are limitations imposed by the local lighting model that we have used. - Consider, for example, an array of spheres - Figure 6. 41 - CS 480/680 Chapter 6 -- Shading 57

- Our lighting model cannot handle these situations. • It also cannot produce shadows.

- Our lighting model cannot handle these situations. • It also cannot produce shadows. - If these effects are important, than we can use a more sophisticated (and slower) rendering technique, such as ray tracing and radiosity. • Ray Tracing works well for highly specular surfaces; for example, in scenes composed of highly reflective and translucent objects, such as glass balls. • Radiosity is best suited for scenes with perfectly diffuse surfaces, such as the interior of buildings. CS 480/680 Chapter 6 -- Shading 58

n 10. 1 Ray Tracing - In many ways ray tracing is an extension

n 10. 1 Ray Tracing - In many ways ray tracing is an extension of our approach to rendering with a local lighting model. • It is based upon the observation that, of the rays of light leaving a source, the only ones that contribute to our image are those that enter the lens of our synthetic camera and pass through the COP. • Figure 6. 42 CS 480/680 Chapter 6 -- Shading 59

- Most of the rays that leave a source do not enter the lens

- Most of the rays that leave a source do not enter the lens and do not contribute to our image. • Hence attempting to follow all rays from a light source is a time wasting endeavor. • However, if we reverse the direction of the rays, and consider only those rays starting at the COP, we know that these casting rays MUST contribute to the image. • Figure 6. 43 CS 480/680 Chapter 6 -- Shading 60

- Rays that go off to infinity can be assigned a background color. -

- Rays that go off to infinity can be assigned a background color. - Rays that strike a surface require us to calculate a shade for the point of intersection. • If we just use the Phong model we would produce the same image as our local renderer. • However, we can do much more! - The process that we have just describes thus far requires all of the same steps as we used in our pipeline renderer • Object modeling, Projection, Visible surface determination. • However the order is different. - Also, the renderer works on a vertex-by-vertex basis and the ray tracer works on a pixel-by-pixel basis CS 480/680 Chapter 6 -- Shading 61

- In ray tracing, rather than immediately applying our reflection model, we first check

- In ray tracing, rather than immediately applying our reflection model, we first check whether the point of intersection is illuminated. • We do this by computing shadow or feeler rays from the point on the surface to each light source. • Figure 6. 44 CS 480/680 Chapter 6 -- Shading 62

- Suppose some of our surfaces are highly reflective • Figure 6. 45 •

- Suppose some of our surfaces are highly reflective • Figure 6. 45 • We can follow a shadow ray as it bounces from surface to surface, until it either goes off to infinity or intersects a source. – Such calculations are usually done recursively CS 480/680 Chapter 6 -- Shading 63

- Ray tracing is particularly good at handling surfaces that are both reflecting and

- Ray tracing is particularly good at handling surfaces that are both reflecting and transmitting. • We follow a cast ray to a surface and follow both the reflecting ray (shadow ray) and the transmittal ray • Figure 6. 46 • The easiest way to describe a ray tracer is recursively. CS 480/680 Chapter 6 -- Shading 64

- Color Plate 23 CS 480/680 Chapter 6 -- Shading 65

- Color Plate 23 CS 480/680 Chapter 6 -- Shading 65

n 10. 2 Radiosity - Radiosity is ideal for a scene consisting of only

n 10. 2 Radiosity - Radiosity is ideal for a scene consisting of only perfectly diffuse surfaces. - Suppose we have the following scene - Figure 6. 49 - Our simple shading model has not considered the diffuse-diffuse interactions. CS 480/680 Chapter 6 -- Shading 66

- The rendering equation, if we cold solve it, would give the correct shading

- The rendering equation, if we cold solve it, would give the correct shading for all points on these surfaced. • If we make the assumption that all surfaces are perfectly diffuse, then we can simplify the rendering equation to a point where a numerical method exists. - The basic radiosity method breaks the scene into small flat polygons (patches) • Patches are then considered pair wise to consider light interaction (form factors) – This is O(n 2) • Once the form factors are known we then can solve the rendering equations. - Once these are done, the scene can be rendered in a walkthrough as fast as we could render with a local lighting model. CS 480/680 Chapter 6 -- Shading 67

- Color Plate 24 CS 480/680 Chapter 6 -- Shading 68

- Color Plate 24 CS 480/680 Chapter 6 -- Shading 68

11. Summary - We have developed a lighting model that fits well with our

11. Summary - We have developed a lighting model that fits well with our pipeline approach to graphics. • With it we can create a variety of lighting effects, and can employ different types of light sources. • Although we cannot create the global effects of a raytracer, a good graphics workstation can render a polygonal scene using the Phong reflection model and interpolative shading in the same amount of time it can render a scene without shading!!! CS 480/680 Chapter 6 -- Shading 69

- The recursive subdivision technique is a powerful one that reappears in Chapters 10

- The recursive subdivision technique is a powerful one that reappears in Chapters 10 and 11 when curves are rendered. - This chapter concludes our development of polygonal-based graphics. • You should now be able to generate scenes with lighting and shading. • Techniques for even more sophisticated images, such as texture mapping involve using the pixellevel capabilities of the graphics systems are considered in Chapter 9. - Now is a good time for you to write an application program. CS 480/680 Chapter 6 -- Shading 70

12. Suggested Readings - The use of lighting and reflection in computer graphics has

12. Suggested Readings - The use of lighting and reflection in computer graphics has followed two parallel paths: the physical and the computational • • • Foley (90) gives a great discussion on these models. Phong put together his model in 1975 Ray tracing was introduced to computer graphics by Appel in 1968. • Radiosity is based upon a method first used in heat transfer (Sie 81) and was applied to comptuer graphics in 1984. - The Open. GL Programmer’s Guide (97 a) contains many good hints on effective use of Open. GL’s rendering capability. CS 480/680 Chapter 6 -- Shading 71

Exercises -- Due next class CS 480/680 Chapter 6 -- Shading 72

Exercises -- Due next class CS 480/680 Chapter 6 -- Shading 72