示例#1
0
 public void DrawReflectionMap(Terrain terrain, List<GameObject> objects, Texture2D normals, Texture2D speculars)
 {
     Vector4 reflectionPlane = CreatePlane(waterHeight - 0.5f, new Vector3(0, -1, 0), true);
     device.SetRenderTarget(reflectionRenderTarget);
     device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);
     GBuffer.Parameters["xClip"].SetValue(true);
     GBuffer.Parameters["xClipPlane"].SetValue(reflectionPlane);
     terrain.DrawTerrain(GBuffer);
     /*foreach (GameObject obj in objects)
     {
         if (obj is Unit)
         {
             Unit unit = (Unit)obj;
             unit.currentModel.Draw(device, unit.GetWorldMatrix(), GBuffer, normals, speculars, false);
         }
         if (obj is Decoration)
         {
             Decoration decoration = (Decoration)obj;
             decoration.currentModel.Draw(device, decoration.GetWorldMatrix(), GBuffer, normals, speculars, false);
         }
     }*/
     DrawSkyDome(Camera.reflectionViewMatrix);
     device.SetRenderTarget(null);
     GBuffer.Parameters["xClip"].SetValue(false);
     reflectionMap = reflectionRenderTarget;
 }
示例#2
0
 public void CreateShadowMap(List<GameObject> models, Terrain terrain)
 {
     device.BlendState = BlendState.Opaque;
     device.DepthStencilState = DepthStencilState.Default;
     device.RasterizerState = RasterizerState.CullCounterClockwise;
     foreach (PointLight light in pointLights)
         if (light.withShadows)
         {
             light.CreateShadowMap(light, models, depthWriter, terrain);
         }
     foreach (SpotLight light in spotLights)
         if (light.withShadows)
         {
             light.CreateShadowMap(models, depthWriter, terrain);
         }
 }
示例#3
0
        public void CreateShadowMap(List<GameObject> models, Effect depthWriter, Terrain terrain)
        {
            device.SetRenderTarget(shadowMap);
            device.Clear(Color.Transparent);

            depthWriter.Parameters["View"].SetValue(view);
            depthWriter.Parameters["Projection"].SetValue(projection);
            depthWriter.Parameters["LightPosition"].SetValue(position);
            depthWriter.Parameters["DepthPrecision"].SetValue(farPlane);

               // if(Game1.Intro != false)
            terrain.DrawShadow(depthWriter);

            DrawModels(models, depthWriter);
        }
示例#4
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            device = graphics.GraphicsDevice;
            this.IsMouseVisible = true;

            terrain = new Terrain(this);
            camera = new Camera(this, graphics);
            decorations = new DecorationManager(this, device, graphics);

            Minimap.Initialize(device);
            Components.Add(camera);
            Components.Add(terrain);
            Components.Add(decorations);

            base.Initialize();
        }
示例#5
0
        void RenderSceneTo3Targets(List<GameObject> objects, Terrain terrain, float time)
        {
            device.BlendState = BlendState.Opaque;
            device.DepthStencilState = DepthStencilState.Default;
            device.RasterizerState = RasterizerState.CullCounterClockwise;

            foreach (GameObject obj in objects)
            {
                if (obj is Unit)
                {
                    Unit unit = (Unit)obj;
                    unit.currentModel.Draw(device, unit.GetWorldMatrix());
                }
                else if (obj is Building)
                {
                    Building building = (Building)obj;
                    building.currentModel.Draw(device, building.GetWorldMatrix());
                    //building.currentModel.Model.Draw(building.GetWorldMatrix(), Camera.viewMatrix, Camera.projectionMatrix);
                }
                else if (obj is Decoration)
                {
                    Decoration decoration = (Decoration)obj;
                    decoration.currentModel.Draw(device, decoration.GetWorldMatrix());
                    //decoration.currentModel.Model.Draw(decoration.GetWorldMatrix(), Camera.viewMatrix, Camera.projectionMatrix);
                }
            }
            water.DrawSkyDome(Camera.viewMatrix);
            terrain.DrawTerrain(GBuffer);
            water.DrawWater(time);
            device.SetRenderTarget(null);

            //Minimap.SetRenderTarget(device);
            //terrain.DrawTerrain(GBuffer);
            //water.DrawWater(time);
            //Minimap.ResolveRenderTarger(device);
            //Minimap.SaveMiniMap();
            //minimap = false;
        }
