Compute the image intensity on a spherical surface under orthographic projection I got stuck on the folllowing exercise:

Consider a spherical surface of radius $r$ centered at the origin with equation:$$z = d - \sqrt{r^2 - x^2 - y^2}, \quad x^2 + y^2 \leq r$$. The surface is Lambertian with constant albedo $\rho_S = 1$, and is illuminated by a light source at a very large distance, from a direction defined by the unit vector $[a, b, c]$ with $c$ negative. The camera is on the negative $z$-axis. Show that the image intensity under orthographic projection is given by: 
  $$ E(x,y) = \frac{ax + by - c\sqrt{r^2 - x^2 - y^2}}{r}.$$

I made two attempts to solve it.
Attempt 1
The intensity $I$ of a surface at a certain point is:
$$I = \rho_s I_i \vec{n} \cdot \vec{L}, $$
where $I_i$ is the intensity of the light source, $\vec{L}$ the direction of the light source, and $\vec{n}$ the normal of the surface at that point.
If we rewrite the surface equation as:
$$d = \sqrt{r^2 - x^2 - y^2} + z$$
the normal is the gradient of that function:
$$\vec{n} = \left[ \frac{-x}{\sqrt{r^2 - x^2 - y^2}}, \frac{-y}{\sqrt{r^2 - x^2 - y^2}}, 1 \right]$$
The image intensity would then be, simply ignoring $I_i$ and using that $\rho_s = 1$:
$$
E(x,y) = \vec{n} \cdot \vec{L} = \frac{-xa}{\sqrt{r^2 - x^2 - y^2}} + \frac{-yb}{\sqrt{r^2 - x^2 - y^2}} + c$$
Which is clearly not the correct function.
Attempt 2
I found that the normal of a sphere is:
$$\vec{n} = \left[x, y, \sqrt{r^2 - x^2 - y^2} \right].$$
If we then compute the image intensity, once again ignoring $I_i$ and using that $\rho_s = 1$:
$$E(x,y) = - ax - by + c\sqrt{r^2 - x^2 - y^2}$$
Which is once again wrong, but looks more like the correct answer.
Which leaves me with the question, how should I solve this exercise? 
 A: A sphere centered at the origin implies $d=0$. Further, because it is centered at the origin, the unit normal vector is always $\hat{r}=(x\hat x + y\hat y + z\hat z)/r$, where $z=-\sqrt{r^2-x^2-y^2}$. The hat notation implies a unit vector in that direction. For instance, $\hat x=[1,0,0]$ is a unit vector in the $x$ direction. Then the normalized intensity of light striking the sphere at position $\vec{r}$ is proportional to $\hat{r}\cdot\hat u$ (just as you pointed out in attempt 1) where $\hat u = [a,b,c]$. Expanding the dot product gives $$\hat{r}\cdot\hat u = \frac{1}{r}[x,y,z]\cdot[a,b,c]=\frac{ax+by+cz}{r}=\frac{ax+by-c\sqrt{r^2-x^2-y^2}}{r}$$
As to the question asked, one can take the gradient of the function that describes a surface of constant value to find the normal vector to the surface. In this case we look at surfaces of constant radius, $r(x,y,z)=\sqrt{x^2+y^2+z^2}$. This gives $\nabla r = \hat r$ from above. Note that this vector is already normalized, but the gradient doesn't always return a unit vector. 
One final remark is that you must ensure the two vectors in the dot product are unit vectors in order for the formula to work. If you just have any old vector that is normal to the surface then you will need to divide it by its length.
-- Addendum --
If the sphere is not centered at the origin, but instead at position $[x_0,y_0,z_0]$ then the function describing a spherical surface around that point would be $r(x,y,z)=\sqrt{(x-x_0)^2+(y-y_0)^2+(z-z_0)^2}$. In this case the gradient of $r$ gives $\nabla r = [x-x_0,y-y_0,z-z_0]/r=[x-x_0,y-y_0,z_0 \pm \sqrt{r^2-(x-x_0)^2-(y-y_0)^2}]/r$ which again happens to be a unit vector. The $\pm$ comes from the fact that you have two options to choose (just like the $\pm$ in the quadratic equation). 
