예제 #1
0
        public override void Process(int width, int height, GLTextuer2D tex, GLTextuer2D output)
        {
            base.Process(width, height, tex, output);

            if (shader != null)
            {
                Vector2 tiling = new Vector2(TileX, TileY);

                //by using the boxes for gaussian we can produce a more realisitc motion blur
                //then simply using a standard box blur alone (aka a non linear motion blur)
                float[] boxes = Materia.Nodes.Helpers.Blur.BoxesForGaussian(Magnitude, 3);

                shader.Use();
                shader.SetUniform2("tiling", ref tiling);
                shader.SetUniform("width", (float)width);
                shader.SetUniform("height", (float)height);

                //the direction to blur in
                shader.SetUniform("tx", (float)Math.Cos(Direction));
                shader.SetUniform("ty", -(float)Math.Sin(Direction));

                //intensity / magnitude of motion blur
                shader.SetUniform("magnitude", (boxes[0] - 1.0f) / 2.0f);
                shader.SetUniform("MainTex", 0);
                GL.ActiveTexture(TextureUnit.Texture0);
                tex.Bind();

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();

                for (int i = 1; i < 3; i++)
                {
                    shader.SetUniform("magnitude", (boxes[i] - 1.0f) / 2.0f);
                    GL.ActiveTexture(TextureUnit.Texture0);
                    output.Bind();

                    GL.Clear(ClearBufferMask.DepthBufferBit);
                    GL.Clear(ClearBufferMask.ColorBufferBit);

                    if (renderQuad != null)
                    {
                        renderQuad.Draw();
                    }

                    GLTextuer2D.Unbind();

                    output.Bind();
                    output.CopyFromFrameBuffer(width, height);
                    GLTextuer2D.Unbind();
                }
            }
        }
예제 #2
0
        public void Process(int width, int height, GLTextuer2D output)
        {
            CreateBuffersIfNeeded();

            if (Mesh != null)
            {
                //bind our depth framebuffer
                frameBuff.Bind();
                GL.Viewport(0, 0, width, height);
                GL.ClearColor(0, 0, 0, 0);
                GL.Clear(ClearBufferMask.DepthBufferBit);
                GL.Clear(ClearBufferMask.ColorBufferBit);

                //draw in depth
                Mesh.DrawForDepth();

                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();

                GLFrameBuffer.Unbind();
            }

            Process(width, height, output, output);

            if (shader != null)
            {
                Vector2 tiling = new Vector2(TileX, TileY);

                shader.Use();
                shader.SetUniform2("tiling", ref tiling);

                shader.SetUniform("MainTex", 0);
                GL.ActiveTexture(TextureUnit.Texture0);
                output.Bind();

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();

                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();
            }
        }
예제 #3
0
        public override void Process(int width, int height, GLTextuer2D tex, GLTextuer2D output)
        {
            base.Process(width, height, tex, output);

            if (shader != null)
            {
                Vector3 min    = Min;
                Vector3 max    = Max;
                Vector3 mid    = Mid;
                Vector2 tiling = new Vector2(TileX, TileY);

                shader.Use();
                shader.SetUniform2("tiling", ref tiling);
                shader.SetUniform("MainTex", 0);
                GL.ActiveTexture(TextureUnit.Texture0);
                tex.Bind();
                shader.SetUniform3("maxValues", ref max);
                shader.SetUniform3("minValues", ref min);
                shader.SetUniform3("midValues", ref mid);

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();
            }
        }
예제 #4
0
        public override void Process(int width, int height, GLTextuer2D tex, GLTextuer2D output)
        {
            base.Process(width, height, tex, output);

            if (shader != null)
            {
                Matrix3 rot = Rotation;
                Matrix3 sc  = Scale;
                Vector3 tr  = Translation;

                Vector2 tiling = new Vector2(TileX, TileY);

                shader.Use();
                shader.SetUniform2("tiling", ref tiling);
                shader.SetUniform("MainTex", 0);
                GL.ActiveTexture(TextureUnit.Texture0);
                tex.Bind();
                shader.SetUniformMatrix3("rotation", ref rot);
                shader.SetUniformMatrix3("scale", ref sc);
                shader.SetUniform3("translation", ref tr);

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();
            }
        }
예제 #5
0
        public override void Process(int width, int height, GLTextuer2D tex, GLTextuer2D output)
        {
            base.Process(width, height, tex, output);

            if (shader != null)
            {
                ResizeViewTo(tex, output, tex.Width, tex.Height, width, height);
                tex = output;
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                Vector2 tiling = new Vector2(TileX, TileY);
                shader.Use();
                shader.SetUniform2("tiling", ref tiling);
                shader.SetUniform("MainTex", 0);
                GL.ActiveTexture(TextureUnit.Texture0);
                tex.Bind();

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();
            }
        }
예제 #6
0
        public void Process(int width, int height, GLTextuer2D blur, GLTextuer2D orig, GLTextuer2D output)
        {
            base.Process(width, height, blur, output);

            if (shader != null)
            {
                Vector2 tiling = new Vector2(TileX, TileY);

                shader.Use();
                shader.SetUniform2("tiling", ref tiling);
                shader.SetUniform("MainTex", 0);
                GL.ActiveTexture(TextureUnit.Texture0);
                blur.Bind();
                shader.SetUniform("Original", 1);
                GL.ActiveTexture(TextureUnit.Texture1);
                orig.Bind();

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();
            }
        }
예제 #7
0
        protected void ResizeViewTo(GLTextuer2D inc, GLTextuer2D o, int owidth, int oheight, int nwidth, int nheight)
        {
            float wp = (float)nwidth / (float)owidth;
            float hp = (float)nheight / (float)oheight;

            float fp = wp < hp ? wp : hp;

            Matrix4 proj        = Matrix4.CreateOrthographic(nwidth, nheight, 0.03f, 1000f);
            Matrix4 translation = Matrix4.CreateTranslation(0, 0, 0);
            //half width/height for scale as it is centered based
            Matrix4 sm    = Matrix4.CreateScale(fp * (float)(owidth * 0.5f), -fp * (float)(oheight * 0.5f), 1);
            Matrix4 model = sm * translation;
            Matrix4 view  = Matrix4.LookAt(new Vector3(0, 0, 1), Vector3.Zero, Vector3.UnitY);

            resizeProcessor.Model      = model;
            resizeProcessor.View       = view;
            resizeProcessor.Projection = proj;

            resizeProcessor.Bind(inc);

            if (renderQuad != null)
            {
                renderQuad.Draw();
            }

            resizeProcessor.Unbind();

            o.Bind();
            o.CopyFromFrameBuffer(nwidth, nheight);
            GLTextuer2D.Unbind();
        }
예제 #8
0
        public override void Process(int width, int height, GLTextuer2D tex, GLTextuer2D output)
        {
            base.Process(width, height, tex, output);

            if (shader != null)
            {
                Vector2 tiling = new Vector2(TileX, TileY);

                Vector4 w = Weight;
                shader.Use();
                shader.SetUniform2("tiling", ref tiling);
                shader.SetUniform("MainTex", 0);
                shader.SetUniform4F("weight", ref w);
                GL.ActiveTexture(TextureUnit.Texture0);
                tex.Bind();

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();
            }
        }
예제 #9
0
        public override void Process(int width, int height, GLTextuer2D tex, GLTextuer2D output)
        {
            base.Process(width, height, tex, output);

            if (shader != null)
            {
                Vector2 tiling = new Vector2(TileX, TileY);

                shader.Use();
                shader.SetUniform2("tiling", ref tiling);
                shader.SetUniform("MainTex", 0);
                shader.SetUniform("width", (float)width);
                shader.SetUniform("height", (float)height);
                shader.SetUniform("azimuth", Azimuth);
                shader.SetUniform("elevation", Elevation);
                GL.ActiveTexture(0);
                tex.Bind();

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();
            }
        }
예제 #10
0
        public void Process(int width, int height, GLTextuer2D tex, GLTextuer2D other, GLTextuer2D output)
        {
            base.Process(width, height, tex, output);

            if (shader != null)
            {
                Vector2 tiling = new Vector2(TileX, TileY);

                shader.Use();
                shader.SetUniform2("tiling", ref tiling);

                shader.SetUniform("redChannel", RedChannel);
                shader.SetUniform("greenChannel", GreenChannel);
                shader.SetUniform("blueChannel", BlueChannel);
                shader.SetUniform("alphaChannel", AlphaChannel);

                shader.SetUniform("MainTex", 0);
                GL.ActiveTexture(TextureUnit.Texture0);
                tex.Bind();
                shader.SetUniform("Other", 1);
                GL.ActiveTexture(TextureUnit.Texture1);
                other.Bind();

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();
            }
        }
예제 #11
0
        public override void Process(int width, int height, GLTextuer2D tex, GLTextuer2D output)
        {
            base.Process(width, height, tex, output);

            if (shader != null)
            {
                Vector2 tiling = new Vector2(TileX, TileY);

                shader.Use();
                shader.SetUniform2("tiling", ref tiling);
                shader.SetUniform("width", (float)width);
                shader.SetUniform("height", (float)height);
                shader.SetUniform("radius", Radius);
                shader.SetUniform("outline", Outline);

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();
            }
        }
예제 #12
0
        public void Process(int width, int height, GLTextuer2D tex, GLTextuer2D warp, GLTextuer2D output)
        {
            base.Process(width, height, tex, output);

            if (shader != null)
            {
                Vector2 tiling = new Vector2(TileX, TileY);

                shader.Use();
                shader.SetUniform2("tiling", ref tiling);
                shader.SetUniform("MainTex", 0);
                shader.SetUniform("intensity", Intensity);
                GL.ActiveTexture(TextureUnit.Texture0);
                tex.Bind();
                shader.SetUniform("Warp", 1);
                GL.ActiveTexture(TextureUnit.Texture1);
                warp.Bind();

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();
            }
        }
예제 #13
0
        public override void Process(int width, int height, GLTextuer2D tex, GLTextuer2D output)
        {
            base.Process(width, height, tex, output);

            if (shader != null)
            {
                Vector2 tiling = new Vector2(TileX, TileY);

                shader.Use();
                shader.SetUniform("MainTex", 0);
                shader.SetUniform2("tiling", ref tiling);
                shader.SetUniform("invertRed", Red);
                shader.SetUniform("invertGreen", Green);
                shader.SetUniform("invertBlue", Blue);
                shader.SetUniform("invertAlpha", Alpha);

                GL.ActiveTexture(TextureUnit.Texture0);
                tex.Bind();

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();
            }
        }
예제 #14
0
        public void Process(int width, int height, GLTextuer2D tex, GLTextuer2D other, GLTextuer2D output)
        {
            base.Process(width, height, tex, output);

            if (shader != null)
            {
                GLTextuer2D tempColor = new GLTextuer2D(PixelInternalFormat.Rgba);
                tempColor.Bind();
                tempColor.SetFilter((int)TextureMinFilter.Linear, (int)TextureMagFilter.Linear);
                GLTextuer2D.Unbind();

                ResizeViewTo(tex, tempColor, tex.Width, tex.Height, width, height);
                tex = tempColor;
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                ResizeViewTo(other, output, other.Width, other.Height, width, height);
                other = output;
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);


                Vector2 tiling = new Vector2(TileX, TileY);

                shader.Use();
                shader.SetUniform2("tiling", ref tiling);

                shader.SetUniform("redChannel", RedChannel);
                shader.SetUniform("greenChannel", GreenChannel);
                shader.SetUniform("blueChannel", BlueChannel);
                shader.SetUniform("alphaChannel", AlphaChannel);

                shader.SetUniform("MainTex", 0);
                GL.ActiveTexture(TextureUnit.Texture0);
                tex.Bind();
                shader.SetUniform("Other", 1);
                GL.ActiveTexture(TextureUnit.Texture1);
                other.Bind();

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();
                tempColor.Release();
            }
        }
예제 #15
0
        public void Process(int width, int height, GLTextuer2D blur, GLTextuer2D orig, GLTextuer2D output)
        {
            base.Process(width, height, blur, output);

            if (shader != null)
            {
                GLTextuer2D tempColor = new GLTextuer2D(PixelInternalFormat.Rgba);
                tempColor.Bind();
                tempColor.SetFilter((int)TextureMinFilter.Linear, (int)TextureMagFilter.Linear);
                GLTextuer2D.Unbind();

                ResizeViewTo(blur, tempColor, blur.Width, blur.Height, width, height);
                blur = tempColor;
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                ResizeViewTo(orig, output, orig.Width, orig.Height, width, height);
                orig = output;
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                Vector2 tiling = new Vector2(TileX, TileY);

                shader.Use();
                shader.SetUniform2("tiling", ref tiling);
                shader.SetUniform("MainTex", 0);
                GL.ActiveTexture(TextureUnit.Texture0);
                blur.Bind();
                shader.SetUniform("Original", 1);
                GL.ActiveTexture(TextureUnit.Texture1);
                orig.Bind();

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();
                tempColor.Release();
            }
        }
예제 #16
0
        public void Process(int width, int height, GLTextuer2D tex, GLTextuer2D tex2, GLTextuer2D mask, GLTextuer2D output)
        {
            base.Process(width, height, tex, output);

            if (shader != null)
            {
                Vector2 tiling = new Vector2(TileX, TileY);

                shader.Use();
                shader.SetUniform2("tiling", ref tiling);
                shader.SetUniform("Foreground", 0);
                GL.ActiveTexture(TextureUnit.Texture0);
                tex.Bind();
                shader.SetUniform("Background", 1);
                GL.ActiveTexture(TextureUnit.Texture1);
                tex2.Bind();
                shader.SetUniform("blendMode", BlendMode);
                shader.SetUniform("alpha", Alpha);

                if (mask != null)
                {
                    shader.SetUniform("Mask", 2);
                    GL.ActiveTexture(TextureUnit.Texture2);
                    shader.SetUniform("hasMask", 1);
                    mask.Bind();
                }
                else
                {
                    shader.SetUniform("hasMask", 0);
                }

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();
            }
        }
예제 #17
0
        public override void Process(int width, int height, GLTextuer2D tex, GLTextuer2D output)
        {
            base.Process(width, height, tex, output);

            if (shader != null)
            {
                Vector2 tiling = new Vector2(TileX, TileY);
                Vector4 color  = Color;
                shader.Use();
                shader.SetUniform2("tiling", ref tiling);
                shader.SetUniform4F("color", ref color);

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();
            }
        }
예제 #18
0
        public void Process(int width, int height, GLTextuer2D tex, GLTextuer2D tex2, GLTextuer2D output)
        {
            base.Process(width, height, tex, output);

            if (Shader != null)
            {
                Vector2 tiling = new Vector2(TileX, TileY);
                Shader.Use();
                Shader.SetUniform2("tiling", ref tiling);
                Shader.SetUniform("Input0", 0);
                GL.ActiveTexture(TextureUnit.Texture0);

                if (tex != null)
                {
                    tex.Bind();
                }

                Shader.SetUniform("Input1", 1);
                GL.ActiveTexture(TextureUnit.Texture1);

                if (tex2 != null)
                {
                    tex2.Bind();
                }

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();
            }
        }
예제 #19
0
        /// <summary>
        /// This would be too slow for real time performance at 60fps
        /// but since we are not doing 60fps it is fine
        /// it is a fast box gaussian blur
        /// produces results better than adobes gaussian blur
        /// and faster than theirs!
        /// can easily blur 4kx4k textures in low ms on a 1080 gtx gpu with 64+ intensity
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="tex"></param>
        /// <param name="output"></param>
        public override void Process(int width, int height, GLTextuer2D tex, GLTextuer2D output)
        {
            base.Process(width, height, tex, output);

            if (shader != null)
            {
                Vector2 tiling = new Vector2(TileX, TileY);
                float[] boxes  = Materia.Nodes.Helpers.Blur.BoxesForGaussian(Intensity, 3);

                shader.Use();
                shader.SetUniform2("tiling", ref tiling);
                shader.SetUniform("MainTex", 0);
                shader.SetUniform("horizontal", true);
                shader.SetUniform("intensity", (boxes[0] - 1.0f) / 2.0f);
                GL.ActiveTexture(TextureUnit.Texture0);
                tex.Bind();

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();

                shader.SetUniform("horizontal", false);
                GL.ActiveTexture(TextureUnit.Texture0);
                output.Bind();

                GL.Clear(ClearBufferMask.ColorBufferBit);
                GL.Clear(ClearBufferMask.DepthBufferBit);

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();

                //begin second box
                shader.SetUniform("horizontal", true);
                shader.SetUniform("intensity", (boxes[1] - 1.0f) / 2.0f);
                GL.ActiveTexture(TextureUnit.Texture0);
                output.Bind();

                GL.Clear(ClearBufferMask.ColorBufferBit);
                GL.Clear(ClearBufferMask.DepthBufferBit);

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();

                shader.SetUniform("horizontal", false);
                shader.SetUniform("intensity", (boxes[1] - 1.0f) / 2.0f);
                GL.ActiveTexture(TextureUnit.Texture0);
                output.Bind();

                GL.Clear(ClearBufferMask.ColorBufferBit);
                GL.Clear(ClearBufferMask.DepthBufferBit);

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();

                //begin third box
                shader.SetUniform("horizontal", true);
                shader.SetUniform("intensity", (boxes[2] - 1.0f) / 2.0f);
                GL.ActiveTexture(TextureUnit.Texture0);
                output.Bind();

                GL.Clear(ClearBufferMask.ColorBufferBit);
                GL.Clear(ClearBufferMask.DepthBufferBit);

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();

                shader.SetUniform("horizontal", false);
                shader.SetUniform("intensity", (boxes[2] - 1.0f) / 2.0f);
                GL.ActiveTexture(TextureUnit.Texture0);
                output.Bind();

                GL.Clear(ClearBufferMask.ColorBufferBit);
                GL.Clear(ClearBufferMask.DepthBufferBit);

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();
            }
        }
예제 #20
0
        public void Process(int width, int height, GLTextuer2D tex, GLTextuer2D tex2, GLTextuer2D mask, GLTextuer2D output)
        {
            base.Process(width, height, tex, output);

            if (shader != null)
            {
                GLTextuer2D tempColor  = new GLTextuer2D(PixelInternalFormat.Rgba);
                GLTextuer2D tempColor2 = new GLTextuer2D(PixelInternalFormat.Rgba);

                tempColor.Bind();
                tempColor.SetFilter((int)TextureMinFilter.Linear, (int)TextureMagFilter.Linear);
                GLTextuer2D.Unbind();
                tempColor2.Bind();
                tempColor2.SetFilter((int)TextureMinFilter.Linear, (int)TextureMagFilter.Linear);
                GLTextuer2D.Unbind();

                ResizeViewTo(tex, tempColor, tex.Width, tex.Height, width, height);
                tex = tempColor;
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                ResizeViewTo(tex2, tempColor2, tex2.Width, tex2.Height, width, height);
                tex2 = tempColor2;
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                if (mask != null)
                {
                    ResizeViewTo(mask, output, mask.Width, mask.Height, width, height);
                    mask = output;
                    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                }

                Vector2 tiling = new Vector2(TileX, TileY);

                shader.Use();
                shader.SetUniform2("tiling", ref tiling);
                shader.SetUniform("Foreground", 0);
                GL.ActiveTexture(TextureUnit.Texture0);
                tex.Bind();
                shader.SetUniform("Background", 1);
                GL.ActiveTexture(TextureUnit.Texture1);
                tex2.Bind();
                shader.SetUniform("blendMode", BlendMode);
                shader.SetUniform("alpha", Alpha);

                if (mask != null)
                {
                    shader.SetUniform("Mask", 2);
                    GL.ActiveTexture(TextureUnit.Texture2);
                    shader.SetUniform("hasMask", 1);
                    mask.Bind();
                }
                else
                {
                    shader.SetUniform("hasMask", 0);
                }

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();

                tempColor.Release();
                tempColor2.Release();
            }
        }
예제 #21
0
        /// <summary>
        /// This would be too slow for real time performance at 60fps
        /// but since we are not doing 60fps it is fine
        /// it is a fast box gaussian blur
        /// produces results better than adobes gaussian blur
        /// and faster than theirs!
        /// can easily blur 4kx4k textures in low ms on a 1080 gtx gpu with 64+ intensity
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="tex"></param>
        /// <param name="output"></param>
        public override void Process(int width, int height, GLTextuer2D tex, GLTextuer2D output)
        {
            base.Process(width, height, tex, output);

            colorBuff.Bind();
            colorBuff.ClampToEdge();
            GLTextuer2D.Unbind();

            if (shader != null)
            {
                ResizeViewTo(tex, output, tex.Width, tex.Height, width, height);
                tex = output;
                IGL.Primary.Clear((int)(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit));

                Vector2 tiling = new Vector2(TileX, TileY);
                float[] boxes  = Materia.Nodes.Helpers.Blur.BoxesForGaussian(Intensity, 3);

                shader.Use();
                shader.SetUniform2("tiling", ref tiling);
                shader.SetUniform("MainTex", 0);
                shader.SetUniform("horizontal", true);
                shader.SetUniform("intensity", (boxes[0] - 1.0f) / 2.0f);
                IGL.Primary.ActiveTexture((int)TextureUnit.Texture0);
                tex.Bind();

                //clamp to prevent blur wrap
                tex.ClampToEdge();

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();

                /*output.Bind();
                 * output.CopyFromFrameBuffer(width, height);
                 * GLTextuer2D.Unbind();*/
                Blit(output, width, height);

                tex.Bind();
                tex.Repeat();
                GLTextuer2D.Unbind();

                shader.SetUniform("horizontal", false);
                IGL.Primary.ActiveTexture((int)TextureUnit.Texture0);
                output.Bind();

                //clamp to prevent blur wrap
                output.ClampToEdge();

                IGL.Primary.Clear((int)ClearBufferMask.ColorBufferBit);
                IGL.Primary.Clear((int)ClearBufferMask.DepthBufferBit);

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();

                /*output.Bind();
                 * output.CopyFromFrameBuffer(width, height);
                 * GLTextuer2D.Unbind();*/
                Blit(output, width, height);

                //begin second box
                shader.SetUniform("horizontal", true);
                shader.SetUniform("intensity", (boxes[1] - 1.0f) / 2.0f);
                IGL.Primary.ActiveTexture((int)TextureUnit.Texture0);
                output.Bind();

                IGL.Primary.Clear((int)ClearBufferMask.ColorBufferBit);
                IGL.Primary.Clear((int)ClearBufferMask.DepthBufferBit);

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();
                output.Bind();
                output.CopyFromFrameBuffer(width, height);
                GLTextuer2D.Unbind();

                shader.SetUniform("horizontal", false);
                shader.SetUniform("intensity", (boxes[1] - 1.0f) / 2.0f);
                IGL.Primary.ActiveTexture((int)TextureUnit.Texture0);
                output.Bind();

                IGL.Primary.Clear((int)ClearBufferMask.ColorBufferBit);
                IGL.Primary.Clear((int)ClearBufferMask.DepthBufferBit);

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();

                /*output.Bind();
                 * output.CopyFromFrameBuffer(width, height);
                 * GLTextuer2D.Unbind();
                 */

                Blit(output, width, height);

                //begin third box
                shader.SetUniform("horizontal", true);
                shader.SetUniform("intensity", (boxes[2] - 1.0f) / 2.0f);
                IGL.Primary.ActiveTexture((int)TextureUnit.Texture0);
                output.Bind();

                IGL.Primary.Clear((int)ClearBufferMask.ColorBufferBit);
                IGL.Primary.Clear((int)ClearBufferMask.DepthBufferBit);

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();

                /*output.Bind();
                 * output.CopyFromFrameBuffer(width, height);
                 * GLTextuer2D.Unbind();
                 */

                Blit(output, width, height);

                shader.SetUniform("horizontal", false);
                shader.SetUniform("intensity", (boxes[2] - 1.0f) / 2.0f);
                IGL.Primary.ActiveTexture((int)TextureUnit.Texture0);
                output.Bind();

                IGL.Primary.Clear((int)ClearBufferMask.ColorBufferBit);
                IGL.Primary.Clear((int)ClearBufferMask.DepthBufferBit);

                if (renderQuad != null)
                {
                    renderQuad.Draw();
                }

                GLTextuer2D.Unbind();

                /*output.Bind();
                 * output.CopyFromFrameBuffer(width, height);
                 * GLTextuer2D.Unbind();*/
                Blit(output, width, height);
            }

            output.Bind();
            output.Repeat();
            GLTextuer2D.Unbind();

            colorBuff.Bind();
            colorBuff.Repeat();
            GLTextuer2D.Unbind();
        }