Class Light

A light object.

Hierarchy

Constructors

  • Parameters

    • options: Partial<Pick<Light, "position" | "hidden" | "distance" | "diffuse" | "samples">> = {}

      Options to be applied to the light object.

    Returns Light

Properties

#vismaskCache?: CanvasAndContext
#vismaskHash?: string
diffuse: number

The intensity of the light penetration in objects.

Default

0.8
distance: number

Intensity of the light.

Default

100
hidden: boolean

Whether the light is hidden or not.

Default

false
id?: number
position: Vec2

Position of the light object.

Default

new Vec2()
samples: number

The number of points which will be used for shadow projection. It defines the quality of the rendering.

Default

1

Methods

  • Calculate the boundaries of the light using the light's distance.

    Returns Bounds

    An anonymous object with the properties topLeft and bottomRight. The property values are Vec2 objects representing the corners of the boundary.

  • Return the center of the light. i.e. The position where the light intensity is the highest.

    Returns Vec2

    A new vector that represents the center of the light.

  • Invoke a function for every sample generated by the light. Implement it by spreading samples and calling callback at each time.

    Parameters

    • callback: ((position) => void)

      Function to be called for every sample. The function will be passed a vector representing the position of the sample.

        • (position): void
        • Parameters

          Returns void

    Returns void

  • Return a string hash key representing the light.

    Returns string

    The hash key.

  • Creates a canvas context with the visible mask rendered onto it.

    Returns undefined | CanvasAndContext

    A canvas context with the visible mask rendered onto it.

  • Render a mask representing the visibility. (Used by DarkMask)

    Parameters

    • context: CanvasRenderingContext2D

      The canvas context onto which the mask will be rendered.

    Returns void

  • Render the light onto the given context.

    Parameters

    • _context: CanvasRenderingContext2D

      The canvas context onto which the light will be rendered.

    Returns void