Exemple #1
0
        public void Init()
        {
            //seteamos atributos particulares de las naves
            health       = 50;
            score        = 2;
            tiempoMuerte = 5f;
            Device d3dDevice = GuiController.Instance.D3dDevice;

            MESH_SCALE     = 0.5f;
            attackDamage   = 50;
            MOVEMENT_SPEED = 225f;
            //cargamos el mesh
            //las naves no tienen skeletalMesh
            this.mesh = GameManager.Instance.ModeloNave.clone("Nave");


            SPAWN_HEIGHT = 1000f;
            giroInicial  = Matrix.RotationY(0);

            //realizamos el init() comun a todos los enemigos
            base.Init();

            mesh.Effect    = GameManager.Instance.envMap;
            mesh.Technique = "SimpleEnvironmentMapTechnique";
            mesh.Effect.SetValue("lightColor", ColorValue.FromColor(Color.White));
            mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(new Vector3(0, 1400, 0)));
            mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(CustomFpsCamera.Instance.getPosition()));
            mesh.Effect.SetValue("lightIntensity", 0.3f);
            mesh.Effect.SetValue("lightAttenuation", 1.0f);
            mesh.Effect.SetValue("reflection", 0.65f);

            //Cargar variables de shader de Material. El Material en realidad deberia ser propio de cada mesh. Pero en este ejemplo se simplifica con uno comun para todos
            mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Black));
            mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White));
            mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White));
            mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.White));
            mesh.Effect.SetValue("materialSpecularExp", 9);

            mesh.Effect.SetValue("texCubeMap", GameManager.Instance.cubeMap);

            //creamos las boundingbox
            //a pesar de que las naves no tienen legs ni head, le seteamos boxes "vacias" para no tener problemas con Excepciones de null
            HEADSHOT_BOUNDINGBOX = new TgcBoundingBox();
            CHEST_BOUNDINGBOX    = this.mesh.BoundingBox.clone();
            LEGS_BOUNDINGBOX     = new TgcBoundingBox();
            //carga de sonido
            SonidoMovimiento             = new Tgc3dSound(GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Audio\\Robot\\ufoHum.wav", getPosicionActual());
            SonidoMovimiento.MinDistance = 130f;
            SonidoMovimiento.play(true);
        }
Exemple #2
0
 public override void Iluminar(Efecto efecto, Vector3 posicionVision, ColorValue colorEmisor,
     ColorValue colorAmbiente,
     ColorValue colorDifuso, ColorValue colorEspecular, float especularEx)
 {
     efecto.GetEfectoShader().SetValue("lightColor", ColorValue.FromColor(Color.LightYellow));
     efecto.GetEfectoShader().SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(Mesh.Position));
     efecto.GetEfectoShader().SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(posicionVision));
     efecto.GetEfectoShader().SetValue("lightIntensity", 100f);
     efecto.GetEfectoShader().SetValue("lightAttenuation", 0.5f);
     efecto.GetEfectoShader().SetValue("materialEmissiveColor", colorEmisor);
     efecto.GetEfectoShader().SetValue("materialAmbientColor", colorAmbiente);
     efecto.GetEfectoShader().SetValue("materialDiffuseColor", colorDifuso);
     efecto.GetEfectoShader().SetValue("materialSpecularColor", colorEspecular);
     efecto.GetEfectoShader().SetValue("materialSpecularExp", especularEx);
 }
        public override void Render()
        {
            PreRender();

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

            if (lightEnable)
            {
                //Con luz: Cambiar el shader actual por el shader default que trae el framework para iluminacion dinamica con PhongShading
                currentShader = TgcShaders.Instance.TgcMeshPhongShader;
            }
            else
            {
                //Sin luz: Restaurar shader default
                currentShader = TgcShaders.Instance.TgcMeshShader;
            }

            //Aplicar al mesh el shader actual
            mesh.Effect = currentShader;
            //El Technique depende del tipo RenderType del mesh
            mesh.Technique = TgcShaders.Instance.getTgcMeshTechnique(mesh.RenderType);

            //Actualzar posición de la luz
            var lightPos = (Vector3)Modifiers["lightPos"];

            lightMesh.Position = lightPos;

            if (lightEnable)
            {
                //Cargar variables shader
                mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(lightPos));
                mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(Camara.Position));
                mesh.Effect.SetValue("ambientColor", ColorValue.FromColor((Color)Modifiers["ambient"]));
                mesh.Effect.SetValue("diffuseColor", ColorValue.FromColor((Color)Modifiers["diffuse"]));
                mesh.Effect.SetValue("specularColor", ColorValue.FromColor((Color)Modifiers["specular"]));
                mesh.Effect.SetValue("specularExp", (float)Modifiers["specularEx"]);
            }

            //Renderizar modelo
            mesh.render();

            //Renderizar mesh de luz
            lightMesh.render();

            PostRender();
        }
Exemple #4
0
        /// <summary>
        ///     Este metodo esta horrible ya que todas las luces utilizan los parametros de la primera, solo aportan su posición.
        ///     Los parámetros deberían se de cada luz.
        ///     Por el momento no es tan grave ya que solo puedo crear luces con fuegos.
        ///     Soporta un máximo de 4 luces
        /// </summary>
        /// <param name="contexto"></param>
        /// <param name="terreno"></param>
        public override void ActualizarRenderizar(SuvirvalCraft contexto, Terreno terreno)
        {
            if (HayQueIluminarConElementos(contexto))
            {
                var elem = GetElementosIluminacion()[0];
                if (GetElementosIluminacion().Count > 1)
                {
                    var elem2 = GetElementosIluminacion()[1];
                    GetEfectoShader().SetValue("segundaLuz", 1);
                    GetEfectoShader()
                    .SetValue("lightPosition2", TgcParserUtils.vector3ToFloat4Array(elem2.Elemento.posicion()));
                }
                if (GetElementosIluminacion().Count > 2)
                {
                    var elem3 = GetElementosIluminacion()[2];
                    GetEfectoShader().SetValue("terceraLuz", 1);
                    GetEfectoShader()
                    .SetValue("lightPosition3", TgcParserUtils.vector3ToFloat4Array(elem3.Elemento.posicion()));
                }
                if (GetElementosIluminacion().Count > 3)
                {
                    var elem4 = GetElementosIluminacion()[3];
                    GetEfectoShader().SetValue("cuartaLuz", 1);
                    GetEfectoShader()
                    .SetValue("lightPosition4", TgcParserUtils.vector3ToFloat4Array(elem4.Elemento.posicion()));
                }

                //Setea primero aquellos parámetros que son propios del efecto en cuestión.
                GetEfectoShader().SetValue("time", contexto.tiempo);
                GetEfectoShader().SetValue("lightIntensityRelitive", 0.5f);
                elem.Iluminar(this, contexto.personaje.mesh.Position, ColorValue.FromColor(Color.White),
                              ColorValue.FromColor(Color.White),
                              ColorValue.FromColor(Color.White), ColorValue.FromColor(Color.White), 20);
                terreno.executeRender(GetEfectoShader());
            }
            else
            {
                GetEfectoShader().SetValue("time", contexto.tiempo);
                GetEfectoShader().SetValue("lightIntensityRelitive", contexto.dia.GetSol().IntensidadRelativa());
                contexto.dia.GetSol()
                .Iluminar(contexto.personaje.mesh.Position, this, ColorValue.FromColor(Color.White),
                          ColorValue.FromColor(Color.White),
                          ColorValue.FromColor(Color.White), ColorValue.FromColor(Color.White), 20);
                terreno.executeRender(GetEfectoShader());
            }
        }
Exemple #5
0
        public LuzNormal(Vector3 pos)
        {
            d3dDevice = GuiController.Instance.D3dDevice;
            time      = 2;
            string alumnoMediaFolder = GuiController.Instance.AlumnoEjemplosDir;
            var    loader            = new TgcSceneLoader();

            antorcha       = loader.loadSceneFromFile(alumnoMediaFolder + "CucarachaJugosita\\Media\\Antorcha-TgcScene.xml");
            efectoAntorcha = TgcShaders.loadEffect(alumnoMediaFolder + "CucarachaJugosita\\efectoAntorcha.fx");
            //efectoAntorcha.Technique = "MoverAntorcha";
            mesh          = antorcha.Meshes[0];
            mesh.Position = pos;
            Posicion      = pos;
            mesh.Effect   = efectoAntorcha;
            mesh.Effect.SetValue("posMesh", TgcParserUtils.vector3ToFloat4Array(mesh.Position));
            mesh.Technique = GuiController.Instance.Shaders.getTgcMeshTechnique(mesh.RenderType);
        }
        public override void Render()
        {
            PreRender();

            //Actualzar posicion de la luz
            var lightPos = (Vector3)Modifiers["lightPos"];

            lightMesh.Position = lightPos;
            var eyePosition = Camara.Position;

            //Renderizar meshes
            foreach (var mesh in meshes)
            {
                //Cargar variables shader de la luz
                mesh.Effect.SetValue("lightColor",
                                     ColorValue.FromColor((Color)Modifiers["lightColor"]));
                mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(lightPos));
                mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(eyePosition));
                mesh.Effect.SetValue("lightIntensity", (float)Modifiers["lightIntensity"]);
                mesh.Effect.SetValue("lightAttenuation", (float)Modifiers["lightAttenuation"]);
                mesh.Effect.SetValue("bumpiness", (float)Modifiers["bumpiness"]);
                mesh.Effect.SetValue("reflection", (float)Modifiers["reflection"]);

                //Material
                mesh.Effect.SetValue("materialEmissiveColor",
                                     ColorValue.FromColor((Color)Modifiers["mEmissive"]));
                mesh.Effect.SetValue("materialAmbientColor",
                                     ColorValue.FromColor((Color)Modifiers["mAmbient"]));
                mesh.Effect.SetValue("materialDiffuseColor",
                                     ColorValue.FromColor((Color)Modifiers["mDiffuse"]));
                mesh.Effect.SetValue("materialSpecularColor",
                                     ColorValue.FromColor((Color)Modifiers["mSpecular"]));
                mesh.Effect.SetValue("materialSpecularExp", (float)Modifiers["specularEx"]);

                //CubeMap
                mesh.Effect.SetValue("texCubeMap", cubeMap);

                //Renderizar modelo
                mesh.render();
            }

            //Renderizar mesh de luz
            lightMesh.render();

            PostRender();
        }
