Click or drag to resize
DigitalRuneImageBasedLight Class
Represents a light which uses an environment cube map to add diffuse lighting and specular lighting (reflections).
Inheritance Hierarchy

Namespace: DigitalRune.Graphics
Assembly: DigitalRune.Graphics (in DigitalRune.Graphics.dll) Version: 1.2.0.0 (1.2.1.14562)
Syntax
public class ImageBasedLight : Light

The ImageBasedLight type exposes the following members.

Constructors
  NameDescription
Public methodImageBasedLight
Initializes a new instance of the ImageBasedLight class.
Public methodImageBasedLight(TextureCube)
Initializes a new instance of the ImageBasedLight class.
Top
Methods
  NameDescription
Public methodClone
Creates a new Light that is a clone (deep copy) of the current instance.
(Inherited from Light.)
Protected methodCloneCore
Makes the instance a clone (deep copy) of the specified Light.
(Overrides LightCloneCore(Light).)
Protected methodCreateInstanceCore
When implemented in a derived class, creates a new instance of the Light derived class.
(Overrides LightCreateInstanceCore.)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetIntensity
Gets the (approximated) light intensity at the given distance.
(Overrides LightGetIntensity(Single).)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Properties
  NameDescription
Public propertyBlendMode
Gets or sets the blend mode for the diffuse light contribution.
Public propertyColor
Gets or sets the RGB color of the light.
Public propertyDiffuseIntensity
Gets or sets the diffuse intensity of the light.
Public propertyEnableLocalizedReflection
Gets or sets a value indicating whether the cube map reflection is localized.
Public propertyEncoding
Gets or sets the color encoding used by the cube map texture.
Public propertyFalloffRange
Gets or sets the relative distance over which light effect falls off.
Public propertyHdrScale
Gets or sets the HDR scale of the light.
Public propertyLocalizedReflectionBox
Gets or sets the axis-aligned bounding box used to localize the cube map reflection when EnableLocalizedReflection is set.
Public propertyName
Gets or sets the name of the light.
(Inherited from Light.)
Public propertyShape
Gets or sets the bounding shape of the light volume.
Public propertySpecularIntensity
Gets or sets the specular intensity of the light.
Public propertyTexture
Gets or sets the cube map texture.
Top
Remarks

Image-based lighting (IBL) uses a cube map of the environment to define the lighting in a scene.

The property Texture defines the used environment map. This property must be set to valid cube map- otherwise, the ImageBasedLight is disabled. The texture can be a normal sRGB texture or an RGBM encoded HDR texture; see Encoding. The cube map must contain mipmaps.

When a mesh is shaded, the normal vector is used to look up a color value in the environment map to use for diffuse lighting. Reflection vectors are used to look up color values for specular lighting. This allows a mesh to reflect the environment, like a mirror. The mipmap levels are used to create reflections on materials with different glossiness. Materials with a high SpecularPower, like mirrors, use high resolution mipmap levels. Diffuse lighting and dull materials use low resolution mipmap levels.

ImageBasedLights have a Shape, which can be Infinite or a BoxShape. Lights with an infinite shape cover the whole scene. Usually a level contains only one image-based light with an infinite shape. Lights with a box shape cover only the volume inside the box. This allows to set different image-based lights for different rooms or zones of a level.

A LightNode must be used to add an ImageBasedLight to a scene. The LightNode is also used to define the position and the orientation of the light.

The BlendMode determines if the diffuse light contribution of an image-based light is added to the scene (additive blending, BlendMode = 0) or replaces the ambient lighting and other image-based lights (alpha blending, BlendMode = 1). The default is BlendMode = 1, which means that an diffuse light replaces the ambient lighting and other image-based lights.

Note: Image-based lights are usually applied after the ambient light of the scene and before the other lights of the scene. Image-based lights never replace other lights, like directional lights or point lights.

The property FalloffRange can be used to let an image-based light fade out to create smooth blending between different image-based lights or between an image-based light and an area which contains no image-based lights. (Only relevant for box-shaped lights. Infinite lights never fade out.)

Image-based lights have color and intensity, which are used to tint and scale the colors of the environment map. The color of the Texture, the Color, DiffuseIntensity/SpecularIntensity and HdrScale are multiplied to get the final diffuse and specular light intensities which can be used in the lighting equations.

Diffuse only: The SpecularIntensity can be set to NaN to disable the specular light contribution. This creates a pure diffuse light. As mentioned above, the BlendMode determines whether the diffuse light is added to the scene (BlendMode = 0) or replaces the ambient light and other image-based lights (BlendMode = 1).

Specular only: The DiffuseIntensity can be set to NaN to disable the diffuse light contribution. This creates a pure specular light, which can be used for reflections only.

Localized reflections:Usually, environment maps are treated as if the scene in the environment map is infinitely far away. If an image-based light is used to create reflection of a box-shaped room, the reflections will not properly align with the walls of the room. To correct the reflections, EnableLocalizedReflection can be set to . In this case the reflections are computed to fit a given box. This box is either equal to the BoxShape of the light (property Shape) or to an axis-aligned box defined by LocalizedReflectionBox. The box is always aligned with the local space of the LightNode.

Cloning:When the ImageBasedLight is cloned the Encoding and the Texture are not duplicated. These properties are copied by reference.

Usage tips:

  • If you only want to add environment map reflections to a game level, add one infinite image-based light with diffuse intensity set to NaN. This way the light only adds reflections and does not influence the ambient light of the scene.
  • Image-based lights with a diffuse intensity can be used to replace ambient lighting. Ambient lighting is usually very "flat", e.g. an ambient light adds only one color. An image-based light can create more interesting ambient lighting. For example, if the environment map contains the blue sky and a brown ground, then objects lit by the image-based light will be blue on top and brown at the bottom.
  • Image-based lights can also be used to add "light bounces". For example, if the environment map contains a yellow wall, objects near the yellow wall will receive a yellow "bounce light".
  • Environment maps defined by image-based lights can be used in effects using the environment map semantics, see e.g. EnvironmentMap.
  • To get proper reflections in rooms, create one image-based light per room. Set EnableLocalizedReflection to . Set an AABB in LocalizedReflectionBox which is aligned with the floor, ceiling and walls of the room. LightNodes can be rotated to align with rooms which are not axis-aligned with the world space.
  • It is recommended to position the image-based lights at the eye-level of the player and to capture the environment maps from this position.
  • If you want to smoothly fade out an image-based light over time, you can fade the BlendMode from 1 (alpha-blend) to 0 (additive), and at the same time fade the DiffuseIntensity and SpecularIntensity to 0. This creates a smooth change in lighting.

See Also