Layer
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.
Summary
Properties
clearColorBuffer | If true, the camera will clear the color buffer when it renders this layer. |
clearDepthBuffer | If true, the camera will clear the depth buffer when it renders this layer. |
clearStencilBuffer | If true, the camera will clear the stencil buffer when it renders this layer. |
enabled | Enable the layer. |
id | A unique ID of the layer. |
layerReference | Make this layer render the same mesh instances that another layer does instead of having its own mesh instance list. |
name | Name of the layer. |
onDisable | Custom function that is called after the layer has been disabled. |
onDrawCall | Custom function that is called before every mesh instance in this layer is rendered. |
onEnable | Custom function that is called after the layer has been enabled. |
onPostCull | Custom function that is called after visibility culling is performed for this layer. |
onPostRender | Custom function that is called after this layer is rendered. |
onPostRenderOpaque | Custom function that is called after opaque mesh instances (not semi-transparent) in this layer are rendered. |
onPostRenderTransparent | Custom function that is called after semi-transparent mesh instances in this layer are rendered. |
onPreCull | Custom function that is called before visibility culling is performed for this layer. |
onPreRender | Custom function that is called before this layer is rendered. |
onPreRenderOpaque | Custom function that is called before opaque mesh instances (not semi-transparent) in this layer are rendered. |
onPreRenderTransparent | Custom function that is called before semi-transparent mesh instances in this layer are rendered. |
opaqueSortMode | Defines the method used for sorting opaque (that is, not semi-transparent) mesh instances before rendering. |
passThrough | Tells that this layer is simple and needs to just render a bunch of mesh instances without lighting, skinning and morphing (faster). |
shaderPass | A type of shader to use during rendering. |
transparentSortMode | Defines the method used for sorting semi-transparent mesh instances before rendering. |
Methods
addCamera | Adds a camera to this layer. |
addLight | Adds a light to this layer. |
addMeshInstances | Adds an array of mesh instances to this layer. |
addShadowCasters | 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). |
clearCameras | Removes all cameras from this layer. |
clearLights | Removes all lights from this layer. |
clearMeshInstances | Removes all mesh instances from this layer. |
removeCamera | Removes a camera from this layer. |
removeLight | Removes a light from this layer. |
removeMeshInstances | Removes multiple mesh instances from this layer. |
removeShadowCasters | Removes multiple mesh instances from the shadow casters list of this layer, meaning they will stop casting shadows. |
Details
Constructor
Layer(options)
Create a new Layer instance.
Parameters
options | object | Object for passing optional arguments. These arguments are the same as properties of the Layer. |
Properties
If true, the camera will clear the color buffer when it renders this layer.
If true, the camera will clear the depth buffer when it renders this layer.
If true, the camera will clear the stencil buffer when it renders this layer.
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.
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.
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.
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.
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).
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.
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.
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.
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.
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.
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.
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.
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.
Defines the method used for sorting opaque (that is, not semi-transparent) mesh instances before rendering. Can be:
Defaults to SORTMODE_MATERIALMESH.
Tells that this layer is simple and needs to just render a bunch of mesh instances without lighting, skinning and morphing (faster). Used for UI and Gizmo layers (the layer doesn't use lights, shadows, culling, etc).
A type of shader to use during rendering. Possible values are:
- SHADER_FORWARD
- SHADER_FORWARDHDR
- SHADER_DEPTH
- Your own custom value. Should be in 19 - 31 range. Use StandardMaterial#onUpdateShader to apply shader modifications based on this value.
Defaults to SHADER_FORWARD.
Defines the method used for sorting semi-transparent mesh instances before rendering. Can be:
Defaults to SORTMODE_BACK2FRONT.
Methods
addMeshInstances(meshInstances, [skipShadowCasters])
Adds an array of mesh instances to this layer. 1
Parameters
meshInstances | MeshInstance[] | Array of MeshInstance. |
skipShadowCasters | boolean | Set it to true if you don't want these mesh instances to cast shadows in this layer. |
addShadowCasters(meshInstances)
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
meshInstances | MeshInstance[] | Array of MeshInstance. |
clearCameras()
Removes all cameras from this layer.
clearLights()
Removes all lights from this layer.
clearMeshInstances([skipShadowCasters])
Removes all mesh instances from this layer.
Parameters
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. |
removeMeshInstances(meshInstances, [skipShadowCasters])
Removes multiple mesh instances from this layer.
Parameters
meshInstances | MeshInstance[] | Array of MeshInstance. If they were added to this layer, they will be removed. |
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. |
removeShadowCasters(meshInstances)
Removes multiple mesh instances from the shadow casters list of this layer, meaning they will stop casting shadows.
Parameters
meshInstances | MeshInstance[] | Array of MeshInstance. If they were added to this layer, they will be removed. |