예제 #1
0
        private void drawPostProcess(float elapsedTime, bool activado)
        {
            //Arrancamos la escena
            D3DDevice.Instance.Device.BeginScene();

            //Cargamos para renderizar el unico modelo que tenemos, un Quad que ocupa toda la pantalla, con la textura de todo lo dibujado antes
            D3DDevice.Instance.Device.VertexFormat = CustomVertex.PositionTextured.Format;
            D3DDevice.Instance.Device.SetStreamSource(0, screenQuadVB, 0);

            //Ver si el efecto de alarma esta activado, configurar Technique del shader segun corresponda
            if (activado)
            {
                efecto.Technique = "AlarmaTechnique";
            }
            else
            {
                efecto.Technique = "DefaultTechnique";
            }

            //Cargamos parametros en el shader de Post-Procesado
            efecto.SetValue("render_target2D", renderTarget2D);
            efecto.SetValue("textura_alarma", alarmTexture.D3dTexture);
            efecto.SetValue("alarmaScaleFactor", intVaivenAlarm.update(elapsedTime));

            //Limiamos la pantalla y ejecutamos el render del shader
            D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            efecto.Begin(FX.None);
            efecto.BeginPass(0);
            D3DDevice.Instance.Device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            efecto.EndPass();
            efecto.End();

            D3DDevice.Instance.Device.EndScene();
            D3DDevice.Instance.Device.Present();
        }
예제 #2
0
        public void animar(float ElapsedTime)
        {
            var move = new Vector3(esfera.Position.X, interpolador.update(ElapsedTime), esfera.Position.Z);

            esfera.Position            = move;
            esfera.AutoTransformEnable = true;
            esfera.updateValues();
        }
예제 #3
0
        public void Render()
        {
            Device.EndScene();
            Surf.Dispose();

            Device.SetRenderTarget(0, OldRenderTarget);
            Device.DepthStencilSurface = OldDepthStencil;

            Device.BeginScene();
            Device.VertexFormat = CustomVertex.PositionTextured.Format;

            Device.SetStreamSource(0, FullScreenQuad, 0);
            Effect.SetValue("render_target2D", RenderTarget2D);

            if (RenderTeleportEffect)
            {
                Effect.Technique = "Darken";
                Effect.SetValue("time", Time);
            }
            else
            {
                Time = 0;
                if (RenderAlarmEffect)
                {
                    Effect.Technique = "AlarmTechnique";
                    Effect.SetValue("alarmScaleFactor", IntVaivenAlarm.update(ElapsedTime));
                }
                else
                {
                    Effect.Technique = "DivingHelmet";
                }
            }

            if (RenderPDA)
            {
                Effect.Technique = "PDA";
            }

            Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1f, 0);

            Effect.Begin(FX.None);
            Effect.BeginPass(0);
            Device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            Effect.EndPass();
            Effect.End();
        }
예제 #4
0
        public static void RenderPostProcesado()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            // Devuelvo el render target original
            d3dDevice.SetRenderTarget(0, RenderTargetOriginal);

            // Cargo el quad
            d3dDevice.VertexFormat = CustomVertex.PositionTextured.Format;
            d3dDevice.SetStreamSource(0, ScreenQuad, 0);

            // Cargo los parametros al shader
            bool activar_efecto = (bool)GuiController.Instance.Modifiers["lluvia"];

            if (activar_efecto)
            {
                float  time         = (float)GuiController.Instance.UserVars.getValue("time");
                Random random       = new Random();
                int    randomNumber = random.Next(0, 10);

                if (time % 5 > 4 && randomNumber > 5)
                {
                    Shader.Technique = "RayoTechnique";
                }
                else
                {
                    Shader.Technique = "DefaultTechnique";
                }
            }
            else
            {
                Shader.Technique = "DefaultTechnique";
            }

            //Cargamos parametros en el shader de Post-Procesado
            Shader.SetValue("render_target2D", RenderTargetPostprocesado);
            Shader.SetValue("scaleFactor", intVaivenOscurecer.update());
            // Hago el postprocesado propiamente dicho
            d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            Shader.Begin(FX.None);
            Shader.BeginPass(0);
            d3dDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            Shader.EndPass();
            Shader.End();
        }
