コード例 #1
0
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);

            RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor;

            opaqueDesc.depthBufferBits = 0;

            cmd.SetGlobalTexture("_MainTex", source);

            // Can't read and write to same color target, create a temp render target to blit.
            if (destination == RenderTargetHandle.CameraTarget)
            {
                cmd.GetTemporaryRT(m_TemporaryColorTexture.id, opaqueDesc);
                Blit(cmd, source, m_TemporaryColorTexture.Identifier(), blitMaterial);
                Blit(cmd, m_TemporaryColorTexture.Identifier(), source);
            }
            else
            {
                //Blit(cmd, source, destination.Identifier(), blitMaterial);
            }

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
コード例 #2
0
    // Execute is called for every eligible camera every frame. It's not called at the moment that
    // rendering is actually taking place, so don't directly execute rendering commands here.
    // Instead use the methods on ScriptableRenderContext to set up instructions.
    // RenderingData provides a bunch of (not very well documented) information about the scene
    // and what's being rendered.
    public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    {
        Debug.Log(renderingData.cameraData.camera.orthographicSize);

        if (!quad_)
        {
            quad_ = CreateQuad(renderingData.cameraData.camera.rect);
        }

        materialToBlit.SetMatrix("_CamFrustum", CamFrustum(renderingData.cameraData.camera));
        materialToBlit.SetMatrix("_CamToWorld", renderingData.cameraData.camera.cameraToWorldMatrix);

        // fetch a command buffer to use
        CommandBuffer cmd = CommandBufferPool.Get(profilerTag);

        cmd.Clear();

        // the actual content of our custom render pass!
        // we apply our material while blitting to a temporary texture
        cmd.Blit(cameraColorTargetIdent, tempTexture.Identifier(), materialToBlit, 0);

        // ...then blit it back again
        cmd.Blit(tempTexture.Identifier(), cameraColorTargetIdent);

        cmd.DrawMesh(quad_, Matrix4x4.identity, materialToBlit, 0, 0);

        // don't forget to tell ScriptableRenderContext to actually execute the commands
        context.ExecuteCommandBuffer(cmd);

        // tidy up after ourselves
        cmd.Clear();
        CommandBufferPool.Release(cmd);
    }
コード例 #3
0
            public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
            {
                CommandBuffer cmd = CommandBufferPool.Get(profilerTag);

                RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor;

                opaqueDesc.depthBufferBits = 0;

                // Can't read and write to same color target, create a temp render target to blit.
                if (destination == RenderTargetHandle.CameraTarget)
                {
                    cmd.GetTemporaryRT(temporaryColorTexture.id, opaqueDesc, filterMode);
                    atmosphereMaterial.SetVector("_PlanetCenter", atmosphereParameters.planetCenter);
                    atmosphereMaterial.SetFloat("_PlanetRadius", atmosphereParameters.planetRadius);
                    atmosphereMaterial.SetFloat("_AtmosphereRadius", atmosphereParameters.atmosphereRadius);
                    atmosphereMaterial.SetFloat("_AtmosphereFalloffRayleigh", atmosphereParameters.atmosphereDensityFalloffRayleigh);
                    atmosphereMaterial.SetFloat("_AtmosphereFalloffMie", atmosphereParameters.atmosphereDensityFalloffMie);
                    atmosphereMaterial.SetVector("_AtmosphereWavelengthsRayleigh", atmosphereParameters.atmosphereWavelengthsRayleigh);
                    atmosphereMaterial.SetVector("_AtmosphereWavelengthsMie", atmosphereParameters.atmosphereWavelengthsMie);
                    atmosphereMaterial.SetFloat("_AtmosphereSunIntensity", atmosphereParameters.atmosphereSunIntensity);
                    Blit(cmd, source, temporaryColorTexture.Identifier(), atmosphereMaterial, atmosphereShaderPassIndex);
                    Blit(cmd, temporaryColorTexture.Identifier(), source);
                }
                else
                {
                    Blit(cmd, source, destination.Identifier(), atmosphereMaterial, atmosphereShaderPassIndex);
                }

                context.ExecuteCommandBuffer(cmd);
                CommandBufferPool.Release(cmd);
            }
コード例 #4
0
        /// <inheritdoc/>
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);

            RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor;

            opaqueDesc.depthBufferBits = 0;

            // Can't read and write to same color target, create a temp render target to blit.
            if (destination.Identifier() == source)
            {
                cmd.GetTemporaryRT(m_TemporaryColorTexture.id, opaqueDesc, filterMode);
                Blit(cmd, source, m_TemporaryColorTexture.Identifier(), blitMaterial, blitShaderPassIndex);
                Blit(cmd, m_TemporaryColorTexture.Identifier(), source);
            }
            else
            {
                if (createTemporaryDst)
                {
                    // Create a new render texture as the render target.
                    cmd.GetTemporaryRT(destination.id, opaqueDesc, filterMode);
                }

                Blit(cmd, source, destination.Identifier(), blitMaterial, blitShaderPassIndex);
            }

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
コード例 #5
0
 public void Setup(RenderTextureDescriptor baseDescriptor, RenderTargetHandle colorHandle)
 {
     if (m_Source?.nameID != colorHandle.Identifier())
     {
         m_Source = RTHandles.Alloc(colorHandle.Identifier());
     }
 }
コード例 #6
0
        /// <inheritdoc/>
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);

            RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor;

            opaqueDesc.depthBufferBits = 0;

            if (!m_UsefulShader)
            {
                return;
            }

            // Can't read and write to same color target, create a temp render target to blit.
            cmd.GetTemporaryRT(m_TemporaryColorTexture.id, opaqueDesc, FilterMode.Bilinear);
            Blit(cmd, source, m_TemporaryColorTexture.Identifier());
            for (int i = 0; i < blitMaterial.passCount; i++)
            {
                cmd.Blit(m_TemporaryColorTexture.Identifier(), source, blitMaterial, i);
            }

            context.ExecuteCommandBuffer(cmd);
            cmd.Clear();
            CommandBufferPool.Release(cmd);
        }
コード例 #7
0
ファイル: Blit.cs プロジェクト: makscee/prototype-1
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);

            RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor;

            opaqueDesc.depthBufferBits = 0;

            if (settings.setInverseViewMatrix)
            {
                Shader.SetGlobalMatrix("_InverseView", renderingData.cameraData.camera.cameraToWorldMatrix);
            }

            if (settings.dstType == Target.TextureID)
            {
                cmd.GetTemporaryRT(m_DestinationTexture.id, opaqueDesc, filterMode);
            }

            //Debug.Log($"src = {source},     dst = {destination} ");
            // Can't read and write to same color target, use a TemporaryRT
            if (source == destination || (settings.srcType == settings.dstType && settings.srcType == Target.CameraColor))
            {
                cmd.GetTemporaryRT(m_TemporaryColorTexture.id, opaqueDesc, filterMode);
                Blit(cmd, source, m_TemporaryColorTexture.Identifier(), blitMaterial, settings.blitMaterialPassIndex);
                Blit(cmd, m_TemporaryColorTexture.Identifier(), destination);
            }
            else
            {
                Blit(cmd, source, destination, blitMaterial, settings.blitMaterialPassIndex);
            }

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
コード例 #8
0
        // Here you can implement the rendering logic.
        // Use <c>ScriptableRenderContext</c> to issue drawing commands or execute command buffers
        // https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html
        // You don't have to call ScriptableRenderContext.submit, the render pipeline will call it at specific points in the pipeline.
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get(k_RenderTag);

            using (new ProfilingScope(cmd, new ProfilingSampler("DepthOnlyRenderPass")))
            {
                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();

                var sortFlags    = renderingData.cameraData.defaultOpaqueSortFlags;
                var drawSettings = CreateDrawingSettings(shaderTagId, ref renderingData, sortFlags);
                drawSettings.perObjectData = PerObjectData.None;

                RenderQueueRange range = new RenderQueueRange();
                range.lowerBound = passSetting.queueMin;
                range.upperBound = passSetting.queueMax;

                FilteringSettings filteringSettings = new FilteringSettings();
                filteringSettings.renderQueueRange   = range;
                filteringSettings.renderingLayerMask = 1;
                filteringSettings.layerMask          = passSetting.layer;

                context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref filteringSettings);

                cmd.SetGlobalTexture(depthTexHandle.id, depthTexHandle.Identifier());
            }

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
コード例 #9
0
    public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
    {
        if (enabled == false)
        {
            return;
        }

        #if UNITY_EDITOR
        m_Material.SetColor("_Color", tintColor);
        m_Material.SetFloat("_Size", blurSize);
        m_Material.SetFloat("_Sigma", blurSigma);
        #endif

        CommandBuffer cmd = CommandBufferPool.Get(k_RenderGrabPassTag);

        using (new ProfilingSample(cmd, k_RenderGrabPassTag))
        {
            // copy screen into temporary RT
            screenCopyID = Shader.PropertyToID("_ScreenCopyTexture");
            RenderTextureDescriptor opaqueDesc = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData);

            cmd.GetTemporaryRT(screenCopyID, opaqueDesc, FilterMode.Bilinear);
            cmd.Blit(m_ColorHandle.Identifier(), screenCopyID);

            cmd.SetGlobalVector("offsets", new Vector4(2.0f / Screen.width, 0, 0, 0));
            cmd.Blit(screenCopyID, m_ColorHandle.Identifier(), m_Material);
        }

        context.ExecuteCommandBuffer(cmd);
        CommandBufferPool.Release(cmd);
    }
