The visibility Layer which implements dynamic vision, lighting, and fog of war This layer uses an event-driven workflow to perform the minimal required calculation in response to changes.

Hierarchy (view full)

Properties

vision: any

The currently revealed vision.

explored: Container

The exploration container which tracks exploration progress.

visibilityOverlay: Sprite

The optional visibility overlay sprite that should be drawn instead of the unexplored color in the fog of war.

visionModeData: {
    source: any;
    activeLightingOptions: any;
} = ...

The active vision source data object

Type declaration

  • source: any
  • activeLightingOptions: any
lightingVisibility: {
    illumination: number;
    background: number;
    coloration: number;
    darkness: number;
    any: boolean;
} = ...

Define whether each lighting layer is enabled, required, or disabled by this vision mode. The value for each lighting channel is a number in LIGHTING_VISIBILITY

Type declaration

  • illumination: number
  • background: number
  • coloration: number
  • darkness: number
  • any: boolean
options: {
    name: string;
} = ...

Options for this layer instance.

Type declaration

  • name: string
#cachedLights: LegacyGraphics = ...

The graphics used to render cached light sources.

#renderTransform: Matrix = ...

Matrix used for visibility rendering transformation.

#visibilityOverlayDimensions: number[]

Dimensions of the visibility overlay texture and base texture used for tiling texture into the visibility filter.

#cachedLightSourceStates: Map<string, number> = ...

The map with the active cached light source IDs as keys and their update IDs as values.

#textureConfiguration: any
#explorationRect: any
#drawing: Promise<CanvasLayer> = ...

An internal reference to a Promise in-progress to draw the CanvasLayer.

#drawn: boolean = false

Is the layer drawn?

#MAXIMUM_VISIBILITY_TEXTURE_SIZE: number = 4096

The maximum allowable visibility texture size.

Accessors

  • get initialized(): boolean
  • A status flag for whether the layer initialization workflow has succeeded.

    Returns boolean

  • get needsContainment(): boolean
  • Internal

    Indicates whether containment filtering is required when rendering vision into a texture.

    Returns boolean

  • get tokenVision(): boolean
  • Does the currently viewed Scene support Token field of vision?

    Returns boolean

  • get textureConfiguration(): FogTextureConfiguration
  • The configured options used for the saved fog-of-war texture.

    Returns FogTextureConfiguration

  • set explorationRect(rect): void
  • Optional overrides for exploration sprite dimensions.

    Parameters

    • rect: any

    Returns void

  • get name(): string
  • The canonical name of the CanvasLayer is the name of the constructor that is the immediate child of the defined baseClass for the layer type.

    Returns string

    Example

    canvas.lighting.name -> "LightingLayer"
    
  • get hookName(): string
  • The name used by hooks to construct their hook string. Note: You should override this getter if hookName should not return the class constructor name.

    Returns string

  • get layerOptions(): {
        name: string;
    }
  • Customize behaviors of this CanvasLayer by modifying some behaviors at a class level.

    Returns {
        name: string;
    }

    • name: string
  • get instance(): CanvasLayer
  • Return a reference to the active instance of this canvas layer

    Returns CanvasLayer

Methods

  • Initialize all Token vision sources which are present on this layer

    Returns void

  • Initialize the vision mode.

    Returns void

  • Parameters

    • options: any

    Returns Promise<void>

  • The inner _tearDown method which may be customized by each CanvasLayer subclass.

    Parameters

    • options: any

      Options which configure how the layer is deconstructed

    Returns Promise<void>

  • Update the display of the sight layer. Organize sources into rendering queues and draw lighting containers for each source

    Returns void

  • Update vision (and fog if necessary)

    Returns void

  • Reset the exploration container with the fog sprite

    Returns void

  • Restrict the visibility of certain canvas assets (like Tokens or DoorControls) based on the visibility polygon These assets should only be displayed if they are visible given the current player's field of view

    Returns void

  • Test whether a target point on the Canvas is visible based on the current vision and LOS polygons.

    Parameters

    • point: Point

      The point in space to test, an object with coordinates x and y.

    • Optional options: {
          tolerance: number;
          object: any;
      } = {}

      Additional options which modify visibility testing.

      • tolerance: number

        A numeric radial offset which allows for a non-exact match. For example, if tolerance is 2 then the test will pass if the point is within 2px of a vision polygon.

      • object: any

        An optional reference to the object whose visibility is being tested

    Returns boolean

    Whether the point is currently visible.

  • Internal

    Create the visibility test config.

    Parameters

    • point: Point

      The point in space to test, an object with coordinates x and y.

    • Optional options: {
          tolerance: number;
          object: any;
      } = {}

      Additional options which modify visibility testing.

      • tolerance: number

        A numeric radial offset which allows for a non-exact match. For example, if tolerance is 2 then the test will pass if the point is within 2px of a vision polygon.

      • object: any

        An optional reference to the object whose visibility is being tested

    Returns CanvasVisibilityTestConfig

  • Draw the canvas layer, rendering its internal components and returning a Promise. The Promise resolves to the drawn layer once its contents are successfully rendered.

    Parameters

    • Optional options: any = {}

      Options which configure how the layer is drawn

    Returns Promise<CanvasLayer>

  • Deconstruct data used in the current layer in preparation to re-draw the canvas

    Parameters

    • Optional options: any = {}

      Options which configure how the layer is deconstructed

    Returns Promise<CanvasLayer>

  • Identify whether there is one singular vision source active (excluding previews).

    Returns any

    A singular source, or null

  • Configure the visibility of individual lighting channels based on the currently active vision source(s).

    Returns void

  • Update the lighting according to vision mode options.

    Returns void

  • Refresh the tint of the post processing filters.

    Returns void

  • Create the exploration container with its exploration sprite.

    Returns Container

    The newly created exploration container.

  • Create the vision container and all its children.

    Returns Container

    The created vision container.

  • Refresh the dynamic illumination with darkness level meshes and global light. Tell if a fence filter is needed when vision is rendered into a texture.

    Returns void

  • Returns true if the light source should be cached.

    Parameters

    • lightSource: LightSource

      The light source

    Returns boolean

  • Check if the cached light sources need to be fully redrawn.

    Returns boolean

    True if a full redraw is necessary.

  • Render this.#cachedLights into this.vision.light.cached.texture. Note: A full cache redraw needs the texture to be cleared.

    Parameters

    • clearTexture: boolean

      If the texture need to be cleared before rendering.

    Returns void

  • Load the scene fog overlay if provided and attach the fog overlay sprite to this layer.

    Returns Promise<void>

  • Private

    Configure the fog texture will all required options. Choose an adaptive fog rendering resolution which downscales the saved fog textures for larger dimension Scenes. It is important that the width and height of the fog texture is evenly divisible by the downscaling resolution.

    Returns VisibilityTextureConfiguration

  • Give the visibility requirement of the lighting background shader.

    Parameters

    • visionMode: VisionMode

      The single Vision Mode active at the moment (if any).

    Returns {
        DISABLED: number;
        ENABLED: number;
        REQUIRED: number;
    }

    • DISABLED: number
    • ENABLED: number
    • REQUIRED: number