API Reference

Class List

pc.Layer

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 pc.LayerComposition in a desired order.

Summary

Properties

clearColorThe color used to clear the canvas to before each camera starts to render.
clearColorBufferIf true cameras will clear the color buffer to the color set in clearColor.
clearDepthBufferIf true cameras will clear the depth buffer.
clearStencilBufferIf true cameras will clear the stencil buffer.
cullingMaskVisibility mask that interacts with pc.MeshInstance#mask.
enabledEnable the layer.
idA unique ID of the layer.
layerReferenceMake this layer render the same mesh instances that another layer does instead of having its own mesh instance list.
nameName of the layer.
onDisableCustom function that is called after the layer has been disabled.
onDrawCallCustom function that is called before every mesh instance in this layer is rendered.
onEnableCustom function that is called after the layer has been enabled.
onPostCullCustom function that is called after visibiliy culling is performed for this layer.
onPostRenderCustom function that is called after this layer is rendered.
onPostRenderOpaqueCustom function that is called after opaque mesh instances (not semi-transparent) in this layer are rendered.
onPostRenderTransparentCustom function that is called after semi-transparent mesh instances in this layer are rendered.
onPreCullCustom function that is called before visibility culling is performed for this layer.
onPreRenderCustom function that is called before this layer is rendered.
onPreRenderOpaqueCustom function that is called before opaque mesh instances (not semi-transparent) in this layer are rendered.
onPreRenderTransparentCustom function that is called before semi-transparent mesh instances in this layer are rendered.
opaqueSortModeDefines the method used for sorting opaque (that is, not semi-transparent) mesh instances before rendering.
overrideClearDefines 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.
passThroughTells that this layer is simple and needs to just render a bunch of mesh instances without lighting, skinning and morphing (faster).
renderTargetRender target to which rendering is performed.
shaderPassA type of shader to use during rendering.
transparentSortModeDefines the method used for sorting semi-transparent mesh instances before rendering.

Methods

addCameraAdds a camera to this layer.
addLightAdds a light to this layer.
addMeshInstancesAdds an array of mesh instances to this layer.
addShadowCastersAdds 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).
clearCamerasRemoves all cameras from this layer.
clearLightsRemoves all lights from this layer.
clearMeshInstancesRemoves all mesh instances from this layer.
removeCameraRemoves a camera from this layer.
removeLightRemoves a light from this layer.
removeMeshInstancesRemoves multiple mesh instances from this layer.
removeShadowCastersRemoves 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.

Parameters

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

Properties

pc.ColorclearColor

The color used to clear the canvas to before each camera starts to render.

BooleanclearColorBuffer

If true cameras will clear the color buffer to the color set in clearColor.

BooleanclearDepthBuffer

If true cameras will clear the depth buffer.

BooleanclearStencilBuffer

If true cameras will clear the stencil buffer.

functioncullingMask

Visibility mask that interacts with pc.MeshInstance#mask.

Booleanenabled

Enable the layer. Disabled layers are skipped. Defaults to true.

functionid

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.

pc.LayerlayerReference

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.

Stringname

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

functiononDisable

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

functiononDrawCall

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.

functiononEnable

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

  • The layer is created with pc.Layer#enabled set to true (which is the default value).
  • pc.Layer#enabled was changed from false to true
  • pc.Layer#incrementCounter was called and incremented the counter above zero.
Useful for allocating resources this layer will use (e.g. creating render targets).

functiononPostCull

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.

functiononPostRender

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.

functiononPostRenderOpaque

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.

functiononPostRenderTransparent

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.

functiononPreCull

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.

functiononPreRender

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.

functiononPreRenderOpaque

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.

functiononPreRenderTransparent

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.

NumberopaqueSortMode

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

Defaults to pc.SORTMODE_MATERIALMESH.

BooleanoverrideClear

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.

BooleanpassThrough

Tells that this layer is simple and needs to just render a bunch of mesh instances without lighting, skinning and morphing (faster).

pc.RenderTargetrenderTarget

Render target to which rendering is performed. If not set, will render simply to the screen.

NumbershaderPass

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

  • pc.SHADER_FORWARD
  • pc.SHADER_FORWARDHDR
  • pc.SHADER_DEPTH
  • Your own custom value. Should be in 19 - 31 range. Use pc.StandardMaterial#onUpdateShader to apply shader modifications based on this value.
Defaults to pc.SHADER_FORWARD.

NumbertransparentSortMode

Defines the method used for sorting semi-transparent mesh instances before rendering. Possible values are:

Defaults to pc.SORTMODE_BACK2FRONT.

Methods

addCamera(camera)

Adds a camera to this layer.

Parameters

camerapc.CameraComponentA pc.CameraComponent.

addLight(light)

Adds a light to this layer.

Parameters

lightpc.LightComponentA pc.LightComponent.

addMeshInstances(meshInstances, [skipShadowCasters])

Adds an array of mesh instances to this layer.

Parameters

meshInstancesArrayArray of pc.MeshInstance.
skipShadowCastersBooleanSet 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

meshInstancesArrayArray of pc.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

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

removeCamera(camera)

Removes a camera from this layer.

Parameters

camerapc.CameraComponentA pc.CameraComponent.

removeLight(light)

Removes a light from this layer.

Parameters

lightpc.LightComponentA pc.LightComponent.

removeMeshInstances(meshInstances, [skipShadowCasters])

Removes multiple mesh instances from this layer.

Parameters

meshInstancesArrayArray of pc.MeshInstance. If they were added to this layer, they will be removed.
skipShadowCastersBooleanSet 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

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