Struct LightingModel
- Namespace
- Egami.Operations
- Assembly
- Egami.dll
How a surface reflects light in Lighting(Light, LightingModel, LightingOptions?): Diffuse(float) (SVG's feDiffuseLighting, Lambert's N·L) or Specular(float, float) (feSpecularLighting, Phong–Blinn's (N·H)^shininess), with SVG's and Skia's constants.
public readonly record struct LightingModel : IEquatable<LightingModel>
- 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);
Properties
Constant
Gets the reflectance: SVG's diffuseConstant (kd) or specularConstant (ks).
public float Constant { get; }
Property Value
IsSpecular
Gets a value indicating whether the model is specular; otherwise it is diffuse.
public bool IsSpecular { get; }
Property Value
Shininess
Gets the specular exponent (SVG's specularExponent, Skia's shininess); 0 for a diffuse model.
public float Shininess { get; }
Property Value
Methods
Diffuse(float)
A matte surface: each pixel is the light's color times kd times N·L, the cosine between the surface
normal and the direction to the light, clamped to 0..1. The light map is opaque.
public static LightingModel Diffuse(float kd = 1)
Parameters
kdfloatThe reflectance, SVG's diffuseConstant and Skia's kd; 0 or more.
Returns
- LightingModel
The model.
Exceptions
- ArgumentOutOfRangeException
kdis negative or not finite.
Specular(float, float)
A shiny surface: each pixel is the light's color times ks times (N·H)^shininess, where
H is halfway between the direction to the light and the viewer straight above, clamped to 0..1. The light map's alpha is
the largest of its color channels, so it is transparent where there is no highlight.
public static LightingModel Specular(float ks = 1, float shininess = 1)
Parameters
ksfloatThe reflectance, SVG's specularConstant and Skia's ks; 0 or more.
shininessfloatThe exponent, SVG's specularExponent and Skia's shininess, from 1 to 128; larger is a smaller, sharper highlight.
Returns
- LightingModel
The model.
Exceptions
- ArgumentOutOfRangeException
ksis negative or not finite, orshininessis not from 1 to 128.