Esempio n. 1
0
        internal static pTexture CreateBlurTexture(pTexture texture, int radius, BlurType type)
        {
            if (!ConfigManager.sShaders || radius == 0 || texture.TextureGl.IsTransparent)
            {
                return(texture);
            }

            List <BlurTexturePair> currentCache = null;

            if (!blurCache.TryGetValue(texture, out currentCache))
            {
                currentCache = new List <BlurTexturePair>();
            }

            int currentIndex = currentCache.FindIndex(c => c.Radius == radius && c.Type == type);

            if (currentIndex != -1)
            {
                return(currentCache[currentIndex].Texture);
            }

            if (vShader == null || hShader == null)
            {
                Initialize();
            }

            vShader.Properties[@"texSize"] = hShader.Properties[@"texSize"] = new OpenTK.Vector2(texture.Width, texture.Height);

            using (RenderTarget2D target = new RenderTarget2D(texture.Width, texture.Height))
            {
                target.Bind();

                texture.TextureGl.Draw(Vector2.Zero, Vector2.Zero, Color.White, new Vector2(1, -1), 0, null);

                for (int i = 0; i < (int)type; i++)
                {
                    hShader.Begin();
                    hShader.Properties[@"radius"] = radius;
                    target.Texture.Draw(Vector2.Zero, Vector2.Zero, Color.White, new Vector2(1, -1), 0, null);
                    hShader.End();

                    vShader.Begin();
                    vShader.Properties[@"radius"] = radius;
                    target.Texture.Draw(Vector2.Zero, Vector2.Zero, Color.White, new Vector2(1, -1), 0, null);
                    vShader.End();
                }

                target.Unbind();

                target.Texture.WrapMode = texture.TextureGl.WrapMode; // We want to retain the wrap mode we had prior to blurring.
                pTexture newTex = new pTexture(target.Texture);

                currentCache.Add(new BlurTexturePair()
                {
                    Type = type, Radius = radius, Texture = newTex
                });
                blurCache[texture] = currentCache;
                return(newTex);
            }
        }
Esempio n. 2
0
        internal static void BloomEnd()
        {
            if (!(ConfigManager.sBloomSoftening || ExtraPass))
            {
                return;
            }
            renderTarget.Unbind();

#if !DEBUG
            try
            {
#endif
            // If we rendered everything to a frame buffer object, then we first need to blit it to the backbuffer.
            if (OsuGlControl.CanUseFBO)
            {
                OsuGlControl.SetBlend(BlendingFactorSrc.One, BlendingFactorDest.Zero);
                renderTarget.Texture.Draw(Vector2.Zero, Vector2.Zero, Color.White, new Vector2(1, -1), 0, null);
            }

            OsuGlControl.SetBlend(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            bloomShader.Begin();
            if (ConfigManager.sBloomSoftening)
            {
                bloomShader.Properties[@"mag"]     = 0.004f;
                bloomShader.Properties[@"alpha"]   = 0.15f;
                bloomShader.Properties[@"hirange"] = false;
                bloomShader.Properties[@"redtint"] = 0f;
                renderTarget.Texture.Draw(Vector2.Zero, Vector2.Zero, Color.White, new Vector2(1, -1), 0, null);
            }

            if (ExtraPass)
            {
                bloomShader.Properties[@"mag"]     = Magnitude;
                bloomShader.Properties[@"alpha"]   = Alpha;
                bloomShader.Properties[@"hirange"] = HiRange;
                bloomShader.Properties[@"redtint"] = RedTint;

                if (Additive)
                {
                    OsuGlControl.SetBlend(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.One);
                }

                renderTarget.Texture.Draw(Vector2.Zero, Vector2.Zero, Color.White, new Vector2(1, -1), 0, null);

                if (Additive)
                {
                    OsuGlControl.SetBlend(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                }
            }
            bloomShader.End();
#if !DEBUG
        }

        catch
        {
            //Todo:
        }
#endif
        }
Esempio n. 3
0
        /// <summary>
        /// Render a gradient into a 256x1 texture.
        /// </summary>
        private TextureGl RenderSliderTexture(Color shadow, Color border, Color InnerColour, Color OuterColour, float aa_width)
        {
            using (RenderTarget2D target = new RenderTarget2D(TEX_WIDTH, 1))
            {
                target.Bind();

                GL.Disable(EnableCap.DepthTest);
                GL.Disable(EnableCap.Blend);

                GL.ClearColor(0.859f, 0.439f, 0.576f, 1.0f);
                GL.Clear(ClearBufferMask.ColorBufferBit);
                GL.ClearColor(0, 0, 0, 0);

                OsuGlControl.ColourShader2D.Properties[@"g_ProjMatrix"] = OpenTK.Matrix4.CreateOrthographicOffCenter(0.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f);
                OsuGlControl.ColourShader2D.Begin();

                lineBatch.Add(new Vertex2d()
                {
                    Position = new Vector2(-0.5f, 0.0f), Colour = Color.TransparentBlack
                });
                lineBatch.Add(new Vertex2d()
                {
                    Position = new Vector2(0.0f, 0.0f), Colour = Color.TransparentBlack
                });

                lineBatch.Add(new Vertex2d()
                {
                    Position = new Vector2(0.078125f - aa_width, 0.0f), Colour = shadow
                });

                lineBatch.Add(new Vertex2d()
                {
                    Position = new Vector2(0.078125f + aa_width, 0.0f), Colour = border
                });
                lineBatch.Add(new Vertex2d()
                {
                    Position = new Vector2(0.1875f - aa_width, 0.0f), Colour = border
                });

                lineBatch.Add(new Vertex2d()
                {
                    Position = new Vector2(0.1875f + aa_width, 0.0f), Colour = OuterColour
                });

                lineBatch.Add(new Vertex2d()
                {
                    Position = new Vector2(1.0f, 0.0f), Colour = InnerColour
                });
                lineBatch.Add(new Vertex2d()
                {
                    Position = new Vector2(1.5f, 0.0f), Colour = InnerColour
                });

                lineBatch.Draw();

                OsuGlControl.ColourShader2D.End();
                OsuGlControl.ColourShader2D.Properties[@"g_ProjMatrix"] = OsuGlControl.ProjectionMatrix;

                if (!OsuGlControl.CanUseFBO)
                {
                    //We must re-clear the backbuffer
                    target.Unbind();
                    GL.Clear(ClearBufferMask.ColorBufferBit);
                }

                GL.Enable(EnableCap.Blend);

                return(target.Texture);
            }
        }