Exemplo n.º 1
0
        /// <summary>
        /// Hacer blur de bright-pass para generar efecto de bloom
        /// </summary>
        /// <param name="d3dDevice"></param>
        private void bloomPass(Device d3dDevice)
        {
            d3dDevice.BeginScene();

            //Gaussian blur horizontal
            Vector2[] texCoordOffsets;
            float[]   colorWeights;
            Surface   bloomTempS = bloomTempRT.GetSurfaceLevel(0);

            TgcPostProcessingUtils.computeGaussianBlurSampleOffsets15(bloomTempS.Description.Width, 1, 1, true, out texCoordOffsets, out colorWeights);
            effect.Technique = "BloomPass";
            effect.SetValue("texBloomRT", brightPassRT);
            d3dDevice.SetRenderTarget(0, bloomTempS);
            d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            screenQuad.render(effect);

            //Gaussian blur vertical
            TgcPostProcessingUtils.computeGaussianBlurSampleOffsets15(bloomTempS.Description.Height, 1, 1, false, out texCoordOffsets, out colorWeights);
            effect.Technique = "BloomPass";
            effect.SetValue("texBloomRT", bloomTempRT);
            effect.SetValue("gauss_offsets", TgcParserUtils.vector2ArrayToFloat2Array(texCoordOffsets));
            effect.SetValue("gauss_weights", colorWeights);
            Surface bloomS = bloomRT.GetSurfaceLevel(0);

            d3dDevice.SetRenderTarget(0, bloomS);
            d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            screenQuad.render(effect);

            bloomTempS.Dispose();
            bloomS.Dispose();
            d3dDevice.EndScene();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Se toma todo lo dibujado antes, que se guardo en una textura, y se le aplica un shader para borronear la imagen
        /// </summary>
        private void drawPostProcess(Device d3dDevice)
        {
            //Arrancamos la escena
            d3dDevice.BeginScene();

            //Ver si el efecto de oscurecer esta activado, configurar Technique del shader segun corresponda
            bool activar_efecto = (bool)GuiController.Instance.Modifiers["activar_efecto"];

            //Hacer blur
            if (activar_efecto)
            {
                float   deviation = (float)GuiController.Instance.Modifiers["deviation"];
                Surface blurTempS = blurTempRT.GetSurfaceLevel(0);

                //Gaussian blur horizontal
                Vector2[] texCoordOffsets;
                float[]   colorWeights;
                TgcPostProcessingUtils.computeGaussianBlurSampleOffsets15(blurTempS.Description.Width, deviation, 1, true, out texCoordOffsets, out colorWeights);
                effect.Technique = "GaussianBlurPass";
                effect.SetValue("texSceneRT", sceneRT);
                effect.SetValue("gauss_offsets", TgcParserUtils.vector2ArrayToFloat2Array(texCoordOffsets));
                effect.SetValue("gauss_weights", colorWeights);
                d3dDevice.SetRenderTarget(0, blurTempS);
                d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                screenQuad.render(effect);

                //Gaussian blur vertical
                TgcPostProcessingUtils.computeGaussianBlurSampleOffsets15(blurTempS.Description.Height, deviation, 1, false, out texCoordOffsets, out colorWeights);
                effect.Technique = "GaussianBlurPass";
                effect.SetValue("texSceneRT", blurTempRT);
                effect.SetValue("gauss_offsets", TgcParserUtils.vector2ArrayToFloat2Array(texCoordOffsets));
                effect.SetValue("gauss_weights", colorWeights);
                d3dDevice.SetRenderTarget(0, pOldRT);
                d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                screenQuad.render(effect);

                blurTempS.Dispose();
            }
            //No hacer blur
            else
            {
                effect.Technique = "DefaultTechnique";
                effect.SetValue("texSceneRT", sceneRT);
                d3dDevice.SetRenderTarget(0, pOldRT);
                d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                screenQuad.render(effect);
            }


            //Como estamos en modo CustomRenderEnabled, tenemos que dibujar todo nosotros, incluso el contador de FPS
            GuiController.Instance.Text3d.drawText("FPS: " + HighResolutionTimer.Instance.FramesPerSecond, 0, 0, Color.Yellow);

            //Tambien hay que dibujar el indicador de los ejes cartesianos
            GuiController.Instance.AxisLines.render();


            //Terminamos el renderizado de la escena
            d3dDevice.EndScene();
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Se toma todo lo dibujado antes, que se guardo en una textura, y se le aplica un shader para borronear la imagen
        /// </summary>
        private void drawPostProcess(Device d3dDevice)
        {
            //Arrancamos la escena
            d3dDevice.BeginScene();

            //Ver si el efecto de oscurecer esta activado, configurar Technique del shader segun corresponda
            var activar_efecto = (bool)Modifiers["activar_efecto"];

            //Hacer blur
            if (activar_efecto)
            {
                var deviation = (float)Modifiers["deviation"];
                var blurTempS = blurTempRT.GetSurfaceLevel(0);

                //Gaussian blur horizontal
                Vector2[] texCoordOffsets;
                float[]   colorWeights;
                TgcPostProcessingUtils.computeGaussianBlurSampleOffsets15(blurTempS.Description.Width, deviation, 1,
                                                                          true, out texCoordOffsets, out colorWeights);
                effect.Technique = "GaussianBlurPass";
                effect.SetValue("texSceneRT", sceneRT);
                effect.SetValue("gauss_offsets", TgcParserUtils.vector2ArrayToFloat2Array(texCoordOffsets));
                effect.SetValue("gauss_weights", colorWeights);
                d3dDevice.SetRenderTarget(0, blurTempS);
                d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                screenQuad.render(effect);

                //Gaussian blur vertical
                TgcPostProcessingUtils.computeGaussianBlurSampleOffsets15(blurTempS.Description.Height, deviation, 1,
                                                                          false, out texCoordOffsets, out colorWeights);
                effect.Technique = "GaussianBlurPass";
                effect.SetValue("texSceneRT", blurTempRT);
                effect.SetValue("gauss_offsets", TgcParserUtils.vector2ArrayToFloat2Array(texCoordOffsets));
                effect.SetValue("gauss_weights", colorWeights);
                d3dDevice.SetRenderTarget(0, pOldRT);
                d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                screenQuad.render(effect);

                blurTempS.Dispose();
            }
            //No hacer blur
            else
            {
                effect.Technique = "DefaultTechnique";
                effect.SetValue("texSceneRT", sceneRT);
                d3dDevice.SetRenderTarget(0, pOldRT);
                d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                screenQuad.render(effect);
            }

            //Terminamos el renderizado de la escena
            RenderFPS();
            RenderAxis();
            d3dDevice.EndScene();
            d3dDevice.Present();
        }