Version: 2023.2
LanguageEnglish
  • C#

CullingResults

struct in UnityEngine.Rendering

/

Implemented in:UnityEngine.CoreModule

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

A struct containing the results of a culling operation.

In the Scriptable Render Pipeline, when Unity performs a culling operation, it stores the results in a CullingResults struct. This data includes information about visible objects, lights, and reflection probes. Unity uses this data to render objects and process lights. A CullingResults struct also provides several functions to aid shadow rendering.

To obtain a CullingResults struct, call ScriptableRenderContext.Cull.

A CullingResults struct is valid within the scope of a RenderPipeline.Render function; its data goes out of scope when the Render function returns. You can use the same CullingResults struct multiple times within the same render loop, and you can share a CullingResults struct between multiple Cameras if you know that they can see the same objects. This can save on wasted CPU operations, and therefore improve performance.

This example demonstrates how to obtain a CullingResults struct, and then pass it to ScriptableRenderContext.DrawRenderers.

using UnityEngine;
using UnityEngine.Rendering;

public class ExampleRenderPipeline : RenderPipeline { public ExampleRenderPipeline() { }

protected override void Render(ScriptableRenderContext context, Camera[] cameras) { foreach (Camera camera in cameras) { // Get the culling parameters from the current camera camera.TryGetCullingParameters(out var cullingParameters);

// Schedule the cull operation that populates the CullingResults struct CullingResults cullingResults = context.Cull(ref cullingParameters);

// Place code that schedules drawing operations using the CullingResults struct here // See ScriptableRenderContext.DrawRenderers for details and examples // …

// Execute all of the scheduled operations, in order context.Submit(); } } }

Properties

lightAndReflectionProbeIndexCountGets the number of per-object light and reflection probe indices.
lightIndexCountGets the number of per-object light indices.
reflectionProbeIndexCountGets the number of per-object reflection probe indices.
visibleLightsArray of visible lights.
visibleOffscreenVertexLightsOff-screen lights that still affect visible vertices.
visibleReflectionProbesArray of visible reflection probes.

Public Methods

ComputeDirectionalShadowMatricesAndCullingPrimitivesCalculates the view and projection matrices and shadow split data for a directional light.
ComputePointShadowMatricesAndCullingPrimitivesCalculates the view and projection matrices and shadow split data for a point light.
ComputeSpotShadowMatricesAndCullingPrimitivesCalculates the view and projection matrices and shadow split data for a spot light.
FillLightAndReflectionProbeIndicesFills a buffer with per-object light indices.
GetLightIndexMapIf a RenderPipeline sorts or otherwise modifies the VisibleLight list, an index remap will be necessary to properly make use of per-object light lists.
GetReflectionProbeIndexMapIf a RenderPipeline sorts or otherwise modifies the VisibleReflectionProbe list, an index remap will be necessary to properly make use of per-object reflection probe lists.
GetShadowCasterBoundsReturns the bounding box that encapsulates the visible shadow casters. Can be used to, for instance, dynamically adjust cascade ranges.
SetLightIndexMapIf a RenderPipeline sorts or otherwise modifies the VisibleLight list, an index remap will be necessary to properly make use of per-object light lists.
SetReflectionProbeIndexMapIf a RenderPipeline sorts or otherwise modifies the VisibleReflectionProbe list, an index remap will be necessary to properly make use of per-object reflection probe lists.