コード例 #10
0
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            CommandBuffer cmdBuffer = CommandBufferPool.Get(_profilerTag);

            RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor;

            opaqueDesc.depthBufferBits = 0;

            using (new ProfilingScope(cmdBuffer, _profilingSampler))
            {
                cmdBuffer.ExecuteAndClear(context);

                // Can't read and write to same color target, create a temp render target to blit.
                if (_destinationTarget == RenderTargetHandle.CameraTarget)
                {
                    cmdBuffer.GetTemporaryRT(m_TemporaryColorTexture.id, opaqueDesc, _filterMode);
                    Blit(cmdBuffer, _sourceTarget, m_TemporaryColorTexture.Identifier(), _blitMaterial, _blitShaderPassIndex);
                    Blit(cmdBuffer, m_TemporaryColorTexture.Identifier(), _sourceTarget);
                }
                else
                {
                    Blit(cmdBuffer, _sourceTarget, _destinationTarget.Identifier(), _blitMaterial, _blitShaderPassIndex);
                }
            }

            cmdBuffer.ExecuteAndClear(context);
            CommandBufferPool.Release(cmdBuffer);
        }
コード例 #11
0
            public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
            {
                if (renderingData.cameraData.camera != Camera.main)
                {
                    return;
                }

                VolumeStack         stack      = VolumeManager.instance.stack;
                PUnderwaterOverride underwater = stack.GetComponent <PUnderwaterOverride>();
                PWetLensOverride    wetLens    = stack.GetComponent <PWetLensOverride>();

                bool willRenderUnderwater = underwater.intensity.value > 0;
                bool willRenderWetLens    = wetLens.strength.value * wetLens.intensity.value > 0;

                if (!willRenderUnderwater && !willRenderWetLens)
                {
                    return;
                }

                ConfigureMaterial(ref renderingData, underwater, wetLens);

                CommandBuffer           cmd = CommandBufferPool.Get(PROFILER_TAG);
                RenderTextureDescriptor cameraTargetDescriptor = renderingData.cameraData.cameraTargetDescriptor;

                cameraTargetDescriptor.depthBufferBits = 0;
                cmd.GetTemporaryRT(temporaryRenderTexture.id, cameraTargetDescriptor);

                Material material = willRenderUnderwater ? underwaterMaterial : wetLensMaterial;

                Blit(cmd, cameraTarget, temporaryRenderTexture.Identifier(), material, 0);
                Blit(cmd, temporaryRenderTexture.Identifier(), cameraTarget);

                context.ExecuteCommandBuffer(cmd);
                CommandBufferPool.Release(cmd);
            }
コード例 #12
0
        void Render(CommandBuffer cmd, ref RenderingData renderingData)
        {
            if (renderingData.cameraData.isSceneViewCamera)
            {
                return;
            }

            var source = currentTarget;

            RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor;

            opaqueDesc.width /= m_DownSample;

            opaqueDesc.height /= m_DownSample;

            opaqueDesc.depthBufferBits = 0;

            cmd.GetTemporaryRT(bufferTex0.id, opaqueDesc, FilterMode.Bilinear);
            cmd.GetTemporaryRT(bufferTex1.id, opaqueDesc, FilterMode.Bilinear);

            Blit(cmd, source, bufferTex0.Identifier());

            for (int i = 0; i < m_Iterations; i++)
            {
                gaussianBlurMat.SetFloat("_BlurSize", 1.0f + i * m_BlurSpread);

                Blit(cmd, bufferTex0.Identifier(), bufferTex1.Identifier(), gaussianBlurMat, 0);

                Blit(cmd, bufferTex1.Identifier(), bufferTex0.Identifier(), gaussianBlurMat, 1);
            }

            Blit(cmd, bufferTex0.Identifier(), source);
        }
コード例 #13
0
        // Here you can implement the rendering logic.
        // Use <c>ScriptableRenderContext</c> to issue drawing commands or execute command buffers
        // https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html
        // You don't have to call ScriptableRenderContext.submit, the render pipeline will call it at specific points in the pipeline.
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get("RenderClouds");

            RenderTextureDescriptor cameraTextureDesc = renderingData.cameraData.cameraTargetDescriptor;

            cameraTextureDesc.depthBufferBits = 0;

            int width  = Mathf.RoundToInt((float)cameraTextureDesc.width / 2.0f);
            int height = Mathf.RoundToInt((float)cameraTextureDesc.height / 2.0f);

            cmd.GetTemporaryRT(cloudTexture.id, width, height, 0, FilterMode.Bilinear);
            cmd.GetTemporaryRT(denoisedCloudTexture.id, width, height, 0, FilterMode.Bilinear);
            cmd.GetTemporaryRT(sourceCopy.id, cameraTextureDesc, FilterMode.Bilinear);

            cmd.DisableShaderKeyword("_SHADOW_PASS");
            Blit(cmd, _source, cloudTexture.Identifier(), cloudRenderer, this.materialPassIndex);
            cmd.SetGlobalVector("_ImageSize", new Vector4(width, height, 0, 0));

            Blit(cmd, cloudTexture.Identifier(), denoisedCloudTexture.Identifier(), denoiseMaterial, this.materialPassIndex);
            //Blit(cmd, denoisedCloudTexture.Identifier(), cloudTexture.Identifier(), denoiseMaterial, this.materialPassIndex);
            //Blit(cmd, cloudTexture.Identifier(), denoisedCloudTexture.Identifier(), denoiseMaterial, this.materialPassIndex);
            //Blit(cmd, denoisedCloudTexture.Identifier(), cloudTexture.Identifier(), denoiseMaterial, this.materialPassIndex);

            cmd.SetGlobalTexture("_CloudTex", denoisedCloudTexture.Identifier());

            Blit(cmd, _source, sourceCopy.Identifier(), combineTextureMaterial, this.materialPassIndex);
            Blit(cmd, sourceCopy.Identifier(), _source);

            //Execute and release commands
            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
コード例 #14
0
        public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
        {
            cmd.GetTemporaryRT(distortionMarkRenderTextureHandle.id, cameraTextureDescriptor);

            ConfigureTarget(distortionMarkRenderTextureHandle.Identifier());
            ConfigureClear(ClearFlag.Color, CLEAR);
        }
コード例 #15
0
        /// <inheritdoc/>
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            if (m_BlitMaterial == null)
            {
                Debug.LogErrorFormat("Missing {0}. {1} render pass will not execute. Check for missing reference in the renderer resources.", m_BlitMaterial, GetType().Name);
                return;
            }

            bool requiresSRGBConvertion = Display.main.requiresSrgbBlitToBackbuffer;
            bool killAlpha = renderingData.killAlphaInFinalBlit;

            CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);

            if (requiresSRGBConvertion)
            {
                cmd.EnableShaderKeyword(ShaderKeywordStrings.LinearToSRGBConversion);
            }
            else
            {
                cmd.DisableShaderKeyword(ShaderKeywordStrings.LinearToSRGBConversion);
            }

            if (killAlpha)
            {
                cmd.EnableShaderKeyword(ShaderKeywordStrings.KillAlpha);
            }
            else
            {
                cmd.DisableShaderKeyword(ShaderKeywordStrings.KillAlpha);
            }

            if (renderingData.cameraData.isStereoEnabled || renderingData.cameraData.isSceneViewCamera)
            {
                cmd.Blit(m_Source.Identifier(), BuiltinRenderTextureType.CameraTarget);
            }
            else
            {
                cmd.SetGlobalTexture("_BlitTex", m_Source.Identifier());

                // TODO: Final blit pass should always blit to backbuffer. The first time we do we don't need to Load contents to tile.
                // We need to keep in the pipeline of first render pass to each render target to propertly set load/store actions.
                // meanwhile we set to load so split screen case works.
                SetRenderTarget(
                    cmd,
                    BuiltinRenderTextureType.CameraTarget,
                    RenderBufferLoadAction.Load,
                    RenderBufferStoreAction.Store,
                    m_ClearBlitTarget ? ClearFlag.Color : ClearFlag.None,
                    Color.black,
                    m_TargetDimension);

                cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
                cmd.SetViewport(m_PixelRect != Rect.zero ? m_PixelRect : renderingData.cameraData.camera.pixelRect);
                cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, m_BlitMaterial);
            }

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
コード例 #16
0
        public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
        {
            RenderTextureDescriptor cameraTextureDescriptor = renderingData.cameraData.cameraTargetDescriptor;

            cameraTextureDescriptor.colorFormat = RenderTextureFormat.RGHalf;
            cmd.GetTemporaryRT(m_MotionVectorHandle.id, cameraTextureDescriptor, FilterMode.Point);
            ConfigureTarget(m_MotionVectorHandle.Identifier(), m_MotionVectorHandle.Identifier());
            ConfigureClear(ClearFlag.All, Color.black);
        }
