Example #1
0
        public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
            CommandBuffer buffer = data.buffer;

            buffer.SetRenderTarget(cam.targets.gbufferIdentifier, cam.targets.depthIdentifier);
            buffer.ClearRenderTarget(true, true, Color.black);
            HizOcclusionData     hizData = IPerCameraData.GetProperty(cam, () => new HizOcclusionData());
            RenderClusterOptions options = new RenderClusterOptions
            {
                command        = buffer,
                frustumPlanes  = data.frustumPlanes,
                cullingShader  = data.resources.shaders.gpuFrustumCulling,
                terrainCompute = data.resources.shaders.terrainCompute
            };

            if (enableOcclusionCulling)
            {
                HizOptions hizOptions;
                hizOptions = new HizOptions
                {
                    currentCameraUpVec = cam.cam.transform.up,
                    hizData            = hizData,
                    hizDepth           = hizDepth,
                    linearLODMaterial  = linearMat,
                    currentDepthTex    = cam.targets.depthIdentifier
                };
                SceneController.DrawClusterOccDoubleCheck(ref options, ref hizOptions, ref cam.targets, ref data, cam.cam);
            }
            else
            {
                SceneController.DrawCluster(ref options, ref cam.targets, ref data, cam.cam);
            }
        }
Example #2
0
        public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
            //   Material proceduralMaterial = data.baseBuffer.combinedMaterial;
            CommandBuffer buffer = data.buffer;

            buffer.SetRenderTarget(cam.targets.gbufferIdentifier, cam.targets.depthIdentifier);
            buffer.ClearRenderTarget(true, true, Color.black);
            PipelineBaseBuffer baseBuffer;

            if (!SceneController.current.GetBaseBufferAndCheck(out baseBuffer))
            {
                return;
            }
            HizOcclusionData     hizData = IPerCameraData.GetProperty <HizOcclusionData>(cam, getOcclusionData);
            RenderClusterOptions options = new RenderClusterOptions
            {
                command            = buffer,
                frustumPlanes      = data.arrayCollection.frustumPlanes,
                proceduralMaterial = proceduralMaterial,
                isOrtho            = cam.cam.orthographic,
                cullingShader      = data.resources.gpuFrustumCulling
            };
            HizOptions hizOptions;

            switch (occCullingMod)
            {
            case OcclusionCullingMode.None:
                SceneController.current.DrawCluster(ref options);
                break;

            case OcclusionCullingMode.SingleCheck:
                hizOptions = new HizOptions
                {
                    currentCameraUpVec = cam.cam.transform.up,
                    hizData            = hizData,
                    hizDepth           = hizDepth,
                    linearLODMaterial  = linearMat
                };
                SceneController.current.DrawClusterOccSingleCheck(ref options, ref hizOptions);
                break;

            case OcclusionCullingMode.DoubleCheck:
                hizOptions = new HizOptions
                {
                    currentCameraUpVec = cam.cam.transform.up,
                    hizData            = hizData,
                    hizDepth           = hizDepth,
                    linearLODMaterial  = linearMat
                };
                SceneController.current.DrawClusterOccDoubleCheck(ref options, ref hizOptions, ref cam.targets);
                break;
            }
            data.ExecuteCommandBuffer();
        }
Example #3
0
        public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
            CommandBuffer buffer = data.buffer;

            buffer.SetRenderTarget(cam.targets.gbufferIdentifier, cam.targets.depthIdentifier);
            buffer.ClearRenderTarget(true, true, Color.black);
            PipelineBaseBuffer baseBuffer;
            bool                 isClusterEnabled = SceneController.GetBaseBuffer(out baseBuffer);
            HizOcclusionData     hizData          = IPerCameraData.GetProperty <HizOcclusionData>(cam, () => new HizOcclusionData());
            RenderClusterOptions options          = new RenderClusterOptions
            {
                command          = buffer,
                frustumPlanes    = data.arrayCollection.frustumPlanes,
                isOrtho          = cam.cam.orthographic,
                cullingShader    = data.resources.gpuFrustumCulling,
                terrainCompute   = data.resources.terrainCompute,
                isClusterEnabled = isClusterEnabled,
                isTerrainEnabled = true
            };
            HizOptions hizOptions;

            switch (occCullingMod)
            {
            case OcclusionCullingMode.None:
                SceneController.current.DrawCluster(ref options, ref cam.targets);
                break;

            case OcclusionCullingMode.SingleCheck:
                hizOptions = new HizOptions
                {
                    currentCameraUpVec = cam.cam.transform.up,
                    hizData            = hizData,
                    hizDepth           = hizDepth,
                    linearLODMaterial  = linearMat,
                    currentDepthTex    = cam.targets.depthTexture
                };
                SceneController.current.DrawClusterOccSingleCheck(ref options, ref hizOptions, ref cam.targets);
                break;

            case OcclusionCullingMode.DoubleCheck:
                hizOptions = new HizOptions
                {
                    currentCameraUpVec = cam.cam.transform.up,
                    hizData            = hizData,
                    hizDepth           = hizDepth,
                    linearLODMaterial  = linearMat,
                    currentDepthTex    = cam.targets.depthTexture
                };
                SceneController.current.DrawClusterOccDoubleCheck(ref options, ref hizOptions, ref cam.targets);
                break;
            }
            data.ExecuteCommandBuffer();
        }
        public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
            //   Material proceduralMaterial = data.baseBuffer.combinedMaterial;
            CommandBuffer buffer = data.buffer;

            buffer.SetRenderTarget(cam.targets.gbufferIdentifier, cam.targets.depthIdentifier);
            buffer.ClearRenderTarget(true, true, Color.black);
            if (data.baseBuffer.clusterCount <= 0)
            {
                return;
            }
            HizOcclusionData hizData    = IPerCameraData.GetProperty <HizOcclusionData>(cam, getOcclusionData);
            ref var          baseBuffer = ref data.baseBuffer;
        public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
            CommandBuffer        buffer  = data.buffer;
            RenderClusterOptions options = new RenderClusterOptions
            {
                command        = buffer,
                frustumPlanes  = proper.frustumPlanes,
                cullingShader  = data.resources.shaders.gpuFrustumCulling,
                terrainCompute = data.resources.shaders.terrainCompute
            };
            FilteringSettings alphaTestFilter = new FilteringSettings
            {
                layerMask          = cam.cam.cullingMask,
                renderingLayerMask = 1,
                renderQueueRange   = new RenderQueueRange(2450, 2499)
            };
            FilteringSettings opaqueFilter = new FilteringSettings
            {
                layerMask          = cam.cam.cullingMask,
                renderingLayerMask = 1,
                renderQueueRange   = new RenderQueueRange(2000, 2449)
            };
            FilteringSettings mvFilter = new FilteringSettings
            {
                layerMask          = cam.cam.cullingMask,
                renderingLayerMask = 1,
                renderQueueRange   = RenderQueueRange.opaque
            };
            DrawingSettings depthAlphaTestDrawSettings = new DrawingSettings(new ShaderTagId("Depth"),
                                                                             new SortingSettings(cam.cam)
            {
                criteria = SortingCriteria.QuantizedFrontToBack | SortingCriteria.OptimizeStateChanges
            }
                                                                             )
            {
                perObjectData         = UnityEngine.Rendering.PerObjectData.None,
                enableDynamicBatching = false,
                enableInstancing      = false
            };
            DrawingSettings depthOpaqueDrawSettings = new DrawingSettings(new ShaderTagId("Depth"),
                                                                          new SortingSettings(cam.cam)
            {
                criteria = SortingCriteria.QuantizedFrontToBack
            })
            {
                perObjectData             = UnityEngine.Rendering.PerObjectData.None,
                enableDynamicBatching     = false,
                enableInstancing          = false,
                overrideMaterial          = proper.overrideOpaqueMaterial,
                overrideMaterialPassIndex = 1
            };

            DrawingSettings drawSettings = new DrawingSettings(new ShaderTagId("GBuffer"), new SortingSettings(cam.cam)
            {
                criteria = SortingCriteria.RenderQueue | SortingCriteria.OptimizeStateChanges
            })
            {
                perObjectData         = UnityEngine.Rendering.PerObjectData.Lightmaps,
                enableDynamicBatching = false,
                enableInstancing      = false
            };
            DrawingSettings mvDraw = new DrawingSettings(new ShaderTagId("MotionVector"), new SortingSettings {
                criteria = SortingCriteria.OptimizeStateChanges
            })
            {
                perObjectData         = UnityEngine.Rendering.PerObjectData.None,
                enableDynamicBatching = false,
                enableInstancing      = false
            };

            //Draw Depth Prepass
            data.buffer.SetRenderTarget(ShaderIDs._DepthBufferTexture);
            data.buffer.ClearRenderTarget(true, false, Color.black);
            cullHandle.Complete();
            var lst = CustomDrawRequest.allEvents;

            foreach (var i in gbufferCullResults)
            {
                lst[i].DrawDepthPrepass(buffer);
            }
            HizOcclusionData hizOccData = null;

            PipelineFunctions.UpdateFrustumMinMaxPoint(buffer, proper.frustumMinPoint, proper.frustumMaxPoint);
            if (useHiZ && SceneController.gpurpEnabled)
            {
#if UNITY_EDITOR
                if (Application.isPlaying)
                {
#endif
                hizOccData = IPerCameraData.GetProperty(cam, () => new HizOcclusionData());
                SceneController.CullCluster_LastFrameDepthHiZ(ref options, hizOccData, cam);
                buffer.DrawProceduralIndirect(Matrix4x4.identity, clusterMat, 2, MeshTopology.Triangles, SceneController.baseBuffer.instanceCountBuffer, 0);
#if UNITY_EDITOR
            }
#endif
            }
            RenderStateBlock depthBlock = new RenderStateBlock
            {
                depthState = new DepthState(true, CompareFunction.Less),
                mask       = RenderStateMask.Depth
            };
            SceneController.RenderScene(ref data, ref opaqueFilter, ref depthOpaqueDrawSettings, ref proper.cullResults, ref depthBlock);
            data.context.DrawRenderers(proper.cullResults, ref depthAlphaTestDrawSettings, ref alphaTestFilter);
            decalEvt.FrameUpdate(cam, ref data);
            //Draw GBuffer
            data.buffer.SetRenderTarget(colors: cam.targets.gbufferIdentifier, depth: ShaderIDs._DepthBufferTexture);
            data.buffer.ClearRenderTarget(false, true, Color.black);


            foreach (var i in gbufferCullResults)
            {
                lst[i].DrawGBuffer(buffer);
            }
            if (useHiZ && SceneController.gpurpEnabled)
            {
#if UNITY_EDITOR
                if (Application.isPlaying)
                {
#endif
                buffer.SetGlobalBuffer(ShaderIDs._MaterialBuffer, data.resources.clusterResources.vmManager.materialBuffer);
                buffer.SetGlobalTexture(ShaderIDs._GPURPMainTex, data.resources.clusterResources.rgbaPool.rt);
                buffer.SetGlobalTexture(ShaderIDs._GPURPEmissionMap, data.resources.clusterResources.emissionPool.rt);
                buffer.SetGlobalTexture(ShaderIDs._GPURPBumpMap, data.resources.clusterResources.normalPool.rt);
                buffer.SetGlobalTexture(ShaderIDs._GPURPHeightMap, data.resources.clusterResources.heightPool.rt);
                buffer.DrawProceduralIndirect(Matrix4x4.identity, clusterMat, 0, MeshTopology.Triangles, SceneController.baseBuffer.instanceCountBuffer, 0);
#if UNITY_EDITOR
            }
#endif
            }
            SceneController.RenderScene(ref data, ref opaqueFilter, ref drawSettings, ref proper.cullResults);
            if (useHiZ && SceneController.gpurpEnabled)
            {
#if UNITY_EDITOR
                if (Application.isPlaying)
#endif
                SceneController.DrawCluster_RecheckHiz(ref options, ref hizDepth, hizOccData, clusterMat, linearMat, cam);
            }
            if (MTerrain.current)
            {
                MTerrain.current.DrawTerrain(buffer, 0, proper.frustumPlanes);
            }
            //Draw AlphaTest

            /* SortingSettings st = drawSettings.sortingSettings;
             * st.criteria = SortingCriteria.SortingLayer | SortingCriteria.RenderQueue | SortingCriteria.OptimizeStateChanges;
             * drawSettings.sortingSettings = st;*/
            SceneController.RenderScene(ref data, ref alphaTestFilter, ref drawSettings, ref proper.cullResults);
            //Draw Depth
            data.buffer.Blit(ShaderIDs._DepthBufferTexture, ShaderIDs._CameraDepthTexture);
            //Draw Motion Vector
            data.buffer.SetRenderTarget(color: ShaderIDs._CameraMotionVectorsTexture, depth: ShaderIDs._DepthBufferTexture);
            foreach (var i in gbufferCullResults)
            {
                lst[i].DrawMotionVector(buffer);
            }
            SceneController.RenderScene(ref data, ref mvFilter, ref mvDraw, ref proper.cullResults);
            //Draw Static Global Motion Vector
            data.buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, motionVecMat, 0, 0);
        }
Example #6
0
 public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data, CommandBuffer buffer)
 {
     HizOcclusionData hizData    = IPerCameraData.GetProperty <HizOcclusionData>(cam, getOcclusionData);
     ref var          baseBuffer = ref data.baseBuffer;