half vector of two vectors

Started by
14 comments, last by sheep19 11 years, 7 months ago
Perhaps your problem has nothing to do with computing the vector half-way between two other vectors.

I suggest you set up a very simple situation so instead of "the results don't look correct", you can actually get a specific call to this code that doesn't do the right thing. Then fire up the debugger and see where it's going wrong.

For instance (make a picture ignoring the coordinate z to follow along), if you look from the origin along (1,0,0) at a sphere with center (3,-1,0) and radius sqrt(2), you will hit it at (2,0,0). At that point the normal to the sphere is (-sqrt(0.5),sqrt(0.5),0). If you put a light source at (2,10,0), you should be smack in the middle of the specular highlight. What does your code do in that case?
Advertisement
Ok, here are the results:

With 1 point light:
2e21dly.png

With 90 point lights (in a 30x30 grid)
2e3tn6a.png

I understand why the 1st image looks like that - because it's only one light source, and it is directional.

The 2nd one is much better. I think it is "correct"?
You should not add a diffuse or specular contribution if the dot product between the normal and the direction to the light is negative (you have "fabs" in there, which creates the artifact in the middle part of the sphere on the first picture).

EDIT: Wikipedia seems to agree:
Although the above formulation is the common way of presenting the Phong reflection model, each term should only be included if the term's dot product is positive. (Additionally, the specular term should only be included if the dot product of the diffuse term is positive.)[/quote]
Oh, I didn't know that. Thanks a lot!

Here it is now:
2h8bzex.jpg

(rendering is much faster as well)
If you put the light above the object, or perhaps a little bit behind the camera, you'll get a better view of the specular highlight and you'll have a better idea of whether it looks right.

If you put the light above the object, or perhaps a little bit behind the camera, you'll get a better view of the specular highlight and you'll have a better idea of whether it looks right.


It does - I moved the camera and saw it, but I didn't send that picture.

This topic is closed to new replies.

Advertisement