Package javafx.scene

Class SpotLight

All Implemented Interfaces:
Styleable, EventTarget

public class SpotLight extends PointLight
A light source that radiates light in a cone in a specific direction away from itself. The direction is defined by the direction vector property.

In addition to the attenuation factors that control the light intensity over distance, a SpotLight has a light-cone attenuation factor, spot, that is determined by 3 properties:

  • innerAngle: the angle of the inner cone (see image below)
  • outerAngle: the angle of the outer cone (see image below)
  • falloff: the factor that controls the light's intensity drop inside the outer cone
The valid ranges for these properties are 0 <= innerAngle <= outerAngle <= 180 and falloff >= 0; values outside either of these ranges can produce unexpected results.

The angle of a point to the light is defined as the angle between its vector to the light's position and the direction of the light. For such an angle theta, if

  • theta < innerAngle then spot = 1
  • theta > outerAngle then spot = 0
  • innerAngle <= theta <= outerAngle then
    spot = pow((cos(theta) - cos(outer)) / (cos(inner) - cos(outer)), falloff)
    which represents a drop in intensity from the inner angle to the outer angle.
As a result, 0 <= spot <= 1. The overall intensity of the light is I = lambert * atten * spot.

SpotLights can represent point-like light sources with directionality. Flashlights and floodlights are common light sources that can be simulated with this light type.

Image of the Spotlight