Exemple #7
0
        public void Play(Single deltaTime)
        {
            _GraphsConfig();
            _LvlHack();
            var level = _Levels[_LevelIndex];

            if (level == null)
            {
                _BlackQuad.render();
                _LoadSign.Render();
                _LoadWord.Render();
                for (int i = 0; i < 6; i++)
                {
                    _LoadingAnimations[i].Update(deltaTime);
                    _LoadingAnimations[i].Render();
                }
                return;
            }
            var input = GuiController.Instance.D3dInput;

            if (level.IsComplete)
            {
                if (input.keyDown(Key.R))
                {
                    level.RollBack();
                }
                else if (input.keyDown(Key.Return))
                {
                    _SetLevel(_NextIndex);
                }
            }
            else
            {
                level.Play(deltaTime);
            }
            level.SetCamera();
            _LightShader.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(level.LightPosition));
            _LightShader.SetValue("lightIntensity", level.LightIntensity);
            _LightShader.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White));
            _LightShader.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White));
            _LightShader.SetValue("materialSpecularColor", ColorValue.FromColor(Color.White));
            level.Render(IsToonShaderEnabled ? _ToonShader : _LightShader);
            //level.Render(_ToonShader);
            //level.Render(_LightShader);
        }
Exemple #8
0
        /// <summary>
        /// Dibujamos toda la escena pero en vez de a la pantalla, la dibujamos al Render Target con floating point.
        /// De esa forma todos los calculos de iluminacion que superen 1.0 no son clampeados
        /// </summary>
        private void drawSceneToRenderTarget(Device d3dDevice)
        {
            Surface pSurf = sceneRT.GetSurfaceLevel(0);

            d3dDevice.SetRenderTarget(0, pSurf);
            d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);

            //Arrancamos el renderizado
            d3dDevice.BeginScene();

            //Actualzar posición de la luz
            Vector3 lightPos = (Vector3)GuiController.Instance.Modifiers["lightPos"];

            lightMesh.Position = lightPos;

            //Dibujar mesh de fuente de luz
            lightMesh.Effect.Technique = "DrawLightSource";
            lightMesh.render();

            //Renderizar meshes
            foreach (TgcMesh mesh in meshes)
            {
                mesh.Effect.Technique = "LightPass";

                //Cargar variables shader de la luz
                mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(lightPos));
                mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(GuiController.Instance.FpsCamera.getPosition()));
                mesh.Effect.SetValue("lightIntensity", (float)GuiController.Instance.Modifiers["lightIntensity"]);

                //Cargar variables de shader de Material
                mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.DarkGray));
                mesh.Effect.SetValue("materialSpecularExp", 9f);

                //Renderizar modelo
                mesh.render();
            }


            //Renderizar mesh de luz
            lightMesh.render();


            d3dDevice.EndScene();
            pSurf.Dispose();
        }
Exemple #9
0
        public void renderLight(float elapsedTime, List <Luz> luces, Vector3 cameraPosition)
        {
            //Configurar los valores de cada luz
            ColorValue[] lightColors           = new ColorValue[luces.Count];
            Vector4[]    pointLightPositions   = new Vector4[luces.Count];
            float[]      pointLightIntensity   = new float[luces.Count];
            float[]      pointLightAttenuation = new float[luces.Count];

            for (int i = 0; i < luces.Count; i++)
            {
                Luz lightMesh = luces[i];
                lightColors[i]         = ColorValue.FromColor(lightMesh.Color);
                pointLightPositions[i] = TgcParserUtils.vector3ToVector4(lightMesh.Posicion);
                //pointLightIntensity[i] = (float)GuiController.Instance.Modifiers["lightIntensity"];
                //pointLightAttenuation[i] = (float)GuiController.Instance.Modifiers["lightAttenuation"];
                pointLightIntensity[i]   = 50;
                pointLightAttenuation[i] = 20;
            }

            //Cargar variables de shader
            this.lightEffect.SetValue("lightColor", lightColors);
            this.lightEffect.SetValue("lightPosition", pointLightPositions);
            this.lightEffect.SetValue("lightIntensity", pointLightIntensity);
            this.lightEffect.SetValue("lightAttenuation", pointLightAttenuation);
            this.lightEffect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(cameraPosition));

            //Cargar variables de shader de Material. El Material en realidad deberia ser propio de cada mesh. Pero en este ejemplo se simplifica con uno comun para todos
            this.lightEffect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Black));
            this.lightEffect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White));
            this.lightEffect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White));
            this.lightEffect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.White));
            this.lightEffect.SetValue("materialSpecularExp", 20f);

            Effect originalEffect    = this.sphere.Effect;
            string originalTechnique = this.sphere.Technique;

            this.sphere.Effect = this.lightEffect;
            //El Technique depende del tipo RenderType del mesh "VERTEX_COLOR"; "DIFFUSE_MAP";
            this.sphere.Technique = "DIFFUSE_MAP";

            this.render();

            this.sphere.Effect    = originalEffect;
            this.sphere.Technique = originalTechnique;
        }
        private void setEffects(Vector3 camPos, TgcMesh mesh)
        {
            mesh.Effect    = currentShader;
            mesh.Technique = TgcShaders.Instance.getTgcMeshTechnique(mesh.RenderType);

            //2seteo valores
            mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Black));
            mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White));
            mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White));
            mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.White));
            mesh.Effect.SetValue("materialSpecularExp", 9f);

            //3 seteo variables

            mesh.Effect.SetValue("lightColor", ColorValue.FromColor(Color.White));
            mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(lighthPos));
            mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(camPos));
            mesh.Effect.SetValue("lightIntensity", lightIntensity);
            mesh.Effect.SetValue("lightAttenuation", 0.2f);
        }
Exemple #11
0
        public override void aplicarEfecto(TgcSkeletalMesh mesh, Vector3 posicionCamara, Vector3 direccionLuz)
        {
            mesh.Effect = TgcShaders.Instance.TgcSkeletalMeshPointLightShader;
            //El Technique depende del tipo RenderType del mesh
            mesh.Technique = "DIFFUSE_MAP";
            mesh.Effect.SetValue("lightColor", ColorValue.FromColor(Color.FromArgb(0, 255, 207, 46)));
            mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(posicionCamara));
            mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(posicionCamara));
            mesh.Effect.SetValue("lightIntensity", Energia);
            mesh.Effect.SetValue("lightAttenuation", 0.005f);
            mesh.Effect.SetValue("spotLightAngleCos", FastMath.ToRad(30f));
            mesh.Effect.SetValue("spotLightExponent", 15f);
            mesh.Effect.SetValue("spotLightDir", TgcParserUtils.vector3ToFloat3Array(direccionLuz));

            //Cargar variables de shader de Material. El Material en realidad deberia ser propio de cada mesh. Pero en este ejemplo se simplifica con uno comun para todos
            mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Black));
            mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.FromArgb(0, 255, 207, 46)));
            mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White));
            mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.FromArgb(0, 255, 207, 46)));
            mesh.Effect.SetValue("materialSpecularExp", 10000f);
        }
        public override void render(float elapsedTime)
        {
            Device device = GuiController.Instance.D3dDevice;

            //Actualzar posición de la luz
            Vector3 lightPos = (Vector3)GuiController.Instance.Modifiers["lightPos"];

            lightMesh.Position = lightPos;
            Vector3 eyePosition = GuiController.Instance.FpsCamera.getPosition();

            //Renderizar meshes
            foreach (TgcMeshBumpMapping mesh in meshes)
            {
                //Cargar variables shader de la luz
                mesh.Effect.SetValue("lightColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["lightColor"]));
                mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(lightPos));
                mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(eyePosition));
                mesh.Effect.SetValue("lightIntensity", (float)GuiController.Instance.Modifiers["lightIntensity"]);
                mesh.Effect.SetValue("lightAttenuation", (float)GuiController.Instance.Modifiers["lightAttenuation"]);
                mesh.Effect.SetValue("bumpiness", (float)GuiController.Instance.Modifiers["bumpiness"]);
                mesh.Effect.SetValue("reflection", (float)GuiController.Instance.Modifiers["reflection"]);

                //Material
                mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mEmissive"]));
                mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mAmbient"]));
                mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mDiffuse"]));
                mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mSpecular"]));
                mesh.Effect.SetValue("materialSpecularExp", (float)GuiController.Instance.Modifiers["specularEx"]);

                //CubeMap
                mesh.Effect.SetValue("texCubeMap", cubeMap);

                //Renderizar modelo
                mesh.render();
            }


            //Renderizar mesh de luz
            lightMesh.render();
        }
