public void renderSinEfectos(float elapsedTime) { Device d3dDevice = D3DDevice.Instance.Device; // dibujo la escena una textura effect.Technique = "DefaultTechnique"; d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); d3dDevice.BeginScene(); //Dibujamos todos los meshes del escenario renderScene("DefaultTechnique"); //Render skybox skyBox.Render(); d3dDevice.EndScene(); }
/// <summary> /// Se llama cada vez que hay que refrescar la pantalla. /// Escribir aquí todo el código referido al renderizado. /// Borrar todo lo que no haga falta. /// </summary> public override void Render() { //Inicio el render de la escena, para ejemplos simples. Cuando tenemos postprocesado o shaders es mejor realizar las operaciones según nuestra conveniencia. PreRender(); //Dibuja un texto por pantalla //DrawText.drawText("Con la tecla F se dibuja el bounding box.", 0, 20, Color.OrangeRed); DrawText.drawText("Posicion de la camara [Actual]: " + TGCVector3.PrintVector3(Camara.Position), 0, 20, Color.OrangeRed); DrawText.drawText("Posicion del personaje [Actual]: " + TGCVector3.PrintVector3(tgcPersonaje.getPosicion()), 0, 30, Color.OrangeRed); DrawText.drawText("Presionar F para ver las boundingBox", 0, 40, Color.OrangeRed); DrawText.drawText("Vector direccion personaje" + TGCVector3.PrintVector3(tgcPersonaje.getOrientacion()), 0, 50, Color.OrangeRed); DrawText.drawText("Vector direccion colision" + TGCVector3.PrintVector3(tgcPersonaje.getVectorColision()), 0, 60, Color.OrangeRed); skyBox.Render(); tgcPersonaje.Render(); escenario1.Render(); //Finaliza el render y presenta en pantalla, al igual que el preRender se debe para casos puntuales es mejor utilizar a mano las operaciones de EndScene y PresentScene //Mostrar los boundingBox correspondientes, no es algo que el personaje deba poder hacer pero es para ver que if (boundingBox) { tgcPersonaje.DrawBoundingBox(); //Cuando tengamos varios escenarios tendríamos que hacer //escenarioActual.DrawBoundingBox(); //Con escenarioActual variable del gameModel escenario1.DrawBoundingBox(); } PostRender(); }
private void RenderMainScene() { D3DDevice.Instance.Device.BeginScene(); D3DDevice.Instance.ParticlesEnabled = true; D3DDevice.Instance.EnableParticles(); skyBox.Render(); foreach (GameObject o in SceneObjects) { o.Render(); } // HeightMaps foreach (HeightMapTextured hm in heightMaps) { hm.Render(); } //ScenesQuadTree.RenderDebugBoxes(); RenderBubbles(); D3DDevice.Instance.Device.EndScene(); }
private void renderScene(bool cubemap = false) { skyBox.Render(); if (!cubemap) { pelota.Mesh.Effect.SetValue("normal_map", TextureLoader.FromFile(D3DDevice.Instance.Device, MediaDir + "Textures\\pelotaNormalMap.png")); // TODO: Estamos cargando siempre esta textura del disco. Esto habria que evitarlo } pelota.Render(sol); pasto.Render(cubemap); if (!cubemap) { foreach (var jugador in jugadores) { if (jugador.Translation != Camera.Position) { jugador.Mesh.Effect.SetValue("eyePosition", TGCVector3.TGCVector3ToFloat3Array(Camera.Position)); jugador.Render(sol); } } } arcos[0].Render(sol); arcos[1].Render(sol); foreach (var turbo in turbos) { turbo.Render(sol); } paredes.Render(sol); }
public override void Render() { PreRender(); //Obtener boolean para saber si hay que mostrar Bounding Box var showBB = showBoundingBoxModifier.Value; if (collisionManager.Collision) { collisionNormalArrow.Render(); collisionPoint.Render(); } //Render de mallas foreach (var mesh in escenario.Meshes) { mesh.Render(); } //Render personaje personaje.animateAndRender(ElapsedTime); if (showBB) { characterSphere.Render(); } //Render linea directionArrow.Render(); //Render SkyBox skyBox.Render(); PostRender(); }
override public void Render(TgcFrustum frustum) { ClearScreen(); skyBox.Render(); drawer.BeginDrawSprite(); //drawer.DrawSprite(spriteSubnautica); drawer.DrawSprite(spriteBlackRectangle); drawer.DrawSprite(title); drawer.EndDrawSprite(); DrawTextSmall.drawText("Start", (int)x, yStartWord, colors[(int)pointer]); DrawTextSmall.drawText("Exit", (int)x, yStartWord + yOffset, colors[(((int)pointer) + 1) % 2]); DrawTextSmall.drawText("->", (int)x - 40, yStartWord + (int)pointer * yOffset, Color.OrangeRed); if (Cheats.GodMode) { this.DrawTextSmall.drawText("God Mode", 300, 300, Color.Gold); } if (Cheats.StartingItems) { this.DrawTextSmall.drawText("Starting items", 300, 360, Color.Gold); } }
/// <summary> /// Se llama cada vez que hay que refrescar la pantalla. /// Escribir aquí todo el código referido al renderizado. /// Borrar todo lo que no haga falta. /// </summary> public override void Render() { //Inicio el render de la escena, para ejemplos simples. Cuando tenemos postprocesado o shaders es mejor realizar las operaciones según nuestra conveniencia. PreRender(); //BackgroundColor D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); ClearTextures(); //Dibuja un texto por pantalla DrawText.drawText("Con la tecla F se dibuja el bounding box.", 0, 20, Color.OrangeRed); DrawText.drawText("Posición del personaje: " + TGCVector3.PrintVector3(personaje.Position), 0, 40, System.Drawing.Color.Red); //Render personaje //personaje.Render(); personaje.animateAndRender(ElapsedTime); //Render escenas RenderEscenas(); //Render obstaculos RenderObstaculos(); if (huboColision) { DrawText.drawText("PERDISTE!!!: ", 500, 20, System.Drawing.Color.WhiteSmoke); } //Render de BoundingBox, muy útil para debug de colisiones. if (BoundingBox) { BoundingBoxPersonajeYObstaculos(); } //Render del SkyBox skyBox.Render(); PostRender(); }
public override void Render() { PreRender(); DrawText.drawText("Camera pos: " + TGCVector3.PrintVector3(Camara.Position), 5, 20, Color.Red); //Renderizar SkyBox skyBox.Render(); PostRender(); }
public void RenderEscenario() { tgcScene.Meshes.ForEach(mesh => mesh.UpdateMeshTransform()); tgcScene.Meshes.ForEach(mesh => mesh.Render()); heightmap.Render(); skyBox.Render(); }
public override void Render() { D3DDevice.Instance.Device.Clear(Microsoft.DirectX.Direct3D.ClearFlags.Target | Microsoft.DirectX.Direct3D.ClearFlags.ZBuffer, Color.White, 1.0f, 0); D3DDevice.Instance.Device.BeginScene(); pasto.Render(); paredes.Render(); skyBox.Render(); drawer2D.BeginDrawSprite(); drawer2D.DrawSprite(unSprite); drawer2D.EndDrawSprite(); }
public override void Render() { PreRender(); Bandicoot.Transform = Scale * Rotation * new TGCMatrix(Physics.BandicootRigidBody.InterpolationWorldTransform); skyBox.Render(); Bandicoot.Render(); Terrain.Render(); Water.Render(); Physics.Render(); PostRender(); }
public void Render() { shader.SetValue("materialEmissiveColor", ColorValue.FromColor(Color.FromArgb(0, candlesPlaced < 6?0:(candlesPlaced - 6), 0, 0))); shader.SetValue("eyePosition", TGCVector3.Vector3ToFloat4Array(g.camera.eyePosition)); shader.SetValue("lightIntensityEye", 50f + (g.hands.state > 0? (g.hands.state == 1? 250f + Random.Next(-50, 50) : 250f + Random.Next(-50, 50) + 250f + Random.Next(-50, 50)) :0)); for (int i = 0; i < lightCount; i++) { //lightPos del frame anterior shader.SetValue("lightPosition[" + i.ToString() + "]", TGCVector3.Vector3ToFloat4Array(lightPosition[i])); shader.SetValue("lightIntensity[" + i.ToString() + "]", 250f + Random.Next(-50, 50)); //de paso limpio la lightpos para cargar las de este frame lightPosition[i] = TGCVector3.One * float.MaxValue; } lightIndex = 0; sky.Render(); if (renderCandlePlace) { renderCandles(); } g.chunks.render(); if (GameModel.debugColission) { g.chunks.fromCoordinates(g.camera.eyePosition).renderDebugColission(); TGCVector3 ray = g.camera.horx.Origin + TGCVector3.Down * 200f; TGCVector3 end = ray + g.camera.horx.Direction * 200f; TgcLine.fromExtremes(ray, end).Render(); ray = g.camera.horz.Origin + TGCVector3.Down * 200f; end = ray + g.camera.horz.Direction * 200f; TgcLine.fromExtremes(ray, end).Render(); } g.terrain.Render(); deforming += g.game.ElapsedTime * 0.1f; //Console.WriteLine(deforming); }
public override void Render() { PreRender(); var showGrid = showGridModifier.Value; var showTerrain = showTerrainModifier.Value; skyBox.Render(); if (showTerrain) { terreno.Render(); } grilla.render(Frustum, showGrid); PostRender(); }
public override void Render() { PreRender(); var showKdTree = showKdTreeModifier.Value; var showTerrain = showTerrainModifier.Value; skyBox.Render(); if (showTerrain) { terreno.Render(); } kdtree.render(Frustum, showKdTree); PostRender(); }
/// <summary> /// Se llama cada vez que hay que refrescar la pantalla. /// Escribir aquí todo el código referido al renderizado. /// Borrar todo lo que no haga falta. /// </summary> public override void Render() { PreRender(); //Dibuja un texto por pantalla DrawText.drawText("/--INTRUCCIONES------------", 0, 20, Color.LightYellow); DrawText.drawText("Con la tecla F se dibuja el bounding box.", 0, 35, Color.LightYellow); DrawText.drawText("Con la tecla C se cambia la posicion de la camara", 0, 50, Color.LightYellow); DrawText.drawText("/--DATOS-------------------", 0, 80, Color.LightYellow); DrawText.drawText("Velocidad: " + forward_speed + "F", 0, 95, Color.LightYellow); DrawText.drawText("Posicion de la nave: X: " + ship.Position.X + " Y: " + ship.Position.Y + " Z: " + ship.Position.Z, 0, 110, Color.LightYellow); //Siempre antes de renderizar el modelo necesitamos actualizar la matriz de transformacion. //Debemos recordar el orden en cual debemos multiplicar las matrices, en caso de tener modelos jerárquicos, tenemos control total. //Box.Transform = TGCMatrix.Scaling(Box.Scale) * TGCMatrix.RotationYawPitchRoll(Box.Rotation.Y, Box.Rotation.X, Box.Rotation.Z) * TGCMatrix.Translation(Box.Position); //A modo ejemplo realizamos toda las multiplicaciones, pero aquí solo nos hacia falta la traslación. //Finalmente invocamos al render de la caja //Cuando tenemos modelos mesh podemos utilizar un método que hace la matriz de transformación estándar. //Es útil cuando tenemos transformaciones simples, pero OJO cuando tenemos transformaciones jerárquicas o complicadas. //Mesh.UpdateMeshTransform(); //Render del mesh //Mesh.Render(); //pista.Render(); skyBox.Render(); ship.Render(ElapsedTime); //scene.RenderAll(); pista.Render(); if (buliEne) { enemigo.Render(); } //Render de BoundingBox, muy útil para debug de colisiones. if (BoundingBox) { this.ship.RenderBoundingBox(); enemigo.BoundingBox().Render(); } PostRender(); }
public void baseRender() { SkyBox.Render(); //Dibujar bounding boxes de los mesh (Debugging) foreach (var plataforma in Plataformas) { RenderObject(plataforma.Mesh); } foreach (var pozo in ListaPozos) { RenderObject(pozo); } foreach (var caja in ListaCajasEmpujables) { RenderObject(caja.Mesh); } Grilla.render(Env.Frustum, ShowGrilla, this); }
public override void Render() { PreRender(); //Obtener boolean para saber si hay que mostrar Bounding Box var showBB = showBoundingBoxModifier.Value; //Render mallas que no se interponen foreach (var mesh in objectsInFront) { mesh.Render(); if (showBB) { mesh.BoundingBox.Render(); } } //Para las mallas que se interponen a la cámara, solo renderizar su BoundingBox foreach (var mesh in objectsBehind) { mesh.BoundingBox.Render(); } //Render personaje personaje.animateAndRender(ElapsedTime); if (showBB) { characterSphere.Render(); } //Render linea directionArrow.Render(); //Render SkyBox skyBox.Render(); PostRender(); }
public void renderScene(float elapsedTime, bool cubemap) { //Renderizar terreno terrain.Render(); //Renderizar SkyBox skyBox.Render(); // dibujo el bosque foreach (var instance in bosque) { instance.Render(); } // avion //avion.Technique = cubemap ? "RenderCubeMap" : "RenderScene"; avion.Render(); if (!cubemap) { // dibujo el mesh mesh.Technique = "RenderCubeMap"; mesh.Render(); } }
public override void Render() { PreRender(); //Obtener boolean para saber si hay que mostrar Bounding Box var showBB = showBoundingBoxModifier.Value; if (collisionManager.Result.collisionFound) { collisionNormalArrow.Render(); collisionPoint.Transform = TGCMatrix.RotationYawPitchRoll(collisionPoint.Rotation.Y, collisionPoint.Rotation.X, collisionPoint.Rotation.Z) * TGCMatrix.Translation(collisionPoint.Position); collisionPoint.Render(); } //Render de mallas foreach (var mesh in escenario.Meshes) { mesh.Render(); } //Render personaje personaje.animateAndRender(ElapsedTime); if (showBB) { characterElipsoid.Render(); } //Render linea directionArrow.Render(); //Render SkyBox skyBox.Render(); PostRender(); }
public override void Render() { PreRender(); ClearTextures(); bool invisibilidadActivada = ((JugadorActivo == AutoFisico1 && AutoFisico1.Invisible) || (JugadorActivo == AutoFisico2 && AutoFisico2.Invisible)); //Permito las particulas D3DDevice.Instance.ParticlesEnabled = true; D3DDevice.Instance.EnableParticles(); switch (SwitchInicio) { case 1: { Hud.PantallaInicio(); if (Input.keyPressed(Key.C)) { SwitchInicio = 2; } if (Input.keyPressed(Key.D1)) { Jugadores[1] = null; SwitchInicio = 3; //SwitchMusica = true; SwitchFX = true; AutoFisico1.Encendido(); InGame = true; } if (Input.keyPressed(Key.D2)) { juegoDoble = true; SwitchInicio = 4; //SwitchMusica = true; SwitchFX = true; SwitchCamara = 3; AutoFisico1.Encendido(); AutoFisico2.Encendido(); InGame = true; } break; } case 2: { Hud.PantallaControles(); if (Input.keyPressed(Key.V)) { SwitchInicio = 1; } break; } case 3: { var device = D3DDevice.Instance.Device; Tiempo += ElapsedTime; AutoFisico1.ElapsedTime = ElapsedTime; AutoFisico1.FXActivado = SwitchFX; Invisible.PreRender(invisibilidadActivada); Plaza.RenderAll(); AutoFisico1.Render(ElapsedTime); GrupoPolicias.Render(ElapsedTime); Cielo.Render(); Invisible.PostRender(invisibilidadActivada, Tiempo); Hud.Juego(invisibilidadActivada, JugadorActivo, juegoDoble, pantallaDoble, AutoFisico1, AutoFisico2); if (AutoFisico1.Vida < 0) { TiempoFinal = Tiempo; Sonidos.SuenaGameOver(); SwitchInicio = 5; } if (Input.keyDown(Key.F10)) { Hud.Pausar(); } EnvMap.Render(AutoFisico1, AutoFisico2, GrupoPolicias, Camara, juegoDoble); Hud.Tiempo(FastMath.Floor(Tiempo)); break; } case 4: { Tiempo += ElapsedTime; AutoFisico1.ElapsedTime = ElapsedTime; AutoFisico2.ElapsedTime = ElapsedTime; AutoFisico1.FXActivado = SwitchFX; AutoFisico2.FXActivado = SwitchFX; Invisible.PreRender(invisibilidadActivada); DrawText.drawText("Velocidad P1:" + AutoFisico1.Velocidad, 0, 90, Color.Green); Plaza.RenderAll(); AutoFisico1.Render(ElapsedTime); AutoFisico2.Render(ElapsedTime); GrupoPolicias.Render(ElapsedTime); Cielo.Render(); Invisible.PostRender(invisibilidadActivada, Tiempo); Hud.Juego(invisibilidadActivada, JugadorActivo, juegoDoble, pantallaDoble, AutoFisico1, AutoFisico2); if (AutoFisico1.Vida < 0) { Hud.GanoJ2(); SwitchCamara = 2; Sonidos.SuenaAplausos(); InGame = false; } if (AutoFisico2.Vida < 0) { Hud.GanoJ1(); SwitchCamara = 1; Sonidos.SuenaAplausos(); InGame = false; } if (Input.keyDown(Key.F10)) { Hud.Pausar(); } if (Input.keyDown(Key.F10)) { Hud.Pausar(); } EnvMap.Render(AutoFisico1, AutoFisico2, GrupoPolicias, Camara, juegoDoble); Hud.Tiempo(FastMath.Floor(Tiempo)); break; } case 5: { SwitchFX = false; SwitchMusica = false; InGame = false; Hud.JuegoTerminado(); Hud.TiempoFinal(FastMath.Floor(TiempoFinal)); if (Input.keyPressed(Key.M)) { SwitchInicio = 1; } break; } } PostRender(); }
public override void Render() { skyBox.Render(); }
public override void Render() { PreRender(); ClearTextures(); bool invisibilidadActivada = (SwitchInvisibilidadJ1 - 1 == SwitchCamara) || (SwitchInvisibilidadJ2 == SwitchCamara); //Permito las particulas D3DDevice.Instance.ParticlesEnabled = true; D3DDevice.Instance.EnableParticles(); switch (SwitchInicio) { case 1: { Hud.PantallaInicio(); if (Input.keyPressed(Key.C)) { SwitchInicio = 2; } if (Input.keyPressed(Key.D1)) { Jugadores[1] = null; SwitchInicio = 3; SwitchMusica = true; SwitchFX = true; AutoFisico1.Encendido(); inGame = true; } if (Input.keyPressed(Key.D2)) { juegoDoble = true; SwitchInicio = 4; SwitchMusica = true; SwitchFX = true; SwitchCamara = 3; AutoFisico1.Encendido(); AutoFisico2.Encendido(); inGame = true; } break; } case 2: { Hud.PantallaControles(); if (Input.keyPressed(Key.V)) { SwitchInicio = 1; } break; } case 3: { var device = D3DDevice.Instance.Device; Tiempo += ElapsedTime; AutoFisico1.ElapsedTime = ElapsedTime; AutoFisico1.FXActivado = SwitchFX; // ShaderInvisibilidad ----- Invisibilidad.Technique = "DefaultTechnique"; var pOldRT = device.GetRenderTarget(0); var pSurf = g_pRenderTarget.GetSurfaceLevel(0); if (invisibilidadActivada) { device.SetRenderTarget(0, pSurf); } var pOldDS = device.DepthStencilSurface; if (invisibilidadActivada) { device.DepthStencilSurface = g_pDepthStencil; } device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); //--------------------------- Plaza.RenderAll(); AutoFisico1.Render(ElapsedTime); GrupoPolicias.Render(ElapsedTime); Cielo.Render(); pSurf.Dispose(); if (invisibilidadActivada) { device.DepthStencilSurface = pOldDS; device.SetRenderTarget(0, pOldRT); Invisibilidad.Technique = "PostProcess"; Invisibilidad.SetValue("time", Tiempo); device.VertexFormat = CustomVertex.PositionTextured.Format; device.SetStreamSource(0, g_pVBV3D, 0); Invisibilidad.SetValue("g_RenderTarget", g_pRenderTarget); device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); Invisibilidad.Begin(FX.None); Invisibilidad.BeginPass(0); device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); Invisibilidad.EndPass(); Invisibilidad.End(); } Hud.Juego(invisibilidadActivada, JugadorActivo, juegoDoble, pantallaDoble, AutoFisico1, AutoFisico2); if (AutoFisico1.Vida < 0) { TiempoFinal = Tiempo; Sonidos.SuenaGameOver(); SwitchInicio = 5; } if (Input.keyDown(Key.F10)) { Hud.Pausar(); } // Shader Enviroment Map -------------------------------- //D3DDevice.Instance.Device.EndScene(); var g_pCubeMap = new CubeTexture(D3DDevice.Instance.Device, 256, 1, Usage.RenderTarget, Format.A16B16G16R16F, Pool.Default); var pOldRT2 = D3DDevice.Instance.Device.GetRenderTarget(0); D3DDevice.Instance.Device.Transform.Projection = TGCMatrix.PerspectiveFovLH(Geometry.DegreeToRadian(90.0f), 1f, 1f, 10000f).ToMatrix(); // Genero las caras del enviroment map for (var nFace = CubeMapFace.PositiveX; nFace <= CubeMapFace.NegativeZ; ++nFace) { var pFace = g_pCubeMap.GetCubeMapSurface(nFace, 0); D3DDevice.Instance.Device.SetRenderTarget(0, pFace); TGCVector3 Dir, VUP; Color color; switch (nFace) { default: case CubeMapFace.PositiveX: // Left Dir = new TGCVector3(1, 0, 0); VUP = TGCVector3.Up; color = Color.Black; break; case CubeMapFace.NegativeX: // Right Dir = new TGCVector3(-1, 0, 0); VUP = TGCVector3.Up; color = Color.Red; break; case CubeMapFace.PositiveY: // Up Dir = TGCVector3.Up; VUP = new TGCVector3(0, 0, -1); color = Color.Gray; break; case CubeMapFace.NegativeY: // Down Dir = TGCVector3.Down; VUP = new TGCVector3(0, 0, 1); color = Color.Yellow; break; case CubeMapFace.PositiveZ: // Front Dir = new TGCVector3(0, 0, 1); VUP = TGCVector3.Up; color = Color.Green; break; case CubeMapFace.NegativeZ: // Back Dir = new TGCVector3(0, 0, -1); VUP = TGCVector3.Up; color = Color.Blue; break; } D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, color, 1.0f, 0); //Renderizar foreach (var mesh in AutoFisico1.Mayas) { mesh.Effect = EnvMap; mesh.Technique = "RenderScene"; mesh.Render(); } } D3DDevice.Instance.Device.SetRenderTarget(0, pOldRT2); D3DDevice.Instance.Device.Transform.View = Camara.GetViewMatrix().ToMatrix(); D3DDevice.Instance.Device.Transform.Projection = TGCMatrix.PerspectiveFovLH(Geometry.DegreeToRadian(45.0f), D3DDevice.Instance.AspectRatio, 1f, 10000f).ToMatrix(); //D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); EnvMap.SetValue("g_txCubeMap", g_pCubeMap); foreach (var mesh in AutoFisico1.Mayas) { mesh.Effect = EnvMap; mesh.Technique = "RenderScene"; mesh.Render(); } foreach (var rueda in AutoFisico1.Ruedas) { rueda.Effect = EnvMap; rueda.Technique = "RenderScene"; rueda.Render(); } foreach (var mesh in GrupoPolicias.Todos[0].Mayas) { mesh.Effect = EnvMap; mesh.Technique = "RenderScene"; mesh.Render(); } g_pCubeMap.Dispose(); //------------------------------------------------------------- Hud.Tiempo(FastMath.Floor(Tiempo)); break; } case 4: { var device = D3DDevice.Instance.Device; Tiempo += ElapsedTime; AutoFisico1.ElapsedTime = ElapsedTime; AutoFisico2.ElapsedTime = ElapsedTime; AutoFisico1.FXActivado = SwitchFX; AutoFisico2.FXActivado = SwitchFX; // ShaderInvisibilidad ----- Invisibilidad.Technique = "DefaultTechnique"; var pOldRT = device.GetRenderTarget(0); var pSurf = g_pRenderTarget.GetSurfaceLevel(0); if (invisibilidadActivada) { device.SetRenderTarget(0, pSurf); } var pOldDS = device.DepthStencilSurface; if (invisibilidadActivada) { device.DepthStencilSurface = g_pDepthStencil; } device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); //-------------------------- DrawText.drawText("Velocidad P1:" + AutoFisico1.Velocidad, 0, 90, Color.Green); Plaza.RenderAll(); AutoFisico1.Render(ElapsedTime); AutoFisico2.Render(ElapsedTime); GrupoPolicias.Render(ElapsedTime); Cielo.Render(); pSurf.Dispose(); if (invisibilidadActivada) { device.DepthStencilSurface = pOldDS; device.SetRenderTarget(0, pOldRT); Invisibilidad.Technique = "PostProcess"; Invisibilidad.SetValue("time", Tiempo); device.VertexFormat = CustomVertex.PositionTextured.Format; device.SetStreamSource(0, g_pVBV3D, 0); Invisibilidad.SetValue("g_RenderTarget", g_pRenderTarget); device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); Invisibilidad.Begin(FX.None); Invisibilidad.BeginPass(0); device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); Invisibilidad.EndPass(); Invisibilidad.End(); } Hud.Juego(invisibilidadActivada, JugadorActivo, juegoDoble, pantallaDoble, AutoFisico1, AutoFisico2); if (AutoFisico1.Vida < 0) { Hud.GanoJ2(); SwitchCamara = 2; Jugadores[1] = null; Sonidos.SuenaAplausos(); inGame = false; } if (AutoFisico2.Vida < 0) { Hud.GanoJ1(); SwitchCamara = 1; Jugadores[0] = null; Sonidos.SuenaAplausos(); inGame = false; } if (Input.keyDown(Key.F10)) { Hud.Pausar(); } if (Input.keyDown(Key.F10)) { Hud.Pausar(); } // Shader Enviroment Map -------------------------------- //D3DDevice.Instance.Device.EndScene(); var g_pCubeMap = new CubeTexture(D3DDevice.Instance.Device, 256, 1, Usage.RenderTarget, Format.A16B16G16R16F, Pool.Default); var pOldRT2 = D3DDevice.Instance.Device.GetRenderTarget(0); D3DDevice.Instance.Device.Transform.Projection = TGCMatrix.PerspectiveFovLH(Geometry.DegreeToRadian(90.0f), 1f, 1f, 10000f).ToMatrix(); // Genero las caras del enviroment map for (var nFace = CubeMapFace.PositiveX; nFace <= CubeMapFace.NegativeZ; ++nFace) { var pFace = g_pCubeMap.GetCubeMapSurface(nFace, 0); D3DDevice.Instance.Device.SetRenderTarget(0, pFace); TGCVector3 Dir, VUP; Color color; switch (nFace) { default: case CubeMapFace.PositiveX: // Left Dir = new TGCVector3(1, 0, 0); VUP = TGCVector3.Up; color = Color.Black; break; case CubeMapFace.NegativeX: // Right Dir = new TGCVector3(-1, 0, 0); VUP = TGCVector3.Up; color = Color.Red; break; case CubeMapFace.PositiveY: // Up Dir = TGCVector3.Up; VUP = new TGCVector3(0, 0, -1); color = Color.Gray; break; case CubeMapFace.NegativeY: // Down Dir = TGCVector3.Down; VUP = new TGCVector3(0, 0, 1); color = Color.Yellow; break; case CubeMapFace.PositiveZ: // Front Dir = new TGCVector3(0, 0, 1); VUP = TGCVector3.Up; color = Color.Green; break; case CubeMapFace.NegativeZ: // Back Dir = new TGCVector3(0, 0, -1); VUP = TGCVector3.Up; color = Color.Blue; break; } D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, color, 1.0f, 0); //Renderizar foreach (var mesh in AutoFisico1.Mayas) { mesh.Effect = EnvMap; mesh.Technique = "RenderScene"; mesh.Render(); } foreach (var mesh in AutoFisico2.Mayas) { mesh.Effect = EnvMap; mesh.Technique = "RenderScene"; mesh.Render(); } } D3DDevice.Instance.Device.SetRenderTarget(0, pOldRT2); D3DDevice.Instance.Device.Transform.View = Camara.GetViewMatrix().ToMatrix(); D3DDevice.Instance.Device.Transform.Projection = TGCMatrix.PerspectiveFovLH(Geometry.DegreeToRadian(45.0f), D3DDevice.Instance.AspectRatio, 1f, 10000f).ToMatrix(); //D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); EnvMap.SetValue("g_txCubeMap", g_pCubeMap); foreach (var mesh in AutoFisico1.Mayas) { mesh.Effect = EnvMap; mesh.Technique = "RenderScene"; mesh.Render(); } foreach (var mesh in AutoFisico2.Mayas) { mesh.Effect = EnvMap; mesh.Technique = "RenderScene"; mesh.Render(); } foreach (var rueda in AutoFisico1.Ruedas) { rueda.Effect = EnvMap; rueda.Technique = "RenderScene"; rueda.Render(); } foreach (var mesh in GrupoPolicias.Todos[0].Mayas) { mesh.Effect = EnvMap; mesh.Technique = "RenderScene"; mesh.Render(); } g_pCubeMap.Dispose(); //------------------------------------------------------------- Hud.Tiempo(FastMath.Floor(Tiempo)); break; } case 5: { SwitchFX = false; SwitchMusica = false; inGame = false; Hud.JuegoTerminado(); Hud.TiempoFinal(FastMath.Floor(TiempoFinal)); if (Input.keyPressed(Key.M)) { SwitchInicio = 1; } break; } } PostRender(); }
public override void Render(float elapsedTime) { TexturesManager.Instance.clearAll(); var device = D3DDevice.Instance.Device; var pOldRT = device.GetRenderTarget(0); var pSurf = g_pRenderTarget.GetSurfaceLevel(0); device.SetRenderTarget(0, pSurf); var pOldDS = device.DepthStencilSurface; device.DepthStencilSurface = g_pDepthStencil; device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); time += elapsedTime; wavesEffect.SetValue("time", time); recoltableItemEffect.SetValue("time", time); bulletManager.Render(); collectModel.Render(elapsedTime); //Render SkyBox //if (playerModel.UnderSurface()) //{ // skyBoxUndersea.Render(); //} //else //{ // skyBox.Render(); //} fogEffect.SetValue("ColorFog", 2304311); fogEffect.SetValue("CameraPos", TGCVector3.Vector3ToFloat4Array(Camera.Position)); fogEffect.SetValue("StartFogDistance", 2000); fogEffect.SetValue("EndFogDistance", 7000); fogEffect.SetValue("Density", 0.0025f); var heighmap = TgcTexture.createTexture(MediaDir + "Level1\\Textures\\perli2.jpg"); fogEffect.SetValue("texHeighmap", heighmap.D3dTexture); fogEffect.SetValue("time", time); fogEffect.SetValue("spotLightDir", TGCVector3.Vector3ToFloat3Array(new TGCVector3(0, -1f, 0))); fogEffect.SetValue("spotLightAngleCos", FastMath.ToRad(55)); foreach (var mesh in skyBox.Faces) { mesh.Effect = fogEffect; mesh.Technique = "RenderScene"; //mesh.Render(); } skyBox.Render(); underseaTerrain.Effect = fogEffect; underseaTerrain.Technique = "RenderScene2"; underseaTerrain.Render(); //Render Surface surfacePlane.Render(); //Render Meshes foreach (var item in meshes) { item.Mesh.Effect = fogEffect; item.Mesh.Technique = "RenderScene"; item.Mesh.Render(); } if (playerModel.InventoryModel.RenderShipHelm) { foreach (var item in shipHelmMesh) { item.Render(); } } if (playerModel.InventoryModel.ShowShipHelm) { shipHelmPoster.Render(); } playerModel.ShowHistory = historyModel.ShowHistory; if (historyModel.ShowHistory) { historyModel.Render(elapsedTime); } if (playerModel.Win) { youWinModel.Render(elapsedTime); } // restuaro el render target y el stencil device.DepthStencilSurface = pOldDS; device.SetRenderTarget(0, pOldRT); effect.Technique = "PostProcess"; effect.SetValue("time", time); device.VertexFormat = CustomVertex.PositionTextured.Format; device.SetStreamSource(0, g_pVBV3D, 0); effect.SetValue("g_RenderTarget", g_pRenderTarget); device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); effect.Begin(FX.None); effect.BeginPass(0); device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); effect.EndPass(); effect.End(); hudModel.Render(); playerModel.Render(elapsedTime); }
public override void Render() { ClearTextures(); var device = D3DDevice.Instance.Device; effect.Technique = "DefaultTechnique"; // guardo el Render target anterior y seteo la textura como render target var pOldRT = device.GetRenderTarget(0); var pSurf = g_pRenderTarget.GetSurfaceLevel(0); device.SetRenderTarget(0, pSurf); // hago lo mismo con el depthbuffer, necesito el que no tiene multisampling var pOldDS = device.DepthStencilSurface; device.DepthStencilSurface = g_pDepthStencil; device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); device.BeginScene(); // ------------------------------------- //Renderizar terreno terrain.Effect = effect; terrain.Technique = "DefaultTechnique"; terrain.Render(); // skybox skyBox.Render(); //Renderizar pista circuito.render(effect); //Renderizar auto car.Effect = effect; car.Technique = "DefaultTechnique"; car.Render(); // ------------------------------------- device.EndScene(); pSurf.Dispose(); // Ultima pasada vertical va sobre la pantalla pp dicha device.SetRenderTarget(0, pOldRT); device.DepthStencilSurface = g_pDepthStencilOld; device.BeginScene(); effect.Technique = "FrameMotionBlur"; device.VertexFormat = CustomVertex.PositionTextured.Format; device.SetStreamSource(0, g_pVBV3D, 0); effect.SetValue("g_RenderTarget", g_pRenderTarget); effect.SetValue("g_RenderTarget2", g_pRenderTarget2); effect.SetValue("g_RenderTarget3", g_pRenderTarget3); effect.SetValue("g_RenderTarget4", g_pRenderTarget4); effect.SetValue("g_RenderTarget5", g_pRenderTarget5); device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); effect.Begin(FX.None); effect.BeginPass(0); device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); effect.EndPass(); effect.End(); //TgcDrawText.Instance.drawText("Pos: " + this.Camara.Position, 0, 0, Color.Yellow); //TgcDrawText.Instance.drawText("Look At: " + CamaraManager.Instance.CurrentCamera.getLookAt(), 500, 0, Color.Yellow); if (circuito.en_ruta) { DrawText.drawText("Tramo:" + circuito.pos_en_ruta, 0, 15, Color.Yellow); } //TgcDrawText.Instance.drawText("dist_cam:" + dist_cam + "defY" + desf.Y, 0, 0, Color.Yellow); //TgcDrawText.Instance.drawText("vel:" + vel, 0, 0, Color.Yellow); RenderFPS(); RenderAxis(); device.EndScene(); device.Present(); ftime += ElapsedTime; if (ftime > 0.03f) { ftime = 0; var aux = g_pRenderTarget5; g_pRenderTarget5 = g_pRenderTarget4; g_pRenderTarget4 = g_pRenderTarget3; g_pRenderTarget3 = g_pRenderTarget2; g_pRenderTarget2 = g_pRenderTarget; g_pRenderTarget = aux; } }
public void Render() { skyBox.Render(); }
public override void Render() { ClearTextures(); D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); D3DDevice.Instance.Device.BeginScene(); var aspectRatio = D3DDevice.Instance.AspectRatio; time += ElapsedTime; if (Input.keyPressed(Key.C)) { timer_preview = 0; camara_rot = !camara_rot; } if (Input.keyPressed(Key.F)) { if (tipo_vista == 1) { tipo_vista = 0; } else { tipo_vista = 1; } ant_vista = tipo_vista; } if (Input.keyPressed(Key.D)) { if (tipo_vista == 2) { tipo_vista = ant_vista; } else { tipo_vista = 2; } } if (Input.keyPressed(Key.Space)) { if (vel_tanque <= 1) { vel_tanque = 10; } else { vel_tanque = 1; } } if (timer_preview > 0) { timer_preview -= ElapsedTime; if (timer_preview < 0) { timer_preview = 0; } } // animar tanque an_tanque -= ElapsedTime * Geometry.DegreeToRadian(vel_tanque); var alfa = an_tanque; var x0 = 2000f * (float)Math.Cos(alfa); var z0 = 2000f * (float)Math.Sin(alfa); float offset_rueda = 10; var H = terrain.CalcularAltura(x0, z0) + alto_tanque / 2 - offset_rueda; if (H < nivel_mar) { H = nivel_mar; } mesh.Position = new TGCVector3(x0, H, z0); // direccion tangente sobre el piso: var dir_tanque = new TGCVector2(-(float)Math.Sin(alfa), (float)Math.Cos(alfa)); dir_tanque.Normalize(); // Posicion de la parte de adelante del tanque var pos2d = new TGCVector2(x0, z0); pos2d = pos2d + dir_tanque * (largo_tanque / 2); var H_frente = terrain.CalcularAltura(pos2d.X, pos2d.Y) + alto_tanque / 2 - offset_rueda; if (H_frente < nivel_mar - 15) { H_frente = nivel_mar - 15; } var pos_frente = new TGCVector3(pos2d.X, H_frente, pos2d.Y); var Vel = pos_frente - mesh.Position; Vel.Normalize(); mesh.Transform = CalcularMatriz(mesh.Position, mesh.Scale, Vel); // animo la canoa en circulos: alfa = -time *Geometry.DegreeToRadian(10.0f); x0 = 400f * (float)Math.Cos(alfa); z0 = 400f * (float)Math.Sin(alfa); canoa.Position = new TGCVector3(x0, 150, z0); dir_canoa = new TGCVector3(-(float)Math.Sin(alfa), 0, (float)Math.Cos(alfa)); canoa.Transform = CalcularMatriz(canoa.Position, canoa.Scale, dir_canoa); alfa_sol += ElapsedTime * Geometry.DegreeToRadian(1.0f); if (alfa_sol > 2.5) { alfa_sol = 1.5f; } // animo la posicion del sol //g_LightPos = new TGCVector3(1500f * (float)Math.Cos(alfa_sol), 1500f * (float)Math.Sin(alfa_sol), 0f); g_LightPos = new TGCVector3(2000f * (float)Math.Cos(alfa_sol), 2000f * (float)Math.Sin(alfa_sol), 0f); g_LightDir = -g_LightPos; g_LightDir.Normalize(); if (timer_preview > 0) { var an = -time *Geometry.DegreeToRadian(10.0f); LookFrom.X = 1500f * (float)Math.Sin(an); LookFrom.Z = 1500f * (float)Math.Cos(an); } else { if (camara_rot) { CamaraRot.CameraCenter = mesh.BoundingBox.calculateBoxCenter(); CamaraRot.UpdateCamera(ElapsedTime); //FIXME, puede que no haga falta esto. Camara = CamaraRot; } else { Camara = DefaultCamera; } } // -------------------------------------------------------------------- D3DDevice.Instance.Device.EndScene(); if (g_pCubeMapAgua == null) { // solo la primera vez crea el env map del agua CrearEnvMapAgua(); // ya que esta creado, se lo asigno al effecto: effect.SetValue("g_txCubeMapAgua", g_pCubeMapAgua); } // Creo el env map del tanque: var g_pCubeMap = new CubeTexture(D3DDevice.Instance.Device, 256, 1, Usage.RenderTarget, Format.A16B16G16R16F, Pool.Default); var pOldRT = D3DDevice.Instance.Device.GetRenderTarget(0); // ojo: es fundamental que el fov sea de 90 grados. // asi que re-genero la matriz de proyeccion D3DDevice.Instance.Device.Transform.Projection = TGCMatrix.PerspectiveFovLH(Geometry.DegreeToRadian(90.0f), 1f, near_plane, far_plane).ToMatrix(); // Genero las caras del enviroment map for (var nFace = CubeMapFace.PositiveX; nFace <= CubeMapFace.NegativeZ; ++nFace) { var pFace = g_pCubeMap.GetCubeMapSurface(nFace, 0); D3DDevice.Instance.Device.SetRenderTarget(0, pFace); TGCVector3 Dir, VUP; Color color; switch (nFace) { default: case CubeMapFace.PositiveX: // Left Dir = new TGCVector3(1, 0, 0); VUP = TGCVector3.Up; color = Color.Black; break; case CubeMapFace.NegativeX: // Right Dir = new TGCVector3(-1, 0, 0); VUP = TGCVector3.Up; color = Color.Red; break; case CubeMapFace.PositiveY: // Up Dir = TGCVector3.Up; VUP = new TGCVector3(0, 0, -1); color = Color.Gray; break; case CubeMapFace.NegativeY: // Down Dir = TGCVector3.Down; VUP = new TGCVector3(0, 0, 1); color = Color.Yellow; break; case CubeMapFace.PositiveZ: // Front Dir = new TGCVector3(0, 0, 1); VUP = TGCVector3.Up; color = Color.Green; break; case CubeMapFace.NegativeZ: // Back Dir = new TGCVector3(0, 0, -1); VUP = TGCVector3.Up; color = Color.Blue; break; } //Obtener ViewMatrix haciendo un LookAt desde la posicion final anterior al centro de la camara var Pos = mesh.Position; D3DDevice.Instance.Device.Transform.View = TGCMatrix.LookAtLH(Pos, Pos + Dir, VUP).ToMatrix(); D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, color, 1.0f, 0); D3DDevice.Instance.Device.BeginScene(); //Renderizar renderScene(ElapsedTime, true); D3DDevice.Instance.Device.EndScene(); //string fname = string.Format("face{0:D}.bmp", nFace); //SurfaceLoader.Save(fname, ImageFileFormat.Bmp, pFace); } // restuaro el render target D3DDevice.Instance.Device.SetRenderTarget(0, pOldRT); //TextureLoader.Save("test.bmp", ImageFileFormat.Bmp, g_pCubeMap); //Genero el shadow map RenderShadowMap(); // Restauro el estado de las transformaciones if (timer_preview > 0) { D3DDevice.Instance.Device.Transform.View = TGCMatrix.LookAtLH(LookFrom, LookAt, TGCVector3.Up).ToMatrix(); } else { D3DDevice.Instance.Device.Transform.View = Camara.GetViewMatrix().ToMatrix(); } // FIXME! esto no se bien para que lo hace aca. D3DDevice.Instance.Device.Transform.Projection = TGCMatrix.PerspectiveFovLH(Geometry.DegreeToRadian(45.0f), aspectRatio, near_plane, far_plane).ToMatrix(); // Cargo las var. del shader: effect.SetValue("g_txCubeMap", g_pCubeMap); effect.SetValue("fvLightPosition", new Vector4(0, 400, 0, 0)); effect.SetValue("fvEyePosition", TGCVector3.Vector3ToFloat3Array(timer_preview > 0 ? LookFrom : Camara.Position)); effect.SetValue("time", time); // ----------------------------------------------------- // dibujo la escena pp dicha: D3DDevice.Instance.Device.BeginScene(); if (tipo_vista != 1) { // con shaders : if (tipo_vista == 2) { // dibujo en una vista: D3DDevice.Instance.Device.Viewport = View1; } else { // dibujo en la pantalla completa D3DDevice.Instance.Device.Viewport = ViewF; } D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); // 1ero sin el agua renderScene(ElapsedTime, false); // Ahora dibujo el agua D3DDevice.Instance.Device.RenderState.AlphaBlendEnable = true; effect.SetValue("aux_Tex", terrain.terrainTexture); // posicion de la canoa (divido por la escala) effect.SetValue("canoa_x", x0 / 10.0f); effect.SetValue("canoa_y", z0 / 10.0f); piso.Technique = "RenderAgua"; piso.Render(); } if (tipo_vista != 0) { // sin shaders if (tipo_vista == 2) { // dibujo en una vista: D3DDevice.Instance.Device.Viewport = View2; } else { // dibujo en la pantalla completa D3DDevice.Instance.Device.Viewport = ViewF; } D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); //Renderizar terreno terrain.render(); //Renderizar SkyBox skyBox.Render(); // dibujo el bosque foreach (var instance in bosque) { instance.UpdateMeshTransform(); instance.Render(); } // canoa canoa.Render(); // tanque mesh.Render(); // agua var ant_src = D3DDevice.Instance.Device.RenderState.SourceBlend; var ant_dest = D3DDevice.Instance.Device.RenderState.DestinationBlend; var ant_alpha = D3DDevice.Instance.Device.RenderState.AlphaBlendEnable; D3DDevice.Instance.Device.RenderState.AlphaBlendEnable = true; D3DDevice.Instance.Device.RenderState.SourceBlend = Blend.SourceColor; D3DDevice.Instance.Device.RenderState.DestinationBlend = Blend.InvSourceColor; piso.Render(); D3DDevice.Instance.Device.RenderState.SourceBlend = ant_src; D3DDevice.Instance.Device.RenderState.DestinationBlend = ant_dest; D3DDevice.Instance.Device.RenderState.AlphaBlendEnable = ant_alpha; } g_pCubeMap.Dispose(); RenderFPS(); RenderAxis(); D3DDevice.Instance.Device.EndScene(); D3DDevice.Instance.Device.Present(); }
public void Render() => skybox.Render();