How to make Phong shading fast
Some optimalisations to display 3D objects faster:
- Use integer arithmic only. Floating point calculations can be emulated
by using fixed point values represented as integers.
- Use a lookup-table for sinus and cosinus values
- Use a rotation matrix for rotating vertices and normal vectors.
- Do Parallel projection instead of the more natural perspective projection
of the objects. This avoids 2 divisions per vertex for each frame.
Some optimalisations / simplifications to make Phong shading faster:
- Use only one light point that is at the viewpoint.
This simplifies the calculation of the angle between reflection vector
and the view vector, because this is now 2 times the angle between
the view vector and the normal vector of the surface.
- The normal vectors of all vertices of an object are precalculated at
run-time. These vectors are rotated together with the vertices of
the object.
- Use a lookup table (2 dimensional, like a texture) for Phong Illumation
values. This texture consists of a number of circles around the center.
The intensity increases non-linear from a corner of the texture
to the middle. This texture is pre-calculated at run-time.
- No normal vector interpolation but texture mapping of (a part of) the
lookup table.
The rotated normal vector at each vertex of a surface are used to
determine the area that needs to be mapped on that surface.
This is done by projected the normal vector onto the x,y plane
(this leaving out the z) and the resulting (x,y) coordinates are used
as an offset in the texture map (multiplied by some constant linear
scaling factor if needed).
- The object rotates, but the viewpoint remains constant. Now the
normal vector alone is enough to determine the color of the surface