Week 8 Solution

Question 1

We have to normalize the surface normal, so N = (0,0.6,0.8). N.L= 0.8.

Result is 0.8x(0.4×0.2, 0×0.7, 1×0.9) = (0.064,0,0.72)

Question 2

This is a diamond in the x-y plane. Drawing a diagram may help students understand the solution better.

(a) The centre of the polygon is the average of all the vertices, hence. (-1+0+1+0,0-1+0+1,0+0+0+0)/4 = (0,0,0).

(b) Normal is:
\begin{array}{rcl}
(b-a)\times(c-b)&=& (0-(-1), -1-0, 0) \times (1-0, 0-(-1), 0)\\
&=& (1,-1,0) \times (1,1,0)\\
&=& (0,0,2)\end{array}
Normalise = (0,0,1)

(c) From the centre = (5,5,5)-(0,0,0) = (5,5,5).
Normalised = (1,1,1)/\sqrt 3
From D = (5,5,5)-(0,1,0) = (5,4,5)
Normalised = (5,4,5)/\sqrt 66

(d) From the centre = (5,0,10)-(0,0,0) = (5, 0, 10).
Normalised = (5,0,10)/\sqrt 125  = (1,0,2)/\sqrt 5
From D = (5,0,10)-(0,1,0) = (5,-1,10)
Normalised = (5,-1,10)/\sqrt 126

(e) Note, all RGB values are the same so we can just do it once for all three
From centre: (don’t forget, we have to use normalised N and L).
\begin{array}{rcl}I &=& I_ak_a + I_lk_d\vec N\cdot \vec L \\
 &=& 0.2\times0.5 + 0.8\times0.5(0,0,1)\cdot(1,1,1)/ \sqrt 3\\
 &=& 0.1 + 0.8\times 0.5 \times 1/\sqrt 3\\
 &\approx& 0.33\end{array}
Hence colour is (0.33,0.33,0.33)

From D:
\begin{array}{rcl}I &=& 0.2\times0.5 + 0.8\times0.5\times(0,0,1)\cdot (5,4,5)/\sqrt 66\\
  &=& 0.1 + 0.8\times 0.5\times 5/\sqrt 66\\
  &\approx& 0.35\end{array}
Hence colour is (0.35,0.35,0.35)
[i.e. there is very little difference between the two. The top point is slightly brighter, but not by much.]

(f) From centre:
\begin{array}{rcl}\vec R &=& 2\vec N(\vec N\cdot \vec L) - \vec L\\ 
      &=& 2(0,0,1)/\sqrt 3 - (1,1,1)/\sqrt 3\\
      &=& (-1/\sqrt 3 , -1/\sqrt 3, 1/\sqrt 3)\end{array}
From D:
\begin{array}{rcl}   R &=& 10(0,0,1)/\sqrt 66 - (5,4,5)/\sqrt 66\\
       &=& (-5,-4,5)/\sqrt 66\end{array}

(g) From centre:
\begin{array}{rcl} I_s &=& I_lk_s(\vec V\cdot \vec R)^n\\
     &=& 0.8\times 0.9 ((1,0,2)/\sqrt 5\cdot (-1,-1,1)/\sqrt 3)^5\\
     &=& 0.8*0.9*(1/\sqrt 15)^5 \\
     &\approx& 0.001\end{array}
- really insignificant.

From D:
\begin{array}{rcl}I  &=& 0.8\times0.9((5,-1,10)/\sqrt 126 \cdot (-5,-4,5)/\sqrt 66)^5\\
     &\approx& 0.002\end{array}
Hence it doesn’t make too much difference.

(h) Pretty much the same as the ambient and diffuse parts.

(i) This is a situation where it hardly makes any difference at all.

(j) To work this out, take the dot product of N and V. In this case, this is the same as the z value of V. IF it’s > 0, then it is NOT culled, if it is <= 0 it is culled. Answers: not culled, not culled, culled, tricky ... it's on the border, but it's so thin, so it wouldn't be rendered anyway so cull.

Question 3

a=(-1,1,1) b=(-4,2,1) c=(4,1,0)
normal to plane = (b-a)\times(c-a) = (-1,-3,-5) You can get the same answer by taking (b-a)\times(c-b)
The equation of plane -1x -3y -5z + D = 0 so D = 7
(check that each point satisfies this equation.)

Direction to first light source is (roughly) (1,1,1) so
\begin{array}{rcl}
\cos \theta &=& (1,1,1) \cdot (-1, -3, -5)/(\sqrt 3 \sqrt35)\\
&\approx& -0.88\end{array}
The - sign means that the light source is behind the triangle — we can ignore it because it will illuminate the other side of the triangle if we are not lighting up back sides of polygons.

