A Layer represents a renderable subset of the scene. It can contain a list of mesh instances, lights and cameras, their render settings and also defines custom callbacks before, after or during rendering. Layers are organized inside LayerComposition in a desired order.

Constructors

  • Create a new Layer instance.

    Parameters

    • options: object = {}

      Object for passing optional arguments. These arguments are the same as properties of the Layer.

    Returns Layer

Properties

_clusteredLightsSet: Set<Light> = ...

Set of light used by clustered lighting (omni and spot, but no directional).

_lights: Light[] = []

All lights assigned to a layer.

_lightsSet: Set<Light> = ...

All lights assigned to a layer stored in a set.

_splitLights: Light[][] = ...

Lights separated by light type. Lights in the individual arrays are sorted by the key, to match their order in _lightIdHash, so that their order matches the order expected by the generated shader code.

_splitLightsDirty: boolean = true

True if _splitLights needs to be updated, which means if lights were added or removed from the layer, or their key changed.

_visibleInstances: WeakMap<Camera, CulledInstances> = ...

Visible (culled) mesh instances assigned to this layer. Looked up by the Camera.

id: number

A unique ID of the layer. Layer IDs are stored inside ModelComponent#layers, RenderComponent#layers, CameraComponent#layers, LightComponent#layers and ElementComponent#layers instead of names. Can be used in LayerComposition#getLayerById.

layerReference: Layer

Make this layer render the same mesh instances that another layer does instead of having its own mesh instance list. Both layers must share cameras. Frustum culling is only performed for one layer. Useful for rendering multiple passes using different shaders.

name: string

Name of the layer. Can be used in LayerComposition#getLayerByName.

onDisable: Function

Custom function that is called after the layer has been disabled. This happens when:

  • Layer#enabled was changed from true to false
  • Layer#decrementCounter was called and set the counter to zero.
onDrawCall: Function

Custom function that is called before every mesh instance in this layer is rendered. It is not recommended to set this function when rendering many objects every frame due to performance reasons.

onEnable: Function

Custom function that is called after the layer has been enabled. This happens when:

  • The layer is created with Layer#enabled set to true (which is the default value).
  • Layer#enabled was changed from false to true
  • Layer#incrementCounter was called and incremented the counter above zero.

Useful for allocating resources this layer will use (e.g. creating render targets).

onPostCull: Function

Custom function that is called after visibility culling is performed for this layer. Useful for reverting changes done in Layer#onPreCull and determining final mesh instance visibility (see MeshInstance#visibleThisFrame). This function will receive camera index as the only argument. You can get the actual camera being used by looking up LayerComposition#cameras with this index.

onPostRender: Function

Custom function that is called after this layer is rendered. Useful to revert changes made in Layer#onPreRender. This function is called after the last occurrence of this layer in LayerComposition. It will receive camera index as the only argument. You can get the actual camera being used by looking up LayerComposition#cameras with this index.

onPostRenderOpaque: Function

Custom function that is called after opaque mesh instances (not semi-transparent) in this layer are rendered. This function will receive camera index as the only argument. You can get the actual camera being used by looking up LayerComposition#cameras with this index.

onPostRenderTransparent: Function

Custom function that is called after semi-transparent mesh instances in this layer are rendered. This function will receive camera index as the only argument. You can get the actual camera being used by looking up LayerComposition#cameras with this index.

onPreCull: Function

Custom function that is called before visibility culling is performed for this layer. Useful, for example, if you want to modify camera projection while still using the same camera and make frustum culling work correctly with it (see CameraComponent#calculateTransform and CameraComponent#calculateProjection). This function will receive camera index as the only argument. You can get the actual camera being used by looking up LayerComposition#cameras with this index.

onPreRender: Function

Custom function that is called before this layer is rendered. Useful, for example, for reacting on screen size changes. This function is called before the first occurrence of this layer in LayerComposition. It will receive camera index as the only argument. You can get the actual camera being used by looking up LayerComposition#cameras with this index.

onPreRenderOpaque: Function

Custom function that is called before opaque mesh instances (not semi-transparent) in this layer are rendered. This function will receive camera index as the only argument. You can get the actual camera being used by looking up LayerComposition#cameras with this index.

onPreRenderTransparent: Function

Custom function that is called before semi-transparent mesh instances in this layer are rendered. This function will receive camera index as the only argument. You can get the actual camera being used by looking up LayerComposition#cameras with this index.

opaqueSortMode: number

Defines the method used for sorting opaque (that is, not semi-transparent) mesh instances before rendering. Can be:

Defaults to SORTMODE_MATERIALMESH.

shaderPass: number

A type of shader to use during rendering. Possible values are:

Defaults to SHADER_FORWARD.

transparentSortMode: number

Defines the method used for sorting semi-transparent mesh instances before rendering. Can be:

Defaults to SORTMODE_BACK2FRONT.

Accessors

Methods

  • Private

    Parameters

    • drawCalls: MeshInstance[]

      Array of mesh instances.

    • drawCallsCount: number

      Number of mesh instances.

    • camPos: Vec3

      Camera position.

    • camFwd: Vec3

      Camera forward vector.

    Returns void

  • Adds an array of mesh instances to this layer.

    Parameters

    • meshInstances: MeshInstance[]

      Array of MeshInstance.

    • Optional skipShadowCasters: boolean

      Set it to true if you don't want these mesh instances to cast shadows in this layer. Defaults to false.

    Returns void

  • Adds an array of mesh instances to this layer, but only as shadow casters (they will not be rendered anywhere, but only cast shadows on other objects).

    Parameters

    Returns void

  • Removes all mesh instances from this layer.

    Parameters

    • Optional skipShadowCasters: boolean = false

      Set it to true if you want to continue the existing mesh instances to cast shadows. Defaults to false, which removes shadow casters as well.

    Returns void

  • Removes multiple mesh instances from this layer.

    Parameters

    • meshInstances: MeshInstance[]

      Array of MeshInstance. If they were added to this layer, they will be removed.

    • Optional skipShadowCasters: boolean

      Set it to true if you want to still cast shadows from removed mesh instances or if they never did cast shadows before. Defaults to false.

    Returns void

  • Removes multiple mesh instances from the shadow casters list of this layer, meaning they will stop casting shadows.

    Parameters

    Returns void