public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.GraphicsProfile = GraphicsProfile.HiDef; graphics.PreferredBackBufferWidth = 1920; graphics.PreferredBackBufferHeight = 1080; IsMouseVisible = true; msm = new MouseStateManager(this); kbm = new KeyboardStateManager(this); camera = new Base3DCamera(this, .5f, 20000); camera.Position = new Vector3(0, 0, 0); Components.Add(camera); Services.AddService(typeof(Base3DCamera), camera); skyBox = new BaseSkyBox(this, "Textures/SkyBox/HMcubemap"); Components.Add(skyBox); cube = new Base3DObject(this, "Models/cube"); cube.Name = "Cube"; cube.Position = new Vector3(-2, -1, -10); cube.ColorAsset = "Textures/h2mcpCube"; cube.BumpAsset = "Textures/h2mcpCubeNormal"; cube.LightPosition = LightPosition; cube.BoundingBox = new BoundingBox(-Vector3.One * .5f, Vector3.One * .5f); cube.BoundingSphere = new BoundingSphere(Vector3.Zero, .75f); Components.Add(cube); sceneObjects.Add(cube); bunny = new Base3DObject(this, "Models/bunny", "Shaders/RenderObjectNotTangentsOrTexCoords"); bunny.Name = "Bunny"; bunny.Position = new Vector3(0, -1.5f, -10); bunny.LightPosition = LightPosition; bunny.BoundingBox = new BoundingBox(new Vector3(-1, 0, -.6f), new Vector3(.7f, 1.65f, .7f)); bunny.BoundingSphere = new BoundingSphere(new Vector3(-.2f, .75f, 0), 1); Components.Add(bunny); sceneObjects.Add(bunny); earth = new Base3DObject(this, "Models/sphere"); earth.Name = "Globe"; earth.Position = new Vector3(2, -1, -10); earth.ColorAsset = "Textures/Earth_Diffuse"; earth.BumpAsset = "Textures/Earth_NormalMap"; earth.LightPosition = LightPosition; earth.BoundingBox = new BoundingBox(-Vector3.One, Vector3.One); earth.BoundingSphere = new BoundingSphere(Vector3.Zero, 1); Components.Add(earth); sceneObjects.Add(earth); }
public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; kbm = new KeyboardStateManager(this); camera = new Base3DCamera(this, .5f, 2000); camera.Position = new Vector3(0, 0, 10); Components.Add(camera); Services.AddService(typeof(Base3DCamera), camera); Base3DObject tree = new Base3DObject(this, "Models/trees_pine", "Shaders/RenderObjectNoTangents"); tree.ColorAsset = "Models/palette"; tree.Rotate(Vector3.Up, -90); tree.Position = new Vector3(0, -2, 0); tree.Scale = Vector3.One * .01f; Components.Add(tree); }
public void AddShadowCaster(Base3DObject obj) { ShadowCasters.Add(obj); }
public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.GraphicsProfile = GraphicsProfile.HiDef; graphics.PreferredBackBufferWidth = 1920; graphics.PreferredBackBufferHeight = 1080; IsMouseVisible = true; kbm = new KeyboardStateManager(this); lightingManager = new DeferredLightingManager(this); camera = new DeferredLightingCamera(this, .5f, 20000); camera.Position = new Vector3(0, 1, 0); camera.ClearColor = Color.Black; Components.Add(camera); Services.AddService(typeof(Base3DCamera), camera); BaseSkyBox skyBox = new BaseSkyBox(this, "Textures/SkyBox/HMcubemap"); skyBox.effectAsset = "Shaders/DeferredRender/SkyBoxShader"; Components.Add(skyBox); Plane plane = new Plane(this, "Shaders/DeferredRender/DeferredModelRender"); plane.ColorAsset = "Textures/cobbles"; plane.BumpAsset = "Textures/cobblesNormal"; plane.OcclusionAsset = "Textures/cobbleOcclusion"; plane.SpecularAsset = "Textures/cobblesSpecular"; plane.Scale = Vector3.One * 2; plane.UVMultiplier = Vector2.One * 5; plane.Position = new Vector3(0, -1, -20); Components.Add(plane); Base3DObject bunny = new Base3DObject(this, "Models/bunny", "Shaders/DeferredRender/DeferredModelRender"); bunny.Position = new Vector3(0, -1f, -20); Components.Add(bunny); Cube cube = new Cube(this, "Shaders/DeferredRender/DeferredModelRender"); cube.ColorAsset = "Textures/xnauguk"; cube.Position = new Vector3(-3, -.5f, -20); Components.Add(cube); Sphere sphere = new Sphere(this, "Shaders/DeferredRender/DeferredModelRender"); sphere.Scale = Vector3.One * 2; sphere.Position = new Vector3(3, -0, -20); sphere.ColorAsset = "Textures/brick"; sphere.BumpAsset = "Textures/brickNormal"; sphere.OcclusionAsset = "Textures/brickOcclusion"; sphere.SpecularAsset = "Textures/brickSpecular"; sphere.UVMultiplier = Vector2.One * 2; Components.Add(sphere); Cube sandBlock = new Cube(this, "Shaders/DeferredRender/DeferredModelRender"); sandBlock.ColorAsset = "Textures/sand"; sandBlock.BumpAsset = "Textures/sandNormal"; sandBlock.Position = new Vector3(-3, 1.5f, -20); sandBlock.Rotate(Vector3.Up + Vector3.Forward + Vector3.Left, 15); Components.Add(sandBlock); DeferredDirectionalLight directionalLight = new DeferredDirectionalLight(this, new Vector3(10, 10, 10), Color.AliceBlue, 1, true); directionalLight.Transform.LookAt(Vector3.Zero, 1, Vector3.Forward); Components.Add(directionalLight); lightingManager.AddLight(directionalLight); DeferredPointLight pointLight = new DeferredPointLight(this, new Vector3(0, 1, -20), Color.Red, 10, 1, false); Components.Add(pointLight); lightingManager.AddLight(pointLight); coneLight = new DeferredConeLight(this, new Vector3(-10, 5, -25), Color.Gold, 1, MathHelper.ToRadians(45), 5, true); coneLight.Transform.LookAt(new Vector3(0, 0, -20), 1, Vector3.Forward); Components.Add(coneLight); lightingManager.AddLight(coneLight); DeferredConeLight coneLight2 = new DeferredConeLight(this, new Vector3(0, 20, -20), Color.Green, 1, MathHelper.ToRadians(25), 50, true); coneLight2.Transform.LookAt(new Vector3(0, 0, -20), 1, Vector3.Forward); Components.Add(coneLight2); lightingManager.AddLight(coneLight2); // Shadow casters and receivers.. lightingManager.AddShadowCaster(bunny); lightingManager.AddShadowCaster(cube); lightingManager.AddShadowCaster(sphere); lightingManager.AddShadowCaster(sandBlock); }
public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.GraphicsProfile = GraphicsProfile.HiDef; graphics.PreferredBackBufferWidth = 1920; graphics.PreferredBackBufferHeight = 1080; IsMouseVisible = true; kbm = new KeyboardStateManager(this); camera = new Base3DCamera(this, .5f, 20000); camera.Position = new Vector3(0, 0, 0); Components.Add(camera); Services.AddService(typeof(Base3DCamera), camera); skyBox = new BaseSkyBox(this, "Textures/SkyBox/NebulaBlue"); Components.Add(skyBox); bunny = new Base3DObject(this, "Models/bunny", "Shaders/RenderObjectNotTangentsOrTexCoords"); bunny.Position = new Vector3(2, -1.5f, -20); bunny.LightPosition = LightPosition; Components.Add(bunny); cube = new Base3DObject(this, "Models/cube"); cube.Position = new Vector3(0, 0, -10); cube.ColorAsset = "Textures/h2mcpCube"; cube.BumpAsset = "Textures/h2mcpCubeNormal"; cube.LightPosition = LightPosition; Components.Add(cube); bunnies = new Base3DObject[10]; for (int s = 0; s < 10; s++) { bunnies[s] = new Base3DObject(this, "Models/Bunny"); bunnies[s].Position = new Vector3(20 + (s * 12), -1.5f, -10 - (s * 12)); bunnies[s].ColorAsset = "Textures/WindmillTopColor"; bunnies[s].BumpAsset = "Textures/WindmillTopNormal"; bunnies[s].LightPosition = LightPosition; Components.Add(bunnies[s]); } landShark = new Base3DObject(this, "Models/landShark"); landShark.Position = new Vector3(-20, 0, -10); landShark.ColorAsset = "Textures/Speeder_diff"; landShark.BumpAsset = "Textures/Speeder_bump"; landShark.LightPosition = LightPosition; Components.Add(landShark); earth = new Base3DObject(this, "Models/sphere"); earth.Position = new Vector3(0, 0, -200); earth.ColorAsset = "Textures/Earth_Diffuse"; earth.BumpAsset = "Textures/Earth_NormalMap"; earth.LightPosition = LightPosition; Components.Add(earth); ppManager = new PostProcessingManager(this); fog = new FogEffect(this, 50, 100, Color.DarkSlateGray); fog.Enabled = false; ppManager.AddEffect(fog); GodRays = new CrepuscularRays(this, LightPosition, "Textures/flare", 1500, .99f, .99f, .5f, .12f, .25f); GodRays.Enabled = false; ppManager.AddEffect(GodRays); sun = new SunEffect(this, LightPosition); sun.Enabled = false; ppManager.AddEffect(sun); bloom = new BloomEffect(this, 1.25f, 1f, 1f, 1f, .25f, 4f); bloom.Enabled = false; ppManager.AddEffect(bloom); dof = new DepthOfFieldEffect(this, 5, 30); dof.Enabled = false; ppManager.AddEffect(dof); haze = new HeatHazeEffect(this, "Textures/bumpmap", false); haze.Enabled = false; ppManager.AddEffect(haze); radialBlur = new RadialBlurEffect(this, 0.009f); radialBlur.Enabled = false; ppManager.AddEffect(radialBlur); ripple = new RippleEffect(this); ripple.Enabled = false; ppManager.AddEffect(ripple); sepia = new SepiaEffect(this); sepia.Enabled = false; ppManager.AddEffect(sepia); greyScale = new GreyScaleEffect(this); greyScale.Enabled = false; ppManager.AddEffect(greyScale); invert = new InvertColorEffect(this); invert.Enabled = false; ppManager.AddEffect(invert); colorFilter = new ColorFilterEffect(this, Color.White, .5f, .5f, .5f); colorFilter.Enabled = false; ppManager.AddEffect(colorFilter); bleach = new BleachEffect(this, 1); bleach.Enabled = false; ppManager.AddEffect(bleach); scanLines = new ScanLinesEffect(this, .001f, .001f, 128); scanLines.Enabled = false; ppManager.AddEffect(scanLines); deRezed = new DeRezedEffect(this, 128); deRezed.Enabled = false; ppManager.AddEffect(deRezed); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { msm.PreUpdate(gameTime); kbm.PreUpdate(gameTime); base.Update(gameTime); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || kbm.KeyDown(Keys.Escape)) { Exit(); } // Camera controls.. float speedTran = .1f; float speedRot = .01f; if (kbm.KeyDown(Keys.W) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y > 0) { camera.Translate(Vector3.Forward * speedTran); } if (kbm.KeyDown(Keys.S) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y < 0) { camera.Translate(Vector3.Backward * speedTran); } if (kbm.KeyDown(Keys.A) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X < 0) { camera.Translate(Vector3.Left * speedTran); } if (kbm.KeyDown(Keys.D) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X > 0) { camera.Translate(Vector3.Right * speedTran); } if (kbm.KeyDown(Keys.Left) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X < 0) { camera.Rotate(Vector3.Up, speedRot); } if (kbm.KeyDown(Keys.Right) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X > 0) { camera.Rotate(Vector3.Up, -speedRot); } if (kbm.KeyDown(Keys.Up) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.Y > 0) { camera.Rotate(Vector3.Right, speedRot); } if (kbm.KeyDown(Keys.Down) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.Y < 0) { camera.Rotate(Vector3.Right, -speedRot); } // Do picking if (msm.LeftClicked) { float minD = float.MaxValue; foreach (Base3DObject obj in sceneObjects) { BoundingBox tbb = GameComponentHelper.TransformedBoundingBoxAA(obj.BoundingBox, obj.Position, obj.Scale); float d = GameComponentHelper.RayPicking(msm.ScreenPoint, tbb, camera); if (d < minD) { minD = d; if (selected != null) { selected.DrawBoxBounds = false; } selected = obj; selected.DrawBoxBounds = true; } } if (minD == float.MaxValue) { if (selected != null) { selected.DrawBoxBounds = false; } selected = null; } } }