However, if we are lighting up boths sides of a polygon, then we take the absolute value of the colour. Thus the colour from first light is 0.88x(0.9×1.0,0.2×0,0.5×0.2) = (0.79,0,0.08)

Direction to second light source is roughly (2,1,0) so

\begin{array}{rcl}
\cos \theta &=& (2,1,0) \cdot (-1, -3, -5)/(\sqrt 3 \sqrt35)\\
&\approx& -0.38\end{array}
Similarly here. If we are only rendering one side of the polygon, then we would do nothing here. However, if we are lighting both sides of the polygon, then: Colour from second light is 0.38x(0.9×0.5,0.2×0.2,0.5×0) = (0.17,0.02,0)

Hence, the answer to part (b) is the sum of the two components: (0.96,0.02,0.08) (i.e almost pure red). However, since there are no light sources directly incident on it in part (a), then the polygon is black.

Question 4

For this question, we only worry about one value, since we’re only doing greyscale.

The Phong Illumination equation:

I =
 I_lk_d\vec N\cdot \vec L +
 I_lk_s(\vec V\cdot \vec R)^n

where

\begin{array}{rcl}I_l &=
& \mbox{brightness of the light source}\\ 
k_d &=
& \mbox{coefficient of diffuse reflection}\\ 
k_s &=& \mbox{coefficient of specular reflection}\\ 
\vec N  &=& \mbox{Normal vector (normalised)}\\
\vec L  &=& \mbox{Vector to light source (normalised)}\\
\vec V  &=& \mbox{Vector to viewer (normalised)}\\
\vec R  &=& \mbox{Reflection of L} = 2\vec N(\vec N\cdot \vec L)-\vec L \mbox{(normalised)}\end{array}

So, for, say, the left (-1,0,0) corner …

\begin{array}{rcl}
\vec N\cdot \vec L &=& (-1/\sqrt 2, 0, 1/\sqrt 2)\cdot(0,0,1)\\ 
&=
& 1/\sqrt2\\
\vec R &=& 2(-1/\sqrt 2,0,
1/\sqrt 2)/\sqrt 2-(0,0,1)\\ 
&=
& (-1,0,1)-(0,0,1) = (-1,0,0)\end{array}

This means that the ray is reflected along the negative x axis!

So if we work out V.R now …

(0,0,1).(-1,0,0) = 0 !!

Why is this? This is because the light is reflected in a direction perpendicular to the direction to the viewer. Because V.R = 0, there is no specular component!

Hence the brightness of the top corner is:

I = 0.8×0.3×0.707 = 0.17

Further calculations will show that the other corners are exactly the same colour (I wonder why that would be :-) ).

(b) As mentioned above, there is no specular component, because the light is reflected perpendicular to the viewer.

(c) In Gouraud shading, we interpolate the colours of the corners. In this case, however, since the three corners are the same intensity, then interpolation of the same intensity will lead to the whole triangle being the same intensity - 0.17. If they were different colours, we would have to interpolate linearly.

(d) In Phong shading, we interpolate the normals along a polygon. Since the point (0,0,0) is exactly midway along the bottom edge of the polygon, then we would be interpolating between the normals at (-1,0,0) and (1,0,0). Since (0,0,0) is exactly in the middle between these two points, the normal would be the average of the two, i.e.

[(-1/\sqrt 2,0,1/\sqrt 2) + (1/\sqrt 2, 0, 1/\sqrt 2)]/2 = (0,0,1/\sqrt 2)

But now we have to normalise, since we need N to be normal …

(0,0,1/\sqrt 2)/(1/\sqrt 2) =
 (0,0,1)

Hold on … this means that the normal would be pointing straight at the viewer!! Hence we would expect maximum intensity at this point. Let’s see if the maths bears this out.

(e)

\begin{array}{rcl}
\vec N\cdot \vec L &=
& (0,0,1)\cdot(0,0,1) = 1\\
\vec R &=& 2(0,0,1)(\vec N\cdot \vec L)-(0,0,1)\\ 
&=& (0,0,2)-(0,0,1) = (0,0,1)\\
\vec V\cdot \vec R &=
& (0,0,1)\cdot (0,0,1) = 1\end{array}

And now … substituting into the equation.

\begin{array}{rcl}
I &=& 0.8\times 0.3\times 1 + 0.8\times 0.7\times 1^{20}\\
  &=& 0.24+0.56 =0.8
\end{array}

This is a lot brighter than what Gouraud shading would have led to. It is also more correct. Hence this is an example of the superiority of Phong shading over Gouraud shading.

Leave a Reply

You must be logged in to post a comment.


Bad Behavior has blocked 50 access attempts in the last 7 days.