protected override void Render(ScriptableRenderContext RenderContext, Camera[] Views) { //Init FrameContext GPUScene.Gather(GetWorld().GetMeshBatchColloctor(), true); //Debug.Log("X : " + Screen.width + "__" + "Y : " + Screen.height); RTHandles.Initialize(Screen.width, Screen.height, false, MSAASamples.None); //Render Pipeline BeginFrameRendering(RenderContext, Views); for (int ViewIndex = 0; ViewIndex < Views.Length; ViewIndex++) { //Init View Camera View = Views[ViewIndex]; CommandBuffer CmdBuffer = CommandBufferPool.Get(""); CameraComponent HDView = View.GetComponent <CameraComponent>(); //Render View BeginCameraRendering(RenderContext, View); { using (new ProfilingScope(CmdBuffer, HDView ? HDView.ViewProfiler : ProfilingSampler.Get(ERGProfileId.InfinityRenderer))) { #region InitViewContext bool bSceneView = View.cameraType == CameraType.SceneView; bool bRendererView = View.cameraType == CameraType.Game || View.cameraType == CameraType.Reflection || View.cameraType == CameraType.SceneView; #if UNITY_EDITOR if (bSceneView) { ScriptableRenderContext.EmitWorldGeometryForSceneView(View); } #endif VFXManager.PrepareCamera(View); ViewUnifrom.UnpateBufferData(false, View); ViewUnifrom.BindGPUParameter(CmdBuffer); RenderContext.SetupCameraProperties(View); VFXManager.ProcessCameraCommand(View, CmdBuffer); //Culling Context FCullingData CullingData = new FCullingData(); { CullingData.bRendererView = bRendererView; } ScriptableCullingParameters CullingParameters; View.TryGetCullingParameters(out CullingParameters); CullingResults CullingResult = RenderContext.Cull(ref CullingParameters); //Unity Culling RenderContext.DispatchCull(GPUScene, ref CullingParameters, ref CullingData); //Infinity Culling #endregion //InitViewContext #region InitViewCommand RenderOpaqueDepth(View, CullingData, CullingResult); RenderOpaqueGBuffer(View, CullingData, CullingResult); RenderOpaqueMotion(View, CullingData, CullingResult); RenderOpaqueForward(View, CullingData, CullingResult); RenderSkyBox(View); RenderGizmo(View, GizmoSubset.PostImageEffects); RenderPresentView(View, GraphBuilder.ScopeTexture(InfinityShaderIDs.DiffuseBuffer), View.targetTexture); #endregion //InitViewCommand #region ExecuteViewRender GraphBuilder.Execute(RenderContext, GetWorld(), CmdBuffer, ViewUnifrom.FrameIndex); #endregion //ExecuteViewRender #region ReleaseViewContext CullingData.Release(); ViewUnifrom.UnpateBufferData(true, View); #endregion //ReleaseViewContext } } EndCameraRendering(RenderContext, View); //Submit View RenderContext.ExecuteCommandBuffer(CmdBuffer); CommandBufferPool.Release(CmdBuffer); RenderContext.Submit(); } EndFrameRendering(RenderContext, Views); //Release FrameContext GPUScene.Release(); }
protected override void Render(ScriptableRenderContext RenderContext, Camera[] RenderCameras) { //Gather MeshBatch NativeList <FMeshBatch> MeshBatchList = GetWorld().GetMeshBatchColloctor().GetMeshBatchList(); //Render Pipeline BeginFrameRendering(RenderContext, RenderCameras); foreach (Camera RenderCamera in RenderCameras) { RenderCamera.allowHDR = true; bool isSceneViewCam = RenderCamera.cameraType == CameraType.SceneView; #if UNITY_EDITOR if (isSceneViewCam) { ScriptableRenderContext.EmitWorldGeometryForSceneView(RenderCamera); } #endif //Prepare VisualEffects VFXManager.PrepareCamera(RenderCamera); //Prepare ViewUnifrom ViewUnifrom.UnpateBufferData(false, RenderCamera); //View RenderFamily CommandBuffer CmdBuffer = CommandBufferPool.Get(""); //Binding ViewParameter BeginCameraRendering(RenderContext, RenderCamera); CmdBuffer.DisableScissorRect(); ViewUnifrom.BindGPUProperty(CmdBuffer); RenderContext.SetupCameraProperties(RenderCamera); //Binding VisualEffects VFXManager.ProcessCameraCommand(RenderCamera, CmdBuffer); //Culling MeshBatch NativeArray <FPlane> ViewFrustum = new NativeArray <FPlane>(6, Allocator.Persistent); NativeArray <FVisibleMeshBatch> VisibleMeshBatchList = new NativeArray <FVisibleMeshBatch>(MeshBatchList.Length, Allocator.TempJob); Plane[] FrustumPlane = GeometryUtility.CalculateFrustumPlanes(RenderCamera); for (int PlaneIndex = 0; PlaneIndex < 6; PlaneIndex++) { ViewFrustum[PlaneIndex] = FrustumPlane[PlaneIndex]; } CullMeshBatch CullTask = new CullMeshBatch(); { CullTask.ViewFrustum = ViewFrustum; CullTask.ViewOrigin = RenderCamera.transform.position; CullTask.MeshBatchList = MeshBatchList; CullTask.VisibleMeshBatchList = VisibleMeshBatchList; } JobHandle CullTaskHandle = CullTask.Schedule(MeshBatchList.Length, 256); /*SortMeshBatch SortTask = new SortMeshBatch(); * { * SortTask.VisibleMeshBatchList = VisibleMeshBatchList; * } * JobHandle SortTaskHandle = SortTask.Schedule(CullTaskHandle);*/ //Culling Context ScriptableCullingParameters CullingParameter; RenderCamera.TryGetCullingParameters(out CullingParameter); CullingResults CullingResult = RenderContext.Cull(ref CullingParameter); CullTaskHandle.Complete(); //SortTaskHandle.Complete(); //Render Family RenderOpaqueDepth(RenderCamera, CullingResult); RenderOpaqueGBuffer(RenderCamera, CullingResult, VisibleMeshBatchList); RenderOpaqueMotion(RenderCamera, CullingResult); RenderSkyAtmosphere(RenderCamera); RenderPresentView(RenderCamera, GraphBuilder.ScopeTexture(InfinityShaderIDs.RT_ThinGBufferA), RenderCamera.targetTexture); //Draw DrawGizmos #if UNITY_EDITOR if (Handles.ShouldRenderGizmos()) { RenderGizmo(RenderCamera, GizmoSubset.PostImageEffects); } #endif //Execute RenderGraph GraphBuilder.Execute(RenderContext, GetWorld(), CmdBuffer, ViewUnifrom.FrameIndex); EndCameraRendering(RenderContext, RenderCamera); //Execute ViewRender RenderContext.ExecuteCommandBuffer(CmdBuffer); CommandBufferPool.Release(CmdBuffer); RenderContext.Submit(); //Prepare ViewUnifrom ViewUnifrom.UnpateBufferData(true, RenderCamera); //Release View ViewFrustum.Dispose(); VisibleMeshBatchList.Dispose(); } EndFrameRendering(RenderContext, RenderCameras); }