Parasol Framework
  • Gallery
  • API
  • Wiki
  • GitHub
    • Audio
    • Core
    • Display
    • Fluid
    • Font
    • Network
    • Vector
    • Audio
    • Sound
    • File
    • MetaClass
    • Module
    • StorageDevice
    • Task
    • Thread
    • Time
    • Compression
    • Config
    • Script
    • XML
    • Controller
    • BlurFX
    • ColourFX
    • CompositeFX
    • ConvolveFX
    • DisplacementFX
    • FilterEffect
    • FloodFX
    • ImageFX
    • LightingFX
    • MergeFX
    • MorphologyFX
    • OffsetFX
    • RemapFX
    • SourceFX
    • TurbulenceFX
    • WaveFunctionFX
    • Scintilla
    • ScintillaSearch
    • Bitmap
    • Clipboard
    • Display
    • Document
    • Font
    • Picture
    • Pointer
    • Surface
    • SVG
    • ClientSocket
    • HTTP
    • NetSocket
    • Proxy
    • Vector
    • VectorClip
    • VectorColour
    • VectorEllipse
    • VectorFilter
    • VectorGradient
    • VectorGroup
    • VectorImage
    • VectorPath
    • VectorPattern
    • VectorPolygon
    • VectorRectangle
    • VectorScene
    • VectorShape
    • VectorSpiral
    • VectorText
    • VectorTransition
    • VectorViewport
    • VectorWave

LightingFX Class

Enables the application of lighting effects.

The lighting effect class applies a diffuse or specular lighting effect to the alpha channel of an input bitmap, which functions as a bump map. The output is an RGBA representation of the light effect. If no light Colour is specified by the client then the output will be in grey scale.

For diffuse lighting, 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
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

For specular lighting, 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
H  = "Halfway" unit vector between eye unit vector and light unit vector

Lr,Lg,Lb = RGB components of light

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.

Structure

The LightingFX class consists of the following fields:

Access
NameTypeComment
  ColourFLOAT []Defines the colour of the light source.

Set the Colour field to define the colour of the light source. The colour is defined as an array of four 32-bit floating point values between 0 and 1.0. The array elements consist of Red, Green, Blue and Alpha values in that order.

If the algorithm supports it, the Alpha component defines the intensity of the light source.

The default colour is pure white, 1.0,1.0,1.0,1.0.

  ConstantDOUBLESpecifies the ks/kd value in Phong lighting model.

In the Phong lighting model, this field specifies the kd value in diffuse mode, or ks value in specular mode.

  ExponentDOUBLEExponent for specular lighting, larger is more "shiny". Ranges from 1.0 to 128.0.

This field defines the exponent value for specular lighting, within a range of 1.0 to 128.0. The larger the value, shinier the end result.

  ScaleDOUBLEThe maximum height of the input surface (bump map) when the alpha input is 1.0.
  TypeINTDefines the type of surface light scattering, which can be specular or diffuse.
NameDescription
LT::DIFFUSESelect diffuse lighting.
LT::SPECULARSelect specular lighting.
  UnitXDOUBLEThe intended distance in current filter units for dx in the surface normal calculation formulas.

Indicates the intended distance in current filter units (i.e. as determined by the value of PrimitiveUnits) for dx in the surface normal calculation formulas.

By specifying value(s) for UnitX, the kernel becomes defined in a scalable, abstract coordinate system. If UnitX is not specified, the default value is one pixel in the offscreen bitmap, which is a pixel-based coordinate system, and thus potentially not scalable. For some level of consistency across display media and user agents, it is necessary that a value be provided for at least one of ResX and UnitX.

  UnitYDOUBLEThe intended distance in current filter units for dy in the surface normal calculation formulas.

Indicates the intended distance in current filter units (i.e. as determined by the value of PrimitiveUnits) for dy in the surface normal calculation formulas.

By specifying value(s) for UnitY, the kernel becomes defined in a scalable, abstract coordinate system. If UnitY is not specified, the default value is one pixel in the offscreen bitmap, which is a pixel-based coordinate system, and thus potentially not scalable. For some level of consistency across display media and user agents, it is necessary that a value be provided for at least one of ResY and UnitY.

  XMLDefSTRINGReturns an SVG compliant XML string that describes the filter.

Actions

The following actions are currently supported:

DrawRender the effect to the target bitmap.
ERR acDraw(*Object, DOUBLE X, DOUBLE Y, DOUBLE Width, DOUBLE Height)
ParameterDescription
XThe X position of the region to be drawn.
YThe Y position of the region to be drawn.
WidthThe width of the region to be drawn.
HeightThe height of the region to be drawn.

Methods

The following methods are currently supported:

SetDistantLightConfigure lighting with a distant light source.
ERR lt::SetDistantLight(OBJECTPTR Object, DOUBLE Azimuth, DOUBLE Elevation)
ParameterDescription
AzimuthDirection angle for the light source on the XY plane (clockwise), in degrees from the X axis.
ElevationDirection angle for the light source from the XY plane towards the Z axis, in degrees. A positive value points towards the viewer of the content.

This method applies a distant light configuration to the lighting effect. It will override any previously defined light source setting.

A distant light can be thought of as like the light from the sun. An infinite amount of parallel light rays travel in the direction that the distant light points to. Distant lights are handy when you want equal illumination on objects in a scene.

SetPointLightConfigure lighting with a pointed light source.
ERR lt::SetPointLight(OBJECTPTR Object, DOUBLE X, DOUBLE Y, DOUBLE Z)
ParameterDescription
XX location for the light source.
YY location for the light source.
ZZ location for the light source.

This method applies a pointed light configuration to the lighting effect. It will override any previously defined light source setting.

A point light sends light out from the specified (X, Y, Z) location equally in all directions. A light bulb or open flame is a good example of a point light. The intensity of the light can be controlled by altering the alpha component of the light Colour.

SetSpotLightConfigure lighting with a spot light source.
ERR lt::SetSpotLight(OBJECTPTR Object, DOUBLE X, DOUBLE Y, DOUBLE Z, DOUBLE PX, DOUBLE PY, DOUBLE PZ, DOUBLE Exponent, DOUBLE ConeAngle)
ParameterDescription
XX location for the light source.
YY location for the light source.
ZZ location for the light source. The positive Z-axis comes out towards the person viewing the content and assuming that one unit along the Z-axis equals one unit in X and Y.
PXX location of the light source's target.
PYY location of the light source's target.
PZZ location of the light source's target.
ExponentExponent value controlling the focus for the light source.
ConeAngleA limiting cone which restricts the region where the light is projected, or 0 to disable. Specified in degrees.

This method applies a spot light configuration to the lighting effect. It will override any previously defined light source setting.

A spot light beams light rays from the defined (X, Y, Z) position to the (PX, PY, PZ) position. The Exponent and ConeAngle work together to constrain the edge of the light projection.

LightingFX class documentation © Paul Manias © 2010-2025

LT Type

Lighting algorithm for the LightingFX class.

NameDescription
LT::DIFFUSESelect diffuse lighting.
LT::SPECULARSelect specular lighting.
LightingFX module documentation © Paul Manias © 2010-2025