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); } }
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(); }
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 virtual void DrawClusterOccDoubleCheck(ref RenderClusterOptions options, ref HizOptions hizOpts, ref RenderTargets rendTargets) { }
public virtual void DrawClusterOccSingleCheck(ref RenderClusterOptions options, ref HizOptions hizOpts) { }
public override void DrawClusterOccDoubleCheck(ref RenderClusterOptions options, ref HizOptions hizOpts, ref RenderTargets rendTargets) { CommandBuffer buffer = options.command; ComputeShader gpuFrustumShader = options.cullingShader; PipelineFunctions.UpdateOcclusionBuffer( baseBuffer, gpuFrustumShader, buffer, hizOpts.hizData, options.frustumPlanes, options.isOrtho); //绘制第一次剔除结果 PipelineFunctions.DrawLastFrameCullResult(baseBuffer, buffer, options.proceduralMaterial); //更新Vector,Depth Mip Map hizOpts.hizData.lastFrameCameraUp = hizOpts.currentCameraUpVec; PipelineFunctions.ClearOcclusionData(baseBuffer, buffer, gpuFrustumShader); //TODO 绘制其他物体 //TODO buffer.Blit(hizOpts.currentDepthTex, hizOpts.hizData.historyDepth, hizOpts.linearLODMaterial, 0); hizOpts.hizDepth.GetMipMap(hizOpts.hizData.historyDepth, buffer); //使用新数据进行二次剔除 PipelineFunctions.OcclusionRecheck(baseBuffer, gpuFrustumShader, buffer, hizOpts.hizData); //绘制二次剔除结果 buffer.SetRenderTarget(rendTargets.gbufferIdentifier, rendTargets.depthIdentifier); PipelineFunctions.DrawRecheckCullResult(baseBuffer, options.proceduralMaterial, buffer); buffer.Blit(hizOpts.currentDepthTex, hizOpts.hizData.historyDepth, hizOpts.linearLODMaterial, 0); hizOpts.hizDepth.GetMipMap(hizOpts.hizData.historyDepth, buffer); }
public override void DrawClusterOccSingleCheck(ref RenderClusterOptions options, ref HizOptions hizOpts) { CommandBuffer buffer = options.command; buffer.SetComputeVectorParam(options.cullingShader, ShaderIDs._CameraUpVector, hizOpts.hizData.lastFrameCameraUp); buffer.SetComputeBufferParam(options.cullingShader, 5, ShaderIDs.clusterBuffer, baseBuffer.clusterBuffer); buffer.SetComputeTextureParam(options.cullingShader, 5, ShaderIDs._HizDepthTex, hizOpts.hizData.historyDepth); buffer.SetComputeVectorArrayParam(options.cullingShader, ShaderIDs.planes, options.frustumPlanes); buffer.SetComputeBufferParam(options.cullingShader, 5, ShaderIDs.resultBuffer, baseBuffer.resultBuffer); buffer.SetComputeBufferParam(options.cullingShader, 5, ShaderIDs.instanceCountBuffer, baseBuffer.instanceCountBuffer); buffer.SetComputeBufferParam(options.cullingShader, PipelineBaseBuffer.ComputeShaderKernels.ClearClusterKernel, ShaderIDs.instanceCountBuffer, baseBuffer.instanceCountBuffer); ComputeShaderUtility.Dispatch(options.cullingShader, options.command, 5, baseBuffer.clusterCount, 256); hizOpts.hizData.lastFrameCameraUp = hizOpts.currentCameraUpVec; buffer.SetGlobalBuffer(ShaderIDs.resultBuffer, baseBuffer.resultBuffer); buffer.SetGlobalBuffer(ShaderIDs.verticesBuffer, baseBuffer.verticesBuffer); PipelineFunctions.RenderProceduralCommand(baseBuffer, options.proceduralMaterial, buffer); buffer.DispatchCompute(options.cullingShader, PipelineBaseBuffer.ComputeShaderKernels.ClearClusterKernel, 1, 1, 1); //TODO 绘制其他物体 //TODO buffer.Blit(hizOpts.currentDepthTex, hizOpts.hizData.historyDepth, hizOpts.linearLODMaterial, 0); hizOpts.hizDepth.GetMipMap(hizOpts.hizData.historyDepth, buffer); }