public void ResizeBufferIfNeed(GPUDRPCamera camera)
        {
            if (frameBuffer &&
                lastHeight == camera.AcutalHeight && lastWidth == camera.AcutalWidth)
            {
                return;
            }


            lastHeight = camera.AcutalHeight;
            lastWidth  = camera.AcutalWidth;

            //framebuffer
            CoreUtil.Destroy(frameBuffer);
            frameBuffer      = new RenderTexture(lastWidth, lastHeight, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.sRGB);
            frameBuffer.name = camera.name + "_FarmeBuffer";
            frameBuffer.Create();

            //depthBuffer
            CoreUtil.Destroy(depthBuffer);
            depthBuffer                   = new RenderTexture(lastWidth, lastHeight, 16, RenderTextureFormat.Depth, RenderTextureReadWrite.Linear);
            depthBuffer.name              = camera.name + "_DepthBuffer";
            depthBuffer.useMipMap         = false;
            depthBuffer.autoGenerateMips  = false;
            depthBuffer.enableRandomWrite = false;
            depthBuffer.wrapMode          = TextureWrapMode.Clamp;
            depthBuffer.filterMode        = FilterMode.Point;
            depthBuffer.Create();
        }
Esempio n. 2
0
        protected override void Render(ScriptableRenderContext context, Camera[] cameras)
        {
            if (!bFirstCall)
            {
                if (Application.isPlaying)
                {
                    MCRResourcesSystem.Init();
                    GlobalMaterial.Init();
                    GPUCull.GPUCullSystem.Init();
                }

                bFirstCall = true;
            }

            foreach (Camera cam in cameras)
            {
                GPUDRPCamera gpudrpCamera = null;

                if (!allGPUDRPCamera.TryGetValue(cam, out gpudrpCamera))
                {
                    gpudrpCamera = cam.GetComponent <GPUDRPCamera>();

                    if (!gpudrpCamera)
                    {
                        gpudrpCamera = cam.gameObject.AddComponent <GPUDRPCamera>();
                        allGPUDRPCamera.Add(cam, gpudrpCamera);
                    }
                }

                //设置pipelinecontext
                PipelineContext.mainCmdBuffer = CommandBufferPool.Get("MainCommandBuffer");
                PipelineContext.renderContext = context;
                PipelineContext.gpuCamera     = gpudrpCamera;

                if (PipelineContext.gpuCamera.BeginRender())
                {
                    PipelineContext.gpuCamera.Render();
                }

                context.Submit();

                PipelineContext.gpuCamera.EndRender();

                ComputeBufferPool.EndOfRender();
                CommandBufferPool.Release(PipelineContext.mainCmdBuffer);
            }
        }