コード例 #17
0
    public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    {
        //kawase uses 1.5,2.5,2.5,3.5
        int           thresholdKernel = computeShader.FindKernel("ThresholdStep");
        int           KBlurKernel     = computeShader.FindKernel("KBlur");
        int           AddKernel       = computeShader.FindKernel("Add");
        CommandBuffer cmd             = CommandBufferPool.Get(profilerTag);

        cmd.GetTemporaryRT(cameraCopy.id, copySettings);                                                        //this one is full res
        copySettings.width  /= 2;                                                                               //this is a struct so this should be ok and not f**k with the others
        copySettings.height /= 2;
        cmd.SetComputeFloatParam(computeShader, "intensity", intensity);
        cmd.SetComputeFloatParam(computeShader, "threshold", threshold);
        cmd.SetComputeFloatParam(computeShader, "skip", 1.5f);
        cmd.SetComputeIntParam(computeShader, "width", copySettings.width);
        cmd.SetComputeIntParam(computeShader, "height", copySettings.height);
        cmd.GetTemporaryRT(tempCopy.id, copySettings);
        cmd.GetTemporaryRT(tempCopy2.id, copySettings);
        cmd.SetComputeTextureParam(computeShader, thresholdKernel, "Source", targetID);
        cmd.SetComputeTextureParam(computeShader, thresholdKernel, "Result", tempCopy.Identifier());
        cmd.SetComputeTextureParam(computeShader, AddKernel, "Source", tempCopy.Identifier());
        cmd.SetComputeTextureParam(computeShader, AddKernel, "CameraTex", targetID);
        cmd.SetComputeTextureParam(computeShader, AddKernel, "Final", cameraCopy.Identifier());

        cmd.SetComputeTextureParam(computeShader, KBlurKernel, "Source", tempCopy.Identifier());
        cmd.SetComputeTextureParam(computeShader, KBlurKernel, "Result", tempCopy2.Identifier());

        cmd.DispatchCompute(computeShader, thresholdKernel, copySettings.width / 8, copySettings.height / 8, 1); //threshold tempcopy
        cmd.DispatchCompute(computeShader, KBlurKernel, copySettings.width / 8, copySettings.height / 8, 1);     //kblur populates tempcopy2

        cmd.SetComputeTextureParam(computeShader, KBlurKernel, "Source", tempCopy2.Identifier());                //reverse textures and do second pass
        cmd.SetComputeTextureParam(computeShader, KBlurKernel, "Result", tempCopy.Identifier());
        cmd.SetComputeFloatParam(computeShader, "skip", 2.5f);
        cmd.DispatchCompute(computeShader, KBlurKernel, copySettings.width / 8, copySettings.height / 8, 1);

        cmd.SetComputeTextureParam(computeShader, KBlurKernel, "Source", tempCopy.Identifier());             //reverse textures and do 3rd pass
        cmd.SetComputeTextureParam(computeShader, KBlurKernel, "Result", tempCopy2.Identifier());
        cmd.DispatchCompute(computeShader, KBlurKernel, copySettings.width / 8, copySettings.height / 8, 1);

        cmd.SetComputeTextureParam(computeShader, KBlurKernel, "Source", tempCopy2.Identifier());             //reverse textures and do 4th pass
        cmd.SetComputeTextureParam(computeShader, KBlurKernel, "Result", tempCopy.Identifier());              //textures wind up in tempCopy
        cmd.SetComputeFloatParam(computeShader, "skip", 3.5f);
        cmd.DispatchCompute(computeShader, KBlurKernel, copySettings.width / 8, copySettings.height / 8, 1);

        cmd.SetComputeIntParam(computeShader, "width", copySettings.width * 2);
        cmd.SetComputeIntParam(computeShader, "height", copySettings.height * 2);
        cmd.DispatchCompute(computeShader, AddKernel, copySettings.width / 4, copySettings.height / 4, 1);
        //cmd.Blit(targetID, tempCopy.Identifier());
        cmd.Blit(cameraCopy.Identifier(), targetID);


        cmd.ReleaseTemporaryRT(tempCopy.id);
        cmd.ReleaseTemporaryRT(tempCopy2.id);
        cmd.ReleaseTemporaryRT(cameraCopy.id);
        context.ExecuteCommandBuffer(cmd);
        CommandBufferPool.Release(cmd);
    }
