5.30. Light (media-object)

<light> ‐ A light

5.30.1. Attributes

NameTypeDefaults
idIDNone (required)
typeSTRINGNone (required)
fade_distanceFLOAT1000.0
fade_powerINTEGER0
radiusFLOAT30.0
constant_attenuationFLOAT1.0
linear_attenuationFLOAT0.0
quadratic_attenuationFLOAT0.0
falloffFLOAT45.0
tightnessFLOAT0.0
spot_exponentFLOAT0.0
beginFLOATNone (required for strobolight)
endFLOATNone (required for strobolight)
durationFLOATNone (required for strobolight)
periodFLOATNone (required for strobolight)
shadowBOOLEANfalse

5.30.2. Description

This element defines a light source.

The string value of the type attribute is equal to light in the case of a point light. It is equal to strobolight in the case of an intermittent spot light such as a stroboscope. The values spotlight and cylinder correspond respectively to a conical spot light and a cylindrical spot light. Last, parallel defines a directional light.

The float value of the fade_distance attribute and the integer value of the fade_power attribute define the light attenuation with respect to distance. The float values of the radius and falloff attributes define the angular attenuation of a spot light in POVray (see Figure 5-10 for a geometrical description of these attributes). In POVray, the float value of the tightness attribute controls the way that light tapers off at the edge of the cone. In OpenGL, the values that define the angular attenuation of a spot light are the radius attribute (an angular cutoff) and spot_exponent attribute (a coefficient for angular attenuation around cutoff value).

Figure 5-10. Spot Geometry in POVray

The float values of the constant_attenuation, linear_attenuation, and quadratic_attenuation attributes define the three OpenGL attenuation factors used to compute light attenuation according to figure Figure 5-11

Figure 5-11. Formula for OpenGL Light Attenuation

In the case of an intermittent spot light, the float values begin and end of the begin and end attributes define the maximal time interval during which the light is on. Lighting begins at begin time and is stops at end time. The float value period of the period attribute is used to define the intervals at which lighting is restarted. Lighting is periodically restarted at begin+n×period for n in 1, 2,...,N. N is the the largest integer smaller than or equal to (end-begin)/period. The float value duration of the duration attribute must be smaller than or equal to period; it defines the lighting time during each period (see Figure 5-12).

Figure 5-12. Periodical Light Emission

The value of the radius attribute is used to define a square bounding box centered at the location of the light source. A light source can be selected and dragged by the pointing device if the boolean attribute interactable of the node is true.

This element can have three element in its scope: two points that define the location and the direction of the spot light and color that defines the color of the light source.

5.30.3. Expected children

The following elements must occur in light: two point elements indexed 1 and 2, and a color or a material element. The default values for the point elements are (0,0,0) for the point with index 1, and (0,0,-1) for the point with index 2.

5.30.4. Example

The example below defines a spot light that casts shadows. Its color is red, it is located at the origin of the local coordinates, and is directed towards the positive x-axis.

<light id="light_#2.red" fade_distance="10.0"
       fade_power="1" radius="30" falloff="45" tightness="1" shadow="true" 
       type="spotlight"> 
  <color id="reddish" r="0.9" g="0.15" b="0.1"/>
  <point  index="1" x="0.00" y="0.00" z="0.00" />
  <point  index="2" x="1.00" y="0.00" z="0.00" />
</light>

The example below defines a directional light. Its ambient component is white and there is no diffuse and specular component. It is located at the origin of the local coordinates, and is directed towards the positive z-axis.

<light id="light_#1" type="parallel">
  <material id="mat_1">
    <ambient r="1.0" g="1.0" b="1.0" a="1.0" />
    <diffuse r="0.0" g="0.0" b="0.0" a="1.0" />
    <specular r="0.0" g="0.0" b="0.0" a="1.0" />
  </material>
  <point index="1" x="0.0" y="0.0" z="0.0" />
  <point index="2" x="0.0" y="0.0" z="1.0" />
</light>