private void RenderCamera(ref ScriptableRenderContext context, Camera camera) { if (m_ShadowMap == null) { m_ShadowMap = new RenderTexture(1024, 1024, 24, RenderTextureFormat.Shadowmap); m_ShadowMap.name = "Shadow Map"; m_ShadowMap.Create(); } if (camera.TryGetCullingParameters(out ScriptableCullingParameters cullingParameters)) { // Start camera render RenderPipeline.BeginCameraRendering(context, camera); cullingParameters.shadowDistance = 30; // Perform culling operations CullingResults cullingResults = context.Cull(ref cullingParameters); // Shadow map rendering Matrix4x4 worldToShadowMatrix = Matrix4x4.identity; bool didRenderShadowMap = RenderShadowMaps(ref context, ref cullingResults, ref worldToShadowMatrix); // Setup camera for rendering context.SetupCameraProperties(camera); // Clear camera CommandBuffer cb_ClearCamera = new CommandBuffer(); cb_ClearCamera.name = "ClearCamera"; cb_ClearCamera.SetRenderTarget(camera.targetTexture); cb_ClearCamera.ClearRenderTarget(true, true, camera.backgroundColor); context.ExecuteCommandBuffer(cb_ClearCamera); // Draw opaque objects SortingSettings sortSettings = new SortingSettings(camera); sortSettings.criteria = SortingCriteria.CommonOpaque; FilteringSettings filterSettings = FilteringSettings.defaultValue; filterSettings.renderQueueRange = RenderQueueRange.opaque; if (didRenderShadowMap) { CommandBuffer cb = new CommandBuffer(); cb.name = "Set up shadow shader properties"; cb.SetGlobalTexture("_ShadowMapTexture", m_ShadowMap); cb.SetGlobalMatrix("_WorldToShadowMatrix", worldToShadowMatrix); cb.SetGlobalVector("_LightDirection", -cullingResults.visibleLights[0].light.transform.forward); // Direction towards the light context.ExecuteCommandBuffer(cb); } DrawingSettings opaqueDrawSettings = new DrawingSettings(s_OpaquePassTag, sortSettings); context.DrawRenderers(cullingResults, ref opaqueDrawSettings, ref filterSettings); // Draw skybox context.DrawSkybox(camera); // Final submission context.Submit(); // End camera render RenderPipeline.EndCameraRendering(context, camera); } }