Lights

A scene bundle maintains a list of lights to illuminate all 3D graphics in the scene. TSceneBundle has functions to adopt, orphan, or replace a light in the list. The AdoptLight function adopts the light to the light list and returns a light surrogate to the caller for future manipulation of the light,

      virtual TLightSurrogate AdoptLight( TLight* aLight );
      virtual TLight* OrphanLight( const TLightSurrogate& lightSurrogate );
      virtual TLight* ReplaceLight( const TlightSurrogate& lightSurrogate, TLight* aNewLight);
TLight is an abstract base class with member functions for calculating the diffuse and specular contribution of a light at a particular surface point based on the geometry, surface orientation, camera setting (for specular computation), and light color in the scene. Figure 211 shows the Light classes architecture. All TLight derived classes implement ComputeDiffuse, ComputeSpecular, and ComputeIntensity.


ComputeDiffuse and ComputeSpecular are called by a shader that adds up the diffuse and specular reflection from all lights in the scene bundle. This summation occurs in the implementations of the Diffuse and Specular functions for each TShader derived class.

The ComputeDiffuse function computes the diffuse color by iterating through the light list, calling the ComputeDiffuse function for each light, and adding the returned value to the diffuse color.

The ComputeSpecular function computes the specular color by iterating through the light list, calling the ComputeSpecular function for each light, and adding the returned value to the specular color.

ComputeIntensity is called by both ComputeDiffuse and ComputeSpecular. It calculates the intensity of a light at the location of interest, which is most often the surface point to be shaded.

Point light

A point light emits a light similar in intensity to the light emitted by a small light bulb.An attenuation factor that is computed internally reduces the light intensity as a function of the distance between a surface point and the light. This ensures that surfaces of the same coordinate and orientation with respect to the light, but at different distances from the light, are not assigned the same intensity.

    TPointLight( const TGPoint3D& position, const TColor& color );
position: The location from which the light emanates.

color: The color of t the light.

Parallel light

A parallel light is a light that is similar to sunlight. The attenuation factor is not involved in the intensity calculation. The directional vector does not need to be normalized and causes an exception if the vector is zero (all points set to zero).

    TParallelLight( const TGPoint3D& vector, const TColor& color );
vector: A 3-D point to which the light is parallel.

color: The color of the light.

Spotlight

A spotlight is a direct, non-parallel light that has two cones for a lampshade effect. The intensity is greatest within the inner cone, zero outside the outer cone, and interpolated between these two extremes for the region between the inner and outer cones. Figure 212 shows a spotlight and its parts.


      TSpotLight( const TGPoint3D& position, 
                  const TGPoint3D& vector, 
                  const TColor& color,
                  double fallOffExponent, 
                  gDegrees innerConeAngle, 
                  gDegrees outerConeAngle );
position: The spotlight location. The default is TGPoint3D(1000, 1000, 1000).

vector: A point to which the rays are parallel. The default is TGPoint3D( 1, 1, 1 ).

color: The color of the light. The default is TRGBColor( 1, 1, 1 ).

fallOffExponent: A factor used to calculate the color intensity for the outer cone. The default is 4.

innerConeAngle: The angle at which the inner cone of the spotlight tilts. The default is 20 degrees.

outerConeAngle: The angle at which the outer cone of the spotlight tilts. The default is 25 degrees. The intensity is determined by the distance attenuation; the falloff factor based on the off-axis angle and the falloff exponent; and the fuzzy factor that causes a smooth interpolation of the intensity in the region between the inner cone and the outer cone.

ComputeColor

The derived classes of TLight have a ComputeColor function that returns the color of a light at the location of interest, which is often the surface point to be shaded. You can implement a ComputeColor function to create interesting light sources such as the window light shown in Figure 213. During rendering, the window light determines the light intensity from the position of the point. Either black or a color interpolated from the window boundary is displayed at the point.



[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker