Пример #1
0
        private void dilateVelocity(fx_Quad quad, fx_Special special, Texture velocity_texture)
        {
            int blur_amount = 150;


            _pDilate.bind();
            GL.Uniform1(_pDilate.getUniform("blur_amount"), blur_amount);
            GL.Uniform2(_pDilate.getUniform("texture_size"), _tVelocity_1.dimensions.Xy);

            int fragmentation = 2;

            //------------------------------------------------------
            // Horizontal
            //------------------------------------------------------
            GL.Uniform1(_pDilate.getUniform("direction_selector"), 0);
            velocity_texture.bind(_pDilate.getSamplerUniform(0), 0);
            _tVelocity_2.bindImageUnit(_pDilate.getSamplerUniform(1), 1, TextureAccess.WriteOnly);

            GL.DispatchCompute((int)_tVelocity_1.dimensions.Y, fragmentation, 1);

            GL.MemoryBarrier(MemoryBarrierFlags.ShaderImageAccessBarrierBit);


            //------------------------------------------------------
            // Vertical
            //------------------------------------------------------
            GL.Uniform1(_pDilate.getUniform("direction_selector"), 1);
            _tVelocity_2.bind(_pDilate.getSamplerUniform(0), 0);
            _tVelocity_1.bindImageUnit(_pDilate.getSamplerUniform(1), 1, TextureAccess.WriteOnly);

            GL.DispatchCompute((int)_tVelocity_1.dimensions.X, fragmentation, 1);

            GL.MemoryBarrier(MemoryBarrierFlags.ShaderImageAccessBarrierBit);
        }
Пример #2
0
        public void render(fx_Quad quad, fx_Special special, Texture scene_texture, FrameBuffer scene_fbo, Matrix4 camera_matrix)
        {
            getBrightSpots(quad, scene_texture);

            genFlare(quad, special);
            genBloom(quad, special);

            blend(quad, scene_fbo, camera_matrix);
        }
Пример #3
0
        private void genBloom(fx_Quad quad, fx_Special special)
        {
            // Blur bloom texture at multiple levels of detail and combine for noice effect
            GL.Enable(EnableCap.Blend);
            GL.BlendEquation(BlendEquationMode.FuncAdd);
            GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One);

            special.blur_Gauss(quad, 40, _tBloom, _fLens, DrawBuffersEnum.ColorAttachment0, 1);
            special.blur_Gauss(quad, 40, _tBloom, _fLens, DrawBuffersEnum.ColorAttachment0, 0.5f);
            special.blur_Gauss(quad, 40, _tBloom, _fLens, DrawBuffersEnum.ColorAttachment0, 0.25f);
            special.blur_Gauss(quad, 40, _tBloom, _fLens, DrawBuffersEnum.ColorAttachment0, 0.125f);

            GL.Disable(EnableCap.Blend);
        }
Пример #4
0
        public void render(fx_Quad quad, fx_Special special, Texture depth_texture, FrameBuffer scene_fbo, Texture scene_texture)
        {
            autoFocus(depth_texture);

            //printFocusDistance();
            genCOC(quad, special, depth_texture);

            resetBokeh();
            extractBokeh(quad, depth_texture, scene_texture);
            //printBokehCount();
            genBokeh(depth_texture);

            genDOF(quad, depth_texture);
            blendDOF(quad, special, scene_fbo, scene_texture);
        }
Пример #5
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);
        }
Пример #6
0
        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();
        }
Пример #7
0
 public void render(fx_Quad quad, fx_Special special, FrameBuffer scene_fbo, Texture scene_texture, Texture depth_texture, Texture velocity_texture, float fps)
 {
     dilateVelocity(quad, special, velocity_texture);
     motionBlur(quad, scene_fbo, scene_texture, depth_texture, fps);
 }
Пример #8
0
        //------------------------------------------------------
        // 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();
        }