CS 417 Homework 5 Solutions ------------------------------------------------------------------------ Problem 1 1.1. I was looking for an actual drawing of a little mask, and the right answer is: 1---1 / \ / \ 1---2---1 \ / \ / 1---1 This is an abbreviation for the weights 1/8 and 1/4, so it's also correct to write this mask with those numbers. One way to get this answer is to write the formulas for the fine vertex position in two ways. Label the vertices like this: d---c / \ / \ e---a---b \ / \ / f---g The two ways are the direct approach: (1/16) (b + c + d + e + f + g) + (10/16) a and the two-stage approach: (x) ( (a+b)/2 + (a+c)/2 + (a+d)/2 + (a+e)/2 + (a+f)/2 + (a+g)/2 ) + (1-6x) a which reduces to (x/2) (b + c + d + e + f + g) + (1 - 3x) a It's clear that this will be equal to the first one above when x = 1/8. See the scan for a slightly different formulation of the same idea, and another variant using the odd mask. 1.2 (see scan) ------------------------------------------------------------------------ Problem 2 Because of the simple geometry, the image coordinates of all the vertices in this problem are simple fractions like 1/3 and 1/4. This makes it easy to draw the projected polygons pretty accurately. The question of which is in front comes down to where the z value for square B becomes equal to the z value for square A, which is always equal to 4 and therefore doesn't matter whether it's interpolated or not. Whenever z is being interpolated between 3 and 5 across square B, it will be equal to 4 exactly halfway, in screen space, between the endpoints. In the configuration in the problem, the endpoints are at x = 1/3 and x = 1/5, so the midpoint is 8/30, which is a little more than 1/4. 2.1. The intersection between the squares is a bit off and does not depend on which way the square is split (see scan). 2.2. When square B' is split vertically there is no problem, because the edge separating the two triangles lines up with the intersection. When it is split horizontally the result is that the intersection happens in the right place at the top and bottom but at the wrong place in the middle (see scan). Since it's a little confusing about which way x goes, it's fine if your drawings are the mirror images of the ones in the scan. The moral of the story is that you can't really do z-buffering using world-space z unless you do something extra with the interpolation. You can, however, do it with screen-space z, which is a nonlinear remapping of world-space z under which linear interpolation does work. ------------------------------------------------------------------------ Problem 3 The exact curves are shown in the accompanying accompanying image. I was expecting hand drawn plots, though, and the accuracy requirements are just to get the discontinuities and maxima at the right places. For the curious, here is Matlab code that produced those plots. figure subplot(2,1,1); hold on fplot('max(0,cos(asin(x) - pi/4))', [-sqrt(2)/2, 1], 'k') fplot('max(0,cos(2*asin(x) - pi/4))', [-sqrt(2)/2, 1], 'r') fplot('max(0,cos(2*asin(x) - pi/4))^2', [-sqrt(2)/2, 1], 'g') fplot('max(0,cos(2*asin(x) - pi/4))^100', [-sqrt(2)/2, 1], 'b') axis([-1.33 1.33 0 1]); subplot(2,1,2); hold on fplot('max(0,cos(asin(x) - 3*pi/4))', [sqrt(2)/2, 1], 'k') fplot('max(0,cos(2*asin(x) - 3*pi/4))', [sqrt(2)/2, 1], 'r') fplot('max(0,cos(2*asin(x) - 3*pi/4)^2)', [sqrt(2)/2, 1], 'g') fplot('max(0,cos(2*asin(x) - 3*pi/4)^100)', [sqrt(2)/2, 1], 'b') axis([-1.33 1.33 0 1]); (the absence of a curve at a particular x coordinate should be interpreted as zero, in the resulting plots) In these plots there are value discontinuities at the edge of the sphere for the diffuse, front-lit case and for all the back-lit cases. There are value discontinuities at the point where the light direction is tangent to the surface for the specular, back-lit cases. There are derivative discontinuities in both diffuse plots and the n = 1 front-lit specular plot. ------------------------------------------------------------------------ Problem 4 4.1 The surface is a torus. Note that r2 is the major radius (the radius of a circle through the center of the ring) and r1 is the minor radius (the radius of a slice through the ring). The r1 < r2 requirement means there is actually a hole in the middle (otherwise the surface can become self-intersecting). 4.2 The singularities occur when the projection direction is tangent to the surface. I was expecting you'd work this out geometrically, though it is possible to write down the Jacobian of the mapping from the unit square via 3-space to texture coordinates and set its determinant equal to zero. (a) the projection is parallel to the plane along which you would slice a bagel. If we think of the torus sitting on a table (so that y is up) the rays are tangent at the top and bottom rings of the torus, which are s = 0.25 and 0.75, and at the intersection of the torus with the $z = 0$ plane, which is t = 0 and 0.5. (b) The projection is parallel to the axis through the hole in the torus. This way the rays are only tangent on the inner and outer rings of the torus, which is s = 0 and 0.5. (c) The rays are again in the horizontal plane so they are tangent at the top and bottom, s = 0.25 and 0.75. This time, since the radial rays are always crossing the surface, there are no others. (d) These rays emanate from the center of the hole, and the only time they become tangent to the surface is on the cone that just fits in the doughnut hole with the apex at the origin. This means the answer depends on the r1/r2 ratio: 2 pi s = pi +/- acos(r1/r2) (e) The projection is the same even though the surface is different so the answer is the same as (d). 4.3 The mapping from texture space (u,v) to (x,y) on the image plane is simply to divide by -z: (u, v) -> (u, -1, -v) -> (u/v, -1/v) Jacobian (derivative of (x,y) wrt. (u,v)): [ dx ] = [ 1/v -u/v^2 ] [ du ] [ dy ] [ 0 1/v^2 ] [ dv ] 4.4 The mapping the other way is the inverse of the function above: y = -1/v => v = -1/y x = u/v = -yu => u = -x/y and the derivative is [ du ] = [ -1/y x/y^2 ] [ dx ] [ dv ] [ 0 1/y^2 ] [ dy ] if we now evaluate that at (x = u/v, y = -1/v) we get the derivative as a function of (u,v): [ du ] = [ v uv ] [ dx ] [ dv ] [ 0 v^2 ] [ dy ] Along the axis the derivative is just [ v 0 ] [ 0 v^2 ] 4.5 The resolutions are set up so that the pixels on the image plane are the same size as the texels on the ground plane (both are .01 units by .01 units). (a) The small circular area of a pixel footprint will become an ellipse that is stretched horizontally by a factor of v and vertically by a factor of v^2 compared to its size on the projection plane. So the area of the texture plane that is covered is v^3 times the area in the image, which is 1. Thus we need to solve k = 1 * v^3 for k = to 2, 3, and 4, resulting in: v = 2^(1/3), v = 3^(1/3), v = 4^(1/3), or 1.26, 1.44, 1.59 (b) The long axis is in the v direction, and we already worked out that it is v^2 times the height of the pixel footprint in image plane. The diameter of a unit-area circle (in pixel space) is pi D^2 / 4 = 1 D = 2 / sqrt(pi) pixels so we have k = 2 v^2 / sqrt(pi) v = sqrt(k sqrt(pi) / 2) for k = 2, 3, 4, or 1.33, 1.63, 1.88 (c) As we move off the v axis, the projected footprint is sheared by the introduction of the uv entry in the Jacobian. This shear does not affect the area of the footprint but it does cause the length of the long axis to increase.