Small World Engine API Reference - v0.78.00
    Preparing search index...

    Class Optics

    Physically-based optics helpers: vector Snell's law refraction and Cauchy dispersion, for any effect that needs a real refracted ray direction (a prism, a lens preview, chromatic aberration) instead of a hand-placed decorative angle. 2D-only for now (extracted from apps/showcases/28's prism dispersion, its one proven use case) -- add a Vector3D overload only once a second, real 3D use case needs it.

    Index
    • Cauchy's dispersion equation: n(lambda) = a + b / lambda^2. See CauchyMaterials for ready-made material coefficients.

      Parameters

      • wavelengthNm: number

        Wavelength in nanometres (e.g. ~700 for red, ~400 for violet).

      • coefficients: CauchyCoefficients

        The material's Cauchy a/b coefficients.

      Returns number

    • Vector form of Snell's law (same convention as GLSL's built-in refract()): both incident and normal must be unit vectors, with normal pointing back against incident (toward the medium the ray arrived from). Returns undefined on total internal reflection.

      Parameters

      • incident: Vector2D

        Unit incident ray direction.

      • normal: Vector2D

        Unit surface normal, pointing against incident.

      • n1: number

        Refractive index of the medium the ray is leaving.

      • n2: number

        Refractive index of the medium the ray is entering.

      Returns Vector2D | undefined