예제 #5
0
        /// <summary>
        ///     Se toma todo lo dibujado antes, que se guardo en una textura, y se le aplica un shader para oscurecer la imagen
        /// </summary>
        private void drawPostProcess(Device d3dDevice, float elapsedTime)
        {
            //Arrancamos la escena
            d3dDevice.BeginScene();

            //Cargamos para renderizar el unico modelo que tenemos, un Quad que ocupa toda la pantalla, con la textura de todo lo dibujado antes
            d3dDevice.VertexFormat = CustomVertex.PositionTextured.Format;
            d3dDevice.SetStreamSource(0, screenQuadVB, 0);

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

            if (activar_efecto)
            {
                effect.Technique = "OscurecerTechnique";
            }
            else
            {
                effect.Technique = "DefaultTechnique";
            }

            //Cargamos parametros en el shader de Post-Procesado
            effect.SetValue("render_target2D", renderTarget2D);
            effect.SetValue("scaleFactor", intVaivenOscurecer.update(elapsedTime));

            //Limiamos la pantalla y ejecutamos el render del shader
            d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            effect.Begin(FX.None);
            effect.BeginPass(0);
            d3dDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            effect.EndPass();
            effect.End();

            //Terminamos el renderizado de la escena
            RenderFPS();
            RenderAxis();
            d3dDevice.EndScene();
            d3dDevice.Present();
        }
예제 #6
0
        public override void Render()
        {
            PreRender();

            //Habilitar luz
            var    lightEnable = (bool)Modifiers["lightEnable"];
            Effect currentShader;
            string currentTechnique;

            if (lightEnable)
            {
                //Shader personalizado de iluminacion
                currentShader    = effect;
                currentTechnique = "MultiDiffuseLightsTechnique";
            }
            else
            {
                //Sin luz: Restaurar shader default
                currentShader    = TgcShaders.Instance.TgcMeshShader;
                currentTechnique = TgcShaders.Instance.getTgcMeshTechnique(TgcMesh.MeshRenderType.DIFFUSE_MAP);
            }

            //Aplicar a cada mesh el shader actual
            foreach (var mesh in scene.Meshes)
            {
                mesh.Effect    = currentShader;
                mesh.Technique = currentTechnique;
            }

            //Configurar los valores de cada luz
            var move = new Vector3(0, 0,
                                   (bool)Modifiers["lightMove"] ? interp.update(ElapsedTime) : 0);
            var lightColors           = new ColorValue[lightMeshes.Length];
            var pointLightPositions   = new Vector4[lightMeshes.Length];
            var pointLightIntensity   = new float[lightMeshes.Length];
            var pointLightAttenuation = new float[lightMeshes.Length];

            for (var i = 0; i < lightMeshes.Length; i++)
            {
                var lightMesh = lightMeshes[i];
                lightMesh.Position = origLightPos[i] + Vector3.Scale(move, i + 1);

                lightColors[i]           = ColorValue.FromColor(lightMesh.Color);
                pointLightPositions[i]   = TgcParserUtils.vector3ToVector4(lightMesh.Position);
                pointLightIntensity[i]   = (float)Modifiers["lightIntensity"];
                pointLightAttenuation[i] = (float)Modifiers["lightAttenuation"];
            }

            //Renderizar meshes
            foreach (var mesh in scene.Meshes)
            {
                mesh.UpdateMeshTransform();
                if (lightEnable)
                {
                    //Cargar variables de shader
                    mesh.Effect.SetValue("lightColor", lightColors);
                    mesh.Effect.SetValue("lightPosition", pointLightPositions);
                    mesh.Effect.SetValue("lightIntensity", pointLightIntensity);
                    mesh.Effect.SetValue("lightAttenuation", pointLightAttenuation);
                    mesh.Effect.SetValue("materialEmissiveColor",
                                         ColorValue.FromColor((Color)Modifiers["mEmissive"]));
                    mesh.Effect.SetValue("materialDiffuseColor",
                                         ColorValue.FromColor((Color)Modifiers["mDiffuse"]));
                }

                //Renderizar modelo
                mesh.render();
            }

            //Renderizar meshes de luz
            for (var i = 0; i < lightMeshes.Length; i++)
            {
                var lightMesh = lightMeshes[i];
                lightMesh.render();
            }

            PostRender();
        }
