521493S Comuter Grahics Exercise 3 (Chaters 6-8) 1 Most grahics systems and APIs use the simle lighting and reflection models that we introduced for olygon rendering Describe the ways in which each of these models are incorrect For each defect, give an examle of a scene in which you would notice the roblem Point sources roduce a very harsh lighting Such images are characterized by abrut transitions between light and dark The ambient light in a real scene is deendent in both the lights on the scene and the reflectivity roerties of the objects in the scene, something that cannot be comuted correctly with OenGL The Phong reflection term is not hysically correct; the reflection term in the modified Phong model is even further from being hysically correct 2 Comare the shadow-generation algorithm that uses rojections to the generation of shadows to a global rendering method that solves the rendering equation What tyes of shadows can be generated by one method but not the other? Global rendered that solves rendering equation calculates all shadows almost erfectly In that renderer, as each oint is shaded, a calculation is done to see which light sources shine on it through any route hotons can take and how much The rojection aroach assumes that we can roject each olygon onto all other olygons If the shadow of a given olygon rojects onto multile olygons, we could not comute these shadow olygons very easily In addition, we have not accounted for the different shades we might see if there were intersecting shadows from multile light sources, reflection of light from other surfaces, refractions of light through transarent surfaces etc Plainly, shadow rojection is very crude aroximation of lighting Even ray tracing doesn t get close 3 How is an image roduced with an environment ma different from a ray traced image of the same scene? The major roblem is that the environment ma is comuted without the object in the scene Thus, all global lighting calculations of which it should be art are incorrect These errors can be most noticeable if there are other reflective objects will now not show the reflection of the removed object Other errors can be caused by the removed object no longer blocking light and by its shadows being missing Other visual errors can be due to distortions in the maing of the environment to a simle shae, such as a cube, and to errors in a two ste maing In addition, a new environment ma should be comuted for each viewoint 1
4 In what tyes of alications might you refer a front-to-back rendering instead of a back-to-front rendering? Generally back-to-front rendering is nice because faces in front always aint over surfaces behind them However, the final color is not determined until the front most object is rocessed Suose you have a lot of overlaing oaque objects Then most of the rendering will have been wasted since only the final faces will determine the image In alications such as ray tracers, a front-to-back rendering can be far more efficient as we can sto rocessing objects along a ray as soon as we encounter the first oaque object 5 In what circumstances can you see aliasing roblems with texture maed surfaces? What tools does OenGL rovide to counter these effects? When texture is drawn on a surface by samling each texture osition at frequency that is lower than the actual rate the texture changes, aliasing can occur For examle with a black and white stried texture, we might samle values that are all white while all black stries can be resent between those samling oints In general, this kind of samling can cause flickering of small details in the texture OenGL allows use of different detail levels for textures At highest level, the original texture is used At next level, texture scaled to 1/4 size of the original is used At this level, each texture ixel values get average values of 4 ixels each At next level image is scaled down again and ixel values get averages of the revious level This technique is called mimaing When texture is alied during the rendering, roer level or even interolation between two closest levels of the texture is selected to avoid aliasing deending on the selected texturing mode When texture should be scaled down only on one direction and not on other, mimaing generally roduces blurry results as it assumes isotroic filtering requirements and not anisotroic Anisotroic filtering may be available as OenGL extension with the name of GL_EXT_texture_filter_anisotroic 2
6 Consider two line segments reresented in arametric form: (α) = (1 α) 1 + α 2, q(β) = (1 β)q 1 + βq 2 Find a rocedure for determining whether the segments intersect, and, if they do, for finding the oint of intersection Assume three dimensional coordinates First, consider the roblem in two dimensions We are looking for α and β such that both arametric equations yield the same oint, that is x(α) = (1 α)x 1 + αx 2 = (1 β)x 3 + βx 4, y(α) = (1 α)y 1 + αy 2 = (1 β)y 3 + βy 4 These two equations in the two unknowns an α and β and, as long as the line segments are not arallel (a condition that will lead to a division by zero), we can solve for α and β If both these values are between 0 and 1, the segments intersect As the equations are in 3D, we can solve two of them for the α and β where x and y meet If when we use these values of the arameters in the two equations for z, the segments intersect if we get the same z from both equations ----------------------------------------- 7 Prove that cliing a convex object against another convex object result in at most one convex object If we cli a convex region against a convex region, we roduce the intersection of the two regions, which is the set of all oints in both regions, which is a convex set and describes a convex region To see this, consider any two oints in the intersection The line segment connecting them must be in both sets and therefore the intersection is convex 8 Draw a one ixel wide line using Bresenham s algorithm from (10, 3) to (6, 8) We are drawing a line from (10, 3) to (6, 8) For Bresenham s line drawing algorithm, we need to calculate the following variables: x = 6 10 = 4 y = 8 3 = 5 The formulas in lecture material assume that y and both of them are 0 For more generic aroach we can define the movement so that east (E) is always the longer axis and 3
north (N) is the shorter one and they are always ositive Actual movement delta deends on the sign of the and y Because in this case y we define the variables in the following way: Long direction E y 5 Short direction N 4 Movement directions are E 0 1 and 1 1 NE Initial decision variable d 2 N E 2 y 2 4 5 3 Forward udate incre 2 N 2 2 4 8 incrne 2 N E 2 y 2 4 5 Diagonal udate 2 1 Setu initial oint: 10 3 ; Draw ixel at d 3 0 NE 9 4 ; d d incrne 2 1 3 1 ; Draw ixel at d 1 0 NE 8 5 ; d d incrne ; Draw ixel at d 1 0 E 8 6 ; d d incre 4 7 d 7 0 NE 7 7 ; d d incrne 5 5 d 5 0 NE 6 8 ; d d incrne 6 3 7 End oint reached ; Draw ixel at ; Draw ixel at ; Draw ixel at The easiest way to verify correctness is to use DDA algorithm as they should match exactly 9 Check if oint (3, 4) is inside concave olygon defined by vertices (1, 1), (6, 3), (4, 6), (1, 5), (2, 3), (1, 1) 4
Vertices (1, 1), (6, 3), (4, 6), (1, 5), (2, 3), (1, 1) form a olygon from line segments (1, 1; 6, 3), (6, 3; 4, 6), (4, 6; 1, 5), (1, 5; 2,3), (2, 3; 1, 1) One way to check if a oint is inside a olygon (even a concave one) is by counting how many times a horizontal line starting from it crosses olygon borders As we are investigating oint (3, 4) using a horizontal line, we need to check only lines that cross line y=4 Lines that cross this line are (6, 3; 4, 6) and (1, 5; 2, 3) Next we need to solve what are the x values for those line segments when y = 4 For line (6, 3; 4, 6): x = ky + b = d x y + b = 4 6 y + b = 2 y + b d y 6 3 3 Solving b at oint (6, 3): 6 = 2 3 + b b = 8 3 When y=4: x = 2 16 4 + 8 x = 5,33 > 3 so crossing is on right side of oint to 3 3 check Similarly for line (1, 5; 2, 3): x = ky + b = d x y + b = 2 1 y + b = 1 y + b d y 3 5 2 Solving b at oint (1, 5): 1 = 1 2 5 + b b = 7 2 When y=4: x = 1 4 + 7 x = 3 = 15 < 3 so crossing is on left side of oint to check 2 2 2 Odd number of olygon border crossings on one side means that the oint is inside the given olygon as we don t have any secial cases here either Even number would have been outside We can verify the correctness by drawing a icture 10 Images roduced on dislays that suort only a few colors or gray levels tend to show contour effects because the viewer can detect the differences between adjacent shades One technique for avoiding this visual effect is to add a little noise (jitter) to the ixel values Why does this technique work? How much noise should you add? Does it make sense to conclude that the degraded image created by the addition of noise is of quality higher than the original image? 5
If there are very few levels, we cannot dislay a gradual change in brightness Instead the viewer will see stes of intensity A simle rule of thumb is that we need enough gray levels so that a change of one ste is not visible We can mitigate the roblem by adding one bit of random noise to the least significant bit of a ixel Thus if we have 3 bits (8 levels), the third bit will be noise The effect of the noise will be to break u regions of almost constant intensity so the user will not be able to see a ste because it will be masked by the noise In a statistical sense the jittered image is a noisy (degraded) version of the original but in a visual sense it aears better 6