The 3D Story
Your guide to the third dimension.

Shading

The shading method described here is really only a continuation of the face-hiding method described in the previous chapter. I call it NVB-shading, which is short for Normal Vector Based shading.
This method is based on the angle to the viewer, or any other lightsource. Also, a weighted medium can be used. This most often provide the best looking results.
How do we do this then. Well, when we check if the surface is hidden or not, we also get a cos value. This cos value varies from -1 to 0 (if the surface is visible). To use this in shading, I use 16 main colours with 16 sub colours (shades of the main colour). To get the index of a specified colour, use the following formula :

I=CMain*16-cos(A)*15

The ...16-cos(... is due to that the angle is negative when the surface is visible.
As the cos value is negative, the result will be equivalent to an addition.


This means that the index of the colour is the main colour's number, multiplied by 16. This value is then added to the cos value multiplied by 15. The surface is then drawn using this colour.
To use light sources, just get the angle between the light and the surface's normal vector. This value can then be used in the formula specified above. Otherwise, you can use a weighted medium of the two.
For example, if we want the light source to be the main factor, specifing 70% of the light, and the angle to the viewer to specify the remaining 30%, we can achieve this using the following formula :

I=CMain*16-(cos(AViewer)*15)*0.3-(cos(ALight)*15)*0.7

By using any of these methods, you make it possible to differ a sphere from a flat circular surface.



[ Previous | Main Page | Next ]
Copyright©1997 Johan E. Thelin