Click or drag to resize
DigitalRuneLensFlareOnGetSizeAndIntensity Method
Called when the size and intensity of a lens flare is determined.

Namespace: DigitalRune.Graphics
Assembly: DigitalRune.Graphics (in DigitalRune.Graphics.dll) Version: 1.2.0.0 (1.2.1.14562)
Syntax
protected virtual void OnGetSizeAndIntensity(
	LensFlareNode node,
	RenderContext context,
	int visiblePixels,
	int totalPixels,
	out float size,
	out float intensity
)

Parameters

node
Type: DigitalRune.Graphics.SceneGraphLensFlareNode
The lens flare node.
context
Type: DigitalRune.GraphicsRenderContext
The render context.
visiblePixels
Type: SystemInt32
The number of visible pixels as determined by the last hardware occlusion query. (Not available in Reach profile.)
totalPixels
Type: SystemInt32
The total number of pixels tested in the hardware occlusion query. (Not available in Reach profile.)
size
Type: SystemSingle
Out: The actual size of the lens flare in relative to the viewport.
intensity
Type: SystemSingle
Out: The actual intensity of the lens flare.
Remarks
Notes to Inheritors:
This method can be overridden in derived types to adjust the size and intensity of the lens flare. The base implementation creates a lens flare with constant size. The intensity depends on the number of visible pixels and the fog.
C#
protected virtual void OnGetSizeAndIntensity(LensFlareNode node, RenderContext context, int visiblePixels, int totalPixels, out float size, out float intensity)
{
  // Constant size.
  var size = Size;

  intensity = node.Intensity * Intensity;

  // Intensity depends on the number of visible (unoccluded) pixels.
  if (context.GraphicsService.GraphicsDevice.GraphicsProfile == GraphicsProfile.HiDef)
    intensity *= (float)visiblePixels / totalPixels;

  // Fog decreases the intensity.
  var scene = context.Scene;
  var cameraNode = context.CameraNode;
  if (scene != null && cameraNode != null)
  {
    var query = scene.Query<FogQuery>(cameraNode);
    foreach (var fogNode in query.FogNodes)
    {
      var flarePosition = IsDirectional   // For directional flares, choose a position "far" away.
                        ? cameraNode.PoseWorld.Position + node.PoseWorld.Orientation.GetColumn(2) * cameraNode.Camera.Projection.Far
                        : node.PoseWorld.Position;
      intensity *= (1 - fogNode.Fog.GetIntensity(fogNode, cameraNode, flarePosition));
    }
  }
}
See Also