private void motionBlur(fx_Quad quad, FrameBuffer scene_fbo, Texture scene_texture, Texture depth_texture, float fps)
        {
            GL.Viewport(0, 0, _tFinal.width, _tFinal.height);

            _pBlur.bind();


            GL.Uniform1(_pBlur.getUniform("fps_scaler"), fps);


            // Velocity Texture
            _tVelocity_1.bind(_pBlur.getSamplerUniform(1), 1);

            // Depth Texture
            depth_texture.bind(_pBlur.getSamplerUniform(2), 2);


            //------------------------------------------------------
            // Pass 1
            //------------------------------------------------------
            _fFullResolution.bind(DrawBuffersEnum.ColorAttachment0);

            // Source Texture
            scene_texture.bind(_pBlur.getSamplerUniform(0), 0);

            quad.render();


            //------------------------------------------------------
            // Pass 2
            //------------------------------------------------------
            scene_fbo.bind(DrawBuffersEnum.ColorAttachment0);

            // Source Texture
            _tFinal.bind(_pBlur.getSamplerUniform(0), 0);

            quad.render();


            ////------------------------------------------------------
            //// Pass 3
            ////------------------------------------------------------
            //_fMotionBlur.bind(DrawBuffersEnum.ColorAttachment0);

            //// Source Texture
            //scene_texture.bind(_pBlur.getSamplerUniform(0), 0);

            //quad.render();


            ////------------------------------------------------------
            //// Pass 4
            ////------------------------------------------------------
            //scene_fbo.bind(DrawBuffersEnum.ColorAttachment0);

            //// Source Texture
            //_tFinal.bind(_pBlur.getSamplerUniform(0), 0);

            //quad.render();
        }
Beispiel #2
0
        private void blur_Gauss(
            fx_Quad quad,
            int blur_amount,
            Vector2 horizontal_mod, Vector2 vertical_mod,
            Texture texture_to_blur, FrameBuffer texture_frame_buffer, DrawBuffersEnum attachement,
            float destination_scale = 1)
        {
            _pBlur_Gauss.bind();


            GL.Uniform1(_pBlur_Gauss.getUniform("blur_amount"), blur_amount);


            Vector2 texture_to_blur_size = new Vector2(texture_to_blur.width, texture_to_blur.height) * destination_scale;

            Vector2 horizontal_texture_size = new Vector2(1.0f / texture_to_blur_size.X, 1.0f / texture_to_blur_size.Y);
            Vector2 vertical_texture_size   = new Vector2(1.0f / _tSpecial.width, 1.0f / _tSpecial.height);


            //------------------------------------------------------
            // Horizontal
            //------------------------------------------------------
            // Bind special texture and clear it
            clearAndBindSpecialFrameBuffer();
            GL.Viewport(0, 0, (int)texture_to_blur_size.X, (int)texture_to_blur_size.Y);

            GL.Uniform2(_pBlur_Gauss.getUniform("texture_size"), horizontal_mod * horizontal_texture_size);

            // Source
            texture_to_blur.bind(_pBlur_Gauss.getSamplerUniform(0), 0);

            quad.render();


            //------------------------------------------------------
            // Vertical
            //------------------------------------------------------

            // If client supplies framebuffer for desintation, use that. Otherwise attach destination to special framebuffer
            if (texture_frame_buffer.id != _fSpecial.id)
            {
                texture_frame_buffer.bind(attachement);
            }
            else
            {
                bindExternalTexture(texture_to_blur);
            }
            GL.Viewport(0, 0, (int)(_tSpecial.width / destination_scale), (int)(_tSpecial.height / destination_scale));



            GL.Uniform2(_pBlur_Gauss.getUniform("texture_size"), vertical_mod * vertical_texture_size);

            // Source
            _tSpecial.bind(_pBlur_Gauss.getSamplerUniform(0), 0);

            quad.render();
        }