コード例 #18
0
            public static RenderTargetIdentifier Request(CommandBuffer cmd, RenderTextureDescriptor renderTextureDescriptor, FilterMode filterMode = FilterMode.Point)
            {
                var handle = new RenderTargetHandle();

                handle.Init("_POST_PROCESSING_TEMP_" + _tempIndex++);
                cmd.GetTemporaryRT(handle.id, renderTextureDescriptor, filterMode);
                _usingTempRTs.Add(handle.Identifier(), handle);
                return(handle.Identifier());
            }
コード例 #19
0
        public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
        {
            cmd.GetTemporaryRT(m_ScreenSpaceShadowmap.id, m_RenderTextureDescriptor, FilterMode.Bilinear);

            RenderTargetIdentifier screenSpaceOcclusionTexture = m_ScreenSpaceShadowmap.Identifier();

            ConfigureTarget(screenSpaceOcclusionTexture);
            ConfigureClear(ClearFlag.All, Color.white);
        }
コード例 #20
0
ファイル: BlitPass.cs プロジェクト: TheoJiang/RenderingLab
    public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    {
        // Camera camera = renderingData.cameraData.camera;
        // if (!camera.name.Contains("RTCamera"))
        // {
        //     return;
        // }

        CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);

        // var ca = renderingData.cameraData.camera;
        // // var ca = GameObject.Find("RTCamera");
        // if (ca.name.Contains("RTCamera"))
        // {
        //
        //     var came = ca.GetComponent<Camera>();
        //     came.enabled = true;
        //
        //     if (came)
        //     {
        //         // var pixelRect = came.pixelRect;
        //         // came.targetTexture.width = (int)pixelRect.width;
        //         // came.targetTexture.height = (int)pixelRect.height;
        //         //
        //         var currentRT = RenderTexture.active;
        //         RenderTexture.active = came.targetTexture;
        //         cmd.SetGlobalTexture("_MaskTexture", RenderTexture.active);
        //         RenderTexture.active = currentRT;
        //     }
        //
        //     // came.enabled = false;
        // }

        RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor;

        opaqueDesc.depthBufferBits = 0;
        opaqueDesc.msaaSamples     = 1;

        // Can't read and write to same color target, create a temp render target to blit.
        if (destination == RenderTargetHandle.CameraTarget)
        {
            cmd.GetTemporaryRT(m_TemporaryColorTexture.id, opaqueDesc, filterMode);
            // 将Source(当前Buffer) Blit至 tempColorTexture, 过程中经材质球对应处理
            // Shader.PropertyToID("_CameraColorTexture") == source.m_NameID == 1142
            Blit(cmd, source, m_TemporaryColorTexture.Identifier(), blitMaterial, blitShaderPassIndex);
            // 将处理后的rt传回
            Blit(cmd, m_TemporaryColorTexture.Identifier(), source);
        }
        else
        {
            Blit(cmd, source, destination.Identifier(), blitMaterial, blitShaderPassIndex);
        }

        context.ExecuteCommandBuffer(cmd);
        CommandBufferPool.Release(cmd);
    }
