float Attenuation { get; set; }

book_4_sparkGenerated
code_blocksInput

Description

The Attenuation property of the SpotLight class defines how the intensity of the light diminishes over distance. It is a float value that can be adjusted to control the rate at which the light fades as it moves away from the source.

This property is decorated with several attributes:

  • PropertyAttribute: Marks this as a property that can be exposed in the editor.
  • MakeDirtyAttribute: Indicates that changes to this property should mark the object as "dirty," prompting updates or re-renders.
  • RangeAttribute: Constrains the value between 0 and 10, with a step of 0.01. This ensures that the attenuation value remains within a reasonable range for light calculations.
  • DefaultValueAttribute: Specifies a default value for the property, though the exact default is not detailed here.
  • SourceLocationAttribute: Provides the source file and line number where this property is defined, useful for debugging and development purposes.

Usage

To adjust the attenuation of a SpotLight in your scene, you can set the Attenuation property to a desired value within the specified range. This will affect how quickly the light intensity decreases with distance.

For example, a lower attenuation value will result in a light that maintains its intensity over a longer distance, while a higher value will cause the light to fade more quickly.

Example

// Create a new SpotLight instance
SpotLight mySpotLight = new SpotLight();

// Set the attenuation to a moderate value
mySpotLight.Attenuation = 5.0f;

// Add the SpotLight to the scene
Scene.Add(mySpotLight);