Defining Your Materials

[ LiB ]

Defining Your Materials

Light brings the visual awareness to our brains by which we perceive how light interacts with different kinds of surfaces. To define the different types of natural lighting effects, you must use numbers in the computer to differentiate each type of material. The size, weight, and appearance of an object are the base values that our brains use to interpret our reality. You must create values that can track each phenomenon for an object's color , opacity, specu-lar reflection, diffuse reflection, and the index of refraction. These are just a few factors you have to take into account as you develop your 3D environment. Most of the numbers will be defined in a unit range that will have a maximum value of 1.0 and a minimum value of 0.0. The following code defines a structure that includes these attributes:

 class cMaterial {   public:        // for global lighting         float fAmbientFactor;         color3 Color;         // for diffuse related effects         float fDiffuseFactor;         float fOpacity;         // for specular related effects      float fShininess;      float fSpecularFactor;      float fSpecularExponent;      // for refracted effects       float fIndex_Of_Refraction;      // texture filename      char Texture[16];       cMaterial()       {           fAmbientFactor              = 0.1f;           Color                       = color3::White;           fDiffuseFactor              = 0.5f;           fOpacity                    = 1.0f;           fShininess                  = 0.5f;           fSpecularFactor             = 0.0f;           fSpecularExponent           = 26.5f;           fIndex_Of_Refraction        = 0.0f;           memset( Texture, 0, 16);       }; }; 

The following sections briefly discuss each member variable, so you'll have a better understanding of the Material's class design.

Ambient Factor

The ambient factor applies to ray tracing. It's primarily used to give the scene a predetermined baseline value of lighting in order to shade dark areas. If this value is 0.10 or 10% it means that 90% of the lighting will be calculated in the scene. This factor produces better realism in shadows.

Color

The color of an object is very important to defining a beautiful scene; you have 16.7 million colors to choose from. Colors on surfaces just give an overall appearance but the real magic is shading each point on the surface with a variation of the overall color. This is what creates the illusion of lighting.

Diffuse Factor

The diffuse factor indicates how much of the light coming from an arbitrary light source is diffusively reflected. This is the light that scatters on a surface as well as reflects arbitrarily in random directions. For example, a diffuse factor of 0.9 states that 90% of the light observed from the surface comes directly from the light. The brightness and scattering of the light on the surface determines the diffuse factor value. This value ranges from 0.0 to 1.0.

Opacity

The opacity of an object, or how solid it appears, is very important. For example, if an object is 0.5 opaque , it will look half transparent and half solid. The maximum opacity value is 1.0, which means that the object is perfectly solid. A smaller value can be used for glass, water, and diamonds.

Shininess

The shininess of an object is the smoothness of the object. The smoother the object is, the less imperfection in the material, which causes the light to reflect off the surface. Metals such as chrome, mercury , gold, and aluminum are all examples of shiny surfaces. This value is in a range of 0.0 to 1.0.

Specular Factor

The specular factor defines the light that reflects off of the same angle of incidence as it hits the object. Specular reflections mostly reflect light directly off of the surface in a particular direction instead of many directions as in diffuse reflection. This value is in a range of 0.0 to 1.0. Mirrors typically have a specular reflection of 1.0.

Specular Exponent

The specular exponent generates a specific highlight on a smooth surface. This is a specific spot on the surface that directly reflects the intensity of the light source. For example, an apple has a bright shiny highlight on the surface when placed next to a lamp. The specular exponent on a surface contributes to this type of highlight.

Index of Refraction

The index of refraction depicts the bending of the light as the light changes from medium to medium. The following table illustrates this fact.

Material

Refraction Index

Air (STP)

1.00029

Water

1.33

Ice

1.31

Glass:

Light flint

1.58

Heavy flint

1.65

Heaviest flint

1.89

Diamond

2.42


Texture

The texture parameter is a character array of the texture image file you would like to use when rendering the surface. Adding texture support to an application increases realism tremendously. Although we have a texture parameter it won't be used in this book.

[ LiB ]


Focus On Photon Mapping
Focus On Photon Mapping (Premier Press Game Development)
ISBN: 1592000088
EAN: 2147483647
Year: 2005
Pages: 128
Authors: Marlon John

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net