Exemple #13
0
        public override void render(float elapsedTime)
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Cargar variables shader
            mesh.Effect.SetValue("ambientColor", ColorValue.FromColor(Color.Gray));
            mesh.Effect.SetValue("diffuseColor", ColorValue.FromColor(Color.LightBlue));
            mesh.Effect.SetValue("specularColor", ColorValue.FromColor(Color.White));
            mesh.Effect.SetValue("specularExp", 10f);
            mesh.Effect.SetValue("lightPosition", lightPos);
            mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(GuiController.Instance.FpsCamera.getPosition()));


            mesh.rotateY(-elapsedTime / 2);
            mesh.render();

            textHelp.render();

            //Help
            if (GuiController.Instance.D3dInput.keyPressed(Microsoft.DirectX.DirectInput.Key.H))
            {
                helpForm.ShowDialog(GuiController.Instance.MainForm);
            }
        }
        public override void Render()
        {
            PreRender();

            //Actualzar posición de la luz
            var lightPos = (Vector3)Modifiers["lightPos"];

            lightMesh.Position = lightPos;
            var eyePosition = Camara.Position;

            //Renderizar meshes
            foreach (var mesh in meshes)
            {
                //Cargar variables shader de la luz
                mesh.Effect.SetValue("lightColor",
                                     ColorValue.FromColor((Color)Modifiers["lightColor"]));
                mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(lightPos));
                mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(eyePosition));
                mesh.Effect.SetValue("lightIntensity", (float)Modifiers["lightIntensity"]);
                mesh.Effect.SetValue("lightAttenuation", (float)Modifiers["lightAttenuation"]);
                mesh.Effect.SetValue("bumpiness", (float)Modifiers["bumpiness"]);

                //Material
                mesh.Effect.SetValue("materialEmissiveColor",
                                     ColorValue.FromColor((Color)Modifiers["mEmissive"]));
                mesh.Effect.SetValue("materialAmbientColor",
                                     ColorValue.FromColor((Color)Modifiers["mAmbient"]));
                mesh.Effect.SetValue("materialDiffuseColor",
                                     ColorValue.FromColor((Color)Modifiers["mDiffuse"]));
                mesh.Effect.SetValue("materialSpecularColor",
                                     ColorValue.FromColor((Color)Modifiers["mSpecular"]));
                mesh.Effect.SetValue("materialSpecularExp", (float)Modifiers["specularEx"]);

                //Renderizar modelo
                mesh.render();
            }

            //Renderizar mesh de luz
            lightMesh.render();

            //Dibujar flechas de debug
            var showNormals   = (bool)Modifiers["showNormals"];
            var showTangents  = (bool)Modifiers["showTangents"];
            var showBinormals = (bool)Modifiers["showBinormals"];

            for (var i = 0; i < normals.Count; i++)
            {
                if (showNormals)
                {
                    normals[i].render();
                }
                if (showTangents)
                {
                    tangents[i].render();
                }
                if (showBinormals)
                {
                    binormals[i].render();
                }
            }

            PostRender();
        }
        public override void render(float elapsedTime)
        {
            Device device = GuiController.Instance.D3dDevice;


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

            if (lightEnable)
            {
                //Con luz: Cambiar el shader actual por el shader default que trae el framework para iluminacion dinamica con PointLight
                currentShader = GuiController.Instance.Shaders.TgcMeshPointLightShader;
            }
            else
            {
                //Sin luz: Restaurar shader default
                currentShader = GuiController.Instance.Shaders.TgcMeshShader;
            }

            //Aplicar a cada mesh el shader actual
            foreach (TgcMesh mesh in scene.Meshes)
            {
                mesh.Effect = currentShader;
                //El Technique depende del tipo RenderType del mesh
                mesh.Technique = GuiController.Instance.Shaders.getTgcMeshTechnique(mesh.RenderType);
            }


            //Actualzar posición de la luz
            Vector3 lightPos = (Vector3)GuiController.Instance.Modifiers["lightPos"];

            lightMesh.Position = lightPos;

            //Renderizar meshes
            foreach (TgcMesh mesh in scene.Meshes)
            {
                if (lightEnable)
                {
                    //Cargar variables shader de la luz
                    mesh.Effect.SetValue("lightColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["lightColor"]));
                    mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(lightPos));
                    mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(GuiController.Instance.FpsCamera.getPosition()));
                    mesh.Effect.SetValue("lightIntensity", (float)GuiController.Instance.Modifiers["lightIntensity"]);
                    mesh.Effect.SetValue("lightAttenuation", (float)GuiController.Instance.Modifiers["lightAttenuation"]);

                    //Cargar variables de shader de Material. El Material en realidad deberia ser propio de cada mesh. Pero en este ejemplo se simplifica con uno comun para todos
                    mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mEmissive"]));
                    mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mAmbient"]));
                    mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mDiffuse"]));
                    mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mSpecular"]));
                    mesh.Effect.SetValue("materialSpecularExp", (float)GuiController.Instance.Modifiers["specularEx"]);
                }

                //Renderizar modelo
                mesh.render();
            }


            //Renderizar mesh de luz
            lightMesh.render();
        }
        public void Update(TgcCamera camara)
        {
            var camaraPosition = camara.Position;

            effect.SetValue("CameraPos", TgcParserUtils.vector3ToFloat4Array(camaraPosition));
        }
Exemple #17
0
        /*public void titilar()
         * {
         *  foreach(LuzNormal luz in listaLuces)
         *  {
         *      luz.titilar();
         *  }
         * }*/
        public void iluminar(TipoIluminador objeto, Camara camara)
        {
            //titilar();
            Device device = GuiController.Instance.D3dDevice;


            Vector3 lightDir;

            lightDir = camara.getLookAt() - camara.getPosition();
            lightDir.Normalize();
            LuzNormal luzDelMesh;

            if (objeto.tipo == TipoIluminador.Tipo.Linterna)
            {
                foreach (ElementoDesaparecedor elemento in elementosDesaparecedores)
                {
                    if (elemento.desaparecer())
                    {
                        luzDelMesh = luzMasCercana(elemento.getMesh().BoundingBox.calculateBoxCenter());
                        elemento.getMesh().Effect    = effectSpotYPoint;
                        elemento.getMesh().Technique = GuiController.Instance.Shaders.getTgcMeshTechnique(elemento.getMesh().RenderType);
                    }
                }
                foreach (ElementoDesaparecedor elemento in elementosDesaparecedores)
                {
                    if (elemento.desaparecer())
                    {
                        luzDelMesh = luzMasCercana(elemento.getMesh().BoundingBox.calculateBoxCenter());
                        elemento.getMesh().Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Black));
                        elemento.getMesh().Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White));
                        elemento.getMesh().Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White));
                        elemento.getMesh().Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.White));
                        elemento.getMesh().Effect.SetValue("materialSpecularExp", 9f);
                        elemento.getMesh().Effect.SetValue("lightColor", ColorValue.FromColor(objeto.color));
                        elemento.getMesh().Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(camara.getPosition()));
                        elemento.getMesh().Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(camara.getPosition()));
                        elemento.getMesh().Effect.SetValue("spotLightDir", TgcParserUtils.vector3ToFloat4Array(lightDir));
                        if (objeto.Encendida)
                        {
                            elemento.getMesh().Effect.SetValue("lightIntensity", objeto.Intensity);
                        }
                        else
                        {
                            elemento.getMesh().Effect.SetValue("lightIntensity", 0);
                        }
                        elemento.getMesh().Effect.SetValue("lightAttenuation", objeto.Attenuation);
                        elemento.getMesh().Effect.SetValue("spotLightAngleCos", FastMath.ToRad(objeto.SpotAngle));
                        elemento.getMesh().Effect.SetValue("spotLightExponent", objeto.SpotExponent);
                        elemento.getMesh().Effect.SetValue("lightColorP", ColorValue.FromColor(luzDelMesh.lightColor));
                        elemento.getMesh().Effect.SetValue("lightPositionP", TgcParserUtils.vector3ToFloat4Array(luzDelMesh.Posicion));
                        elemento.getMesh().Effect.SetValue("lightIntensityP", luzDelMesh.Intensity);
                        elemento.getMesh().Effect.SetValue("lightAttenuationP", luzDelMesh.Attenuation);
                        elemento.getMesh().render();
                    }
                }
                foreach (TgcMesh mesh in todosLosElementos) //Esto lo pongo aca, ya que las sombras tengo que hacerlas primero si no se vuelve loquito
                {
                    mesh.Effect = effectSpotYPoint;

                    mesh.Technique = GuiController.Instance.Shaders.getTgcMeshTechnique(mesh.RenderType);
                }
                foreach (TgcMesh mesh in todosLosElementos)
                {
                    luzDelMesh = luzMasCercana(mesh.BoundingBox.calculateBoxCenter());
                    mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Black));
                    mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White));
                    mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White));
                    mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.White));
                    mesh.Effect.SetValue("materialSpecularExp", 9f);
                    mesh.Effect.SetValue("lightColor", ColorValue.FromColor(objeto.color));
                    mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(camara.getPosition()));
                    mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(camara.getPosition()));
                    mesh.Effect.SetValue("spotLightDir", TgcParserUtils.vector3ToFloat4Array(lightDir));
                    if (objeto.Encendida)
                    {
                        mesh.Effect.SetValue("lightIntensity", objeto.Intensity);
                    }
                    else
                    {
                        mesh.Effect.SetValue("lightIntensity", 0);
                    }
                    mesh.Effect.SetValue("lightAttenuation", objeto.Attenuation);
                    mesh.Effect.SetValue("spotLightAngleCos", FastMath.ToRad(objeto.SpotAngle));
                    mesh.Effect.SetValue("spotLightExponent", objeto.SpotExponent);
                    mesh.Effect.SetValue("lightColorP", ColorValue.FromColor(luzDelMesh.lightColor));
                    mesh.Effect.SetValue("lightPositionP", TgcParserUtils.vector3ToFloat4Array(luzDelMesh.Posicion));
                    mesh.Effect.SetValue("lightIntensityP", luzDelMesh.Intensity);
                    mesh.Effect.SetValue("lightAttenuationP", luzDelMesh.Attenuation);
                    mesh.render();
                }
                foreach (TgcMesh mesh in listaPuertas) //Esto lo pongo aca, ya que las sombras tengo que hacerlas primero si no se vuelve loquito
                {
                    mesh.Effect = effectSpotYPoint;

                    mesh.Technique = GuiController.Instance.Shaders.getTgcMeshTechnique(mesh.RenderType);
                }
                foreach (TgcMesh mesh in listaPuertas)
                {
                    luzDelMesh = luzMasCercana(mesh.BoundingBox.calculateBoxCenter());
                    mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Black));
                    mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White));
                    mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White));
                    mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.White));
                    mesh.Effect.SetValue("materialSpecularExp", 9f);
                    mesh.Effect.SetValue("lightColor", ColorValue.FromColor(objeto.color));
                    mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(camara.getPosition()));
                    mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(camara.getPosition()));
                    mesh.Effect.SetValue("spotLightDir", TgcParserUtils.vector3ToFloat4Array(lightDir));
                    if (objeto.Encendida)
                    {
                        mesh.Effect.SetValue("lightIntensity", objeto.Intensity);
                    }
                    else
                    {
                        mesh.Effect.SetValue("lightIntensity", 0);
                    }
                    mesh.Effect.SetValue("lightAttenuation", objeto.Attenuation);
                    mesh.Effect.SetValue("spotLightAngleCos", FastMath.ToRad(objeto.SpotAngle));
                    mesh.Effect.SetValue("spotLightExponent", objeto.SpotExponent);
                    mesh.Effect.SetValue("lightColorP", ColorValue.FromColor(luzDelMesh.lightColor));
                    mesh.Effect.SetValue("lightPositionP", TgcParserUtils.vector3ToFloat4Array(luzDelMesh.Posicion));
                    mesh.Effect.SetValue("lightIntensityP", luzDelMesh.Intensity);
                    mesh.Effect.SetValue("lightAttenuationP", luzDelMesh.Attenuation);
                    mesh.render();
                }

                /*foreach (TgcSkeletalMesh mesh in todosLosElementos)
                 * {
                 *  mesh.Effect = effectSpotYPoint;
                 *  mesh.Technique = GuiController.Instance.Shaders.getTgcSkeletalMeshTechnique(mesh.RenderType);
                 * }
                 * foreach (TgcSkeletalMesh mesh in todosLosElementos)
                 * {
                 *  luzDelMesh = luzMasCercana(mesh.BoundingBox.calculateBoxCenter());
                 *  mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Black));
                 *  mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White));
                 *  mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White));
                 *  mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.White));
                 *  mesh.Effect.SetValue("materialSpecularExp", 9f);
                 *  mesh.Effect.SetValue("lightColor", ColorValue.FromColor(objeto.color));
                 *  mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(camara.getPosition()));
                 *  mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(camara.getPosition()));
                 *  mesh.Effect.SetValue("spotLightDir", TgcParserUtils.vector3ToFloat4Array(lightDir));
                 *  if (objeto.Encendida)
                 *  {
                 *      mesh.Effect.SetValue("lightIntensity", objeto.Intensity);
                 *  }
                 *  else
                 *  {
                 *      mesh.Effect.SetValue("lightIntensity", 0);
                 *  }
                 *  mesh.Effect.SetValue("lightAttenuation", objeto.Attenuation);
                 *  mesh.Effect.SetValue("spotLightAngleCos", FastMath.ToRad(objeto.SpotAngle));
                 *  mesh.Effect.SetValue("spotLightExponent", objeto.SpotExponent);
                 *  mesh.Effect.SetValue("lightColorP", ColorValue.FromColor(luzDelMesh.lightColor));
                 *  mesh.Effect.SetValue("lightPositionP", TgcParserUtils.vector3ToFloat4Array(luzDelMesh.Posicion));
                 *  mesh.Effect.SetValue("lightIntensityP", luzDelMesh.Intensity);
                 *  mesh.Effect.SetValue("lightAttenuationP", luzDelMesh.Attenuation);
                 *  mesh.render();
                 * }*/
            }
            else
            {
                foreach (ElementoDesaparecedor elemento in elementosDesaparecedores)
                {
                    if (elemento.desaparecer())
                    {
                        elemento.getMesh().Effect = effectPointYPoint;
                        // elemento.getMesh().Effect = GuiController.Instance.Shaders.TgcMeshShader;
                        elemento.getMesh().Technique = GuiController.Instance.Shaders.getTgcMeshTechnique(elemento.getMesh().RenderType);
                    }
                }
                foreach (ElementoDesaparecedor elemento in elementosDesaparecedores)
                {
                    if (elemento.desaparecer())
                    {
                        luzDelMesh = luzMasCercana(elemento.getMesh().BoundingBox.calculateBoxCenter());
                        elemento.getMesh().Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Black));
                        elemento.getMesh().Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White));
                        elemento.getMesh().Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White));
                        elemento.getMesh().Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.White));
                        elemento.getMesh().Effect.SetValue("materialSpecularExp", 0f);
                        elemento.getMesh().Effect.SetValue("lightColor", ColorValue.FromColor(objeto.color));
                        elemento.getMesh().Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(camara.getPosition()));
                        elemento.getMesh().Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(camara.getPosition()));
                        if (objeto.Encendida)
                        {
                            elemento.getMesh().Effect.SetValue("lightIntensity", objeto.Intensity);
                        }
                        else
                        {
                            elemento.getMesh().Effect.SetValue("lightIntensity", 0);
                        }
                        elemento.getMesh().Effect.SetValue("lightAttenuation", objeto.Attenuation);
                        elemento.getMesh().Effect.SetValue("lightColorP", ColorValue.FromColor(luzDelMesh.lightColor));
                        elemento.getMesh().Effect.SetValue("lightPositionP", TgcParserUtils.vector3ToFloat4Array(luzDelMesh.Posicion));
                        elemento.getMesh().Effect.SetValue("lightIntensityP", luzDelMesh.Intensity);
                        elemento.getMesh().Effect.SetValue("lightAttenuationP", luzDelMesh.Attenuation);
                        elemento.getMesh().render();
                    }
                }
                foreach (TgcMesh mesh in todosLosElementos)
                {
                    mesh.Effect = effectPointYPoint;
                    //mesh.Effect = GuiController.Instance.Shaders.TgcMeshPointLightShader;
                    //mesh.Effect = GuiController.Instance.Shaders.TgcMeshShader;
                    mesh.Technique = GuiController.Instance.Shaders.getTgcMeshTechnique(mesh.RenderType);
                }
                foreach (TgcMesh mesh in todosLosElementos)
                {
                    luzDelMesh = luzMasCercana(mesh.BoundingBox.calculateBoxCenter());
                    mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Black));
                    mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White));
                    mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White));
                    mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.White));
                    mesh.Effect.SetValue("materialSpecularExp", 9f);
                    mesh.Effect.SetValue("lightColor", ColorValue.FromColor(objeto.color));
                    mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(camara.getPosition()));
                    mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(camara.getPosition()));
                    if (objeto.Encendida)
                    {
                        mesh.Effect.SetValue("lightIntensity", objeto.Intensity);
                    }
                    else
                    {
                        mesh.Effect.SetValue("lightIntensity", 0);
                    }
                    mesh.Effect.SetValue("lightAttenuation", objeto.Attenuation);
                    mesh.Effect.SetValue("lightColorP", ColorValue.FromColor(luzDelMesh.lightColor));
                    mesh.Effect.SetValue("lightPositionP", TgcParserUtils.vector3ToFloat4Array(luzDelMesh.Posicion));
                    mesh.Effect.SetValue("lightIntensityP", luzDelMesh.Intensity);
                    mesh.Effect.SetValue("lightAttenuationP", luzDelMesh.Attenuation);
                    mesh.AlphaBlendEnable = true;
                    mesh.render();
                }
                foreach (TgcMesh mesh in listaPuertas) //Esto lo pongo aca, ya que las sombras tengo que hacerlas primero si no se vuelve loquito
                {
                    mesh.Effect = effectPointYPoint;

                    mesh.Technique = GuiController.Instance.Shaders.getTgcMeshTechnique(mesh.RenderType);
                }
                foreach (TgcMesh mesh in listaPuertas)
                {
                    luzDelMesh = luzMasCercana(mesh.BoundingBox.calculateBoxCenter());
                    mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Black));
                    mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White));
                    mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White));
                    mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.White));
                    mesh.Effect.SetValue("materialSpecularExp", 9f);
                    mesh.Effect.SetValue("lightColor", ColorValue.FromColor(objeto.color));
                    mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(camara.getPosition()));
                    mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(camara.getPosition()));
                    if (objeto.Encendida)
                    {
                        mesh.Effect.SetValue("lightIntensity", objeto.Intensity);
                    }
                    else
                    {
                        mesh.Effect.SetValue("lightIntensity", 0);
                    }
                    mesh.Effect.SetValue("lightAttenuation", objeto.Attenuation);
                    mesh.Effect.SetValue("lightColorP", ColorValue.FromColor(luzDelMesh.lightColor));
                    mesh.Effect.SetValue("lightPositionP", TgcParserUtils.vector3ToFloat4Array(luzDelMesh.Posicion));
                    mesh.Effect.SetValue("lightIntensityP", luzDelMesh.Intensity);
                    mesh.Effect.SetValue("lightAttenuationP", luzDelMesh.Attenuation);
                    mesh.AlphaBlendEnable = true;
                    mesh.render();
                }
            }
            foreach (LuzNormal luz in listaLuces)
            {
                luz.render();
            }
        }