Beispiel #3
0
        public void blur_Streak(
            fx_Quad quad,
            int blur_amount, float streak_angle,
            Texture texture_to_blur, FrameBuffer texture_frame_buffer, DrawBuffersEnum attachement,
            float destination_scale = 1)
        {
            _pBlur_Streak.bind();

            GL.Uniform1(_pBlur_Streak.getUniform("blur_amount"), blur_amount);
            Vector2 rotation_vector = EngineHelper.createRotationVector(streak_angle);


            Vector2 texture_to_blur_size     = new Vector2(texture_to_blur.width, texture_to_blur.height) * destination_scale;
            Vector2 destination_texture_size = new Vector2(1.0f / texture_to_blur_size.X, 1.0f / texture_to_blur_size.Y);
            Vector2 source_texture_size      = new Vector2(1.0f / _tSpecial.width, 1.0f / _tSpecial.height);

            //------------------------------------------------------
            // Iteration 1
            //------------------------------------------------------
            // Bind special texture and clear it
            clearAndBindSpecialFrameBuffer();
            GL.Viewport(0, 0, (int)texture_to_blur_size.X, (int)texture_to_blur_size.Y);


            GL.Uniform2(_pBlur_Streak.getUniform("size_and_direction"), rotation_vector * destination_texture_size);
            GL.Uniform1(_pBlur_Streak.getUniform("iteration"), 0);
            texture_to_blur.bind(_pBlur_Streak.getSamplerUniform(0), 0);

            quad.render();


            //------------------------------------------------------
            // Iteration 2
            //------------------------------------------------------
            // Bind special texture and clear it
            if (texture_frame_buffer.id != _fSpecial.id)
            {
                texture_frame_buffer.bind(attachement);
            }
            else
            {
                bindExternalTexture(texture_to_blur);
            }
            GL.Viewport(0, 0, (int)(_tSpecial.width / destination_scale), (int)(_tSpecial.height / destination_scale));


            GL.Uniform2(_pBlur_Streak.getUniform("size_and_direction"), rotation_vector * source_texture_size);
            GL.Uniform1(_pBlur_Streak.getUniform("iteration"), 1);
            _tSpecial.bind(_pBlur_Streak.getSamplerUniform(0), 0);


            quad.render();
        }
Beispiel #4
0
        public void render(fx_Quad quad)
        {
            GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, 0);
            GL.Clear(ClearBufferMask.ColorBufferBit);

            GL.Viewport(0, 0, _resolution.W, _resolution.H);

            _pFinalScene.bind();

            _tFinalScene.bind(_pFinalScene.getSamplerUniform(0), 0);

            quad.render();
        }
Beispiel #5
0
        private void getBrightSpots(fx_Quad quad, Texture scene_texture)
        {
            _fLens.bind(DrawBuffersEnum.ColorAttachment0);
            GL.Clear(ClearBufferMask.ColorBufferBit);
            GL.Viewport(0, 0, _tBloom.width, _tBloom.height);

            _pBrightSpots.bind();

            scene_texture.bind(_pBrightSpots.getSamplerUniform(0), 0);

            quad.render();

            _tBloom.generateMipMap();
        }