示例#6
0
        public void Draw(List<GameObject> objects, Terrain terrain, GameTime GameTime)
        {
            if (!Menu.inMenu)
            {
                List<Model> models = new List<Model>();
                foreach (GameObject obj in objects)
                    models.Add(obj.currentModel.Model);
                float time = (float)GameTime.TotalGameTime.TotalMilliseconds / 100.0f;
                float waterTime = (float)GameTime.TotalGameTime.TotalMilliseconds / 300.0f;
                water.DrawRefractionMap(terrain, objects, normals, speculars);
                water.DrawReflectionMap(terrain, objects, normals, speculars);
                gameTime = GameTime;
                CreateLights(objects);
                SetGBuffer();
                ClearGBuffer();
                RenderSceneTo3Targets(objects, terrain, waterTime);
                ResolveGBuffer();
                lights.CreateShadowMap(objects, terrain);
                DrawLights(objects);
                explosionParticles.Draw(gameTime, device);
                explosionSmokeParticles.Draw(gameTime, device);
              /*  foreach (GameObject obj in objects)
                {
                    if (obj is Decoration)
                    {
                        Decoration decoration = (Decoration)obj;
                        //decoration.currentModel.Draw(device, decoration.GetWorldMatrix(), GBuffer, normals, speculars, false);
                        //decoration.currentModel.Model.Draw(decoration.GetWorldMatrix(), Camera.viewMatrix, Camera.projectionMatrix);
                    }
                    if (obj is Building)
                    {
                        Building building = (Building)obj;
                        //building.currentModel.Draw(device, building.GetWorldMatrix(), GBuffer, normals, speculars, false);
                        //building.currentModel.Model.Draw(building.GetWorldMatrix(), Camera.viewMatrix, Camera.projectionMatrix);
                    }
                }*/

                    GUI.Draw();
                    GUI.Update(gameTime);

            }
            else
            menu.Draw();
            menu.Update();
            //Debug();
        }
示例#7
0
        public void CreateShadowMap(PointLight light, List<GameObject> Models, Effect depthWriter, Terrain terrain)
        {
            Matrix[] views = new Matrix[6];

            //Creating view matrices
            views[0] = Matrix.CreateLookAt(light.position, light.position + Vector3.Forward, Vector3.Up);
            views[1] = Matrix.CreateLookAt(light.position, light.position + Vector3.Backward, Vector3.Up);
            views[2] = Matrix.CreateLookAt(light.position, light.position + Vector3.Left, Vector3.Up);
            views[3] = Matrix.CreateLookAt(light.position, light.position + Vector3.Right, Vector3.Up);
            views[4] = Matrix.CreateLookAt(light.position, light.position + Vector3.Down, Vector3.Forward);
            views[5] = Matrix.CreateLookAt(light.position, light.position + Vector3.Up, Vector3.Backward);

            Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(90.0f), 1.0f, 1.0f, radius);

            depthWriter.Parameters["Projection"].SetValue(projection);
            depthWriter.Parameters["LightPosition"].SetValue(position);
            depthWriter.Parameters["DepthPrecision"].SetValue(radius);

            //Forward
            device.SetRenderTarget(shadowMap, CubeMapFace.PositiveZ);
            device.Clear(Color.Transparent);
            depthWriter.Parameters["View"].SetValue(views[0]);
            DrawModels(Models, depthWriter);

            //Backward
            device.SetRenderTarget(shadowMap, CubeMapFace.NegativeZ);
            device.Clear(Color.Transparent);
            depthWriter.Parameters["View"].SetValue(views[1]);
            DrawModels(Models, depthWriter);

            //Left
            device.SetRenderTarget(shadowMap, CubeMapFace.NegativeX);
            device.Clear(Color.Transparent);
            depthWriter.Parameters["View"].SetValue(views[2]);
            DrawModels(Models, depthWriter);

            //Right
            device.SetRenderTarget(shadowMap, CubeMapFace.PositiveX);
            device.Clear(Color.Transparent);
            depthWriter.Parameters["View"].SetValue(views[3]);
            DrawModels(Models, depthWriter);

            //Down
            device.SetRenderTarget(shadowMap, CubeMapFace.NegativeY);
            device.Clear(Color.Transparent);
            depthWriter.Parameters["View"].SetValue(views[4]);
            DrawModels(Models, depthWriter);

            //Up
            device.SetRenderTarget(shadowMap, CubeMapFace.PositiveY);
            device.Clear(Color.Transparent);
            depthWriter.Parameters["View"].SetValue(views[5]);
            DrawModels(Models, depthWriter);
        }