Exemple #18
0
        public override void Render()
        {
            PreRender();

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

            if (lightEnable)
            {
                //Con luz: Cambiar el shader actual por el shader default que trae el framework para iluminacion dinamica con SpotLight
                currentShader = TgcShaders.Instance.TgcMeshSpotLightShader;
            }
            else
            {
                //Sin luz: Restaurar shader default
                currentShader = TgcShaders.Instance.TgcMeshShader;
            }

            //Aplicar a cada mesh el shader actual
            foreach (var mesh in scene.Meshes)
            {
                mesh.Effect = currentShader;
                //El Technique depende del tipo RenderType del mesh
                mesh.Technique = TgcShaders.Instance.getTgcMeshTechnique(mesh.RenderType);
            }

            //Actualzar posicion de la luz
            var lightPos = (Vector3)Modifiers["lightPos"];

            lightMesh.Position = lightPos;

            //Normalizar direccion de la luz
            var lightDir = (Vector3)Modifiers["lightDir"];

            lightDir.Normalize();

            //Renderizar meshes
            foreach (var mesh in scene.Meshes)
            {
                if (lightEnable)
                {
                    //Cargar variables shader de la luz
                    mesh.Effect.SetValue("lightColor", ColorValue.FromColor((Color)Modifiers["lightColor"]));
                    mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(lightPos));
                    mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(Camara.Position));
                    mesh.Effect.SetValue("spotLightDir", TgcParserUtils.vector3ToFloat3Array(lightDir));
                    mesh.Effect.SetValue("lightIntensity", (float)Modifiers["lightIntensity"]);
                    mesh.Effect.SetValue("lightAttenuation", (float)Modifiers["lightAttenuation"]);
                    mesh.Effect.SetValue("spotLightAngleCos", FastMath.ToRad((float)Modifiers["spotAngle"]));
                    mesh.Effect.SetValue("spotLightExponent", (float)Modifiers["spotExponent"]);

                    //Cargar variables de shader de Material. El Material en realidad deberia ser propio de cada mesh. Pero en este ejemplo se simplifica con uno comun para todos
                    mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor((Color)Modifiers["mEmissive"]));
                    mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor((Color)Modifiers["mAmbient"]));
                    mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor((Color)Modifiers["mDiffuse"]));
                    mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor((Color)Modifiers["mSpecular"]));
                    mesh.Effect.SetValue("materialSpecularExp", (float)Modifiers["specularEx"]);
                }

                //Renderizar modelo
                mesh.render();
            }

            //Renderizar mesh de luz
            lightMesh.render();

            PostRender();
        }
Exemple #19
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 = "ThreeLightsTechnique";
            }
            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 meshData in meshesWithLight)
            {
                meshData.mesh.Effect    = currentShader;
                meshData.mesh.Technique = currentTechnique;
            }

            var eyePosition = Camara.Position;

            //Renderizar meshes con BumpMapping
            foreach (var meshData in meshesWithLight)
            {
                var mesh = meshData.mesh;

                if (true) //FIXME da error cuando se desabilitan las luces.) (lightEnable)
                {
                    mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(eyePosition));
                    mesh.Effect.SetValue("bumpiness", (float)Modifiers["bumpiness"]);
                    mesh.Effect.SetValue("reflection", (float)Modifiers["reflection"]);

                    //Cargar variables de shader del Material
                    mesh.Effect.SetValue("materialEmissiveColor",
                                         ColorValue.FromColor((Color)Modifiers["mEmissive"]));
                    mesh.Effect.SetValue("materialAmbientColor",
                                         ColorValue.FromColor((Color)Modifiers["mAmbient"]));
                    mesh.Effect.SetValue("materialDiffuseColor",
                                         ColorValue.FromColor((Color)Modifiers["mDiffuse"]));
                    mesh.Effect.SetValue("materialSpecularColor",
                                         ColorValue.FromColor((Color)Modifiers["mSpecular"]));
                    mesh.Effect.SetValue("materialSpecularExp", (float)Modifiers["specularEx"]);

                    //CubeMap
                    mesh.Effect.SetValue("texCubeMap", cubeMap);

                    //Cargar variables de shader de las 3 luces
                    //Intensidad y atenuacion deberian ser atributos propios de cada luz
                    var lightIntensity   = (float)Modifiers["lightIntensity"];
                    var lightAttenuation = (float)Modifiers["lightAttenuation"];
                    mesh.Effect.SetValue("lightIntensity", new[] { lightIntensity, lightIntensity, lightIntensity });
                    mesh.Effect.SetValue("lightAttenuation",
                                         new[] { lightAttenuation, lightAttenuation, lightAttenuation });

                    mesh.Effect.SetValue("lightColor",
                                         new[]
                    {
                        ColorValue.FromColor(meshData.lights[0].color),
                        ColorValue.FromColor(meshData.lights[1].color),
                        ColorValue.FromColor(meshData.lights[2].color)
                    });
                    mesh.Effect.SetValue("lightPosition",
                                         new[]
                    {
                        TgcParserUtils.vector3ToVector4(meshData.lights[0].pos),
                        TgcParserUtils.vector3ToVector4(meshData.lights[1].pos),
                        TgcParserUtils.vector3ToVector4(meshData.lights[2].pos)
                    });
                }

                //Renderizar modelo
                mesh.render();
            }

            //Renderizar meshes comunes
            foreach (var mesh in commonMeshes)
            {
                mesh.render();
            }

            PostRender();
        }
Exemple #20
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 = "ThreeLightsTechnique";
            }
            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 (MeshLightData meshData in meshesWithLight)
            {
                meshData.mesh.Effect    = currentShader;
                meshData.mesh.Technique = currentTechnique;
            }


            Vector3 eyePosition = GuiController.Instance.FpsCamera.getPosition();

            //Renderizar meshes con BumpMapping
            foreach (MeshLightData meshData in meshesWithLight)
            {
                TgcMeshBumpMapping mesh = meshData.mesh;

                if (lightEnable)
                {
                    mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(eyePosition));
                    mesh.Effect.SetValue("bumpiness", (float)GuiController.Instance.Modifiers["bumpiness"]);
                    mesh.Effect.SetValue("reflection", (float)GuiController.Instance.Modifiers["reflection"]);

                    //Cargar variables de shader del Material
                    mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mEmissive"]));
                    mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mAmbient"]));
                    mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mDiffuse"]));
                    mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mSpecular"]));
                    mesh.Effect.SetValue("materialSpecularExp", (float)GuiController.Instance.Modifiers["specularEx"]);

                    //CubeMap
                    mesh.Effect.SetValue("texCubeMap", cubeMap);

                    //Cargar variables de shader de las 3 luces
                    //Intensidad y atenuacion deberian ser atributos propios de cada luz
                    float lightIntensity   = (float)GuiController.Instance.Modifiers["lightIntensity"];
                    float lightAttenuation = (float)GuiController.Instance.Modifiers["lightAttenuation"];
                    mesh.Effect.SetValue("lightIntensity", new float[] { lightIntensity, lightIntensity, lightIntensity });
                    mesh.Effect.SetValue("lightAttenuation", new float[] { lightAttenuation, lightAttenuation, lightAttenuation });

                    mesh.Effect.SetValue("lightColor", new ColorValue[] { ColorValue.FromColor(meshData.lights[0].color), ColorValue.FromColor(meshData.lights[1].color), ColorValue.FromColor(meshData.lights[2].color) });
                    mesh.Effect.SetValue("lightPosition", new Vector4[] { TgcParserUtils.vector3ToVector4(meshData.lights[0].pos), TgcParserUtils.vector3ToVector4(meshData.lights[1].pos), TgcParserUtils.vector3ToVector4(meshData.lights[2].pos) });
                }


                //Renderizar modelo
                mesh.render();
            }

            //Renderizar meshes comunes
            foreach (TgcMesh mesh in commonMeshes)
            {
                mesh.render();
            }
        }
