Beispiel #1
0
        private void loadFrameBuffer()
        {
            frameBufferObject = GL.GenFramebuffer();
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBufferObject);
            GL.DrawBuffers(1, new DrawBuffersEnum[] { DrawBuffersEnum.ColorAttachment0 });

            ScreenGrab = new Texture(Width, Height);
            ppBufferA  = new Texture(Width, Height);
            ppBufferB  = new Texture(Width, Height);

            quadVertexObject = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, quadVertexObject);
            GL.BufferData(BufferTarget.ArrayBuffer, quad.Length * sizeof(float), quad, BufferUsageHint.StaticDraw);

            quadArrayObject = GL.GenVertexArray();
            GL.BindVertexArray(quadArrayObject);
            GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 2 * sizeof(float), 0);
            GL.EnableVertexAttribArray(0);

            // set up post-proc material list

            ppList = new List <Material>();

            threshMat = new ThresholdMaterial();
            ppList.Add(threshMat);

            blurMat = new BlurMaterial();
            ppList.Add(blurMat);

            combineMat = new CombineMaterial();
            ppList.Add(combineMat);

            blitMat = new Material();
        }
Beispiel #2
0
 protected override void OnRelease()
 {
     ProcessedTexture = null;
     Objects.Clear();
     PostProcessingActions = null;
     Material                = null;
     SourceTextureBuffer     = null;
     FirstTemporaryBuffer    = null;
     SecondTemporaryBuffer   = null;
     ColorCorrectionBuffer   = null;
     ColorCorrectionMaterial = null;
     BlurBuffer              = null;
     BlurMaterial            = null;
     BloomBuffer             = null;
     BloomMaterial           = null;
     DistortionBuffer        = null;
     DistortionMaterial      = null;
     SharpenBuffer           = null;
     SharpenMaterial         = null;
     NoiseBuffer             = null;
     NoiseTexture            = null;
     NoiseMaterial           = null;
     FXAABuffer              = null;
     FXAAMaterial            = null;
     VignetteMaterial        = null;
     TransparentTexture      = null;
     AlphaDiffuseMaterial    = null;
     AddDiffuseMaterial      = null;
     OpaqueDiffuseMaterial   = null;
 }
Beispiel #3
0
        private void FourTapCone(RenderTexture source, RenderTexture dest, int iteration)
        {
            float off = BlurMinSpread + iteration * BlurSpread;

            BlurMaterial.SetFloat("_OffsetScale", off);
            Graphics.Blit(source, dest, BlurMaterial);
        }
Beispiel #4
0
        private void DownSample4x(RenderTexture source, RenderTexture dest)
        {
            float off = 1.0f;

            BlurMaterial.SetFloat("_OffsetScale", off);
            Graphics.Blit(source, dest, BlurMaterial);
        }
Beispiel #5
0
        private void PerformBlur(RenderTexture src, RenderTexture dest)
        {
            float off = BlurSpread;

            BlurMaterial.SetTexture("_MainTex", src);
            BlurMaterial.SetFloat("_Shift", off);
            Graphics.Blit(src, dest, BlurMaterial);
        }
Beispiel #6
0
        private void PerformBlur(RenderTexture src, RenderTexture dest, int iteration)
        {
            float offset = iteration * BlurSpread;

            offset *= gaussFilter[iteration];

            BlurMaterial.SetTexture("_MainTex", src);
            BlurMaterial.SetFloat("_Shift", offset);
            Graphics.Blit(src, dest, BlurMaterial);
        }
Beispiel #7
0
    void RenderShadowMap()
    {
        //ideally, a cheaper version should be rendered here.
        //So lets render a version with no lighting stuff
        Profiler.BeginSample(Fog.name + " shadows");
        Fog.FogVolumeShader.maximumLOD = 100;

        SetQuality(textureSize);


        GetRT(ref RT_Opacity, (int)textureSize, "Opacity");

        ThisCamera.targetTexture = RT_Opacity;

        // print(Fog.ShadowCameraSkippedFrames);



        ThisCamera.Render();
        Fog.RT_Opacity = RT_Opacity;

        // Shader.SetGlobalTexture("RT_Opacity", RT_Opacity);


        if (RT_Opacity != null)
        {
            GetRT(ref RT_PostProcess, (int)textureSize, "Shadow PostProcess");
            PostProcessMaterial.SetFloat("ShadowColor", Fog.ShadowColor.a);
            // PostProcessMaterial.SetFloat("_jitter", Fog._jitter);
            Graphics.Blit(RT_Opacity, RT_PostProcess, PostProcessMaterial);
            // ThisCamera.targetTexture = null;
            Graphics.Blit(RT_PostProcess, RT_Opacity);
            //RenderTexture.ReleaseTemporary(RT_Opacity);
            if (iterations > 0)
            {
                Blur(RT_Opacity, (int)textureSize >> Downsampling);
            }
            else
            {
                Shader.SetGlobalTexture("RT_OpacityBlur", RT_Opacity);
                Fog.RT_OpacityBlur = RT_Opacity;
            }
            Fog.RT_Opacity = RT_Opacity;
        }
        //Shader.SetGlobalTexture("RT_Opacity", RT_Opacity);
        BlurMaterial.SetFloat("ShadowColor", Fog.ShadowColor.a);

        // back to normal
        Fog.FogVolumeShader.maximumLOD = 600;

        Profiler.EndSample();
    }
Beispiel #8
0
    void RenderShadowMap()
    {
        SetQuality(textureSize);

        GetRT(ref RT_Opacity, (int)textureSize, "Opacity");

        if (RT_Opacity != null)
        {
            ThisCamera.targetTexture = RT_Opacity;
        }

        //ideally, a cheaper version should be rendered here.
        //So lets render a version with no lighting stuff
        //Jitter is also BAD here, so lets turn it off
        Fog.FogVolumeShader.maximumLOD = 100;
        //this is throwing an error when deactivating
        if (RT_Opacity)
        {
            ThisCamera.Render();
        }
        //back to normal
        Fog.FogVolumeShader.maximumLOD = 600;

        GetRT(ref RT_PostProcess, (int)textureSize, "Shadow PostProcess");
        PostProcessMaterial.SetFloat("ShadowColor", Fog.ShadowColor.a);
        // PostProcessMaterial.SetFloat("_jitter", Fog._jitter);
        if (RT_Opacity != null)
        {
            Graphics.Blit(RT_Opacity, RT_PostProcess, PostProcessMaterial);
            ThisCamera.targetTexture = null;
            Graphics.Blit(RT_PostProcess, RT_Opacity);

            if (iterations > 0)
            {
                Blur(RT_Opacity, (int)textureSize >> Downsampling);
            }
            else
            {
                Shader.SetGlobalTexture("RT_OpacityBlur", RT_Opacity);
                Fog.RT_OpacityBlur = RT_Opacity;
                Fog.RT_Opacity     = RT_Opacity;
            }
        }
        //Shader.SetGlobalTexture("RT_Opacity", RT_Opacity);
        BlurMaterial.SetFloat("ShadowColor", Fog.ShadowColor.a);
    }
Beispiel #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShadowMap"/> class.
        /// </summary>
        public ShadowMap(GraphicsDevice graphics)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException("graphics");
            }

            this.graphics       = graphics;
            this.depthMaterial  = new DepthMaterial(graphics);
            this.blur           = new BlurMaterial(graphics);
            this.fullScreenQuad = new FullScreenQuad(graphics);

#if SILVERLIGHT
            this.SurfaceFormat = SurfaceFormat.Color;
#else
            this.SurfaceFormat = SurfaceFormat.Single;
#endif
        }
Beispiel #10
0
        private void UpdateBlurAmount()
        {
            // TODO: Use down scale
            var i        = 0;
            var leftover = this.blurAmount;

            while (leftover > 0)
            {
                var amount = Math.Min(leftover, BlurMaterial.MaxBlurAmount);
                leftover = Math.Max(leftover - BlurMaterial.MaxBlurAmount, 0);

                if (i * 2 >= blurs.Count)
                {
                    BlurMaterial blurH, blurV;
                    Effects.Add(new PostEffect(blurH = new BlurMaterial(GraphicsDevice)
                    {
                        DepthBufferEnabled = depthBufferEnabled, BlurAmount = amount
                    }));
                    Effects.Add(new PostEffect(blurV = new BlurMaterial(GraphicsDevice)
                    {
                        DepthBufferEnabled = depthBufferEnabled, Direction = MathHelper.PiOver2, BlurAmount = amount
                    }));
                    blurs.Add(blurH);
                    blurs.Add(blurV);
                }
                else
                {
                    Effects[i * 2].Enabled      = true;
                    Effects[i * 2 + 1].Enabled  = true;
                    blurs[i * 2].BlurAmount     = amount;
                    blurs[i * 2 + 1].BlurAmount = amount;
                }

                i++;
            }

            while (i * 2 < blurs.Count)
            {
                Effects[i * 2].Enabled     = false;
                Effects[i * 2 + 1].Enabled = false;
                i++;
            }
        }
Beispiel #11
0
        void IHandler <Start> .Handle(FrameArgs frame, Start e)
        {
            _cam = new Camera2D(e.Size, 1000f, Camera2DOrigin.Center);

            _sprites = new Atlas("sprites.atlas");

            // create our frame buffer
            var tex = new Texture(64, 64);

            _fb = new FrameBuffer(tex)
            {
                ClearOnBegin = true
            };

            // use a separate camera sized for the buffer
            _fbcam = new Camera2D(new Vector2(64, 64), 1000f,
                                  Camera2DOrigin.Center);

            // horizontal blur material
            _matHblur = new BlurMaterial(
                new BlurShader(BlurDirection.Horizontal, 24, 5),
                ((SpriteMaterial)_sprites["star"].Material).Texture,
                1f / 64f
                );

            // vertical blur material
            _matVblur = new BlurMaterial(
                new BlurShader(BlurDirection.Vertical, 24, 5),
                tex, 1f / 64f);

            // quad used to draw the contents of the frame buffer
            _quad = new Quad(_matVblur, new Vector4(-32, -32, 32, 32),
                             Vector4.One);

            // a black background suits this example better
            this.ClearColor = System.Drawing.Color.Black;
        }
Beispiel #12
0
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        ConvolveFogVolume();
        GetRT(ref _source, new int2(Screen.width, Screen.height), "_source");
        Graphics.Blit(source, _source);
        fastBloomMaterial.SetTexture("_source", _source);
        BlurMaterial.SetTexture("_source", _source);
        //Graphics.Blit(_source, destination, BlurMaterial);
        // RT_Format = source.format;
        #region Density convolution
        UniformFogCamera.cullingMask = 1 << instance.FogVolumeLayer;
        //UniformFogCamera.cullingMask |= 1 << LayerMask.NameToLayer("FogVolumeUniform");//add Fog volume uniforms
        FOV_compensation = initFOV / SceneCamera.fieldOfView;
        Shader.SetGlobalFloat("FOV_compensation", FOV_compensation);
        fastBloomMaterial.SetFloat("_Falloff", _Falloff);
        // BlurMaterial.SetFloat("_Dither", _Dither);
        // BlurMaterial.SetFloat("_Distortion", ImageDistortion * -.08f);

        RenderTexture RT_DensityBlur = RenderTexture.GetTemporary(screenX / Downsample, screenY / Downsample, 0, RT_Format);


        DownSample4x(source, RT_DensityBlur);

        for (int i = 0; i < iterations; i++)
        {
            RenderTexture RT_DensityBlur2 = RenderTexture.GetTemporary(screenX / Downsample, screenY / Downsample, 0, RT_Format);
            FourTapCone(RT_DensityBlur, RT_DensityBlur2, i);
            RenderTexture.ReleaseTemporary(RT_DensityBlur);
            RT_DensityBlur = RT_DensityBlur2;
        }
        // Graphics.Blit(RT_DensityBlur, destination);

        #endregion

        #region Bloom
        if (intensity > 0)
        {
            Rendering.EnsureKeyword(fastBloomMaterial, "BLOOM", true);
            float widthMod = 2.0f / (float)_BloomDowsample;
            fastBloomMaterial.SetFloat("_Saturation", _Saturation);
            fastBloomMaterial.SetVector("_Parameter", new Vector4(blurSize * widthMod, 0.0f, threshold, intensity));
            var rtW = source.width / _BloomDowsample;
            var rtH = source.height / _BloomDowsample;

            // downsample
            RenderTexture rt = RenderTexture.GetTemporary(rtW, rtH, 0, RT_Format);
            rt.filterMode = FilterMode.Bilinear;

            if (SceneBloom)
            {
                Graphics.Blit(source, rt, fastBloomMaterial, 1);
            }
            else
            {
                Graphics.Blit(RT_DensityBlur, rt, fastBloomMaterial, 1);
            }

            var passOffs = blurType == BlurType.Standard ? 0 : 2;

            for (int i = 1; i < blurIterations; i++)
            {
                fastBloomMaterial.SetVector("_Parameter", new Vector4(blurSize * widthMod + (i * 1.0f), 0.0f, threshold, intensity));

                // vertical blur
                RenderTexture rt2 = RenderTexture.GetTemporary(rtW, rtH, 0, RT_Format);
                rt2.filterMode = FilterMode.Bilinear;
                Graphics.Blit(rt, rt2, fastBloomMaterial, 2 + passOffs);
                RenderTexture.ReleaseTemporary(rt);
                rt = rt2;

                // horizontal blur
                rt2            = RenderTexture.GetTemporary(rtW, rtH, 0, RT_Format);
                rt2.filterMode = FilterMode.Bilinear;
                Graphics.Blit(rt, rt2, fastBloomMaterial, 3 + passOffs);
                RenderTexture.ReleaseTemporary(rt);
                rt = rt2;
            }

            fastBloomMaterial.SetTexture("_Bloom", rt);
            RenderTexture.ReleaseTemporary(rt);
        }
        else
        {
            Rendering.EnsureKeyword(fastBloomMaterial, "BLOOM", false);
        }
        #endregion
        Graphics.Blit(RT_DensityBlur, destination, fastBloomMaterial, 0);
        RenderTexture.ReleaseTemporary(RT_DensityBlur);
    }
Beispiel #13
0
        private void Start()
        {
            //不支持后期特效
            if (!SystemInfo.supportsImageEffects)
            {
                Log.Warning("HighlightingSystem : Image effects is not supported on this platform! Disabling.");
                enabled = false;
                return;
            }

            //不支持渲染纹理格式
            if (!SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGB32))
            {
                Log.Warning("HighlightingSystem : RenderTextureFormat.ARGB32 is not supported on this platform! Disabling.");
                enabled = false;
                return;
            }

            //不支持Highlighting Stencil着色器
            if (!Shader.Find("Hidden/Highlighted/StencilOpaque").isSupported)
            {
                Log.Warning("HighlightingSystem : HighlightingStencilOpaque shader is not supported on this platform! Disabling.");
                enabled = false;
                return;
            }

            //不支持Highlighting StencilTransparent着色器
            if (!Shader.Find("Hidden/Highlighted/StencilTransparent").isSupported)
            {
                Log.Warning("HighlightingSystem : HighlightingStencilTransparent shader is not supported on this platform! Disabling.");
                enabled = false;
                return;
            }

            //不支持Highlighting StencilZ着色器
            if (!Shader.Find("Hidden/Highlighted/StencilOpaqueZ").isSupported)
            {
                Log.Warning("HighlightingSystem : HighlightingStencilOpaqueZ shader is not supported on this platform! Disabling.");
                enabled = false;
                return;
            }

            //不支持Highlighting StencilTransparentZ着色器
            if (!Shader.Find("Hidden/Highlighted/StencilTransparentZ").isSupported)
            {
                Log.Warning("HighlightingSystem : HighlightingStencilTransparentZ shader is not supported on this platform! Disabling.");
                enabled = false;
                return;
            }

            //不支持HighlightingBlur着色器
            if (!BlurShader.isSupported)
            {
                Log.Warning("HighlightingSystem : HighlightingBlur shader is not supported on this platform! Disabling.");
                enabled = false;
                return;
            }

            //不支持HighlightingComposite着色器
            if (!CompositeShader.isSupported)
            {
                Log.Warning("HighlightingSystem : HighlightingComposite shader is not supported on this platform! Disabling.");
                enabled = false;
                return;
            }

            BlurMaterial.SetFloat("_Intensity", BlurIntensity);
        }
Beispiel #14
0
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        #region Density convolution
        UniformFogCamera.cullingMask = 1 << FogVolumeScreen.instance.FogVolumeLayer;
        Shader.SetGlobalFloat("FOV_compensation", initFOV / SceneCamera.fieldOfView);
        BlurMaterial.SetFloat("_Falloff", _Falloff);
        BlurMaterial.SetFloat("_Dither", _Dither);
        ConvolveFogVolume();
        screenX = source.width;
        screenY = source.height;
        RenderTexture RT_DensityBlur = RenderTexture.GetTemporary(screenX, screenY, 0, source.format);

        Graphics.Blit(source, RT_DensityBlur);

        for (int i = 0; i < iterations; i++)
        {
            RenderTexture RT_DensityBlur2 = RenderTexture.GetTemporary(screenX, screenY, 0, source.format);
            FourTapCone(RT_DensityBlur, RT_DensityBlur2, i);
            RenderTexture.ReleaseTemporary(RT_DensityBlur);
            RT_DensityBlur = RT_DensityBlur2;
        }
        //  Graphics.Blit(RT_DensityBlur, destination);

        #endregion

        #region Bloom

        float widthMod = 2.0f / (float)_BloomDowsample;
        fastBloomMaterial.SetFloat("_Saturation", _Saturation);
        fastBloomMaterial.SetVector("_Parameter", new Vector4(blurSize * widthMod, 0.0f, threshold, intensity));
        var rtW = source.width / _BloomDowsample;
        var rtH = source.height / _BloomDowsample;

        // downsample
        RenderTexture rt = RenderTexture.GetTemporary(rtW, rtH, 0, source.format);
        rt.filterMode = FilterMode.Bilinear;

        if (!SceneBloom)
        {
            Graphics.Blit(RT_FogVolumeConvolution, rt, fastBloomMaterial, 1);
        }
        else
        {
            Graphics.Blit(RT_DensityBlur, rt, fastBloomMaterial, 1);
        }

        var passOffs = blurType == BlurType.Standard ? 0 : 2;

        for (int i = 1; i < blurIterations; i++)
        {
            fastBloomMaterial.SetVector("_Parameter", new Vector4(blurSize * widthMod + (i * 1.0f), 0.0f, threshold, intensity));

            // vertical blur
            RenderTexture rt2 = RenderTexture.GetTemporary(rtW / i, rtH / i, 0, source.format);
            rt2.filterMode = FilterMode.Bilinear;
            Graphics.Blit(rt, rt2, fastBloomMaterial, 2 + passOffs);
            RenderTexture.ReleaseTemporary(rt);
            rt = rt2;

            // horizontal blur
            rt2            = RenderTexture.GetTemporary(rtW / i, rtH / i, 0, source.format);
            rt2.filterMode = FilterMode.Bilinear;
            Graphics.Blit(rt, rt2, fastBloomMaterial, 3 + passOffs);
            RenderTexture.ReleaseTemporary(rt);
            rt = rt2;
        }

        fastBloomMaterial.SetTexture("_Bloom", rt);

        Graphics.Blit(RT_DensityBlur, destination, fastBloomMaterial, 0);
        RenderTexture.ReleaseTemporary(RT_DensityBlur);
        RenderTexture.ReleaseTemporary(rt);
        #endregion
    }
    void OnRenderImage(RenderTexture sourceTexture, RenderTexture destTexture)
    {
        //Setup
        float WidthOverHeight = (sourceTexture.width) / (sourceTexture.height);
        float OneOverBase     = 1.0f / 512.0f;

        RenderTexture ScreenColor = null;
        RenderTexture HalfRez     = null;
        RenderTexture HalfRez2    = null;

        if (VignetteShader && ChromaticAbberationShader && SeparableBlurShader != null)
        {
            //OptimizationCheck
            if (Mathf.Abs(BlurDistance) > 0.0f || Mathf.Abs(VignettePower) > 0.0f)
            {
                ;
            }
            {
                ScreenColor = RenderTexture.GetTemporary(sourceTexture.width, sourceTexture.height, 0, sourceTexture.format);

                if (BlurDistance > 0.0f)
                {
                    HalfRez  = RenderTexture.GetTemporary(sourceTexture.width / Downsampling, sourceTexture.height / Downsampling, 0, sourceTexture.format);
                    HalfRez2 = RenderTexture.GetTemporary(sourceTexture.width / Downsampling, sourceTexture.height / Downsampling, 0, sourceTexture.format);
                    //Chromatic Abberation
                    Graphics.Blit(sourceTexture, HalfRez, ChromaMaterial);
                    //Seperable Blur (Unitys approach)
                    for (int i = 0; i < 2; i++)
                    {
                        BlurMaterial.SetVector("offsets", new Vector4(0.0f, BlurSpread * OneOverBase, 0.0f, 0.0f));
                        Graphics.Blit(HalfRez, HalfRez2, BlurMaterial);
                        BlurMaterial.SetVector("offsets", new Vector4(BlurSpread * OneOverBase / WidthOverHeight, 0.0f, 0.0f, 0.0f));
                        Graphics.Blit(HalfRez2, HalfRez, BlurMaterial);
                    }
                }

                VigMaterial.SetFloat("_VignettePower", VignettePower);
                VigMaterial.SetFloat("_Blur", BlurDistance);
                VigMaterial.SetTexture("_VignetteTex", HalfRez);

                Graphics.Blit(sourceTexture, destTexture, VigMaterial);
                ScreenColor.wrapMode = TextureWrapMode.Clamp;
                //if(ScreenColor) RenderTexture.ReleaseTemporary(ScreenColor);
                //if(HalfRez) RenderTexture.ReleaseTemporary(HalfRez);
                //if(HalfRez2) RenderTexture.ReleaseTemporary(HalfRez2);
            }

            ChromaMaterial.SetFloat("_AberrationOffset", ChromaticAbberation);
        }

        if (ScreenColor)
        {
            RenderTexture.ReleaseTemporary(ScreenColor);
        }
        if (HalfRez)
        {
            RenderTexture.ReleaseTemporary(HalfRez);
        }
        if (HalfRez2)
        {
            RenderTexture.ReleaseTemporary(HalfRez2);
        }
    }
Beispiel #16
0
 public Material GetBlurMaterial()
 {
     return(_blurMaterial ?? (_blurMaterial = BlurMaterial.CreateMaterial()));
 }