예제 #7
0
        /// <summary>
        /// Render del oceano y su shader.
        /// </summary>
        public static void Render()
        {
            if (!ParametrosDeConfiguracion.RenderOceano)
            {
                return;
            }

            Device d3dDevice = GuiController.Instance.D3dDevice;

            bool culling = ParametrosDeConfiguracion.VerFrustumCulling;

            if (culling)
            {
                // cargo la camara fps para hacer el culling en base al frustum de esa camara
                GuiController.Instance.ThirdPersonCamera.Enable = false;
                GuiController.Instance.FpsCamera.Enable         = true;
                GuiController.Instance.FpsCamera.setCamera(Barco.mesh.Position, Barco.vDireccion * GuiController.Instance.Frustum.FarPlane.D);
                GuiController.Instance.CurrentCamera.updateCamera();
                GuiController.Instance.CurrentCamera.updateViewMatrix(d3dDevice);
                GuiController.Instance.Frustum.updateVolume(d3dDevice.Transform.View, d3dDevice.Transform.Projection);
            }

            // Especificar formato de triangulos
            d3dDevice.VertexFormat = CustomVertex.PositionNormalTextured.Format;
            d3dDevice.SetStreamSource(0, _vertexBuffer, 0);

            // Almacenar información en IndexBuffer
            var listaIndices      = QuadTree.IndiceVerticesVisibles();
            var cantidadDeIndices = listaIndices.Count;

            if (cantidadDeIndices != 0)
            {
                var indexBuffer = new IndexBuffer(typeof(int), sizeof(int) * cantidadDeIndices, d3dDevice, Usage.Dynamic | Usage.WriteOnly, Pool.Default);
                indexBuffer.SetData(listaIndices.ToArray(), 0, LockFlags.None);
                d3dDevice.Indices = indexBuffer;
            }

            if (culling)
            {
                // vuelvo a cargar la camara en 3ra persona
                GuiController.Instance.ThirdPersonCamera.Enable = true;
                GuiController.Instance.FpsCamera.Enable         = false;
                GuiController.Instance.CurrentCamera.updateCamera();
                GuiController.Instance.CurrentCamera.updateViewMatrix(d3dDevice);
            }

            // Cargamos parametros en el shader

            // Matrices de transformacion para pasar de world a clip space
            PerlinShader.SetValue("world", GuiController.Instance.D3dDevice.Transform.World);
            PerlinShader.SetValue("view", GuiController.Instance.D3dDevice.Transform.View);
            PerlinShader.SetValue("proj", GuiController.Instance.D3dDevice.Transform.Projection);

            // Propiedades del Sol (posicion, shiness, strength)
            PerlinShader.SetValue("sun_vec", new Vector4(Sol.Posicion.X, Sol.Posicion.Y, Sol.Posicion.Z, 0.0f));
            PerlinShader.SetValue("sun_shininess", 4 * ParametrosDeConfiguracion.Sol.Shininess);
            PerlinShader.SetValue("sun_strength", ParametrosDeConfiguracion.Sol.Strength);

            // Valores de Enviroment Mapping
            PerlinShader.SetValue("reflrefr_offset", ParametrosDeConfiguracion.Agua.ReflRefrOffset);
            PerlinShader.SetValue("LODbias", ParametrosDeConfiguracion.p_fLODbias);
            Vector3 posCamara = GuiController.Instance.CurrentCamera.getPosition();

            PerlinShader.SetValue("view_position", new Vector4(posCamara.X, posCamara.Y, posCamara.Z, 1));
            PerlinShader.SetValue("EnvironmentMap", SkyDome.Textura);
            PerlinShader.SetValue("FresnelMap", surf_fresnel);
            PerlinShader.SetValue("Refractionmap", surf_refraction);
            PerlinShader.SetValue("Reflectionmap", surf_reflection);

            // Dimensiones del Oceano
            PerlinShader.SetValue("radio", RADIO);
            PerlinShader.SetValue("largo", LARGO);
            PerlinShader.SetValue("dev", DISTANCIA_ENTRE_VERTICES);

            // periodo del día, para saber si reflejar el sol o la luna
            PerlinShader.SetValue("noche", ParametrosDeConfiguracion.EsDeNoche);

            // Caso particular para placas que no tengan texture lookup de
            // cualquier textura se usa el formato particular A32B32G32R32F.
            if (ParametrosDeConfiguracion.TexturaA32B32G32R32F)
            {
                textPerlinNoise1 = TextureLoader.FromFile(d3dDevice, Utiles.TexturasDir("PerlinNoiseHeightmap1.png"), 0, 0, 1, 0,
                                                          Format.A32B32G32R32F, Pool.Managed, Filter.Point, Filter.Point, Color.Black.ToArgb());
                textPerlinNoise2 = TextureLoader.FromFile(d3dDevice, Utiles.TexturasDir("PerlinNoiseHeightmap2.png"), 0, 0, 1, 0,
                                                          Format.A32B32G32R32F, Pool.Managed, Filter.Point, Filter.Point, Color.Black.ToArgb());
            }
            else
            {
                // Setea las texturas de acuerdo a las octavas seleccionadas en el combo.
                switch (ParametrosDeConfiguracion.Agua.Octavas)
                {
                case 2:
                    textPerlinNoise1 = textPerlinNoise1_2Octavas;
                    textPerlinNoise2 = textPerlinNoise2_2Octavas;
                    PerlinNoise1     = PerlinNoise1_2Octavas;
                    PerlinNoise2     = PerlinNoise2_2Octavas;
                    break;

                case 4:
                    textPerlinNoise1 = textPerlinNoise1_4Octavas;
                    textPerlinNoise2 = textPerlinNoise2_4Octavas;
                    PerlinNoise1     = PerlinNoise1_4Octavas;
                    PerlinNoise2     = PerlinNoise2_4Octavas;
                    break;

                case 8:
                    textPerlinNoise1 = textPerlinNoise1_8Octavas;
                    textPerlinNoise2 = textPerlinNoise2_8Octavas;
                    PerlinNoise1     = PerlinNoise1_8Octavas;
                    PerlinNoise2     = PerlinNoise2_8Octavas;
                    break;
                }
            }

            // Texturas que representan los heightmaps
            PerlinShader.SetValue("perlinNoise1", textPerlinNoise1);
            PerlinShader.SetValue("perlinNoise2", textPerlinNoise2);

            // Parametros para el movimiento del oceano
            Desplazamiento += GuiController.Instance.ElapsedTime;
            PerlinShader.SetValue("desplazamiento", Desplazamiento);
            PerlinShader.SetValue("maxHeightSuperficial", ParametrosDeConfiguracion.Agua.AlturaSuperficieal);
            PerlinShader.SetValue("amplitud", ParametrosDeConfiguracion.Agua.Amplitud);
            PerlinShader.SetValue("frecuencia", ParametrosDeConfiguracion.Agua.Frecuencia);
            PerlinShader.SetValue("smallvalue", ParametrosDeConfiguracion.Agua.DistanciaEntreNormales);

            // Niebla
            PerlinShader.SetValue("FogActiva", ParametrosDeConfiguracion.Niebla);
            ColorValue fogcolor = Utiles.CamaraSumergida ? ColorValue.FromColor(ParametrosDeConfiguracion.Agua.Color) : ColorValue.FromColor(Color.DarkGray);

            PerlinShader.SetValue("FogColor", fogcolor);
            PerlinShader.SetValue("FogStart", Niebla.START);
            PerlinShader.SetValue("FogEnd", Niebla.END);

            // Colorear el oceano bajo la moneda
            Vector4 moneda_pos = new Vector4(Juego.Moneda.Position.X, Juego.Moneda.Position.Y, Juego.Moneda.Position.Z, 1);

            PerlinShader.SetValue("moneda_pos", moneda_pos);

            // Posicion de la isla para atenuacion de las olas
            PerlinShader.SetValue("isla_pos", new Vector4(Isla.Posicion.X, Isla.Posicion.Y, Isla.Posicion.Z, 1));


            // Parametro de animacion del movimiento superficial
            // para interpolar entre los dos heightmaps de perlin noise
            interpoladorPerlinNoiseHeightmaps.update();
            PerlinShader.SetValue("alpha", interpoladorPerlinNoiseHeightmaps.Current);

            // Aplico el effect
            if (ParametrosDeConfiguracion.Shader)
            {
                PerlinShader.Begin(FX.None);
                PerlinShader.BeginPass(0);
            }

            // Dibuja la superficie
            d3dDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, CANTIDAD_DE_VERTICES, 0, cantidadDeIndices / 3);

            // Fin del effect
            if (ParametrosDeConfiguracion.Shader)
            {
                PerlinShader.EndPass();
                PerlinShader.End();
            }
        }
