How to use `ScriptableRenderContext.Cull` without camera?

I’m trying to implement custom lightning system for my game. For this purpose, I want to render a shadowmap texture. I want to do this without using any camera, but only basing on light object transform. I write this code to do this:

var pos = _transform.position;

var farClipPlane = new Plane(Vector3.forward, pos + Vector3.forward * _nearClip);
var nearClipPlane = new Plane(-Vector3.forward, pos + Vector3.forward * _farClip);

var cullParams = new ScriptableCullingParameters()
{
    isOrthographic = true,
    cullingMatrix =  _projectionMatrix,
    origin = pos,
    cullingOptions = CullingOptions.None,
    cullingPlaneCount = 2,
    maximumVisibleLights = 0,
};

cullParams.SetCullingPlane(0, farClipPlane);
cullParams.SetCullingPlane(1, nearClipPlane);

var cullData = context.Cull(ref cullParams);

_commandBuffer.SetRenderTarget(_depthTexture);
_commandBuffer.ClearRenderTarget(true, true, Color.clear);
_commandBuffer.SetViewMatrix(_viewMatrix);
_commandBuffer.SetProjectionMatrix(_projectionMatrix);

var rendererListDesc = new RendererListDesc(new ShaderTagId("UniversalForward") , cullData, renderingData.cameraData.camera)
{
    sortingCriteria = SortingCriteria.CommonOpaque,
    rendererConfiguration = PerObjectData.None,
    renderQueueRange = RenderQueueRange.opaque,
    overrideMaterial = _testMaterial
};

var rendererList = context.CreateRendererList(rendererListDesc);

_commandBuffer.DrawRendererList(rendererList);

context.ExecuteCommandBuffer(_commandBuffer);
_commandBuffer.Clear();

But got an error on 19th line in var cullData = context.Cull(ref cullParams);. The error is next: A valid camera must be specified to provide for per-camera intermediate renderers & LOD fade.

How can I solve this and get a CullingResults without using Camera component?

Maybe someone knows the answer?

The working approach is to use the dummy camera that has its Camera component disabled. Setup this camera with your matrices and you can call Cull from it in your render pass.

    context.SetupCameraProperties(_camera);

    if (!_camera.TryGetCullingParameters(out var cullParams))
    {
       return;
    }

    var cullResults = context.Cull(ref cullParams);

Yes, this is a solution, but I would like to not have a dummy camera, because then in the Scene window the camera gizmo is visible if the object on which this camera hangs is selected. :frowning_face: At the same time, the gizmo for a specific camera cannot be disabled.

You can create this camera with HideFlags.HideAndDontSave so you won’t be able to select it.

Thanks that you mention it! I applied hideFlag for the GameObject which contains Camera component, but I needed to use this flag for the Camera too, and now I don’t see camera’s gizmo.