Beispiel #6
0
        private void genFlare(fx_Quad quad, fx_Special special)
        {
            _fLens.bind(DrawBuffersEnum.ColorAttachment1);
            GL.Clear(ClearBufferMask.ColorBufferBit);
            GL.Viewport(0, 0, _tFlare.width, _tFlare.height);

            _pFlare.bind();

            _tBloom.bind(_pFlare.getSamplerUniform(0), 0);
            _iLensColor.bind(_pFlare.getSamplerUniform(1), 1);

            quad.render();

            //special.blur_MovingAverage(15, _tFlare);
            special.blur_Gauss(quad, 75, _tFlare, _fLens, DrawBuffersEnum.ColorAttachment1);
        }
        public void pass_LightAccumulation(fx_Quad quad, Texture atmoshpere_texture, Texture indirect_texture, FrameBuffer fFinalScene)
        {
            fFinalScene.bind(DrawBuffersEnum.ColorAttachment0);
            GL.Clear(ClearBufferMask.ColorBufferBit);

            GL.Viewport(0, 0, _resolution.W, _resolution.H);

            _pAccumulation.bind();

            _tDiffuse_ID.bind(_pAccumulation.getSamplerUniform(0), 0);
            _tLighting_Diffuse.bind(_pAccumulation.getSamplerUniform(1), 1);
            _tLighting_Specular.bind(_pAccumulation.getSamplerUniform(2), 2);
            atmoshpere_texture.bind(_pAccumulation.getSamplerUniform(3), 3);
            indirect_texture.bind(_pAccumulation.getSamplerUniform(4), 4);

            quad.render();
        }
        private void blendDOF(fx_Quad quad, fx_Special special, FrameBuffer scene_fbo, Texture scene_texture)
        {
            GL.CopyImageSubData(scene_texture.id, ImageTarget.Texture2D, 0, 0, 0, 0,
                                special.tSpecial.id, ImageTarget.Texture2D, 0, 0, 0, 0,
                                _resolution.W, _resolution.H, 1);

            scene_fbo.bind(DrawBuffersEnum.ColorAttachment0);
            GL.Clear(ClearBufferMask.ColorBufferBit);
            GL.Viewport(0, 0, _resolution.W, _resolution.H);

            _pDOF_Blend.bind();

            special.tSpecial.bind(_pDOF_Blend.getSamplerUniform(0), 0);
            _tDOF_Scene.bind(_pDOF_Blend.getSamplerUniform(1), 1);
            _tCOC_Final.bind(_pDOF_Blend.getSamplerUniform(2), 2);
            _tBokeh_Points.bind(_pDOF_Blend.getSamplerUniform(3), 3);

            quad.render();
        }