Exemple #21
0
        public override void Render()
        {
            PreRender();

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

            if (lightEnable)
            {
                //Con luz: Cambiar el shader actual por el shader default que trae el framework para iluminacion dinamica con PointLight
                currentShader = TgcShaders.Instance.TgcMeshPointLightShader;
            }
            else
            {
                //Sin luz: Restaurar shader default
                currentShader = TgcShaders.Instance.TgcMeshShader;
            }

            //Aplicar a cada mesh el shader actual
            foreach (var mesh in scene.Meshes)
            {
                mesh.Effect = currentShader;
                //El Technique depende del tipo RenderType del mesh
                mesh.Technique = TgcShaders.Instance.getTgcMeshTechnique(mesh.RenderType);
            }

            //Renderizar meshes
            foreach (var mesh in scene.Meshes)
            {
                if (lightEnable)
                {
                    /* Obtener la luz que corresponde a este mesh.
                     * En este escenario a un mesh lo pueden estar iluminando varias luces a la vez.
                     * Cuando se tienen varias luces en un escenario surge el problema de "Many-Light shader"
                     * No existe una unica forma de resolverlo. Algunas alternativas son:
                     *  1) Cada mesh solo se ilumina por una unica luz. Aunque haya varias
                     *  2) El shader se programa para que soporte 2 o mas luces.
                     *  3) Se hacen varias pasadas, renderizando una vez con cada luz
                     *  4) Se utiliza la tecnica de Deferred Shading. Ver: http://ogldev.atspace.co.uk/www/tutorial35/tutorial35.html
                     *
                     * En este ejemplo se utiliza la tecnica 1, por ser la mas simple. Para cada objeto se usa solo la luz mas cercana.
                     * El problema es que un mesh solo se ve influenciado por una unica luz.
                     * Para un mesh chico no es muy problematico. Pero para un mesh largo, como una pared, se nota bastante.
                     * Si la pared tiene 3 luces, solo una va a contribuir en la iluminacion, las otras dos no.
                     * Se podria usar otro criterio distinto que cercania. Cada mesh podria tener asignada una luz segun el cuarto en el que se encuentra o
                     * segun algun otro criterio de diseno.
                     * Si es por cercania y hay muchas luces lo mejor armar una grilla o octree offline que indique que luz corresponde a cada celda.
                     * En este ejemplo en cambio por cada mesh se sale a recorrer todas las luces que hay para ver las mas cercana (no es para nada optimo)
                     * Como posicion del mesh se toma el centro del AABB. En este ejemplo el centro se calcula en cada cuadro. Deberia estar precalculado para
                     * todos los meshes.
                     *
                     * La tecnica 2 requiere hacer todas la cuentas de iluminacion N veces en el shader (N dot L, N dot H, etc, una vez por cada luz).
                     * El problema de esto es que los calculos del shader se pueden volver bastante costosos.
                     * Muchas aplicaciones definen una cantidad X de luces, por ejemplo hasta 3. Y el shader hace los calculos 3 veces.
                     * Otros aplicaciones permiten una luz principal con todo el modelo de iluminacion (ambiente + diffuse + specular) y otras dos luces
                     * mas sencillas (por ejemplo solo diffuse). Para asi reducer los calculos.
                     * Ver presentacion de "Physically-based lighting in Call of Duty: Black Ops" en http://advances.realtimerendering.com/s2011/index.html
                     *
                     * La tecnica 3 permite usar el mismo shader sin hacerlo mas complejo, pero requiere renderizar varias veces el mismo mesh.
                     * Si el mesh tiene muchos triangulos puede ser bastante costoso dibujarlo varias veces.
                     *
                     * La tecnica 4 es a la que muchas aplicaciones estan tendiendo hoy en dia. Pero es compleja, requiere que la GPU soporte un modelo
                     * de Pixel Shader bastante nuevo, y consume bastante memoria de GPU.
                     *
                     */
                    var light = getClosestLight(mesh.BoundingBox.calculateBoxCenter());

                    //Cargar variables shader de la luz
                    mesh.Effect.SetValue("lightColor", ColorValue.FromColor(light.color));
                    mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(light.pos));
                    mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(Camara.Position));
                    mesh.Effect.SetValue("lightIntensity", (float)Modifiers["lightIntensity"]);
                    mesh.Effect.SetValue("lightAttenuation", (float)Modifiers["lightAttenuation"]);

                    //Cargar variables de shader de Material. El Material en realidad deberia ser propio de cada mesh. Pero en este ejemplo se simplifica con uno comun para todos
                    mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor((Color)Modifiers["mEmissive"]));
                    mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor((Color)Modifiers["mAmbient"]));
                    mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor((Color)Modifiers["mDiffuse"]));
                    mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor((Color)Modifiers["mSpecular"]));
                    mesh.Effect.SetValue("materialSpecularExp", (float)Modifiers["specularEx"]);
                }

                //Renderizar modelo
                mesh.render();
            }
            PostRender();
        }