コード例 #21
0
        /// <inheritdoc/>
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            if (m_BlitMaterial == null)
            {
                Debug.LogErrorFormat("Missing {0}. {1} render pass will not execute. Check for missing reference in the renderer resources.", m_BlitMaterial, GetType().Name);
                return;
            }

            bool requiresSRGBConvertion = Display.main.requiresSrgbBlitToBackbuffer;
            bool killAlpha = renderingData.killAlphaInFinalBlit;

            CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);

            if (requiresSRGBConvertion)
            {
                cmd.EnableShaderKeyword(ShaderKeywordStrings.LinearToSRGBConversion);
            }
            else
            {
                cmd.DisableShaderKeyword(ShaderKeywordStrings.LinearToSRGBConversion);
            }

            if (killAlpha)
            {
                cmd.EnableShaderKeyword(ShaderKeywordStrings.KillAlpha);
            }
            else
            {
                cmd.DisableShaderKeyword(ShaderKeywordStrings.KillAlpha);
            }

            if (renderingData.cameraData.isStereoEnabled || renderingData.cameraData.isSceneViewCamera)
            {
                cmd.Blit(m_Source.Identifier(), BuiltinRenderTextureType.CameraTarget);
            }
            else
            {
                cmd.SetGlobalTexture("_BlitTex", m_Source.Identifier());

                SetRenderTarget(
                    cmd,
                    BuiltinRenderTextureType.CameraTarget,
                    RenderBufferLoadAction.DontCare,
                    RenderBufferStoreAction.Store,
                    ClearFlag.None,
                    Color.black,
                    m_TargetDimension);

                cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
                cmd.SetViewport(renderingData.cameraData.camera.pixelRect);
                cmd.DrawMesh(RenderingUtils.fullscreenTriangleMesh, Matrix4x4.identity, m_BlitMaterial);
            }

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
コード例 #22
0
        public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
        {
            // Configure Render Target
            cmd.GetTemporaryRT(m_MotionVectorHandle.id, cameraTextureDescriptor, FilterMode.Point);
            ConfigureTarget(m_MotionVectorHandle.Identifier(), m_MotionVectorHandle.Identifier());
            cmd.SetRenderTarget(m_MotionVectorHandle.Identifier(), m_MotionVectorHandle.Identifier());

            ConfigureClear(ClearFlag.Color, Color.black);
            ConfigureClear(ClearFlag.Depth, Color.white);
        }
コード例 #23
0
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            CommandBuffer commandBuffer = CommandBufferPool.Get(customIdentifier);

            commandBuffer.GetTemporaryRT(tempRenderTargetHandler.id, renderingData.cameraData.cameraTargetDescriptor); // Set the temporal render texture with the rendering camera's input
            Blit(commandBuffer, sourceCamera, tempRenderTargetHandler.Identifier(), materialReference);                // Apply the shader to the temporal render texture
            Blit(commandBuffer, tempRenderTargetHandler.Identifier(), sourceCamera);                                   // Apply the shader result to the camera's output towards the user's screen
            context.ExecuteCommandBuffer(commandBuffer);
            CommandBufferPool.Release(commandBuffer);
        }
コード例 #24
0
        // Here you can implement the rendering logic.
        // Use <c>ScriptableRenderContext</c> to issue drawing commands or execute command buffers
        // https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html
        // You don't have to call ScriptableRenderContext.submit, the render pipeline will call it at specific points in the pipeline.
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get("Downsample Render Pass");

            Blit(cmd, source, tempRenderTargetHandle.Identifier());
            Blit(cmd, tempRenderTargetHandle.Identifier(), source);

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
コード例 #25
0
        public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
        {
            var rtd = cameraTextureDescriptor;

            rtd.graphicsFormat = m_TargetFormat;
            // Configure Render Target
            m_MotionVectorHandle.Init(kMotionVectorTexture);
            cmd.GetTemporaryRT(m_MotionVectorHandle.id, rtd, FilterMode.Point);
            ConfigureTarget(m_MotionVectorHandle.Identifier(), m_MotionVectorHandle.Identifier());
        }
コード例 #26
0
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);

            Blit(cmd, m_Destination, m_TemporaryColorTexture.Identifier());
            Blit(cmd, m_TemporaryColorTexture.Identifier(), m_Destination, m_Material);

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
コード例 #27
0
        public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
        {
            // Configure Render Target
            m_MotionVectorHandle.Init(kMotionVectorTexture);
            cmd.GetTemporaryRT(m_MotionVectorHandle.id, cameraTextureDescriptor, FilterMode.Point);
            ConfigureTarget(m_MotionVectorHandle.Identifier(), m_MotionVectorHandle.Identifier());
            cmd.SetRenderTarget(m_MotionVectorHandle.Identifier(), m_MotionVectorHandle.Identifier());

            // TODO: Why do I have to clear here?
            cmd.ClearRenderTarget(true, true, Color.black, 1.0f);
        }
コード例 #28
0
        // Here you can implement the rendering logic.
        // Use <c>ScriptableRenderContext</c> to issue drawing commands or execute command buffers
        // https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html
        // You don't have to call ScriptableRenderContext.submit, the render pipeline will call it at specific points in the pipeline.
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            CommandBuffer commandBuffer = CommandBufferPool.Get("CustomBlitRenderPass");

            commandBuffer.GetTemporaryRT(tempRenderTargetHandler.id, renderingData.cameraData.cameraTargetDescriptor);
            Blit(commandBuffer, source, tempRenderTargetHandler.Identifier(), material);
            Blit(commandBuffer, tempRenderTargetHandler.Identifier(), source);

            context.ExecuteCommandBuffer(commandBuffer);
            CommandBufferPool.Release(commandBuffer);
        }