Beispiel #9
0
        public void scaleScene(fx_Quad quad, FrameBuffer scene_fbo, Texture scene_texture)
        {
            // Copy scene texture to temporary texture so we can read and write to main scene texture
            GL.CopyImageSubData(scene_texture.id, ImageTarget.Texture2D, 0, 0, 0, 0,
                                _tTempScene.id, ImageTarget.Texture2D, 0, 0, 0, 0,
                                _resolution.W, _resolution.H, 1);

            scene_fbo.bind(DrawBuffersEnum.ColorAttachment0);
            GL.Clear(ClearBufferMask.ColorBufferBit);
            GL.Viewport(0, 0, _resolution.W, _resolution.H);

            _pScaleScene.bind();

            _tTempScene.bind(_pScaleScene.getSamplerUniform(0), 0);
            _ssboExposure.bind(0);

            quad.render();

            _ssboExposure.unbind(0);
        }
        private void extractBokeh(fx_Quad quad, Texture depth_texture, Texture scene_texture)
        {
            _fHalfResolution.bind(DrawBuffersEnum.ColorAttachment5);
            GL.Clear(ClearBufferMask.ColorBufferBit);
            GL.Viewport(0, 0, _tDOF_Scene.width, _tDOF_Scene.height);

            _pBokeh_Extract.bind();

            scene_texture.bind(_pBokeh_Extract.getSamplerUniform(0), 0);
            depth_texture.bind(_pBokeh_Extract.getSamplerUniform(1), 1);
            _tCOC_Final.bind(_pBokeh_Extract.getSamplerUniform(2), 2);

            _tBokeh_Positions.bindImageUnit(_pBokeh_Extract.getSamplerUniform(3), 3, TextureAccess.WriteOnly);
            _tBokeh_Colors.bindImageUnit(_pBokeh_Extract.getSamplerUniform(4), 4, TextureAccess.WriteOnly);

            GL.BindBufferRange(BufferRangeTarget.AtomicCounterBuffer, 0, _bokeh_indirect_buffer, (IntPtr)4, (IntPtr)sizeof(uint));
            GL.Uniform1(_pBokeh_Extract.getUniform("bokeh_counter"), 0);

            quad.render();

            GL.MemoryBarrier(MemoryBarrierFlags.AllBarrierBits);
        }
        public void precompute(fx_Quad quad)
        {
            if (_precomputed)
            {
                return;
            }

            _fPrecompute.bind(DrawBuffersEnum.ColorAttachment0);


            //------------------------------------------------------

            _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment0, _tTransmittance.id);
            GL.Viewport(0, 0, TRANSMITTANCE_W, TRANSMITTANCE_H);
            _pTransmittance.bind();
            quad.render();

            //------------------------------------------------------

            _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment0, _tDeltaE.id);
            GL.Viewport(0, 0, SKY_W, SKY_H);
            _pIrradiance1.bind();
            _tTransmittance.bind(_pIrradiance1.getUniform("transmittanceSampler"), 0);
            quad.render();

            //------------------------------------------------------

            _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment0, _tDeltaSR.id);
            _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment1, _tDeltaSM.id);
            _fPrecompute.bindAttachements(new DrawBuffersEnum[] {
                DrawBuffersEnum.ColorAttachment0,
                DrawBuffersEnum.ColorAttachment1
            });
            GL.Viewport(0, 0, RES_MU_S * RES_NU, RES_MU);
            _pInscatter1.bind();
            _tTransmittance.bind(_pInscatter1.getUniform("transmittanceSampler"), 0);
            for (int layer = 0; layer < RES_R; layer++)
            {
                setLayer(_pInscatter1, layer);
                quad.render();
            }
            _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment1, 0);
            _fPrecompute.bindAttachements(DrawBuffersEnum.ColorAttachment0);

            //------------------------------------------------------

            _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment0, _tIrradiance.id);
            GL.Viewport(0, 0, SKY_W, SKY_H);
            _pCopyIrradiance.bind();
            GL.Uniform1(_pCopyIrradiance.getUniform("k"), 0f);
            _tDeltaE.bind(_pCopyIrradiance.getUniform("deltaESampler"), 0);
            quad.render();

            //------------------------------------------------------

            _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment0, _tInscatter.id);
            GL.Viewport(0, 0, RES_MU_S * RES_NU, RES_MU);
            _pCopyInscatter1.bind();
            _tDeltaSR.bind(_pCopyInscatter1.getUniform("deltaSRSampler"), 0);
            _tDeltaSM.bind(_pCopyInscatter1.getUniform("deltaSMSampler"), 1);
            for (int layer = 0; layer < RES_R; layer++)
            {
                setLayer(_pCopyInscatter1, layer);
                quad.render();
            }

            //------------------------------------------------------

            for (int order = 2; order <= 4; order++)
            {
                //------------------------------------------------------

                _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment0, _tDeltaJ.id);
                GL.Viewport(0, 0, RES_MU_S * RES_NU, RES_MU);
                _pPJ.bind();
                GL.Uniform1(_pPJ.getUniform("first"), order == 2 ? 1f : 0f);
                _tTransmittance.bind(_pPJ.getUniform("transmittanceSampler"), 0);
                _tDeltaE.bind(_pPJ.getUniform("deltaESampler"), 1);
                _tDeltaSR.bind(_pPJ.getUniform("deltaSRSampler"), 2);
                _tDeltaSM.bind(_pPJ.getUniform("deltaSMSampler"), 3);
                for (int layer = 0; layer < RES_R; layer++)
                {
                    setLayer(_pPJ, layer);
                    quad.render();
                }

                //------------------------------------------------------

                _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment0, _tDeltaE.id);
                GL.Viewport(0, 0, SKY_W, SKY_H);
                _pIrradianceN.bind();
                GL.Uniform1(_pIrradianceN.getUniform("first"), order == 2 ? 1f : 0f);
                _tTransmittance.bind(_pIrradianceN.getUniform("transmittanceSampler"), 0);
                _tDeltaE.bind(_pIrradianceN.getUniform("deltaESampler"), 1);
                _tDeltaSR.bind(_pIrradianceN.getUniform("deltaSRSampler"), 2);
                _tDeltaSM.bind(_pIrradianceN.getUniform("deltaSMSampler"), 3);
                quad.render();

                //------------------------------------------------------

                _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment0, _tDeltaSR.id);
                GL.Viewport(0, 0, RES_MU_S * RES_NU, RES_MU);
                _pInscatterN.bind();
                GL.Uniform1(_pInscatterN.getUniform("first"), order == 2 ? 1f : 0f);
                _tTransmittance.bind(_pInscatterN.getUniform("transmittanceSampler"), 0);
                _tDeltaJ.bind(_pInscatterN.getUniform("deltaJSampler"), 1);
                for (int layer = 0; layer < RES_R; layer++)
                {
                    setLayer(_pInscatterN, layer);
                    quad.render();
                }

                //------------------------------------------------------
                //------------------------------------------------------

                GL.Enable(EnableCap.Blend);
                GL.BlendEquationSeparate(BlendEquationMode.FuncAdd, BlendEquationMode.FuncAdd);
                GL.BlendFuncSeparate(BlendingFactorSrc.One, BlendingFactorDest.One, BlendingFactorSrc.One, BlendingFactorDest.One);

                //------------------------------------------------------

                _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment0, _tIrradiance.id);
                GL.Viewport(0, 0, SKY_W, SKY_H);
                _pCopyIrradiance.bind();
                GL.Uniform1(_pCopyIrradiance.getUniform("k"), 1f);
                _tDeltaE.bind(_pCopyIrradiance.getUniform("deltaESampler"), 0);
                quad.render();

                //------------------------------------------------------

                _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment0, _tInscatter.id);
                GL.Viewport(0, 0, RES_MU_S * RES_NU, RES_MU);
                _pCopyInscatterN.bind();
                _tDeltaSR.bind(_pCopyInscatterN.getUniform("deltaSRSampler"), 0);
                for (int layer = 0; layer < RES_R; layer++)
                {
                    setLayer(_pCopyInscatterN, layer);
                    quad.render();
                }

                //------------------------------------------------------

                GL.Disable(EnableCap.Blend);

                //------------------------------------------------------
                //------------------------------------------------------
            }


            _precomputed = true;
        }
        //------------------------------------------------------
        // COC
        //------------------------------------------------------
        private void genCOC(fx_Quad quad, fx_Special special, Texture depth_texture)
        {
            //------------------------------------------------------
            // Calculate COC
            //------------------------------------------------------

            _fHalfResolution.bind(new DrawBuffersEnum[]
            {
                DrawBuffersEnum.ColorAttachment0,
                DrawBuffersEnum.ColorAttachment1,
                DrawBuffersEnum.ColorAttachment2
            });
            GL.Clear(ClearBufferMask.ColorBufferBit);
            GL.Viewport(0, 0, _tCOC.width, _tCOC.height);

            _pCOC.bind();


            _ssboAutoFocus.bind(0);
            depth_texture.bind(_pCOC.getSamplerUniform(0), 0);

            GL.Uniform1(_pCOC.getUniform("PPM"), _PPM);
            GL.Uniform1(_pCOC.getUniform("focus_length"), _focus_length);
            GL.Uniform1(_pCOC.getUniform("fStop"), _fStop);
            GL.Uniform1(_pCOC.getUniform("max_blur"), _max_blur);

            quad.render();

            special.blur_Gauss(quad, 60, _tCOC_Foreground_Blurred, _fHalfResolution, DrawBuffersEnum.ColorAttachment1);


            //------------------------------------------------------
            // Fix COC
            //------------------------------------------------------

            _fHalfResolution.bind(new DrawBuffersEnum[]
            {
                DrawBuffersEnum.ColorAttachment3,
            });
            GL.Clear(ClearBufferMask.ColorBufferBit);
            GL.Viewport(0, 0, _tCOC.width, _tCOC.height);

            _pCOC_Fix.bind();

            _tCOC_Foreground.bind(_pCOC_Fix.getSamplerUniform(0), 0);
            _tCOC_Foreground_Blurred.bind(_pCOC_Fix.getSamplerUniform(1), 1);

            quad.render();

            special.blur_Gauss(quad, 10, _tCOC_Foreground_Final, _fHalfResolution, DrawBuffersEnum.ColorAttachment3);


            //------------------------------------------------------
            // Combine COC
            //------------------------------------------------------
            _fFullResoution.bind(new DrawBuffersEnum[]
            {
                DrawBuffersEnum.ColorAttachment0,
            });
            GL.Clear(ClearBufferMask.ColorBufferBit);
            GL.Viewport(0, 0, _tCOC_Final.width, _tCOC_Final.height);

            _pCOC_Combine.bind();

            _tCOC.bind(_pCOC_Combine.getSamplerUniform(0), 0);
            _tCOC_Foreground_Final.bind(_pCOC_Combine.getSamplerUniform(1), 1);

            quad.render();
        }