Beispiel #1
0
 public override bool IsEnabledAndSupported(PostProcessRenderContext context)
 {
     return(enabled.value &&
            normalMap.value != null &&
            intensity.value > 0);
 }
Beispiel #2
0
 public override bool IsEnabledAndSupported(PostProcessRenderContext context)
 {
     return(enabled.value && opacity.value != 0);
 }
Beispiel #3
0
        public override void Render(PostProcessRenderContext context)
        {
            PropertySheet sheet   = context.propertySheets.Get(shader);
            CommandBuffer command = context.command;

            command.BeginSample(Uniforms.Name);
            sheet.ClearKeywords();
            sheet.SetKeyword(Uniforms.Keyword_EdgeMode, settings.edgeMode);
            sheet.SetKeyword(Uniforms.Keyword_BlendMode, settings.blendMode);

            GetGlowTexture(context);
            sheet.properties.SetTexture(Uniforms.Property_GlowDepthTex, glowDepthTexture);

            // Determine the iteration count
            int   width       = glowDepthTexture.width / 2;
            int   height      = glowDepthTexture.height / 2;
            int   size        = Mathf.Max(width, height);
            float logSize     = Mathf.Log(size, 2f) + settings.diffusion - 10f;
            int   logSizeInt  = Mathf.FloorToInt(logSize);
            int   iterations  = Mathf.Clamp(logSizeInt, 1, k_MaxPyramidSize);
            float sampleScale = 0.5f + logSize - logSizeInt;

            sheet.properties.SetFloat(Uniforms.Property_SampleScale, sampleScale);

            for (int i = 0; i < iterations; i++)
            {
                context.GetScreenSpaceTemporaryRT(command, m_Pyramid[i].down, 0, pyramidFormat, RenderTextureReadWrite.Default, FilterMode.Bilinear, width, height);
                context.GetScreenSpaceTemporaryRT(command, m_Pyramid[i].up, 0, pyramidFormat, RenderTextureReadWrite.Default, FilterMode.Bilinear, width, height);
                width  = Mathf.Max(width / 2, 1);
                height = Mathf.Max(height / 2, 1);
            }

            int lastDown = m_Pyramid[0].down;

            command.BlitFullscreenTriangle(glowDepthTexture, lastDown, sheet, settings.mode.value == EZGlow.Mode.Outer ? (int)Pass.GlowOuter : (int)Pass.GlowInner);
            for (int i = 1; i < iterations; i++)
            {
                int mipDown = m_Pyramid[i].down;
                command.BlitFullscreenTriangle(lastDown, mipDown, sheet, (int)Pass.DownSample);
                lastDown = mipDown;
            }

            int lastUp = m_Pyramid[iterations - 1].down;

            for (int i = iterations - 2; i >= 0; i--)
            {
                int mipDown = m_Pyramid[i].down;
                int mipUp   = m_Pyramid[i].up;
                command.SetGlobalTexture(Uniforms.Property_GlowBloomTex, mipDown);
                command.BlitFullscreenTriangle(lastUp, mipUp, sheet, (int)Pass.UpSample);
                lastUp = mipUp;
            }

            command.SetGlobalTexture(Uniforms.Property_GlowTex, m_Pyramid[0].down);
            command.SetGlobalTexture(Uniforms.Property_GlowBloomTex, lastUp);
            sheet.properties.SetFloat(Uniforms.Property_GlowIntensity, settings.intensity);
            sheet.properties.SetColor(Uniforms.Property_GlowColor, settings.color);
            command.BlitFullscreenTriangle(context.source, context.destination, sheet, (int)Pass.Combine);

            for (int i = 0; i < iterations; i++)
            {
                command.ReleaseTemporaryRT(m_Pyramid[i].down);
                command.ReleaseTemporaryRT(m_Pyramid[i].up);
            }

            command.EndSample(Uniforms.Name);
        }
 public override bool IsEnabledAndSupported(PostProcessRenderContext context)
 {
     return(enabled.value && VolumetricLightsManager.PrepareLightsForRender(context.camera, maxDistance, fadeRange));
 }