コード例 #29
0
        /// <inheritdoc/>
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            SortingCriteria sortingCriteria = (renderQueueType == RenderQueueType.Transparent)
                ? SortingCriteria.CommonTransparent
                : renderingData.cameraData.defaultOpaqueSortFlags;

            DrawingSettings drawingSettings = CreateDrawingSettings(m_ShaderTagIdList, ref renderingData, sortingCriteria);

            drawingSettings.overrideMaterial          = overrideMaterial;
            drawingSettings.overrideMaterialPassIndex = overrideMaterialPassIndex;

            Camera camera       = renderingData.cameraData.camera;
            float  cameraAspect = (float)camera.pixelWidth / (float)camera.pixelHeight;

            CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);

            using (new ProfilingSample(cmd, m_ProfilerTag))
            {
                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();

                ConfigureTarget(m_TemporaryOutlineTexture.Identifier());

                context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref m_FilteringSettings, ref m_RenderStateBlock);
            }

            // ------------
            //
            // ------------
            // CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);

            RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor;

            opaqueDesc.depthBufferBits = 0;

            // Can't read and write to same color target, create a temp render target to blit.
            if (destination == RenderTargetHandle.CameraTarget)
            {
                cmd.GetTemporaryRT(m_TemporaryOutlineTexture.id, opaqueDesc, filterMode);
                Blit(cmd, source, m_TemporaryOutlineTexture.Identifier(), blitMaterial, blitShaderPassIndex);
                Blit(cmd, m_TemporaryOutlineTexture.Identifier(), source);
            }
            else
            {
                //Blit(cmd, source, destination.Identifier(), blitMaterial, blitShaderPassIndex);
                cmd.GetTemporaryRT(m_TemporaryOutlineTexture.id, opaqueDesc, filterMode);
                Blit(cmd, destination.Identifier(), m_TemporaryOutlineTexture.Identifier(), blitMaterial, blitShaderPassIndex);
                Blit(cmd, m_TemporaryOutlineTexture.Identifier(), source);
            }

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
コード例 #30
0
    public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
    {
        if (!IsActive)
        {
            return;
        }
        //copy opaque + transparent color

        CommandBuffer cmd = CommandBufferPool.Get(copyColorTag);

        RenderTargetIdentifier  colorRT       = _colorHandle.Identifier();
        RenderTargetIdentifier  opaqueColorRT = _destination.Identifier();
        RenderTextureDescriptor opaqueDesc    = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData, 1);

        cmd.GetTemporaryRT(_destination.id, opaqueDesc);
        cmd.Blit(colorRT, opaqueColorRT);

        context.ExecuteCommandBuffer(cmd);
        CommandBufferPool.Release(cmd);


        //draw custom distortion with transparent

        cmd = CommandBufferPool.Get(transparentsTag);
        using (new ProfilingSample(cmd, transparentsTag))
        {
            var loadOp  = RenderBufferLoadAction.Load;
            var storeOp = RenderBufferStoreAction.Store;
            SetRenderTarget(cmd, _colorHandle.Identifier(), loadOp, storeOp,
                            _depthHandle.Identifier(), loadOp, storeOp, ClearFlag.None, Color.black, _baseDescriptor.dimension);

            context.ExecuteCommandBuffer(cmd);
            cmd.Clear();

            Camera camera = renderingData.cameraData.camera;
#if UNITY_2019_1_OR_NEWER
            DrawingSettings   drawingSettings   = new DrawingSettings(new ShaderTagId("CustomDistortion"), new SortingSettings(camera));
            FilteringSettings filteringSettings = new FilteringSettings(RenderQueueRange.transparent);
            context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref filteringSettings);
#else
            var drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonTransparent, RendererConfiguration.None, renderingData.supportsDynamicBatching);
            var transparentFilterSettings = new FilterRenderersSettings(true)
            {
                renderQueueRange = RenderQueueRange.transparent
            };
            context.DrawRenderers(renderingData.cullResults.visibleRenderers, ref drawSettings, transparentFilterSettings);
#endif
        }

        context.ExecuteCommandBuffer(cmd);
        CommandBufferPool.Release(cmd);
    }