Setting culling

In Kanzi render passes you can optimize the performance of meshes in your applications by setting the culling properties.

Setting the cull mode

By default Kanzi culls in 3D content the polygons whose normal points away from the active camera. To override this, you can set the cull mode in a Pipeline State Render Pass.

To set the cull mode:

  1. In the Library > Rendering > Render Pass Prefabs create a Pipeline State Render Pass, or select an existing Pipeline State Render Pass. See Render passes.

    ../../_images/create-pipeline-state-render-pass.png
  2. In the Pipeline State Render Pass create the render passes that you use to draw the nodes you want to cull.

    For example, create a Clear Render Pass, a Gather Lights Render Pass, and inside the Gather Lights Render Pass create a Draw Objects Render Pass.

    You can use filters to collect specific nodes for rendering. See Filters.

  3. In the Library select the Pipeline State Render Pass and in the Properties set the Cull Mode property to:

    • Back to make Kanzi not render the polygons whose normal points away from the active camera This is the default value for the Cull Mode property. If you do not set the Cull Mode property in a Pipeline State Render Pass, Kanzi uses the value for the property set in the nearest ancestor Pipeline State Render Pass. If there is no ancestor Pipeline State Render Pass, Kanzi uses the default value.

    • Front to make Kanzi not render the polygons whose normal points towards the active camera

    • None to disable culling

    ../../_images/cull-mode-set-to-back.png
  4. Take into use the render passes you created:

    1. In the Node Tree select the Viewport 2D node which contains the content that you want to render.

    2. In the Properties set the Render Pass Prefab property to the Pipeline State Render Pass or to the render pass prefab which contains the Pipeline State Render Pass that you created.

Controlling frustum culling

Use frustum culling when you have a lot of meshes outside of the view frustum of the camera. The view frustum is the volume visible to the active camera and contains the nodes whose bounding volume clips the view frustum. Frustum culling enables you to trade GPU time spent culling the meshes for CPU time.

To control frustum culling:

  1. In the Library select the Draw Objects Render Pass you use to render the meshes for which you want to set frustum culling. See Rendering.

  2. In the Properties add and enable the Frustum Culling property.

    This way Kanzi does not render the meshes when they are outside of the view frustum.

    ../../_images/frustum-culling-enabled.png
  3. (Optional) In the Node Tree select the nodes that contain the meshes for which you want to set frustum culling, in the Properties click image0, add the Frustum Cull Margin property, and set it to the amount of space around the node you do not want to cull.

    For example, this is useful when a vertex shader radically modifies the geometry of nodes, such as in vertex skinned nodes.

    ../../_images/frustum-cull-margin.png

To see if your frustum culling setting works as you intended it to work, in the Preview click image1 to enter the Analyze mode, right-click image2, select the Performance HUD, and move the camera away from the node for which you want to control culling. When culling does not occur anymore for the node, the Batch Count value drops.

See also

Rendering

Filters

Reducing the number of rendered vertices

Setting the correct size of vertex cache

Loading resources in parallel

Troubleshooting the performance of your application

Best practices