Lightspeed 3D: Surface Properties
The surface of a triangle is described by two functions:
- Shading Function: this determines how bright the triangle appears at each point -- variations in shading can give a single triangle the appearance of curvature or bumps.
- Color Function: this determines the color of each point on the triangle. It may be a solid color, or it may display a complex pattern.
There are several levels of shading, with different speeds. From fastest to slowest, these are:
- Flat, self-lit. Leave the fFlatShading flag set (the default), and after adding the triangle to the scene with myScene.AddTriangle(mytri), zero its normal with mytri.mNormal.Set(0,0,0). The engine will then draw the polygon in its color, with no regard to the lighting angle. (However, it will still appear dark if the light is on the far side of the triangle; i.e., it is still self-shadowing.)
- Flat, normal shading. This is the default. The triangle appears an even shade, but this shade depends on the angle it makes with the light.
- Flat, shading function. After creating your triangle, give it a shading function (e.g., mytry.mShadingFunc = new ShadingFunc). You may also need to set the vertex normals (mNormals through mNormals), if the standard triangle normal doesn't work for you. This option is used for Gouraud shading (done by the base class ShadingFunc), and can also be used for such things as bump maps or custom shaders.
There are two types of coloring, also with different speeds.
- Solid color. This is the default, and obviously faster than the alternative. The triangle appears as a solid color, defined by its mColors property. This is a 3D vector with x,y,z mapped to red, green, and blue, each value in the range 0 to 1. For example, you'd set your triangle to bright yellow with myTriangle.mColors.Set(1,1,0).
- Color function. You can assign a color function, much like assigning a shading function. The base class (ColorFunc) simply interpolates between the color at each vertex (mColors through mColors). Derived classes could instead look up an appropriate color from a picture (i.e., a texture map), or compute a color based on some more complex function.
. . . . . .