Beispiel #5
0
    protected override void Render(ScriptableRenderContext context, Camera[] cameras)
    {
        BeginFrameRendering(context, cameras);

        foreach (Camera camera in cameras)
        {
            BeginCameraRendering(context, camera);

            //Culling
            ScriptableCullingParameters cullingParams;
            if (!camera.TryGetCullingParameters(out cullingParams))
            {
                continue;
            }
            CullingResults cull = context.Cull(ref cullingParams);

            //Camera setup some builtin variables e.g. camera projection matrices etc
            context.SetupCameraProperties(camera);

            //Get the setting from camera component
            bool drawSkyBox = camera.clearFlags == CameraClearFlags.Skybox? true : false;
            bool clearDepth = camera.clearFlags == CameraClearFlags.Nothing? false : true;
            bool clearColor = camera.clearFlags == CameraClearFlags.Color? true : false;

            //************************** Set TempRT ************************************

            CommandBuffer cmdTempId = new CommandBuffer();
            cmdTempId.name = "(" + camera.name + ")" + "Setup TempRT";

            //Color
            m_ColorFormatActive = camera.allowHDR ? m_ColorFormatHDR : m_ColorFormat;
            RenderTextureDescriptor colorRTDesc = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight);
            colorRTDesc.graphicsFormat  = m_ColorFormatActive;
            colorRTDesc.depthBufferBits = depthBufferBits;
            //colorRTDesc.sRGB = ;
            colorRTDesc.msaaSamples       = camera.allowMSAA ? QualitySettings.antiAliasing : 1;
            colorRTDesc.enableRandomWrite = false;
            cmdTempId.GetTemporaryRT(m_ColorRTid, colorRTDesc, FilterMode.Bilinear);

            //Depth
            RenderTextureDescriptor depthRTDesc = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight);
            depthRTDesc.colorFormat     = RenderTextureFormat.Depth;
            depthRTDesc.depthBufferBits = depthBufferBits;
            cmdTempId.GetTemporaryRT(m_DepthRTid, depthRTDesc, FilterMode.Bilinear);

            //MotionVector
            RenderTextureDescriptor motionvectorRTDesc = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight);
            motionvectorRTDesc.graphicsFormat  = UnityEngine.Experimental.Rendering.GraphicsFormat.R16G16_SFloat;
            motionvectorRTDesc.depthBufferBits = depthBufferBits;
            //colorRTDesc.sRGB = ;
            motionvectorRTDesc.msaaSamples       = 1;
            motionvectorRTDesc.enableRandomWrite = false;
            cmdTempId.GetTemporaryRT(m_MotionVectorRTid, motionvectorRTDesc, FilterMode.Bilinear);

            context.ExecuteCommandBuffer(cmdTempId);
            cmdTempId.Release();

            //************************** Setup DrawSettings and FilterSettings ************************************

            camera.depthTextureMode |= DepthTextureMode.MotionVectors | DepthTextureMode.Depth;

            var sortingSettings = new SortingSettings(camera);

            DrawingSettings   drawSettings   = new DrawingSettings(m_PassName, sortingSettings);
            FilteringSettings filterSettings = new FilteringSettings(RenderQueueRange.all);

            DrawingSettings drawSettingsMotionVector = new DrawingSettings(m_PassName, sortingSettings)
            {
                perObjectData             = PerObjectData.MotionVectors,
                overrideMaterial          = motionVectorMaterial,
                overrideMaterialPassIndex = 0
            };
            FilteringSettings filterSettingsMotionVector = new FilteringSettings(RenderQueueRange.all)
            {
                excludeMotionVectorObjects = false
            };

            DrawingSettings drawSettingsDepth = new DrawingSettings(m_PassName, sortingSettings)
            {
                //perObjectData = PerObjectData.None,
                overrideMaterial          = depthOnlyMaterial,
                overrideMaterialPassIndex = 0,
            };
            FilteringSettings filterSettingsDepth = new FilteringSettings(RenderQueueRange.all);

            //************************** Rendering depth ************************************

            //Set RenderTarget & Camera clear flag
            CommandBuffer cmdDepth = new CommandBuffer();
            cmdDepth.name = "(" + camera.name + ")" + "Depth Clear Flag";
            cmdDepth.SetRenderTarget(m_DepthRT); //Set CameraTarget to the depth texture
            cmdDepth.ClearRenderTarget(true, true, Color.black);
            context.ExecuteCommandBuffer(cmdDepth);
            cmdDepth.Release();

            //Opaque objects
            sortingSettings.criteria             = SortingCriteria.CommonOpaque;
            drawSettingsDepth.sortingSettings    = sortingSettings;
            filterSettingsDepth.renderQueueRange = RenderQueueRange.opaque;
            context.DrawRenderers(cull, ref drawSettingsDepth, ref filterSettingsDepth);

            //To let shader has _CameraDepthTexture
            CommandBuffer cmdDepthTexture = new CommandBuffer();
            cmdDepthTexture.name = "(" + camera.name + ")" + "Depth Texture";
            cmdDepthTexture.SetGlobalTexture(m_DepthRTid, m_DepthRT);
            context.ExecuteCommandBuffer(cmdDepthTexture);
            cmdDepthTexture.Release();

            //************************** Rendering motion vectors ************************************

            //Camera clear flag
            CommandBuffer cmdMotionvector = new CommandBuffer();
            cmdMotionvector.SetRenderTarget(m_MotionVectorRT); //Set CameraTarget to the motion vector texture
            cmdMotionvector.ClearRenderTarget(true, true, Color.black);
            context.ExecuteCommandBuffer(cmdMotionvector);
            cmdMotionvector.Release();

            //Opaque objects
            sortingSettings.criteria = SortingCriteria.CommonOpaque;
            drawSettingsMotionVector.sortingSettings    = sortingSettings;
            filterSettingsMotionVector.renderQueueRange = RenderQueueRange.opaque;
            context.DrawRenderers(cull, ref drawSettingsMotionVector, ref filterSettingsMotionVector);

            //Camera motion vector
            CommandBuffer cmdCameraMotionVector = new CommandBuffer();
            cmdCameraMotionVector.name = "(" + camera.name + ")" + "Camera MotionVector";
            _NonJitteredVP             = camera.nonJitteredProjectionMatrix * camera.worldToCameraMatrix;
            cmdCameraMotionVector.SetGlobalMatrix("_CamPrevViewProjMatrix", _PreviousVP);
            cmdCameraMotionVector.SetGlobalMatrix("_CamNonJitteredViewProjMatrix", _NonJitteredVP);
            cmdCameraMotionVector.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
            cmdCameraMotionVector.DrawMesh(fullscreenMesh, Matrix4x4.identity, motionVectorMaterial, 0, 1, null);  // draw full screen quad to make Camera motion
            cmdCameraMotionVector.SetViewProjectionMatrices(camera.worldToCameraMatrix, camera.projectionMatrix);
            context.ExecuteCommandBuffer(cmdCameraMotionVector);
            cmdCameraMotionVector.Release();

            //To let shader has MotionVectorTexture
            CommandBuffer cmdMotionVectorTexture = new CommandBuffer();
            cmdMotionVectorTexture.name = "(" + camera.name + ")" + "MotionVector Texture";
            cmdMotionVectorTexture.SetGlobalTexture(m_MotionVectorRTid, m_MotionVectorRT);
            context.ExecuteCommandBuffer(cmdMotionVectorTexture);
            cmdMotionVectorTexture.Release();

            //************************** Rendering color ************************************

            //Camera clear flag
            CommandBuffer cmd = new CommandBuffer();
            cmd.SetRenderTarget(m_ColorRT); //Set CameraTarget to the color texture
            cmd.ClearRenderTarget(clearDepth, clearColor, camera.backgroundColor);
            context.ExecuteCommandBuffer(cmd);
            cmd.Release();

            //Skybox
            if (drawSkyBox)
            {
                context.DrawSkybox(camera);
            }

            //Opaque objects
            sortingSettings.criteria        = SortingCriteria.CommonOpaque;
            drawSettings.sortingSettings    = sortingSettings;
            filterSettings.renderQueueRange = RenderQueueRange.opaque;
            context.DrawRenderers(cull, ref drawSettings, ref filterSettings);

            //************************** SetUp Post-processing ************************************

            PostProcessLayer m_CameraPostProcessLayer = camera.GetComponent <PostProcessLayer>();
            bool             hasPostProcessing        = m_CameraPostProcessLayer != null;
            bool             usePostProcessing        = false;
            //bool hasOpaqueOnlyEffects = false;
            PostProcessRenderContext m_PostProcessRenderContext = null;
            if (hasPostProcessing)
            {
                m_PostProcessRenderContext = new PostProcessRenderContext();
                usePostProcessing          = m_CameraPostProcessLayer.enabled;
                //hasOpaqueOnlyEffects = m_CameraPostProcessLayer.HasOpaqueOnlyEffects(m_PostProcessRenderContext);
            }

            //************************** Opaque Post-processing ************************************
            //Ambient Occlusion, Screen-spaced reflection are generally not supported for SRP
            //So this part is only for custom opaque post-processing
            // if(usePostProcessing)
            // {
            //     CommandBuffer cmdpp = new CommandBuffer();
            //     cmdpp.name = "("+camera.name+")"+ "Post-processing Opaque";

            //     m_PostProcessRenderContext.Reset();
            //     m_PostProcessRenderContext.camera = camera;
            //     m_PostProcessRenderContext.source = m_ColorRT;
            //     m_PostProcessRenderContext.sourceFormat = UnityEngine.Experimental.Rendering.GraphicsFormatUtility.GetRenderTextureFormat(m_ColorFormatActive);
            //     m_PostProcessRenderContext.destination = m_ColorRT;
            //     m_PostProcessRenderContext.command = cmdpp;
            //     m_PostProcessRenderContext.flip = camera.targetTexture == null;
            //     m_CameraPostProcessLayer.RenderOpaqueOnly(m_PostProcessRenderContext);

            //     context.ExecuteCommandBuffer(cmdpp);
            //     cmdpp.Release();
            // }

            //************************** Rendering Transparent Objects ************************************

            sortingSettings.criteria        = SortingCriteria.CommonTransparent;
            drawSettings.sortingSettings    = sortingSettings;
            filterSettings.renderQueueRange = RenderQueueRange.transparent;
            context.DrawRenderers(cull, ref drawSettings, ref filterSettings);

            //************************** Transparent Post-processing ************************************
            //Bloom, Vignette, Grain, ColorGrading, LensDistortion, Chromatic Aberration, Auto Exposure, Motion Blur
            if (usePostProcessing)
            {
                CommandBuffer cmdpp = new CommandBuffer();
                cmdpp.name = "(" + camera.name + ")" + "Post-processing Transparent";

                m_PostProcessRenderContext.Reset();
                m_PostProcessRenderContext.camera       = camera;
                m_PostProcessRenderContext.source       = m_ColorRT;
                m_PostProcessRenderContext.sourceFormat = UnityEngine.Experimental.Rendering.GraphicsFormatUtility.GetRenderTextureFormat(m_ColorFormatActive);
                m_PostProcessRenderContext.destination  = BuiltinRenderTextureType.CameraTarget;
                m_PostProcessRenderContext.command      = cmdpp;
                m_PostProcessRenderContext.flip         = camera.targetTexture == null;
                m_CameraPostProcessLayer.Render(m_PostProcessRenderContext);

                context.ExecuteCommandBuffer(cmdpp);
                cmdpp.Release();
            }
            else
            {
                //Make sure screen has the thing when Postprocessing is off
                CommandBuffer cmdBlitToCam = new CommandBuffer();
                cmdBlitToCam.name = "(" + camera.name + ")" + "Blit back to Camera";
                cmdBlitToCam.Blit(m_ColorRTid, BuiltinRenderTextureType.CameraTarget);
                context.ExecuteCommandBuffer(cmdBlitToCam);
                cmdBlitToCam.Release();
            }

            //************************** Debug ************************************

            if (_motionVectorDebug)
            {
                CommandBuffer cmdDebug = new CommandBuffer();
                cmdDebug.Blit(BuiltinRenderTextureType.CameraTarget, BuiltinRenderTextureType.CameraTarget, motionVectorDebugMaterial);
                context.ExecuteCommandBuffer(cmdDebug);
                cmdDebug.Release();
            }

            //************************** Clean Up ************************************

            CommandBuffer cmdclean = new CommandBuffer();
            cmdclean.name = "(" + camera.name + ")" + "Clean Up";
            cmdclean.ReleaseTemporaryRT(m_ColorRTid);
            cmdclean.ReleaseTemporaryRT(m_DepthRTid);
            cmdclean.ReleaseTemporaryRT(m_MotionVectorRTid);
            context.ExecuteCommandBuffer(cmdclean);
            cmdclean.Release();

            context.Submit();

            //For camera motion vector
            _PreviousVP = _NonJitteredVP;

            EndCameraRendering(context, camera);
        }

        EndFrameRendering(context, cameras);
    }
Beispiel #6
0
        public override void Render(PostProcessRenderContext context)
        {
            PropertySheet sheet = context.propertySheets.Get(shader);
            CommandBuffer cmd   = context.command;

            #region Parameters
            float sunIntensity = (settings.useCasterIntensity) ? SunshaftCaster.intensity : settings.sunShaftIntensity.value;

            //Screen-space sun position
            Vector3 v = Vector3.one * 0.5f;
            if (Sunshafts.sunPosition != Vector3.zero)
            {
                v = context.camera.WorldToViewportPoint(Sunshafts.sunPosition);
            }
            else
            {
                v = new Vector3(0.5f, 0.5f, 0.0f);
            }
            sheet.properties.SetVector("_SunPosition", new Vector4(v.x, v.y, sunIntensity, settings.falloff));

            Color sunColor = (settings.useCasterColor) ? SunshaftCaster.color : settings.sunColor.value;
            sheet.properties.SetFloat("_BlendMode", (int)settings.blendMode.value);
            sheet.properties.SetColor("_SunColor", (v.z >= 0.0f) ? sunColor : new Color(0, 0, 0, 0));
            sheet.properties.SetColor("_SunThreshold", settings.sunThreshold);
            #endregion

            int res = (int)settings.resolution.value;

            //Create skybox mask
            context.command.GetTemporaryRT(skyboxBufferID, context.width / 2, context.height / 2, 0, FilterMode.Bilinear, context.sourceFormat);
            context.command.BlitFullscreenTriangle(context.source, skyboxBufferID, sheet, (int)Pass.SkySource);
            cmd.SetGlobalTexture("_SunshaftBuffer", skyboxBufferID);

            //Blur buffer
            #region Blur
            cmd.BeginSample("Sunshafts blur");
            int blurredID  = Shader.PropertyToID("_Temp1");
            int blurredID2 = Shader.PropertyToID("_Temp2");
            cmd.GetTemporaryRT(blurredID, context.width / res, context.height / res, 0, FilterMode.Bilinear);
            cmd.GetTemporaryRT(blurredID2, context.width / res, context.height / res, 0, FilterMode.Bilinear);

            cmd.Blit(skyboxBufferID, blurredID);

            float offset = settings.length * (1.0f / 768.0f);

            int   iterations = (settings.highQuality) ? 2 : 1;
            float blurAmount = (settings.highQuality) ? settings.length / 2.5f : settings.length;

            for (int i = 0; i < iterations; i++)
            {
                context.command.BlitFullscreenTriangle(blurredID, blurredID2, sheet, (int)Pass.RadialBlur);
                offset = blurAmount * (((i * 2.0f + 1.0f) * 6.0f)) / context.screenWidth;
                sheet.properties.SetFloat("_BlurRadius", offset);

                context.command.BlitFullscreenTriangle(blurredID2, blurredID, sheet, (int)Pass.RadialBlur);
                offset = blurAmount * (((i * 2.0f + 2.0f) * 6.0f)) / context.screenWidth;
                sheet.properties.SetFloat("_BlurRadius", offset);
            }
            cmd.EndSample("Sunshafts blur");

            cmd.SetGlobalTexture("_SunshaftBuffer", blurredID);
            #endregion

            context.command.BlitFullscreenTriangle(context.source, context.destination, sheet, (int)Pass.Blend);

            cmd.ReleaseTemporaryRT(blurredID);
            cmd.ReleaseTemporaryRT(blurredID2);
            cmd.ReleaseTemporaryRT(skyboxBufferID);
        }
Beispiel #7
0
 internal abstract void Render(PostProcessRenderContext context);
Beispiel #8
0
        public override void Render(PostProcessRenderContext context)
        {
            if (!isValid)               // Avoid applying anything if some shaders are missing
            {
                context.command.Blit(context.source, context.destination);
                return;
            }

            // Fix for exit play mode destroying materials
            if (outlineUnlitMaterial == null)
            {
                outlineUnlitMaterial = new Material(outlineUnlit);
            }
            if (blurMaterial == null)
            {
                blurMaterial = new Material(blur);
            }
            if (outlineCompositorMaterial == null)
            {
                outlineCompositorMaterial = new Material(outlineCompositor);
            }

            // Fix for context.xrActiveEye or context.camera.stereoActiveEye giving incorrect values
            // Will not work if there is not another camera than the VR camera
            bool isStereoSecondEye = (previousCamera != null && previousCamera.stereoEnabled && context.camera.stereoEnabled && context.camera == previousCamera);

            //if (previousCamera != null) Debug.Log((previousCamera.stereoEnabled) + " && " + (context.camera.stereoEnabled) + " && " + (context.camera == previousCamera));
            previousCamera = context.camera;

            // Prepare blur RT descriptor
            RenderTextureDescriptor blurDescriptor;

            //if (context.camera.stereoEnabled) {
            //	blurDescriptor = XRSettings.eyeTextureDesc;
            //	blurDescriptor.depthBufferBits = 0;
            //} else {
            //	blurDescriptor = new RenderTextureDescriptor(context.camera.pixelWidth, context.camera.pixelHeight);
            //}
            blurDescriptor        = new RenderTextureDescriptor(context.camera.pixelWidth * ((context.camera.stereoEnabled) ? 2 : 1), context.camera.pixelHeight);
            blurDescriptor.width  = blurDescriptor.width >> settings.blurDownscale;
            blurDescriptor.height = blurDescriptor.height >> settings.blurDownscale;

            context.command.BeginSample("Outline");

            // Render the outlined objects in the outline RT
            //context.GetScreenSpaceTemporaryRT(context.command, outlineTexID);
            //Debug.Log(context.camera.name);
            context.command.GetTemporaryRT(outlineTexID, new RenderTextureDescriptor(context.camera.pixelWidth * ((context.camera.stereoEnabled) ? 2 : 1), context.camera.pixelHeight));
            context.command.SetRenderTarget(outlineTexID);
            context.command.ClearRenderTarget(true, true, Color.clear);
            context.command.SetGlobalInt("_FIX_IsSecondEye", (isStereoSecondEye) ? 1 : 0);
            if (isStereoSecondEye)
            {
                context.command.SetGlobalMatrix("_FIX_SecondEyeP", Matrix4x4.Scale(new Vector3(1, -1, 1)) * context.camera.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right));
                context.command.SetGlobalMatrix("_FIX_SecondEyeV", context.camera.GetStereoViewMatrix(Camera.StereoscopicEye.Right));
                //Debug.Log("FIX Right");
            }
            else
            {
                //Debug.Log("FIX Left");
            }

            foreach (Outlined outlined in OutlinedManager.I.outlinedObjects)
            {
                if (!outlined.enabled)
                {
                    continue;
                }
                context.command.SetGlobalColor(outlineColorID, outlined.currentColor);
                foreach (Renderer renderer in outlined.renderers)
                {
                    int subMeshCount = renderer.sharedMaterials.Length;                     // Assumes 1 material = 1 submesh
                    for (int i = 0; i < subMeshCount; i++)
                    {
                        context.command.DrawRenderer(renderer, outlineUnlitMaterial, i);
                    }
                }
            }

            // Blur the outlined RT
            context.command.GetTemporaryRT(blurTexID, blurDescriptor, FilterMode.Bilinear);
            context.command.GetTemporaryRT(tmpTexID, blurDescriptor, FilterMode.Bilinear);
            context.command.Blit(outlineTexID, blurTexID);             // Copy outline RT to blur RT
            context.command.SetGlobalVector(blurSizeID, new Vector4(1.5f / blurDescriptor.width, 1.5f / blurDescriptor.height, 0f, 0f));

            for (int i = 0; i < settings.blurPasses; i++)                   // Blur passes
            {
                context.command.Blit(blurTexID, tmpTexID, blurMaterial, 0); // Horizontal
                context.command.Blit(tmpTexID, blurTexID, blurMaterial, 1); // Vertical
            }
            context.command.ReleaseTemporaryRT(tmpTexID);

            // Composite the main RT with the blur RT
            context.command.SetGlobalFloat(blendID, settings.blend);
            context.command.Blit(context.source, context.destination, outlineCompositorMaterial, 0);
            context.command.ReleaseTemporaryRT(blurTexID);
            context.command.ReleaseTemporaryRT(outlineTexID);

            context.command.EndSample("Outline");
        }
Beispiel #9
0
        public override void Render(PostProcessRenderContext context)
        {
            var cmd = context.command;

            cmd.BeginSample("Streak");

            // Shader uniforms
            var sheet = context.propertySheets.Get(Shader.Find("Hidden/Kino/PostProcessing/Streak"));

            sheet.properties.SetFloat("_Threshold", settings.threshold);
            sheet.properties.SetFloat("_Stretch", settings.stretch);
            sheet.properties.SetFloat("_Intensity", settings.intensity);
            sheet.properties.SetColor("_Color", settings.tint);

            // Calculate the mip widths.
            _mipWidth[0] = context.screenWidth;
            for (var i = 1; i < MaxMipLevel; i++)
            {
                _mipWidth[i] = _mipWidth[i - 1] / 2;
            }

            // Apply the prefilter and store into MIP 0.
            var height = context.screenHeight / 2;

            context.GetScreenSpaceTemporaryRT(
                cmd, _rtMipDown[0], 0,
                RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default,
                FilterMode.Bilinear, _mipWidth[0], height
                );
            cmd.BlitFullscreenTriangle(context.source, _rtMipDown[0], sheet, 0);

            // Build the MIP pyramid.
            var level = 1;

            for (; level < MaxMipLevel && _mipWidth[level] > 7; level++)
            {
                context.GetScreenSpaceTemporaryRT(
                    cmd, _rtMipDown[level], 0,
                    RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default,
                    FilterMode.Bilinear, _mipWidth[level], height
                    );
                cmd.BlitFullscreenTriangle(_rtMipDown[level - 1], _rtMipDown[level], sheet, 1);
            }

            // MIP 0 is not needed at this point.
            cmd.ReleaseTemporaryRT(_rtMipDown[level]);

            // Upsample and combine.
            var lastRT = _rtMipDown[--level];

            for (level--; level >= 1; level--)
            {
                context.GetScreenSpaceTemporaryRT(
                    cmd, _rtMipUp[level], 0,
                    RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default,
                    FilterMode.Bilinear, _mipWidth[level], height
                    );
                cmd.SetGlobalTexture(_idHighTex, _rtMipDown[level]);
                cmd.BlitFullscreenTriangle(lastRT, _rtMipUp[level], sheet, 2);

                cmd.ReleaseTemporaryRT(_rtMipDown[level]);
                cmd.ReleaseTemporaryRT(lastRT);

                lastRT = _rtMipUp[level];
            }

            // Final composition.
            cmd.SetGlobalTexture(_idHighTex, context.source);
            cmd.BlitFullscreenTriangle(lastRT, context.destination, sheet, 3);

            // Cleaning up.
            cmd.ReleaseTemporaryRT(lastRT);
            cmd.EndSample("Streak");
        }
 public abstract void Render(PostProcessRenderContext context);
Beispiel #11
0
    public override void Render(PostProcessRenderContext context)
    {
        if (bloomShader == null)
        {
            return;
        }

        var cmd = context.command;

        // cmd.BeginSample("Honkei3Bloom");
        var texFormat = context.sourceFormat;

        sheet = context.propertySheets.Get(bloomShader);
        sheet.ClearKeywords();
        cmd.GetTemporaryRT(rt_320x180, 320, 180, 0, FilterMode.Bilinear, texFormat);
        sheet.properties.SetVector(prop_texelSize, new Vector2(0.00078f, 0.00139f));
        sheet.properties.SetColor(prop_Color, settings._bloomColor.value);
        cmd.BlitFullscreenTriangle(context.source, rt_320x180, sheet, 2); //pass First

        //256
        //copy
        cmd.GetTemporaryRT(rt_256x256, 256, 256, 0, FilterMode.Bilinear, texFormat);
        cmd.GetTemporaryRT(rt_256x256x1, 256, 256, 0, FilterMode.Bilinear, texFormat);
        sheet.properties.SetVector(prop_texelSize, new Vector2(0.00156f, 0.00278f));
        cmd.BlitFullscreenTriangle(rt_320x180, rt_256x256x1, sheet, 2);//pass First
        cmd.ReleaseTemporaryRT(rt_320x180);
        //ScalerThreshold
        sheet.properties.SetFloat(prop_Scaler, settings._Scaler.value);
        sheet.properties.SetFloat(prop_Threshhold, settings._Threshhold.value);
        cmd.BlitFullscreenTriangle(rt_256x256x1, rt_256x256, sheet, 1);//pass ScalerThreshold
        //Scaler
        sheet.properties.SetVector(prop_Scaler, new Vector2(0.5625f, 0.00f));
        cmd.BlitFullscreenTriangle(rt_256x256, rt_256x256x1, sheet, 3); //pass Scaler1
        sheet.properties.SetVector(prop_Scaler, new Vector2(0.00f, 1.00f));
        cmd.BlitFullscreenTriangle(rt_256x256x1, rt_256x256, sheet, 3); //pass Scaler1

        cmd.ReleaseTemporaryRT(rt_256x256x1);
        //res in rt_256x256

        //128
        cmd.GetTemporaryRT(rt_128x128, 128, 128, 0, FilterMode.Bilinear, texFormat);
        cmd.GetTemporaryRT(rt_128x128x1, 128, 128, 0, FilterMode.Bilinear, texFormat);

        cmd.BlitFullscreenTriangle(rt_256x256, rt_128x128, sheet, 0);//pass None

        //scaler
        sheet.properties.SetVector(prop_Scaler, new Vector2(0.5625f, 0.00f));
        cmd.BlitFullscreenTriangle(rt_128x128, rt_128x128x1, sheet, 4); //pass Scaler2
        sheet.properties.SetVector(prop_Scaler, new Vector2(0.00f, 1.00f));
        cmd.BlitFullscreenTriangle(rt_128x128x1, rt_128x128, sheet, 4); //pass Scaler2

        cmd.ReleaseTemporaryRT(rt_128x128x1);
        //res in rt_128x128

        //64
        cmd.GetTemporaryRT(rt_64x64, 64, 64, 0, FilterMode.Bilinear, texFormat);
        cmd.GetTemporaryRT(rt_64x64x1, 64, 64, 0, FilterMode.Bilinear, texFormat);

        cmd.BlitFullscreenTriangle(rt_128x128, rt_64x64, sheet, 0);//pass None

        //scaler
        sheet.properties.SetVector(prop_Scaler, new Vector2(0.5625f, 0.00f));
        cmd.BlitFullscreenTriangle(rt_64x64, rt_64x64x1, sheet, 5); //pass Scaler3
        sheet.properties.SetVector(prop_Scaler, new Vector2(0.00f, 1.00f));
        cmd.BlitFullscreenTriangle(rt_64x64x1, rt_64x64, sheet, 5); //pass Scaler3

        cmd.ReleaseTemporaryRT(rt_64x64x1);
        //res in rt_64x64

        //32
        cmd.GetTemporaryRT(rt_32x32, 32, 32, 0, FilterMode.Bilinear, texFormat);
        cmd.GetTemporaryRT(rt_32x32x1, 32, 32, 0, FilterMode.Bilinear, texFormat);

        cmd.BlitFullscreenTriangle(rt_64x64, rt_32x32, sheet, 0);   //pass None
        sheet.properties.SetVector(prop_Scaler, new Vector2(0.5625f, 0.00f));
        cmd.BlitFullscreenTriangle(rt_32x32, rt_32x32x1, sheet, 6); //pass Scaler4
        sheet.properties.SetVector(prop_Scaler, new Vector2(0.00f, 1.00f));
        cmd.BlitFullscreenTriangle(rt_32x32x1, rt_32x32, sheet, 6); //pass Scaler4

        cmd.ReleaseTemporaryRT(rt_32x32x1);

        sheet.properties.SetVector(prop_Coeff, new Vector4(0.24f, 0.24f, 0.28f, 0.225f));
        cmd.SetGlobalTexture(prop_Tex0, rt_256x256);
        cmd.SetGlobalTexture(prop_Tex1, rt_128x128);
        cmd.SetGlobalTexture(prop_Tex2, rt_64x64);
        cmd.SetGlobalTexture(prop_Tex3, rt_32x32);

        if (settings.ToneType.value == ToneType.ACES)
        {
            sheet.EnableKeyword("TONEMAPPING_ACES");
        }
        else if (settings.ToneType.value == ToneType.Neutral)
        {
            sheet.EnableKeyword("TONEMAPPING_NEUTRAL");
        }
        //sheet.properties.SetVector(prop_HSV,
        //    new Vector4(settings._Hue.value, settings._Saturation.value, settings._Value.value));
        //if (settings._UseACESFile)
        //{
        //    sheet.EnableKeyword("USE_ACESFILM");
        //}

        if (settings._DistortionSwitch == true)
        {
            // 如果开启扭曲,进行扭曲处理,
            cmd.GetTemporaryRT(rt_1920x1080, context.screenWidth, context.screenHeight, 0, FilterMode.Bilinear, texFormat);
            cmd.BlitFullscreenTriangle(context.source, rt_1920x1080, sheet, 7);

            sheet.properties.SetFloat(prop_MoveSpeed, settings._MoveSpeed);
            sheet.properties.SetFloat(prop_MoveForce, settings._MoveForce);
            sheet.properties.SetTexture(prop_NoiseTex, settings._NoiseTex);
            sheet.properties.SetTexture(prop_MaskTex, settings._MaskTex);

            cmd.BlitFullscreenTriangle(rt_1920x1080, context.destination, sheet, 8);
            cmd.ReleaseTemporaryRT(rt_1920x1080);
            settings._DistortionSwitch = false;
        }
        else
        {
            cmd.BlitFullscreenTriangle(context.source, context.destination, sheet, 7);
        }



        cmd.ReleaseTemporaryRT(rt_256x256);
        cmd.ReleaseTemporaryRT(rt_128x128);
        cmd.ReleaseTemporaryRT(rt_64x64);
        cmd.ReleaseTemporaryRT(rt_32x32);

        //cmd.EndSample("Honkei3Bloom");
    }
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 /// <exception cref="NotImplementedException"></exception>
 public override void Render(PostProcessRenderContext context)
 {
     throw new NotImplementedException();
 }
Beispiel #13
0
    // called at the end of each frame's rendering pipe
    public override void Render(PostProcessRenderContext context)
    {
        var sheet = context.propertySheets.Get(Shader.Find("Custom/BoxBlur"));

        context.command.BlitFullscreenTriangle(context.source, context.destination, sheet, 0);
    }
    public override void Render(PostProcessRenderContext context)
    {
        //In case any of the render targets gets destroyed, recreate them
        //Usually only happens when quitting the game in the editor
        if (lastFrame == null || sourceFrame == null || processedFrame == null || motionFrame == null)
        {
            InitRenderTextures();
        }

        //Blit context.source to our sourceFrame RenderTexture so that we can operate on it
        context.command.Blit(context.source, sourceFrameIdentifier);

        //Blit the Motion Vectors to our motionFrame render target
        context.command.Blit(motionFrame, motionFrameIdentifier, motionMaterial);

        //Create the kernel Handle and increment it by one if Fast mode is enabled
        //This way it will then use the second kernel configuration
        int mainKernelHandle = 0;

        if (settings.performanceMode.value == JPEGPerformance.Fast)
        {
            mainKernelHandle = 1;
        }

        //Pass all the RenderTextures to the shader
        dctShader.SetTexture(mainKernelHandle, "Last", lastFrame);
        dctShader.SetTexture(mainKernelHandle, "Input", sourceFrame);
        dctShader.SetTexture(mainKernelHandle, "Motion", motionFrame);
        dctShader.SetTexture(mainKernelHandle, "Result", processedFrame);
        //Pass the user settings to the shader
        dctShader.SetBool("UseSpacial", settings.useSpatialCompression);
        dctShader.SetFloat("CompressionThreshold", settings.compressionThreshold);
        dctShader.SetBool("UseTemporal", settings.useTemporalCompression.value && Application.isPlaying);
        dctShader.SetFloat("Bitrate", settings.bitrate);
        dctShader.SetFloat("BitrateArtifacts", settings.bitrateArtifacts);
        //If there are no B-Frames remaining the next frame will be an I-Frame
        //Motion Vectors do not work in the editor window, so we have to make sure that this only takes effect when
        //the game is running
        if (frameIndex == 0 || !Application.isPlaying)
        {
            dctShader.SetBool("IsIFrame", true);
            frameIndex = Mathf.Max(settings.numBFrames, 0);
        }
        //Otherwise just render another B-Frame
        else
        {
            dctShader.SetBool("IsIFrame", false);
            //A B-Frame was rendered so we decrease the FrameIndex
            //Only if we want to actually use I-Frames though
            if (settings.useIFrames)
            {
                frameIndex--;
            }
        }
        //Dispatch the shader
        //Since each Thread group operates on an 8x8 pixel area we can divide the screen resolution by 8 to determine
        //how many threadgroups are necessary
        //Adding 7 before dividing is some integer magic that prevents potential spawning of offscreen threads
        dctShader.Dispatch(mainKernelHandle, (sourceFrame.width + 7) / 8, (sourceFrame.height + 7) / 8, 1);
        //Blit the processed image to the context's destination texture
        context.command.BlitFullscreenTriangle(processedFrameIdentifier, context.destination);
        //In case we're using the MP4 compression the destination needs to be copied to the lastFrame render target
        context.command.Blit(context.destination, lastFrameIdentifier);
    }
Beispiel #15
0
 public override bool IsEnabledAndSupported(PostProcessRenderContext context)
 {
     return(enabled.value && displacement.value != 0);
 }
Beispiel #16
0
    public override void Render(PostProcessRenderContext context)
    {
        //check if my ressources (the list) is there, else do nothing
        //also do nothing for scene view because the transformation matrices are for the camera -> Screen space Positions are wrong
        if (PPHelper.Instance == null || context.isSceneView)
        {
            context.command.BlitFullscreenTriangle(context.source, context.destination);
            return;
        }


        var sheet = context.propertySheets.Get(Shader.Find("Hidden/Custom/Grayscale"));

        sheet.properties.SetFloat("_Factor", settings.blend);
        sheet.properties.SetFloat("_Black", settings.black);
        sheet.properties.SetFloat("_DistFactor", settings.dist);
        sheet.properties.SetFloat("_DistFactor2", settings.dist2);
        sheet.properties.SetFloat("_a", settings.a);
        sheet.properties.SetFloat("_b", settings.b);
        sheet.properties.SetFloat("_c", settings.c);
        //enemyPos[] test= new enemyPos[5];
        //PPHelper.T.buffer.GetData(test);
        //Debug.Log(test[0].factor);
        sheet.properties.SetBuffer("buffer", PPHelper.Instance.buffer);
        context.command.BlitFullscreenTriangle(context.source, context.destination, sheet, 0);



        //compute shader version:
        //can use groupshared memory for reading of enemy position -> should be an immense performance boost
        //DOES NOT WORK

        /*
         *
         * //find compute shader: -> need to put thin in PPHelper so its only called once
         * //ComputeShader computeShader = (ComputeShader)Resources.Load("PPEffect");
         * ComputeShader computeShader = PPHelper.T.computeShader;
         *
         *
         *
         * //Kernelid:
         * var cmd = context.command;
         * int kernel = computeShader.FindKernel("Effect");
         *
         * //set variables
         * //computeShader.SetFloat("_Factor", settings.blend);
         * //computeShader.SetFloat("_Black", settings.black);
         * //computeShader.SetFloat("_DistFactor", settings.dist);
         * //computeShader.SetFloat("_DistFactor2", settings.dist2);
         * //computeShader.SetFloat("_a", settings.a);
         * //computeShader.SetFloat("_b", settings.b);
         * //computeShader.SetFloat("_c", settings.c);
         * //
         * //computeShader.SetBuffer(kernel, "buffer", PPHelper.T.buffer);
         *
         * cmd.SetComputeVectorParam(computeShader, "_FactorBlackDistDist", new Vector4(settings.blend, settings.black, settings.dist, settings.dist2));
         * cmd.SetComputeVectorParam(computeShader, "_abc", new Vector4(settings.a, settings.b, settings.c, 0));
         *
         * cmd.SetComputeBufferParam(computeShader, kernel, "buffer", PPHelper.T.buffer);
         *
         * //set textures:
         * cmd.SetComputeTextureParam(computeShader, kernel, "_Source", context.source);
         * cmd.SetComputeTextureParam(computeShader, kernel, "_Destination", context.destination);
         *
         * //dispatch
         *
         * // Pixel dimensions of logical screen size
         * //context.screenHeight;
         * //context.screenWidth;
         * cmd.DispatchCompute(computeShader, kernel, 20, 20, 1);
         *
         * //context.destination =
         *
         */
    }
Beispiel #17
0
 internal abstract bool ShaderResourcesAvailable(PostProcessRenderContext context);
Beispiel #18
0
 public override void Render(PostProcessRenderContext context)
 {
     AnimatedRain.Instance.Render(context.camera, context.source, context.destination, context.command);
 }
        public override void Render(PostProcessRenderContext context)
        {
            CommandBuffer cmd   = context.command;
            PropertySheet sheet = context.propertySheets.Get(shader);

            cmd.BeginSample(PROFILER_TAG);


            int tw = (int)(context.screenWidth / settings.RTDownScaling);
            int th = (int)(context.screenHeight / settings.RTDownScaling);

            Vector4 BlurOffset = new Vector4(settings.BlurRadius / (float)context.screenWidth, settings.BlurRadius / (float)context.screenHeight, 0, 0);

            sheet.properties.SetVector(ShaderIDs.BlurOffset, BlurOffset);
            // Downsample
            RenderTargetIdentifier lastDown = context.source;

            for (int i = 0; i < settings.Iteration; i++)
            {
                int mipDownV = m_Pyramid[i].down_vertical;
                int mipDowH  = m_Pyramid[i].down_horizontal;
                int mipUpV   = m_Pyramid[i].up_vertical;
                int mipUpH   = m_Pyramid[i].up_horizontal;

                context.GetScreenSpaceTemporaryRT(cmd, mipDownV, 0, context.sourceFormat, RenderTextureReadWrite.Default, FilterMode.Bilinear, tw, th);
                context.GetScreenSpaceTemporaryRT(cmd, mipDowH, 0, context.sourceFormat, RenderTextureReadWrite.Default, FilterMode.Bilinear, tw, th);
                context.GetScreenSpaceTemporaryRT(cmd, mipUpV, 0, context.sourceFormat, RenderTextureReadWrite.Default, FilterMode.Bilinear, tw, th);
                context.GetScreenSpaceTemporaryRT(cmd, mipUpH, 0, context.sourceFormat, RenderTextureReadWrite.Default, FilterMode.Bilinear, tw, th);

                // horizontal blur
                sheet.properties.SetVector(ShaderIDs.BlurOffset, new Vector4(settings.BlurRadius / context.screenWidth, 0, 0, 0));
                context.command.BlitFullscreenTriangle(lastDown, mipDowH, sheet, 0);

                // vertical blur
                sheet.properties.SetVector(ShaderIDs.BlurOffset, new Vector4(0, settings.BlurRadius / context.screenHeight, 0, 0));
                context.command.BlitFullscreenTriangle(mipDowH, mipDownV, sheet, 0);

                lastDown = mipDownV;
                tw       = Mathf.Max(tw / 2, 1);
                th       = Mathf.Max(th / 2, 1);
            }

            // Upsample
            int lastUp = m_Pyramid[settings.Iteration - 1].down_vertical;

            for (int i = settings.Iteration - 2; i >= 0; i--)
            {
                int mipUpV = m_Pyramid[i].up_vertical;
                int mipUpH = m_Pyramid[i].up_horizontal;

                // horizontal blur
                sheet.properties.SetVector(ShaderIDs.BlurOffset, new Vector4(settings.BlurRadius / context.screenWidth, 0, 0, 0));
                context.command.BlitFullscreenTriangle(lastUp, mipUpH, sheet, 0);

                // vertical blur
                sheet.properties.SetVector(ShaderIDs.BlurOffset, new Vector4(0, settings.BlurRadius / context.screenHeight, 0, 0));
                context.command.BlitFullscreenTriangle(mipUpH, mipUpV, sheet, 0);

                lastUp = mipUpV;
            }


            // Render blurred texture in blend pass
            cmd.BlitFullscreenTriangle(lastUp, context.destination, sheet, 1);

            // Cleanup
            for (int i = 0; i < settings.Iteration; i++)
            {
                if (m_Pyramid[i].down_vertical != lastUp)
                {
                    cmd.ReleaseTemporaryRT(m_Pyramid[i].down_vertical);
                }
                if (m_Pyramid[i].down_horizontal != lastUp)
                {
                    cmd.ReleaseTemporaryRT(m_Pyramid[i].down_horizontal);
                }
                if (m_Pyramid[i].up_horizontal != lastUp)
                {
                    cmd.ReleaseTemporaryRT(m_Pyramid[i].up_horizontal);
                }
                if (m_Pyramid[i].up_vertical != lastUp)
                {
                    cmd.ReleaseTemporaryRT(m_Pyramid[i].up_vertical);
                }
            }

            cmd.EndSample(PROFILER_TAG);
        }
Beispiel #20
0
 public override bool IsEnabledAndSupported(PostProcessRenderContext context)
 {
     return(base.IsEnabledAndSupported(context) && AnimatedRain.Instance);
 }
Beispiel #21
0
 // called at the end of each frame's rendering pipe
 public override void Render(PostProcessRenderContext context)
 {
     this.sheet = context.propertySheets.Get(Shader.Find("Custom/BoxBlur"));
     sheet.properties.SetFloat("_KernelSize", settings.kernelSize);
     context.command.BlitFullscreenTriangle(context.source, context.destination, sheet, 0);
 }
Beispiel #22
0
 public override bool IsEnabledAndSupported(PostProcessRenderContext context)
 {
     return(enabled.value && Outlines.OutlinesActive());
 }
Beispiel #23
0
        public override void Render(PostProcessRenderContext context)
        {
            var           sheet = context.propertySheets.Get(shader);
            CommandBuffer cmd   = context.command;

            sheet.properties.SetFloat("_Intensity", settings.intensity);
            float luminanceThreshold = Mathf.GammaToLinearSpace(settings.luminanceThreshold.value);

            sheet.properties.SetFloat("_Threshold", luminanceThreshold);
            sheet.properties.SetFloat("_Distance", settings.distance);
            sheet.properties.SetFloat("_Falloff", settings.falloff);
            sheet.properties.SetFloat("_Ghosts", settings.iterations);
            sheet.properties.SetFloat("_HaloSize", settings.haloSize);
            sheet.properties.SetFloat("_HaloWidth", settings.haloWidth);
            sheet.properties.SetFloat("_ChromaticAbberation", settings.chromaticAbberation);


            if (settings.colorTex.value)
            {
                sheet.properties.SetTexture("_ColorTex", settings.colorTex);
            }
            else
            {
                sheet.properties.SetTexture("_ColorTex", Texture2D.whiteTexture);
            }
            if (settings.maskTex.value)
            {
                sheet.properties.SetTexture("_MaskTex", settings.maskTex);
            }
            else
            {
                sheet.properties.SetTexture("_MaskTex", Texture2D.whiteTexture);
            }

            context.command.GetTemporaryRT(emissionTex, context.width, context.height, 0, FilterMode.Bilinear, RenderTextureFormat.DefaultHDR);
            context.command.BlitFullscreenTriangle(context.source, emissionTex, sheet, (int)Pass.LuminanceDiff);
            context.command.SetGlobalTexture("_BloomTex", emissionTex);

            context.command.GetTemporaryRT(flaresTex, context.width, context.height, 0, FilterMode.Bilinear, RenderTextureFormat.DefaultHDR);
            context.command.BlitFullscreenTriangle(emissionTex, flaresTex, sheet, (int)Pass.Ghosting);
            context.command.SetGlobalTexture("_FlaresTex", flaresTex);

            // get two smaller RTs
            int blurredID  = Shader.PropertyToID("_Temp1");
            int blurredID2 = Shader.PropertyToID("_Temp2");

            cmd.GetTemporaryRT(blurredID, context.width / 2, context.height / 2, 0, FilterMode.Bilinear);
            cmd.GetTemporaryRT(blurredID2, context.width / 2, context.height / 2, 0, FilterMode.Bilinear);

            // downsample screen copy into smaller RT, release screen RT
            cmd.Blit(flaresTex, blurredID);
            cmd.ReleaseTemporaryRT(flaresTex);


            for (int i = 0; i < settings.passes; i++)
            {
                // horizontal blur
                cmd.SetGlobalVector("_Offsets", new Vector4(settings.blur / context.screenWidth, 0, 0, 0));
                context.command.BlitFullscreenTriangle(blurredID, blurredID2, sheet, (int)Pass.Blur);  // source -> tempRT

                // vertical blur
                cmd.SetGlobalVector("_Offsets", new Vector4(0, settings.blur / context.screenHeight, 0, 0));
                context.command.BlitFullscreenTriangle(blurredID2, blurredID, sheet, (int)Pass.Blur);  // source -> tempRT
            }

            context.command.SetGlobalTexture("_FlaresTex", blurredID);

            //Blend tex with image
            context.command.BlitFullscreenTriangle(context.source, context.destination, sheet, (settings.debug) ? (int)Pass.Debug : (int)Pass.Blend);

            // release
            context.command.ReleaseTemporaryRT(emissionTex);
            context.command.ReleaseTemporaryRT(flaresTex);
            context.command.ReleaseTemporaryRT(blurredID);
            context.command.ReleaseTemporaryRT(blurredID2);
        }
Beispiel #24
0
    public override void Render(PostProcessRenderContext context)
    {
        var cmd = context.command;

        cmd.BeginSample("OutlineRenderer");

        // initialization
        cmd.GetTemporaryRT(_depthRTID, _RTWidth, _RTHeight, 0, FilterMode.Bilinear, context.sourceFormat);
        cmd.SetRenderTarget(_depthRTID, BuiltinRenderTextureType.CurrentActive);
        cmd.ClearRenderTarget(false, true, Color.clear);

        // render selected objects into a mask buffer, with different colors for visible vs occluded ones
        float id = 0f;

        foreach (var collection in settings.ObjectRenderers.value)
        {
            id += 0.25f;
            cmd.SetGlobalFloat("_ObjectId", id);

            foreach (var render in collection.Value)
            {
                for (var i = 0; i < render.sharedMaterials.Length; i++)
                {
                    cmd.DrawRenderer(render, _outlineMaterial, i, 1);
                    cmd.DrawRenderer(render, _outlineMaterial, i, 0);
                }
            }
        }

        // object ID edge dectection pass
        cmd.GetTemporaryRT(_idRTID, _RTWidth, _RTHeight, 0, FilterMode.Bilinear, RenderTextureFormat.ARGB32);
        cmd.Blit(_depthRTID, _idRTID, _outlineMaterial, 3);

        // Blur
        int rtW      = _RTWidth;
        int rtH      = _RTHeight;
        var blurSize = settings.BlurSize.value;

        if (settings.Downsample)
        {
            blurSize /= 4;
            rtW     >>= 1;
            rtH     >>= 1;
        }

        cmd.GetTemporaryRT(_temporaryRTID, rtW, rtH, 0, FilterMode.Bilinear, RenderTextureFormat.ARGB32);
        cmd.GetTemporaryRT(_blurredRTID, rtW, rtH, 0, FilterMode.Bilinear, RenderTextureFormat.ARGB32);

        cmd.Blit(_idRTID, _blurredRTID);


        cmd.SetGlobalVector("_BlurDirection", new Vector2(blurSize, 0));
        cmd.Blit(_blurredRTID, _temporaryRTID, _outlineMaterial, 2);
        cmd.SetGlobalVector("_BlurDirection", new Vector2(0, blurSize));
        cmd.Blit(_temporaryRTID, _blurredRTID, _outlineMaterial, 2);


        // final overlay
        cmd.SetGlobalColor("_OutlineColor", settings.OutlineColor.value);

        cmd.BlitFullscreenTriangle(context.source, context.destination);
        cmd.Blit(_blurredRTID, context.destination, _outlineMaterial, 4);

        // release tempRTs
        cmd.ReleaseTemporaryRT(_blurredRTID);
        cmd.ReleaseTemporaryRT(_outlineRTID);
        cmd.ReleaseTemporaryRT(_temporaryRTID);
        cmd.ReleaseTemporaryRT(_depthRTID);

        cmd.EndSample("OutlineRenderer");
    }
Beispiel #25
0
 public override void Render(PostProcessRenderContext context)
 {
     var sheet = context.propertySheets.Get(Shader.Find("Hidden/Custom/Grayscale"));
     sheet.properties.SetFloat("_Blend", settings.blend);
     context.command.BlitFullscreenTriangle(context.source, context.destination, sheet, 0);
 }
Beispiel #26
0
 public override bool IsEnabledAndSupported(PostProcessRenderContext context)
 {
     return(ObjectRenderers.value.Any() && base.IsEnabledAndSupported(context));
 }
        public override void Render(PostProcessRenderContext context)
        {
            CommandBuffer command = context.command;

            command.BeginSample("Screen-space Reflections");
            if (base.settings.preset.value != ScreenSpaceReflectionPreset.Custom)
            {
                int value = (int)base.settings.preset.value;
                base.settings.maximumIterationCount.value = m_Presets[value].maximumIterationCount;
                base.settings.thickness.value             = m_Presets[value].thickness;
                base.settings.resolution.value            = m_Presets[value].downsampling;
            }
            base.settings.maximumMarchDistance.value = Mathf.Max(0f, base.settings.maximumMarchDistance.value);
            int num = Mathf.ClosestPowerOfTwo(Mathf.Min(context.width, context.height));

            if (base.settings.resolution.value == ScreenSpaceReflectionResolution.Downsampled)
            {
                num >>= 1;
            }
            else if (base.settings.resolution.value == ScreenSpaceReflectionResolution.Supersampled)
            {
                num <<= 1;
            }
            int a = Mathf.FloorToInt(Mathf.Log(num, 2f) - 3f);

            a = Mathf.Min(a, 12);
            CheckRT(ref m_Resolve, num, num, context.sourceFormat, FilterMode.Trilinear, useMipMap: true);
            Texture2D     texture2D     = context.resources.blueNoise256[0];
            PropertySheet propertySheet = context.propertySheets.Get(context.resources.shaders.screenSpaceReflections);

            propertySheet.properties.SetTexture(ShaderIDs.Noise, texture2D);
            Matrix4x4 value2 = default(Matrix4x4);

            value2.SetRow(0, new Vector4((float)num * 0.5f, 0f, 0f, (float)num * 0.5f));
            value2.SetRow(1, new Vector4(0f, (float)num * 0.5f, 0f, (float)num * 0.5f));
            value2.SetRow(2, new Vector4(0f, 0f, 1f, 0f));
            value2.SetRow(3, new Vector4(0f, 0f, 0f, 1f));
            Matrix4x4 gPUProjectionMatrix = GL.GetGPUProjectionMatrix(context.camera.projectionMatrix, renderIntoTexture: false);

            value2 *= gPUProjectionMatrix;
            propertySheet.properties.SetMatrix(ShaderIDs.ViewMatrix, context.camera.worldToCameraMatrix);
            propertySheet.properties.SetMatrix(ShaderIDs.InverseViewMatrix, context.camera.worldToCameraMatrix.inverse);
            propertySheet.properties.SetMatrix(ShaderIDs.InverseProjectionMatrix, gPUProjectionMatrix.inverse);
            propertySheet.properties.SetMatrix(ShaderIDs.ScreenSpaceProjectionMatrix, value2);
            propertySheet.properties.SetVector(ShaderIDs.Params, new Vector4(base.settings.vignette.value, base.settings.distanceFade.value, base.settings.maximumMarchDistance.value, a));
            propertySheet.properties.SetVector(ShaderIDs.Params2, new Vector4((float)context.width / (float)context.height, (float)num / (float)texture2D.width, base.settings.thickness.value, base.settings.maximumIterationCount.value));
            command.GetTemporaryRT(ShaderIDs.Test, num, num, 0, FilterMode.Point, context.sourceFormat);
            command.BlitFullscreenTriangle(context.source, ShaderIDs.Test, propertySheet, 0);
            if (context.isSceneView)
            {
                command.BlitFullscreenTriangle(context.source, m_Resolve, propertySheet, 1);
            }
            else
            {
                CheckRT(ref m_History, num, num, context.sourceFormat, FilterMode.Bilinear, useMipMap: false);
                if (m_ResetHistory)
                {
                    context.command.BlitFullscreenTriangle(context.source, m_History);
                    m_ResetHistory = false;
                }
                command.GetTemporaryRT(ShaderIDs.SSRResolveTemp, num, num, 0, FilterMode.Bilinear, context.sourceFormat);
                command.BlitFullscreenTriangle(context.source, ShaderIDs.SSRResolveTemp, propertySheet, 1);
                propertySheet.properties.SetTexture(ShaderIDs.History, m_History);
                command.BlitFullscreenTriangle(ShaderIDs.SSRResolveTemp, m_Resolve, propertySheet, 2);
                command.CopyTexture(m_Resolve, 0, 0, m_History, 0, 0);
                command.ReleaseTemporaryRT(ShaderIDs.SSRResolveTemp);
            }
            command.ReleaseTemporaryRT(ShaderIDs.Test);
            if (m_MipIDs == null || m_MipIDs.Length == 0)
            {
                m_MipIDs = new int[12];
                for (int i = 0; i < 12; i++)
                {
                    m_MipIDs[i] = Shader.PropertyToID("_SSRGaussianMip" + i);
                }
            }
            ComputeShader          gaussianDownsample = context.resources.computeShaders.gaussianDownsample;
            int                    kernelIndex        = gaussianDownsample.FindKernel("KMain");
            RenderTargetIdentifier rt = new RenderTargetIdentifier(m_Resolve);

            for (int j = 0; j < a; j++)
            {
                num >>= 1;
                command.GetTemporaryRT(m_MipIDs[j], num, num, 0, FilterMode.Bilinear, context.sourceFormat, RenderTextureReadWrite.Default, 1, enableRandomWrite: true);
                command.SetComputeTextureParam(gaussianDownsample, kernelIndex, "_Source", rt);
                command.SetComputeTextureParam(gaussianDownsample, kernelIndex, "_Result", m_MipIDs[j]);
                command.SetComputeVectorParam(gaussianDownsample, "_Size", new Vector4(num, num, 1f / (float)num, 1f / (float)num));
                command.DispatchCompute(gaussianDownsample, kernelIndex, num / 8, num / 8, 1);
                command.CopyTexture(m_MipIDs[j], 0, 0, m_Resolve, 0, j + 1);
                rt = m_MipIDs[j];
            }
            for (int k = 0; k < a; k++)
            {
                command.ReleaseTemporaryRT(m_MipIDs[k]);
            }
            propertySheet.properties.SetTexture(ShaderIDs.Resolve, m_Resolve);
            command.BlitFullscreenTriangle(context.source, context.destination, propertySheet, 3);
            command.EndSample("Screen-space Reflections");
        }
Beispiel #28
0
        public override void Render(PostProcessRenderContext context)
        {
            var sheet = context.propertySheets.Get(Shader.Find("Hidden/PostProcessing/Extensions/GammaCorrection"));

            context.command.BlitFullscreenTriangle(context.source, context.destination, sheet, 0);
        }
Beispiel #29
0
 public override bool IsEnabledAndSupported(PostProcessRenderContext context)
 {
     return(enabled.value &&
            blend.value > 0f);
 }
Beispiel #30
0
 public override void Render(PostProcessRenderContext context)
 {
     DoRadialBlur(context, context.source, context.destination, settings.amount, settings.iterations, Vector2.one * .5f);
 }