Exemple #22
0
        public void render(float tiempo)
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            string selectedTexture = (string)GuiController.Instance.Modifiers["texture"];

            if (currentTexurePah != selectedTexture)
            {
                texture = TextureLoader.FromFile(d3dDevice, selectedTexture);
            }
            float selectedDistancia_verices = (float)GuiController.Instance.Modifiers["distancia_verices"];

            if (distancia_verices != selectedDistancia_verices)
            {
                distancia_verices = selectedDistancia_verices;
                vertices          = crearMatriz();
            }
            amplitud   = (float)GuiController.Instance.Modifiers["amplitud"];
            frecuencia = (float)GuiController.Instance.Modifiers["frecuencia"];
            efecto     = (string)GuiController.Instance.Modifiers["efectos"];
            velocidad  = (float)GuiController.Instance.Modifiers["velocidad"];

            vertices = this.crearMovimiento(tiempo);
            this.crearVertices();

            //Almacenar información en VertexBuffer
            vertexBuffer.SetData(data, 0, LockFlags.None);
            indexBuffer.SetData(indice, 0, LockFlags.None);

            d3dDevice.Transform.World = Matrix.Identity;
            //d3dDevice.VertexDeclaration = GuiController.Instance.Shaders.VdecPositionTextured;
            effect.Technique = technique;
            GuiController.Instance.Shaders.setShaderMatrix(effect, Matrix.Identity);
            effect.SetValue("texDiffuseMap", texture);
            effect.SetValue("lightColor", ColorValue.FromColor((Color)Color.White));

            //effect.SetValue("fvLightPosition", TgcParserUtils.vector3ToFloat4Array(new Vector3(0, 100, -200)));
            //effect.SetValue("fvEyePosition", TgcParserUtils.vector3ToFloat4Array(GuiController.Instance.FpsCamera.getPosition()));
            effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(new Vector3(0, 100, -200)));
            effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(GuiController.Instance.FpsCamera.getPosition()));

            //CubeMap
            effect.SetValue("texCubeMap", cubeMap);
            effect.SetValue("lightIntensity", 10f);
            effect.SetValue("lightAttenuation", 0.3f);
            if ((bool)GuiController.Instance.Modifiers["reflection"])
            {
                effect.SetValue("reflection", 0.5f);
            }
            else
            {
                effect.SetValue("reflection", 0f);
            }
            //Cargar variables de shader de Material. El Material en realidad deberia ser propio de cada mesh. Pero en este ejemplo se simplifica con uno comun para todos
            effect.SetValue("materialEmissiveColor", ColorValue.FromColor((Color)Color.Black));
            effect.SetValue("materialAmbientColor", ColorValue.FromColor((Color)Color.White));
            effect.SetValue("materialDiffuseColor", ColorValue.FromColor((Color)Color.White));
            effect.SetValue("materialSpecularColor", ColorValue.FromColor((Color)Color.White));
            effect.SetValue("materialSpecularExp", (float)15f);


            //Habilitar textura
            d3dDevice.SetTexture(0, texture);
            //d3dDevice.Material = TgcD3dDevice.DEFAULT_MATERIAL;

            //Especificar formato de triangulos
            d3dDevice.VertexFormat = CustomVertex.PositionNormalTextured.Format;
            //Cargar VertexBuffer a renderizar
            d3dDevice.SetStreamSource(0, vertexBuffer, 0);
            d3dDevice.Indices = indexBuffer;
            //Dibujar 1 primitiva
            //Render con shader
            effect.Begin(0);
            effect.BeginPass(0);
            d3dDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, TOTAL_VERTICES_CUADRADO, 0, TOTAL_TRIANGULOS);
            effect.EndPass();
            effect.End();

            /*
             * foreach (TgcArrow a in normals)
             * {
             *  a.render();
             * }
             */
        }
        public override void Render()
        {
            PreRender();

            Effect currentShader;
            Effect currentShaderSkeletalMesh;

            if (lightMesh.Enabled)
            {
                //Con luz: Cambiar el shader actual por el shader default que trae el framework para iluminacion dinamica con PointLight
                currentShader = TgcShaders.Instance.TgcMeshPointLightShader;
                //Con luz: Cambiar el shader actual por el shader default que trae el framework para iluminacion dinamica con PointLight para Skeletal Mesh
                currentShaderSkeletalMesh = TgcShaders.Instance.TgcSkeletalMeshPointLightShader;
            }
            else
            {
                //Sin luz: Restaurar shader default
                currentShader             = TgcShaders.Instance.TgcMeshShader;
                currentShaderSkeletalMesh = TgcShaders.Instance.TgcSkeletalMeshShader;
            }

            //Aplicar a cada mesh el shader actual
            foreach (var mesh in scene.Meshes)
            {
                mesh.Effect = currentShader;
                //El Technique depende del tipo RenderType del mesh
                mesh.Technique = TgcShaders.Instance.getTgcMeshTechnique(mesh.RenderType);
            }

            //Aplicar al mesh el shader actual
            skeletalMesh.Effect = currentShaderSkeletalMesh;
            //El Technique depende del tipo RenderType del mesh
            skeletalMesh.Technique = TgcShaders.Instance.getTgcSkeletalMeshTechnique(skeletalMesh.RenderType);

            //Renderizar meshes
            foreach (var mesh in scene.Meshes)
            {
                if (lightMesh.Enabled)
                {
                    //Cargar variables shader de la luz
                    mesh.Effect.SetValue("lightColor", ColorValue.FromColor(lightMesh.Color));
                    mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(lightMesh.Position));
                    mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(Camara.Position));
                    mesh.Effect.SetValue("lightIntensity", (float)Modifiers["lightIntensity"]);
                    mesh.Effect.SetValue("lightAttenuation", (float)Modifiers["lightAttenuation"]);

                    //Cargar variables de shader de Material. El Material en realidad deberia ser propio de cada mesh. Pero en este ejemplo se simplifica con uno comun para todos
                    mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor((Color)Modifiers["mEmissive"]));
                    mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor((Color)Modifiers["mAmbient"]));
                    mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor((Color)Modifiers["mDiffuse"]));
                    mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor((Color)Modifiers["mSpecular"]));
                    mesh.Effect.SetValue("materialSpecularExp", (float)Modifiers["specularEx"]);
                }

                //Renderizar modelo
                mesh.render();
            }

            //Renderizar mesh
            if (lightMesh.Enabled)
            {
                //Cargar variables shader de la luz
                skeletalMesh.Effect.SetValue("lightColor", ColorValue.FromColor(lightMesh.Color));
                skeletalMesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(lightMesh.Position));
                skeletalMesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(Camara.Position));
                skeletalMesh.Effect.SetValue("lightIntensity", (float)Modifiers["lightIntensity"]);
                skeletalMesh.Effect.SetValue("lightAttenuation", (float)Modifiers["lightAttenuation"]);

                //Cargar variables de shader de Material. El Material en realidad deberia ser propio de cada mesh. Pero en este ejemplo se simplifica con uno comun para todos
                skeletalMesh.Effect.SetValue("materialEmissiveColor",
                                             ColorValue.FromColor((Color)Modifiers["mEmissive"]));
                skeletalMesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor((Color)Modifiers["mAmbient"]));
                skeletalMesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor((Color)Modifiers["mDiffuse"]));
                skeletalMesh.Effect.SetValue("materialSpecularColor",
                                             ColorValue.FromColor((Color)Modifiers["mSpecular"]));
                skeletalMesh.Effect.SetValue("materialSpecularExp", (float)Modifiers["specularEx"]);
            }
            skeletalMesh.animateAndRender(ElapsedTime);

            //Renderizar mesh de luz
            lightMesh.render();

            PostRender();
        }
        public void renderizarLuz(int tipo, Vector3 posicionCamara, Vector3 direccionDeLuz, TgcMesh mesh, float intensidad, float temblor)
        {
            g_LightPos = posicionCamara;
            //g_LightDir = direccionDeLuz - g_LightPos;
            g_LightDir = direccionDeLuz;
            g_LightDir.Normalize();

            var random = FastMath.Cos(6 * temblor);

            //Actualzar posición de la luz
            Vector3 lightPos = posicionCamara;

            //Normalizar direccion de la luz

            Vector3 lightDir = direccionDeLuz;

            lightDir.Normalize();
            //Cargar variables shader de la luz
            if (tipo == 0)
            {
                lightColors[0]           = ColorValue.FromColor(Color.White);
                pointLightPositions[0]   = TgcParserUtils.vector3ToVector4(lightPos);
                pointLightIntensity[0]   = intensidad;
                pointLightAttenuation[0] = 0.48f;
                for (int i = 1; i < 5; i++)
                {
                    lightColors[i]           = ColorValue.FromColor(Color.White);
                    pointLightPositions[i]   = TgcParserUtils.vector3ToVector4(posicionesDeLuces[i - 1]);
                    pointLightIntensity[i]   = (float)GuiController.Instance.Modifiers["lightIntensity"];
                    pointLightAttenuation[i] = (float)GuiController.Instance.Modifiers["lightAttenuation"];
                }

                mesh.Effect.SetValue("lightColor", lightColors);
                mesh.Effect.SetValue("lightPosition", pointLightPositions);
                mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(lightPos));
                mesh.Effect.SetValue("spotLightDir", TgcParserUtils.vector3ToFloat3Array(lightDir));
                mesh.Effect.SetValue("lightIntensity", pointLightIntensity);
                mesh.Effect.SetValue("lightAttenuation", pointLightAttenuation);
                mesh.Effect.SetValue("spotLightAngleCos", FastMath.ToRad(39f));
                mesh.Effect.SetValue("spotLightExponent", 14f);



                //Variables de los materiales
                mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Black));
                mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White));
                mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White));
                mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.White));
                mesh.Effect.SetValue("materialSpecularExp", 11f);
                mesh.render();
            }
            else if (tipo == 1)
            {    // Calculo la matriz de view de la luz
                //mesh.Effect.SetValue("g_vLightPos", new Vector4(g_LightPos.X, g_LightPos.Y, g_LightPos.Z, 1));
                mesh.Effect.SetValue("g_vLightPos", new Vector4(posicionCamara.X, posicionCamara.Y, posicionCamara.Z, 1));
                //mesh.Effect.SetValue("g_vLightDir", new Vector4(g_LightDir.X, g_LightDir.Y, g_LightDir.Z, 1));
                mesh.Effect.SetValue("g_vLightDir", new Vector4(g_LightDir.X, g_LightDir.Y, g_LightDir.Z, 1));
                mesh.Effect.SetValue("texProy", miTex);
                g_LightView = Matrix.LookAtLH(g_LightPos, g_LightPos + g_LightDir, new Vector3(0, 0, 1));
                // inicializacion standard:
                //mesh.Effect.SetValue("g_mProjLight", g_mShadowProj);
                mesh.Effect.SetValue("g_mViewLightProj", g_LightView * g_mShadowProj);
                lightColors[0]           = ColorValue.FromColor(Color.Yellow);
                pointLightPositions[0]   = TgcParserUtils.vector3ToVector4(lightPos);
                pointLightIntensity[0]   = intensidad; //POR 2??
                pointLightAttenuation[0] = 0.67f;
                for (int i = 1; i < 5; i++)
                {
                    lightColors[i]           = ColorValue.FromColor(Color.White);
                    pointLightPositions[i]   = TgcParserUtils.vector3ToVector4(posicionesDeLuces[i - 1]);
                    pointLightIntensity[i]   = (float)GuiController.Instance.Modifiers["lightIntensity"];
                    pointLightAttenuation[i] = (float)GuiController.Instance.Modifiers["lightAttenuation"];
                }

                mesh.Effect.SetValue("lightColor", lightColors);
                mesh.Effect.SetValue("lightPosition", pointLightPositions);
                mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(lightPos));
                mesh.Effect.SetValue("lightIntensity", pointLightIntensity);
                mesh.Effect.SetValue("lightAttenuation", pointLightAttenuation);

                //Cargar variables de shader de Material. El Material en realidad deberia ser propio de cada mesh. Pero en este ejemplo se simplifica con uno comun para todos
                mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Black));
                mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.Yellow));
                mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White));
                mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.Yellow));
                mesh.Effect.SetValue("materialSpecularExp", 33f);
                mesh.render();
            }
            else if (tipo == 2)
            {
                lightColors[0]           = ColorValue.FromColor(Color.LightGoldenrodYellow);
                pointLightPositions[0]   = TgcParserUtils.vector3ToVector4(lightPos);
                pointLightIntensity[0]   = intensidad + random * 3;
                pointLightAttenuation[0] = 0.67f;

                for (int i = 1; i < 5; i++)
                {
                    lightColors[i]           = ColorValue.FromColor(Color.White);
                    pointLightPositions[i]   = TgcParserUtils.vector3ToVector4(posicionesDeLuces[i - 1]);
                    pointLightIntensity[i]   = (float)GuiController.Instance.Modifiers["lightIntensity"];
                    pointLightAttenuation[i] = (float)GuiController.Instance.Modifiers["lightAttenuation"];
                }

                mesh.Effect.SetValue("lightColor", lightColors);
                mesh.Effect.SetValue("lightPosition", pointLightPositions);
                mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(lightPos));
                mesh.Effect.SetValue("lightIntensity", pointLightIntensity);
                mesh.Effect.SetValue("lightAttenuation", pointLightAttenuation);
                //Cargar variables de shader de Material. El Material en realidad deberia ser propio de cada mesh. Pero en este ejemplo se simplifica con uno comun para todos
                mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Black));
                mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White));
                mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White));
                mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.Orange));
                mesh.Effect.SetValue("materialSpecularExp", 23f);
                mesh.render();
            }
        }
        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 = "EnvironmentMapTechnique";
            }
            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 bumpMeshes)
            {
                mesh.Effect    = currentShader;
                mesh.Technique = currentTechnique;
            }


            Vector3 eyePosition = GuiController.Instance.FpsCamera.getPosition();

            //Renderizar meshes con BumpMapping
            foreach (TgcMeshBumpMapping mesh in bumpMeshes)
            {
                if (lightEnable)
                {
                    //Obtener la luz que corresponde a este mesh (buscamos la mas cercana)
                    LightData light = getClosestLight(mesh.BoundingBox.calculateBoxCenter());

                    mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(eyePosition));
                    mesh.Effect.SetValue("bumpiness", (float)GuiController.Instance.Modifiers["bumpiness"]);
                    mesh.Effect.SetValue("reflection", (float)GuiController.Instance.Modifiers["reflection"]);
                    mesh.Effect.SetValue("lightIntensity", (float)GuiController.Instance.Modifiers["lightIntensity"]);
                    mesh.Effect.SetValue("lightAttenuation", (float)GuiController.Instance.Modifiers["lightAttenuation"]);


                    //Cargar variables de shader de la luz
                    mesh.Effect.SetValue("lightColor", ColorValue.FromColor(light.color));
                    mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(light.pos));

                    //Cargar variables de shader del Material
                    mesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mEmissive"]));
                    mesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mAmbient"]));
                    mesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mDiffuse"]));
                    mesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["mSpecular"]));
                    mesh.Effect.SetValue("materialSpecularExp", (float)GuiController.Instance.Modifiers["specularEx"]);

                    //CubeMap
                    mesh.Effect.SetValue("texCubeMap", cubeMap);
                }


                //Renderizar modelo
                mesh.render();
            }

            //Renderizar meshes comunes
            foreach (TgcMesh mesh in commonMeshes)
            {
                mesh.render();
            }
        }
        public void Init()
        {
            //seteamos atributos particulares del robot
            health = 100;
            score  = 1;
            Device d3dDevice = GuiController.Instance.D3dDevice;

            MESH_SCALE   = 0.5f;
            tiempoMuerte = 5f;
            attackDamage = 25;
            //cargamos el mesh
            //Despues de agregar el skeletalMesh dejamos de renderizar este mesh, pero igual lo utilizamos para calcular muchas cosas
            this.mesh = GameManager.Instance.ModeloRobot.clone("robot");

            giroInicial = Matrix.RotationY(-(float)Math.PI / 2);


            //carga de animaciones
            TgcSkeletalLoader skeletalLoader = new TgcSkeletalLoader();

            skeletalMesh = skeletalLoader.loadMeshAndAnimationsFromFile(
                GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\" + "Robot-TgcSkeletalMesh.xml",
                new string[] {
                GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\" + "Caminando-TgcSkeletalAnim.xml",
                GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\" + "Patear-TgcSkeletalAnim.xml",
                GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\" + "Arrojar-TgcSkeletalAnim.xml",
            });

            skeletalMesh.playAnimation("Caminando", true);
            skeletalMesh.AnimationEnds += this.onAnimationEnds;

            skeletalMesh.Effect = GameManager.Instance.skeletalEnvMap;
            //skeletalMesh.Technique = "SkeletalEnvMap";

            skeletalMesh.Effect.SetValue("lightColor", ColorValue.FromColor(Color.White));
            skeletalMesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(new Vector3(0, 1400, 0)));
            skeletalMesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(CustomFpsCamera.Instance.getPosition()));
            skeletalMesh.Effect.SetValue("lightIntensity", 0.3f);
            skeletalMesh.Effect.SetValue("lightAttenuation", 0.3f);
            skeletalMesh.Effect.SetValue("reflection", 0.65f);

            //Cargar variables de shader de Material. El Material en realidad deberia ser propio de cada mesh. Pero en este ejemplo se simplifica con uno comun para todos
            skeletalMesh.Effect.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.Black));
            skeletalMesh.Effect.SetValue("materialAmbientColor", ColorValue.FromColor(Color.White));
            skeletalMesh.Effect.SetValue("materialDiffuseColor", ColorValue.FromColor(Color.White));
            skeletalMesh.Effect.SetValue("materialSpecularColor", ColorValue.FromColor(Color.White));
            skeletalMesh.Effect.SetValue("materialSpecularExp", 7);

            skeletalMesh.Effect.SetValue("texCubeMap", GameManager.Instance.cubeMap);

            skeletalMesh.setColor(Color.Peru);

            //realizamos el init() comun a todos los enemigos
            base.Init();
            //Creamos boundingBox nuevas para la cabeza, pecho y piernas del robot
            HEADSHOT_BOUNDINGBOX = this.mesh.BoundingBox.clone();
            CHEST_BOUNDINGBOX    = this.mesh.BoundingBox.clone();
            LEGS_BOUNDINGBOX     = this.mesh.BoundingBox.clone();
            Matrix escalabox     = Matrix.Scaling(new Vector3(0.43f, 0.3f, 0.43f));
            Matrix traslationbox = Matrix.Translation(new Vector3(0, 90f, 0));

            HEADSHOT_BOUNDINGBOX.transform(escalabox * traslationbox);
            posicionActualHeadshot = escalabox * traslationbox * posicionActual;
            Matrix escalabox2     = Matrix.Scaling(new Vector3(0.6f, 0.3f, 0.6f));
            Matrix traslationbox2 = Matrix.Translation(new Vector3(0, 50f, 0));

            CHEST_BOUNDINGBOX.transform(escalabox2 * traslationbox2);
            posicionActualChest = escalabox2 * traslationbox2 * posicionActual;
            Matrix escalabox3     = Matrix.Scaling(new Vector3(0.4f, 0.38f, 0.4f));
            Matrix traslationbox3 = Matrix.Translation(new Vector3(0, 0f, 0));

            LEGS_BOUNDINGBOX.transform(escalabox3 * traslationbox3);
            posicionActualLegs = escalabox3 * traslationbox3 * posicionActual;


            skeletalMesh.AutoTransformEnable = false;

            //carga de sonido
            SonidoMovimiento             = new Tgc3dSound(GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Audio\\Robot\\servomotor.wav", getPosicionActual());
            SonidoMovimiento.MinDistance = 70f;
            SonidoMovimiento.play(true);

            //setBaseEffect();
            skeletalMesh.computeNormals();
        }
Exemple #27
0
        public override void Render()
        {
            PreRender();

            Effect currentShader;
            string currentTechnique;

            //Shader personalizado de iluminacion
            currentShader    = effect;
            currentTechnique = "EnvironmentMapTechnique";

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

            var eyePosition = Camara.Position;

            //Renderizar meshes con BumpMapping
            foreach (var mesh in bumpMeshes)
            {
                if (true) //FIXME da error cuando se desabilitan las luces.) (lightEnable)
                {
                    //Obtener la luz que corresponde a este mesh (buscamos la mas cercana)
                    var light = getClosestLight(mesh.BoundingBox.calculateBoxCenter());

                    mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(eyePosition));
                    mesh.Effect.SetValue("bumpiness", (float)Modifiers["bumpiness"]);
                    mesh.Effect.SetValue("reflection", (float)Modifiers["reflection"]);
                    mesh.Effect.SetValue("lightIntensity", (float)Modifiers["lightIntensity"]);
                    mesh.Effect.SetValue("lightAttenuation",
                                         (float)Modifiers["lightAttenuation"]);

                    //Cargar variables de shader de la luz
                    mesh.Effect.SetValue("lightColor", ColorValue.FromColor(light.color));
                    mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(light.pos));

                    //Cargar variables de shader del Material
                    mesh.Effect.SetValue("materialEmissiveColor",
                                         ColorValue.FromColor((Color)Modifiers["mEmissive"]));
                    mesh.Effect.SetValue("materialAmbientColor",
                                         ColorValue.FromColor((Color)Modifiers["mAmbient"]));
                    mesh.Effect.SetValue("materialDiffuseColor",
                                         ColorValue.FromColor((Color)Modifiers["mDiffuse"]));
                    mesh.Effect.SetValue("materialSpecularColor",
                                         ColorValue.FromColor((Color)Modifiers["mSpecular"]));
                    mesh.Effect.SetValue("materialSpecularExp", (float)Modifiers["specularEx"]);

                    //CubeMap
                    mesh.Effect.SetValue("texCubeMap", cubeMap);
                }

                mesh.UpdateMeshTransform();
                //Renderizar modelo
                mesh.render();
            }

            //Renderizar meshes comunes
            foreach (var mesh in commonMeshes)
            {
                mesh.UpdateMeshTransform();
                mesh.render();
            }

            PostRender();
        }
        public override void Render()
        {
            ClearTextures();
            D3DDevice.Instance.Device.BeginScene();
            D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);

            //Cargar valores de niebla
            var fogShader = (bool)Modifiers["FogShader"];

            fog.Enabled       = !(bool)Modifiers["FogShader"];
            fog.StartDistance = (float)Modifiers["startDistance"];
            fog.EndDistance   = (float)Modifiers["endDistance"];
            fog.Density       = (float)Modifiers["density"];
            fog.Color         = (Color)Modifiers["color"];

            if (fog.Enabled)
            {
                fog.updateValues();
            }

            if (fogShader)
            {
                // Cargamos las variables de shader,
                //color del fog.
                effect.SetValue("ColorFog", fog.Color.ToArgb());
                effect.SetValue("CameraPos", TgcParserUtils.vector3ToFloat4Array(Camara.Position));
                effect.SetValue("StartFogDistance", fog.StartDistance);
                effect.SetValue("EndFogDistance", fog.EndDistance);
                effect.SetValue("Density", fog.Density);
            }

            //Actualizar valores
            //
            foreach (var mesh in skyBox.Faces)
            {
                if (fogShader)
                {
                    mesh.Effect    = effect;
                    mesh.Technique = "RenderScene";
                }
                else
                {
                    mesh.Effect    = TgcShaders.Instance.TgcMeshShader;
                    mesh.Technique = "DIFFUSE_MAP";
                }

                mesh.render();
            }

            //skyBox.render();

            foreach (var mesh in scene.Meshes)
            {
                if (fogShader)
                {
                    mesh.Effect    = effect;
                    mesh.Technique = "RenderScene";
                }
                else
                {
                    mesh.Effect    = TgcShaders.Instance.TgcMeshShader;
                    mesh.Technique = "DIFFUSE_MAP";
                }

                mesh.render();
            }

            RenderAxis();
            RenderFPS();
            D3DDevice.Instance.Device.EndScene();
            D3DDevice.Instance.Device.Present();
        }