Since:
17
See Also:
  • Property Details

    • direction

      public final ObjectProperty<Point3D> directionProperty
      The direction vector of the spotlight. It can be rotated by setting a rotation transform on the SpotLight. The vector need not be normalized.
      Default value:
      Point3D(0, 0, 1)
      See Also:
    • innerAngle

      public final DoubleProperty innerAngleProperty
      The angle of the spotlight's inner cone, in degrees. A point whose angle to the light is less than this angle is not attenuated by the spotlight factor (spot = 1). At larger angles, the light intensity starts to drop. See the class doc for more information.

      The valid range is 0 <= innerAngle <= outerAngle; values outside of this range can produce unexpected results.

      Default value:
      0
      See Also:
    • outerAngle

      public final DoubleProperty outerAngleProperty
      The angle of the spotlight's outer cone, in degrees (as shown in the class doc image). A point whose angle to the light is greater than this angle receives no light (spot = 0). A point whose angle to the light is less than the outer angle but greater than the inner angle receives partial intensity governed by the falloff factor. See the class doc for more information.

      The valid range is innerAngle <= outerAngle <= 180; values outside of this range can produce unexpected results.

      Default value:
      30
      See Also:
    • falloff

      public final DoubleProperty falloffProperty
      The intensity falloff factor of the spotlight's outer cone. A point whose angle to the light is greater than the inner angle but less than the outer angle receives partial intensity governed by this factor. The larger the falloff, the sharper the drop in intensity from the inner cone. A falloff factor of 1 gives a linear drop in intensity, values greater than 1 give a convex drop, and values smaller than 1 give a concave drop. See the class doc for more information.

      The valid range is 0 <= falloff; values outside of this range can produce unexpected results.

      Default value:
      1
      See Also:
  • Constructor Details

    • SpotLight

      public SpotLight()
      Creates a new instance of SpotLight class with a default Color.WHITE light source.
    • SpotLight

      public SpotLight(Color color)
      Creates a new instance of SpotLight class using the specified color.
      Parameters:
      color - the color of the light source
  • Method Details

    • setDirection

      public final void setDirection(Point3D value)
      Sets the value of the direction property.
      Property description:
      The direction vector of the spotlight. It can be rotated by setting a rotation transform on the SpotLight. The vector need not be normalized.
      Default value:
      Point3D(0, 0, 1)
      Parameters:
      value - the value for the direction property
      See Also:
    • getDirection

      public final Point3D getDirection()
      Gets the value of the direction property.
      Property description:
      The direction vector of the spotlight. It can be rotated by setting a rotation transform on the SpotLight. The vector need not be normalized.
      Default value:
      Point3D(0, 0, 1)
      Returns:
      the value of the direction property
      See Also:
    • directionProperty

      public final ObjectProperty<Point3D> directionProperty()
      The direction vector of the spotlight. It can be rotated by setting a rotation transform on the SpotLight. The vector need not be normalized.
      Default value:
      Point3D(0, 0, 1)
      Returns:
      the direction property
      See Also:
    • setInnerAngle

      public final void setInnerAngle(double value)
      Sets the value of the innerAngle property.
      Property description:
      The angle of the spotlight's inner cone, in degrees. A point whose angle to the light is less than this angle is not attenuated by the spotlight factor (spot = 1). At larger angles, the light intensity starts to drop. See the class doc for more information.

      The valid range is 0 <= innerAngle <= outerAngle; values outside of this range can produce unexpected results.

      Default value:
      0
      Parameters:
      value - the value for the innerAngle property
      See Also:
    • getInnerAngle

      public final double getInnerAngle()
      Gets the value of the innerAngle property.
      Property description:
      The angle of the spotlight's inner cone, in degrees. A point whose angle to the light is less than this angle is not attenuated by the spotlight factor (spot = 1). At larger angles, the light intensity starts to drop. See the class doc for more information.

      The valid range is 0 <= innerAngle <= outerAngle; values outside of this range can produce unexpected results.

      Default value:
      0
      Returns:
      the value of the innerAngle property
      See Also:
    • innerAngleProperty

      public final DoubleProperty innerAngleProperty()
      The angle of the spotlight's inner cone, in degrees. A point whose angle to the light is less than this angle is not attenuated by the spotlight factor (spot = 1). At larger angles, the light intensity starts to drop. See the class doc for more information.

      The valid range is 0 <= innerAngle <= outerAngle; values outside of this range can produce unexpected results.

      Default value:
      0
      Returns:
      the innerAngle property
      See Also:
    • setOuterAngle

      public final void setOuterAngle(double value)
      Sets the value of the outerAngle property.
      Property description:
      The angle of the spotlight's outer cone, in degrees (as shown in the class doc image). A point whose angle to the light is greater than this angle receives no light (spot = 0). A point whose angle to the light is less than the outer angle but greater than the inner angle receives partial intensity governed by the falloff factor. See the class doc for more information.

      The valid range is innerAngle <= outerAngle <= 180; values outside of this range can produce unexpected results.

      Default value:
      30
      Parameters:
      value - the value for the outerAngle property
      See Also:
    • getOuterAngle

      public final double getOuterAngle()
      Gets the value of the outerAngle property.
      Property description:
      The angle of the spotlight's outer cone, in degrees (as shown in the class doc image). A point whose angle to the light is greater than this angle receives no light (spot = 0). A point whose angle to the light is less than the outer angle but greater than the inner angle receives partial intensity governed by the falloff factor. See the class doc for more information.

      The valid range is innerAngle <= outerAngle <= 180; values outside of this range can produce unexpected results.

      Default value:
      30
      Returns:
      the value of the outerAngle property
      See Also:
    • outerAngleProperty

      public final DoubleProperty outerAngleProperty()
      The angle of the spotlight's outer cone, in degrees (as shown in the class doc image). A point whose angle to the light is greater than this angle receives no light (spot = 0). A point whose angle to the light is less than the outer angle but greater than the inner angle receives partial intensity governed by the falloff factor. See the class doc for more information.

      The valid range is innerAngle <= outerAngle <= 180; values outside of this range can produce unexpected results.

      Default value:
      30
      Returns:
      the outerAngle property
      See Also:
    • setFalloff

      public final void setFalloff(double value)
      Sets the value of the falloff property.
      Property description:
      The intensity falloff factor of the spotlight's outer cone. A point whose angle to the light is greater than the inner angle but less than the outer angle receives partial intensity governed by this factor. The larger the falloff, the sharper the drop in intensity from the inner cone. A falloff factor of 1 gives a linear drop in intensity, values greater than 1 give a convex drop, and values smaller than 1 give a concave drop. See the class doc for more information.

      The valid range is 0 <= falloff; values outside of this range can produce unexpected results.

      Default value:
      1
      Parameters:
      value - the value for the falloff property
      See Also:
    • getFalloff

      public final double getFalloff()
      Gets the value of the falloff property.
      Property description:
      The intensity falloff factor of the spotlight's outer cone. A point whose angle to the light is greater than the inner angle but less than the outer angle receives partial intensity governed by this factor. The larger the falloff, the sharper the drop in intensity from the inner cone. A falloff factor of 1 gives a linear drop in intensity, values greater than 1 give a convex drop, and values smaller than 1 give a concave drop. See the class doc for more information.

      The valid range is 0 <= falloff; values outside of this range can produce unexpected results.

      Default value:
      1
      Returns:
      the value of the falloff property
      See Also:
    • falloffProperty

      public final DoubleProperty falloffProperty()
      The intensity falloff factor of the spotlight's outer cone. A point whose angle to the light is greater than the inner angle but less than the outer angle receives partial intensity governed by this factor. The larger the falloff, the sharper the drop in intensity from the inner cone. A falloff factor of 1 gives a linear drop in intensity, values greater than 1 give a convex drop, and values smaller than 1 give a concave drop. See the class doc for more information.

      The valid range is 0 <= falloff; values outside of this range can produce unexpected results.

      Default value:
      1
      Returns:
      the falloff property
      See Also: