Foundation > Image Processing Filters > IlvBitmapFilter: The Image Processing Class > The IlvLightingFilter Class
 
The IlvLightingFilter Class
The IlvLightingFilter class lets you light an image using the alpha channel as a bump map. Several types of lights can be specified (see later).
This class is an abstract class and has two usable subclasses.
The IlvDiffuseLightingFilter Class
For the IlvDiffuseLightingFilter class, the resulting image is an RGBA opaque image based on the light color with alpha = 1.0 everywhere. The lighting calculation follows the standard diffuse component of the Phong lighting model. The resulting image depends on the light color, light position, and surface geometry of the input bump map.
The light map produced by this filter primitive can be combined with a texture image using the multiply term of the arithmetic IlvComposeFilter compositing method. Multiple light sources can be simulated by adding several of these light maps together before applying it to the texture image.
The resulting RGBA image is computed as follows:
Dr = kd * N.L * Lr
Dg = kd * N.L * Lg
Db = kd * N.L * Lb
Da = 1.0
where:
kd
Diffuse lighting constant
N
Surface normal unit vector, a function of x and y (see below)
L
Unit vector pointing from surface to light, a function of x and y in the point and spot light cases
Lr, Lg, Lb
RGB components of light, a function of x and y in the spot light case
N is a function of x and y and depends on the surface gradient as follows:
The surface described by the input alpha image Ain (x,y) is:
Z (x,y) = surfaceScale * Ain (x,y)
Surface normal is calculated using the Sobel gradient 3x3 filter:
Nx (x,y)= - surfaceScale * 1/4*(( I(x+1,y-1) + 2*I(x+1,y) + I(x+1,y+1))
- (I(x-1,y-1) + 2*I(x-1,y) + I(x-1,y+1)))
 
Ny (x,y)= - surfaceScale * 1/4*(( I(x-1,y+1) + 2*I(x,y+1) + I(x+1,y+1))
- (I(x-1,y-1) + 2*I(x,y-1) + I(x+1,y-1)))
 
Nz (x,y) = 1.0
 
N = (Nx, Ny, Nz) / Norm((Nx,Ny,Nz))
See IlvLightSource for a further description of L, the unit vector from the image sample to the light.
The IlvSpecularLightingFilter Class
For IlvSpecularLightingFilter, the resulting image is an RGBA image based on the light color. The lighting calculation follows the standard specular component of the Phong lighting model. The resulting image depends on the light color, light position, and surface geometry of the input bump map. The result of the lighting calculation is added. The filter primitive assumes that the viewer is at infinity in the z direction (that is, the unit vector in the eye direction is (0,0,1) everywhere).
This filter primitive produces an image that contains the specular reflection part of the lighting calculation. Such a map is intended to be combined with a texture using the add term of the arithmetic IlvComposeFilter method. Multiple light sources can be simulated by adding several of these light maps before applying it to the texture image.
The resulting RGBA image is computed as follows:
Sr = ks * pow(N.H, specularExponent) * Lr
Sg = ks * pow(N.H, specularExponent) * Lg
Sb = ks * pow(N.H, specularExponent) * Lb
Sa = max(Sr, Sg, Sb)
where:
ks
Specular lighting constant
N
Surface normal unit vector, a function of x and y (see below)
H
"Halfway" unit vector between eye unit vector and light unit vector
Lr, Lg, Lb
RGB components of light
See IlvDiffuseLightingFilter for definitions of N and (Lr, Lg, Lb).
The definition of H reflects our assumption of the constant eye vector E = (0,0,1):
H = (L + E) / Norm(L+E)
where L is the light unit vector.

Version 6.1
Copyright © 2016, Rogue Wave Software, Inc. All Rights Reserved.