Class SpotLight
- Namespace
- Egami.Operations
- Assembly
- Egami.dll
A light at one point that shines toward a target, as SVG's feSpotLight and Skia's SpotLit factories. Light falls off away from the axis as cos(angle)^Exponent and stops at ConeAngle, with Skia's soft cone edge.
public sealed record SpotLight : Light, IEquatable<Light>, IEquatable<SpotLight>
- Inheritance
-
SpotLight
- Implements
- Inherited Members
Examples
// Three light sources, as SVG and Skia have them. Positions are pixels: x right, y down, z up out of the image.
Light sun = new DistantLight(azimuth: 225, elevation: 40); // from the top left, 40° up
Light bulb = new PointLight(new Vector3(60, 20, 80)) { Color = new Rgba8(255, 240, 210, 255) };
Light spot = new SpotLight(new Vector3(0, 0, 150), target: new Vector3(120, 60, 0), exponent: 4, coneAngle: 30);
// Two ways a surface reflects: matte (N·L) or shiny (a highlight, (N·H)^shininess).
LightingModel matte = LightingModel.Diffuse(kd: 1.2f);
LightingModel shiny = LightingModel.Specular(ks: 1, shininess: 20);
using Raster<Rgba8> map = logo.Derive(ops => ops.Lighting(sun, matte), Ct); // the light map, opaque
using Raster<Rgba8> glints = logo.Derive(ops => ops.Lighting(bulb, shiny), Ct); // alpha = brightest channel
using Raster<Rgba8> pool = logo.Derive(ops => ops.Lighting(spot, matte), Ct);
Constructors
SpotLight(Vector3, Vector3, float, float)
Initializes a new instance of the SpotLight class.
public SpotLight(Vector3 position, Vector3 target, float exponent = 1, float coneAngle = 90)
Parameters
positionVector3Where the light is, in pixels: x to the right, y down, z above the image.
targetVector3The point the light shines at, in the same coordinates; it must differ from
position.exponentfloatHow fast the light falls off away from its axis (SVG's specularExponent, Skia's falloffExponent), from 0 to 128.
coneAnglefloatThe half-angle of the cone outside which nothing is lit, in degrees (SVG's limitingConeAngle, Skia's cutoffAngle), above 0 and at most 180.
Exceptions
- ArgumentOutOfRangeException
A coordinate is not finite, the two points are the same, or a value is out of range.
Properties
ConeAngle
Gets the half-angle of the lit cone, in degrees.
public float ConeAngle { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is not above 0 and at most 180.
Exponent
Gets how fast the light falls off away from its axis: the light is scaled by cos(angle)^Exponent.
public float Exponent { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is not from 0 to 128.
Position
Gets where the light is.
public Vector3 Position { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
A coordinate is not finite.
Target
Gets the point the light shines at.
public Vector3 Target { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
A coordinate is not finite.