Download presentation
Presentation is loading. Please wait.
1
CS 376 Introduction to Computer Graphics 03 / 26 / 2007 Instructor: Michael Eckmann
2
Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Today’s Topics Questions? Visible Surface determination –Scanline algorithm –Raycasting Illumination modeling
3
Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Scanline Algorithm The Scanline algorithm for visible surface determination is an image precision algorithm. It is an extension to the scan conversion algorithm we discussed for filling a polygon. But now, we need to deal with a set of polygons, not just one. The Scanline algorithm processes one scanline of the frame buffer at a time. One assumption we are making (which can be overcome with modifications to the algorithm) is that no polygons penetrate each other.
4
Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Scanline Algorithm 1) Create an edge table for all edges that are not horizontal (ignore those) that are projected onto the view plane. 2) Given the x,y,z coordinates of the 2 endpoints of the edge, –Sort the edges in the edge table according to the smaller y (the y of the lower endpoint) of its two endpoints and then within those with the same smaller y, sort by increasing x of the lower endpoint. 3) Each entry in the edge table contains the following information about each edge –a) x coordinate of the endpoint with smaller y –b) y coordinate of the other endpoint –c) x increment – the value to increment x when moving from one scanline to the next –d) polygon ID 4) A polygon table, keyed on polygon ID contains coefficients of the plane that polygon is on, the color info for it, and a boolean in-out flag used during the algorithm.
5
Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Scanline Algorithm 5) An Active Edge Table is also stored during the running of the algorithm. For the current scanline, the active edge table contains the edges, in order by increasing x, whose projections onto the view plane intersect with the current scanline. Pseudocode for this algorithm: –Initialize frame buffer to background color –Add edges to edge table –Add polygons to polygon table –For (each scanline) Update active edge table Starting at the edge with the lowest x For (each pixel in scanline) –Determine if went in or out of any polygons (set appropriate in-out flags) –Test in-out flags, if “in” only one polygon, draw that color –If not “in” any polygons do nothing –If “in” multiple polygons then determine which polygon is closest (make depth calculations based on plane coefficients) and draw that color
7
Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Scanline Algorithm Modifications can be made for efficiency by exploiting different coherence properties. To reduce depth computations - –Within a scanline, the same polygon influences the color of the pixels between two edges, regardless of how many polygons we are “in”, so depth computations are only necessary when entering a polygon or leaving a polygon. –Assuming we have two or more overlapping (in z) polygons and as we scan across the scan line we leave (go past right edge of) one of the polygons. If the polygon we just left was just obscured then we don't need to compute the depth among the other polygons, we can just draw the color of the polygon that was closest (because it must still be closest). Only when leaving a closest polygon are depth calculations necessary. Example on the board. –Also if the same edges are active and in the same order from one scanline to the next, no depth computations are necessary because no depth relationship changes have occurred. Just draw the same colors in the same order (but possibly a different number of pixels each.) Example on the board.
8
Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Scanline Algorithm This algorithm, although specified as working only for polygons can be extended to work for arbitrary (curved) surfaces. This is accomplished (partially) by replacing the edge table and active edge table with a surface table and an active surface table.
9
Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Raycasting method Raycasting is an image precision visible surface detection method. Consider line of sight from a pixel position on a viewplane through a scene. We are tracing the paths of light rays. Light rays emanate from objects into our eyes. To determine which object influences the color at a pixel, we trace the light ray path backwards from the pixel out into the world and determine which object it passes through first. Works well for scenes with curved surfaces, like spheres, etc. Ray-tracing is an extension of ray casting that we will discuss in detail in the weeks to come.
11
Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Looking ahead The topics that I plan to cover next are mostly in chapter 10: –Illumination models and Shading models –Texture mapping, bump mapping – to add details –Ray tracing and radiosity
12
Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Illumination Until now we have been dealing with solid colored polygons. Solid colors make objects look flat --- do not give a 3d effect. There are many schemes to shade and to simulate light and shadows in a scene. Depth cueing (discussed at the end of chapter 9) is one way to achieve some sense of depth / clarity in a scene. –Imagine a polygon that is not perpendicular to the x-y plane (that is, it spans a range of depths (z) in the scene). –The nearer points of the polygon can be made more intense than the further points of the polygon. This can be done gradually to get the effect of fading into the distance. –The intensity can be multiplied by a factor. The factor is a function of the depth of the point. Depth cueing is a light source independent model of illumination.
13
Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Illumination Illumination models are used to calculate the color of a point on the surface of an object. A surface rendering method uses the calculations from the illumination model to determine the pixel colors of all the projected points in a scene. –Can be done by doing illumination model calculations at each pixel position (like you'll see is done in ray tracing). OR –Can be done by doing a small number of illumination calculations and interpolating between pixels (like is often done in scan line algorithms.) Two main areas that influence the realism in computer graphics are –Accurate representations of surface properties (e.g. How shiny or dull, or textured, etc.) –Good descriptions of lighting (e.g. Color of the light, position, etc.)
14
Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Illumination Besides the lighting model and the surface properties of an object, the position of the viewer has an effect on what an object looks like. Light source dependent models of illumination –The color of a point on an object is influenced by light sources Some of the properties of light sources include –Color –Intensity –Position –Direction –It is also influenced by surface properties of the object like –Color –How shiny or dull it is (how much light is reflected from it.) –It is also influenced by where the viewer is viewing the scene.
15
Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Illumination When light hits an object, it is either –Reflected (light “bounces” off the object, this is what we see) Diffuse Specular –Absorbed (what light is not seen after hitting the object) –Transmitted (refracted) passes through if the object is translucent or transparent –Or some combination of these Surface properties and lighting models are complex entities.
16
Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Illumination The simplest illumination model (the one we've been using during the course so far) is one where no lights are modelled, objects are therefore nonreflective and are self-luminous (they emit their own colors without light hitting them.) Each object's surface has a constant single color. Illumination models can be expressed with illumination equations. This particular simple model is expressed with I = k i where I is the resulting intensity and k i is the object's constant intensity –I in this case does not depend on the position of the point of which we are determining intensity
17
Illumination To take illumination one step further from that simple method, assume –Instead of self luminous objects we have objects that reflect light and –We have a nondirectional, diffuse light source (ambient/background light) that equally effects all surfaces in all directions It represents the amount of light equally reflected from all surfaces ---- Think daylight/sunlight This illumination model can be expressed with illumination equation: I = I a k a where I is the resulting intensity k a is the ambient reflection coefficient of the object (a material property of the surface that doesn't correspond directly to a physical property of materials (it's sort of a catch-all)) I a is the intensity of the ambient light
18
Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Illumination The illumination model with just the ambient light results in about the same kind of look to the scene as the self luminous objects --- uniform intensity across surfaces. To go further in our illumination model discussion, let's consider point light sources. A point light source is a light source whose light rays emanate in all directions from a point, uniformly. The point light source has a position in 3d space. Therefore, a surface's intensity will vary with the distance from the position of the point light source.
19
Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Illumination Diffuse reflection reflects light of equal intensity in all directions. Contrast this with specular reflection which reflects light in unequal intensities at different directions. Shiny surfaces result in specular reflection and dull, matte surfaces result in diffuse reflection. A Lambertian surface is one that reflects light, equally intense in all directions, independent of the viewing position. A Lambertian surface reflects light diffusely. Examples of Lambertian surfaces are matte photographic prints (as opposed to glossy prints), chalk, etc.
21
Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Illumination Lambert's cosine law is: –The intensity of the light reflected from a surface is proportional to the cosine of the angle between the surface normal and the direction to the light source. From the diagram on the last slide –If L is a vector from the surface towards the light source and N is a normal vector to the surface and A is the angle between them, then cos A = L ● N / |L||N| –If L and N are of unit length then cos A = L ● N I p is the intensity of a point white light source, k d is the diffuse reflection coefficient of the surface Our Illumination equation for a lambertian surface with a point light source is: I = I p k d L ● N
22
Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Illumination To simulate both ambient light and point light sources on diffuse reflecting surfaces, we can simply add in the ambient light term to our previous illumination equation and end up with: I = I a k a + I p k d L ● N This creates a more realistic look. Without the ambient light term objects will look harshly lit.
23
Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Illumination Light is attenuated as it moves through space. The attenuation factor is 1 / d L 2 –where d L 2 is the square of the distance from the light source Light hitting surfaces closer to the light source receive higher energy than further surfaces. Without taking this into account, two equal surfaces in the world at different distances (that overlap eachother in the viewplane), will appear to be one surface in the view plane. Example on the board.
24
Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Illumination But, because actual lights are not point light sources, and ambient light isn't exactly accurately modelling light in the world we do not use this attenuation factor exactly as 1 / d L 2 Instead, to get a more realistic look (than if we had used the inverse square law) we use an inverse quadratic function f radatten (d L ) = 1/ (a 0 + a 1 d L + a 2 d L 2 ) where the a coefficients can be adjusted for realism. We use this factor as a multiplier of the point light source term: I = I a k a + f radatten (d L ) I p k d L ● N
25
Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Illumination Specular reflection as stated before is a property of a surface where light is reflected in unequal intensities at different directions. A perfect mirror reflects light in only one direction. Less perfectly shiny surfaces reflect light more in one particular direction than other directions. Either way, consider the angle the light and the surface normal makes. The direction that the most intense light is reflected is at an angle which is equal to that angle but on the other side of the surface normal. The next slide has a diagram for specular reflection.
27
Illumination L is a vector in the direction of the light source. N is the surface normal. R is the vector which is in the direction of the maximum specular reflection. V is the vector in the direction toward the viewer. The angle between L and N is the same as the angle between N and R. The angle phi, between R and V affects how much light is reflected in V's direction. If the surface was a perfect mirror, then light is only reflected along R. If the surface is shiny, but not perfect, light is reflected mostly in R's direction but decreases reflection as we go in directions at angles away from R. An illumination model that takes into account non perfect specular reflections is the Phong model.
28
Illumination The Phong model sets the intensity of the specular reflection proportional to cos ns (phi), where phi is the angle between V and R. ns is the specular reflection exponent and is specified based on the type of surface you are modelling. Very shiny surfaces have ns values of 100 or more and less shiny surfaces can have ns values closer to 1. The Phong equation is: f radatten (d L ) I p W(theta)cos ns (phi) where W(theta) is the fraction of specularly reflected light, which is typically set to some constant, otherwise it is a function on theta which is the angle between L and N.
29
Illumination
30
Our illumination model with the Phong term added in now becomes I = I a k a + f radatten (d L ) I p k d L ● N + f radatten (d L ) I p W(theta)cos ns (phi) which can be simplified to: I = I a k a + f radatten (d L ) I p (k d L ● N + W(theta)cos ns (phi))
31
Illumination I = I a k a + f radatten (d L ) I p (k d L ● N + W(theta)cos ns (phi)) Notice the following: –the Phong term is dependent on the point light source and the attenuation factor –our whole illumination model at this point is influenced by ambient light and a point light source. Further, our object has diffuse reflection properties and specular reflection properties. And the phi angle is dependent on where the viewer is.
32
Illumination If we have more than one point light source (which is white light), then we sum up over all the light sources i: I = I a k a + Sum all i [f radatten (d L ) I pi (k d L ● N + W(theta)cos ns (phi))]
33
Illumination If the light sources are not white light sources, then we can seperate out the red, green and blue components. Also, if objects are to be colored, then they reflect different wavelengths and absorb others. Specify ambient light now as 3 components: I aR I aG I aB Specify point light now as 3 components: I pR I pG I pB Specify objects with color: O R O G O B I R = I a R k a O R + Sum all i [f radatten (d L ) I pRi (k d L ● N + W(theta)cos ns (phi))] I G and I B can be expressed similarly.
34
Illumination We typically want our Intensities to be in the range 0 to 1. With many light sources that are specified as too intense, computed intensities of objects can easily be too large (> 1). We can normalize the range of calculated intensities into the range 0 to 1. Or we can specify our light source intensities better and if any calculations go over 1, then clip them to intensity 1.
35
Directional light source The light sources that we have discussed so far were point light sources which radiated light in all directions. Real lights in the world do not have this property. Instead, real lights typically are directional. A directional light source can be described as having –a position –a directional vector –an angular limit from that vector –a color The vector will be the axis in a cone shaped volume. This volume is the only part of space that will be illuminated by this light. Anything outside the cone will not be illuminated by this light. See diagram next slide.
38
Directional light source To determine how intense the light is from a directional light source on an object we determine the angle between –the vector V o from the position of the light to the point on the object we're illuminating and –the cone axis vector V l –So, we take the dot product: V o V l = cos alpha, alpha is the angle between them. –If V o is in the same direction as V l, then the light should be the most intense (alpha = 0). The light should get less intense as we go in larger angles away from V l. –We can attenuate the light as function of alpha like so: cos al alpha where al is the attenuation exponent (a property of the light source) --- if al is 0, it's a point light source, the smaller al is, the larger the attenuation is (because the cos is less than 1.)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.