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?