예제 #8
0
        public override void render(float elapsedTime)
        {
            Device device = GuiController.Instance.D3dDevice;

            //Habilitar luz
            bool   lightEnable = (bool)GuiController.Instance.Modifiers["lightEnable"];
            Effect currentShader;
            String currentTechnique;

            if (lightEnable)
            {
                //Shader personalizado de iluminacion
                currentShader    = this.effect;
                currentTechnique = "MultiDiffuseLightsTechnique";
            }
            else
            {
                //Sin luz: Restaurar shader default
                currentShader    = GuiController.Instance.Shaders.TgcMeshShader;
                currentTechnique = GuiController.Instance.Shaders.getTgcMeshTechnique(TgcMesh.MeshRenderType.DIFFUSE_MAP);
            }

            //Aplicar a cada mesh el shader actual
            foreach (TgcMesh mesh in scene.Meshes)
            {
                mesh.Effect    = currentShader;
                mesh.Technique = currentTechnique;
            }



            //Configurar los valores de cada luz
            Vector3 move = new Vector3(0, 0, ((bool)GuiController.Instance.Modifiers["lightMove"]) ? interp.update() : 0);

            ColorValue[] lightColors           = new ColorValue[lightMeshes.Length];
            Vector4[]    pointLightPositions   = new Vector4[lightMeshes.Length];
            float[]      pointLightIntensity   = new float[lightMeshes.Length];
            float[]      pointLightAttenuation = new float[lightMeshes.Length];
            for (int i = 0; i < lightMeshes.Length; i++)
            {
                TgcBox lightMesh = lightMeshes[i];
                lightMesh.Position = origLightPos[i] + Vector3.Scale(move, i + 1);

                lightColors[i]           = ColorValue.FromColor(lightMesh.Color);
                pointLightPositions[i]   = TgcParserUtils.vector3ToVector4(lightMesh.Position);
                pointLightIntensity[i]   = (float)GuiController.Instance.Modifiers["lightIntensity"];
                pointLightAttenuation[i] = (float)GuiController.Instance.Modifiers["lightAttenuation"];
            }


            //Renderizar meshes
            foreach (TgcMesh mesh in scene.Meshes)
            {
                if (lightEnable)
                {
                    //Cargar variables de shader
                    mesh.Effect.SetValue("lightColor", lightColors);
                    mesh.Effect.SetValue("lightPosition", pointLightPositions);
                    mesh.Effect.SetValue("lightIntensity", pointLightIntensity);
                    mesh.Effect.SetValue("lightAttenuation", pointLightAttenuation);
                    mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mEmissive"]));
                    mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mDiffuse"]));
                }

                //Renderizar modelo
                mesh.render();
            }


            //Renderizar meshes de luz
            for (int i = 0; i < lightMeshes.Length; i++)
            {
                TgcBox lightMesh = lightMeshes[i];
                lightMesh.render();
            }
        }