Constructor
new Layer(options)
Create a new layer.
Parameters:
Name | Type | Description |
---|---|---|
options |
Object | Object for passing optional arguments. These arguments are the same as properties of the Layer. |
Properties:
Name | Type | Description |
---|---|---|
enabled |
Boolean | Enable the layer. Disabled layers are skipped. Defaults to true. |
name |
String | Name of the layer. Can be used in pc.LayerComposition#getLayerByName. |
opaqueSortMode |
Number | Defines the method used for sorting opaque (that is, not semi-transparent) mesh instances before rendering. Possible values are: Defaults to pc.SORTMODE_MATERIALMESH. |
transparentSortMode |
Number | Defines the method used for sorting semi-transparent mesh instances before rendering. Possible values are: Defaults to pc.SORTMODE_BACK2FRONT. |
renderTarget |
pc.RenderTarget | Render target to which rendering is performed. If not set, will render simply to the screen. |
shaderPass |
Number | A type of shader to use during rendering. Possible values are:
|
passThrough |
Boolean | Tells that this layer is simple and needs to just render a bunch of mesh instances without lighting, skinning and morphing (faster). |
overrideClear |
Boolean | Defines if layer should use camera clear parameters (true) or ignore them and use pc.Layer#clearColor, pc.Layer#clearColorBuffer, pc.Layer#clearDepthBuffer and pc.Layer#clearStencilBuffer. |
clearColor |
pc.Color | The color used to clear the canvas to before each camera starts to render. |
clearColorBuffer |
Boolean | If true cameras will clear the color buffer to the color set in clearColor. |
clearDepthBuffer |
Boolean | If true cameras will clear the depth buffer. |
clearStencilBuffer |
Boolean | If true cameras will clear the stencil buffer. |
layerReference |
pc.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. |
cullingMask |
function | Visibility mask that interacts with pc.MeshInstance#mask. |
onEnable |
function | Custom function that is called after the layer has been enabled.
This happens when:
|
onDisable |
function | Custom function that is called after the layer has been disabled.
This happens when:
|
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 pc.CameraComponent#calculateTransform and pc.CameraComponent#calculateProjection). This function will receive camera index as the only argument. You can get the actual camera being used by looking up pc.LayerComposition#cameras with this index. |
onPostCull |
function | Custom function that is called after visibiliy culling is performed for this layer. Useful for reverting changes done in pc.Layer#onPreCull and determining final mesh instance visibility (see pc.MeshInstance#visibleThisFrame). This function will receive camera index as the only argument. You can get the actual camera being used by looking up pc.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 pc.LayerComposition. It will receive camera index as the only argument. You can get the actual camera being used by looking up pc.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 pc.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 pc.LayerComposition#cameras with this index. |
onPostRender |
function | Custom function that is called after this layer is rendered. Useful to revert changes made in pc.Layer#onPreRender or performing some processing on pc.Layer#renderTarget. This function is called after the last occurrence of this layer in pc.LayerComposition. It will receive camera index as the only argument. You can get the actual camera being used by looking up pc.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 pc.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 pc.LayerComposition#cameras with this index. |
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. |
id |
function | A unique ID of the layer. Layer IDs are stored inside pc.ModelComponent#layers, pc.CameraComponent#layers, pc.LightComponent#layers and pc.ElementComponent#layers instead of names. Can be used in pc.LayerComposition#getLayerById. |
- Source:
Methods
addCamera(camera)
Adds a camera to this layer.
Parameters:
Name | Type | Description |
---|---|---|
camera |
pc.CameraComponent | A pc.CameraComponent. |
- Source:
addLight(light)
Adds a light to this layer.
Parameters:
Name | Type | Description |
---|---|---|
light |
pc.LightComponent | A pc.LightComponent. |
- Source:
addMeshInstances(meshInstances, skipShadowCastersopt)
Adds an array of mesh instances to this layer.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
meshInstances |
Array | Array of pc.MeshInstance. | |
skipShadowCasters |
Boolean |
<optional> |
Set it to true if you don't want these mesh instances to cast shadows in this layer. |
- Source:
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:
Name | Type | Description |
---|---|---|
meshInstances |
Array | Array of pc.MeshInstance. |
- Source:
clearCameras()
Removes all cameras from this layer.
- Source:
clearLights()
Removes all lights from this layer.
- Source:
clearMeshInstances(skipShadowCastersopt)
Removes all mesh instances from this layer.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
skipShadowCasters |
Boolean |
<optional> |
Set it to true if you want to still cast shadows from removed mesh instances or if they never did cast shadows before. |
- Source:
(private) decrementCounter()
Decrements the usage counter of this layer.
Decrementing the counter from 1 to 0 will disable the layer and call pc.Layer.onDisable.
See pc.Layer#incrementCounter for more details.
- Source:
(private) incrementCounter()
Increments the usage counter of this layer.
By default, layers are created with counter set to 1 (if pc.Layer.enabled is true) or 0 (if it was false).
Incrementing the counter from 0 to 1 will enable the layer and call pc.Layer.onEnable.
Use this function to "subscribe" multiple effects to the same layer. For example, if the layer is used to render a reflection texture which is used by 2 mirrors,
then each mirror can call this function when visible and pc.Layer.decrementCounter if invisible.
In such case the reflection texture won't be updated, when there is nothing to use it, saving performance.
- Source:
removeCamera(camera)
Removes a camera from this layer.
Parameters:
Name | Type | Description |
---|---|---|
camera |
pc.CameraComponent | A pc.CameraComponent. |
- Source:
removeLight(light)
Removes a light from this layer.
Parameters:
Name | Type | Description |
---|---|---|
light |
pc.LightComponent | A pc.LightComponent. |
- Source:
removeMeshInstances(meshInstances, skipShadowCastersopt)
Removes multiple mesh instances from this layer.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
meshInstances |
Array | Array of pc.MeshInstance. If they were added to this layer, they will be removed. | |
skipShadowCasters |
Boolean |
<optional> |
Set it to true if you want to still cast shadows from removed mesh instances or if they never did cast shadows before. |
- Source:
removeShadowCasters(meshInstances)
Removes multiple mesh instances from the shadow casters list of this layer, meaning they will stop casting shadows.
Parameters:
Name | Type | Description |
---|---|---|
meshInstances |
Array | Array of pc.MeshInstance. If they were added to this layer, they will be removed. |
- Source: