Esempio n. 1
0
 public Texture Render(Texture fromTexture, bool final = false)
 {
     if (!final)
     {
         fbo.Enable();
     }
     Graphics.TheGLTracking.SetShader(shader);
     fromTexture.Enable();
     shader.UniformMatrix("projection", matrix);
     shader.Uniformi("texture", 0);
     GL.Clear(ClearBufferMask.ColorBufferBit);
     bb.Draw();
     if (!final)
     {
         fbo.Disable();
     }
     return(DestTexture);
 }
Esempio n. 2
0
        /// <summary>
        /// Takes a function that draws the scene, and draws everything with the postprocessing pipeline.
        /// </summary>
        /// <param name="thunk">Thunk.</param>
        public void RenderWith(Action drawScene)
        {
            // Render initial scene to FBO
            fbo.Enable();
            GL.ClearColor(Color4.Black);
            GL.Clear(ClearBufferMask.ColorBufferBit);
            drawScene();
            fbo.Disable();

            var fromTexture = fboTexture;

            // Then we take the drawn scene and run it through each of the postprocessing steps.
            for (int i = 0; i < steps.Count - 1; i++)
            {
                var step          = steps[i];
                var resultTexture = step.Render(fromTexture, final: false);
                fromTexture = resultTexture;
            }
            // Then do the final rendering to the screen.
            steps[steps.Count - 1].Render(fromTexture, final: true);
        }
Esempio n. 3
0
        public Texture Render(Texture fromTexture, bool final = false)
        {
            const int convolutionRadius = 5;
            int       texels            = 512;

            // Do the first step of the separable convolution
            fbo1.Enable();
            fromTexture.Enable();
            Graphics.TheGLTracking.SetShader(hGlowShader);
            hGlowShader.UniformMatrix("projection", matrix);
            hGlowShader.Uniformi("texels", texels);
            hGlowShader.Uniformi("convolutionRadius", convolutionRadius);
            hGlowShader.Uniformi("texture", 0);
            GL.Clear(ClearBufferMask.ColorBufferBit);
            bb1.Draw();
            fbo1.Disable();

            // Do the second step of the separable convolution
            fbo2.Enable();
            Graphics.TheGLTracking.SetShader(vGlowShader);
            DestTexture1.Enable();
            vGlowShader.UniformMatrix("projection", matrix);
            vGlowShader.Uniformi("texels", texels);
            vGlowShader.Uniformi("convolutionRadius", convolutionRadius);
            vGlowShader.Uniformi("texture", 0);
            GL.Clear(ClearBufferMask.ColorBufferBit);
            bb2.Draw();
            fbo2.Disable();

            // Combine the blurred texture with the original texture again
            if (!final)
            {
                fbo1.Enable();
            }


            // Shady-ass multi-texturing
            var textures = new Texture[] {
                fromTexture,
                DestTexture2
            };

            Texture.EnableMultiple(textures);

            Graphics.TheGLTracking.SetShader(combineShader);
            combineShader.UniformMatrix("projection", matrix);
            combineShader.Uniformi("texture", 0);
            combineShader.Uniformi("glowTexture", 1);
            GL.Clear(ClearBufferMask.ColorBufferBit);
            bb3.Draw();
            //DestTexture2.Enable();
            //bb2.Draw();
            Texture.DisableMultiple(textures);

            if (!final)
            {
                fbo1.Disable();
            }

            return(DestTexture1);
        }