public void LoadContent(ContentManager cm, Camera cam) { model = cm.Load<Model>("dome"); model.Meshes[0].MeshParts[0].Effect = cam.CloneFX(); clouds = cm.Load<Texture2D>("ciel"); cloudsRenderTarget = cam.MakeTarget(); }
public void DrawClouds(Camera cam) { cam.device.DepthStencilState = DepthStencilState.None; Matrix[] modelTransforms = new Matrix[model.Bones.Count]; model.CopyAbsoluteBoneTransformsTo(modelTransforms); Matrix wMatrix = Matrix.CreateTranslation(0, -0.4f, 0) * Matrix.CreateScale(500) * Matrix.CreateTranslation(cam.location); foreach (ModelMesh mesh in model.Meshes) { foreach (Effect currentEffect in mesh.Effects) { Matrix worldMatrix = modelTransforms[mesh.ParentBone.Index] * wMatrix; //currentEffect.CurrentTechnique = currentEffect.Techniques["SkyDome"]; currentEffect.CurrentTechnique = currentEffect.Techniques["Textured"]; currentEffect.Parameters["xWorld"].SetValue(worldMatrix); currentEffect.Parameters["xView"].SetValue(cam.View); currentEffect.Parameters["xProjection"].SetValue(cam.Projection); currentEffect.Parameters["xTexture"].SetValue(clouds); currentEffect.Parameters["xAmbient"].SetValue(1.0f); currentEffect.Parameters["xEnableLighting"].SetValue(false); } mesh.Draw(); } cam.device.BlendState = BlendState.Opaque; cam.device.DepthStencilState = DepthStencilState.Default; }
public void LoadContent(ContentManager cm, Ground land, Camera cam) { fx = cm.Load<Effect>("bbEffect"); treeTexture = cm.Load<Texture2D>("tree"); treeMap = cm.Load<Texture2D>("treeMap"); Locations = new List<Vector3>(); GenerateTreePositions(land); List2Buffer(cam.device); }
public void Draw(Camera cam) { fx.CurrentTechnique = fx.Techniques["CylBillboard"]; fx.Parameters["xWorld"].SetValue(Matrix.Identity); fx.Parameters["xView"].SetValue(cam.View); fx.Parameters["xProjection"].SetValue(cam.Projection); fx.Parameters["xCamPos"].SetValue(cam.location); fx.Parameters["xAllowedRotDir"].SetValue(new Vector3(0, 1, 0)); fx.Parameters["xBillboardTexture"].SetValue(treeTexture); fx.Begin(); cam.device.Vertices[0].SetSource(vBuffer, 0, VertexPositionTexture.SizeInBytes); cam.device.VertexDeclaration = vDeclaration; int noVertices = vBuffer.SizeInBytes / VertexPositionTexture.SizeInBytes; int noTriangles = noVertices / 3; { cam.device.RenderState.AlphaTestEnable = true; cam.device.RenderState.AlphaFunction = CompareFunction.GreaterEqual; cam.device.RenderState.ReferenceAlpha = 200; fx.CurrentTechnique.Passes[0].Begin(); cam.device.DrawPrimitives(PrimitiveType.TriangleList, 0, noTriangles); fx.CurrentTechnique.Passes[0].End(); } { cam.device.RenderState.DepthBufferWriteEnable = false; cam.device.RenderState.AlphaBlendEnable = true; cam.device.RenderState.SourceBlend = Blend.SourceAlpha; cam.device.RenderState.DestinationBlend = Blend.InverseSourceAlpha; cam.device.RenderState.AlphaTestEnable = true; cam.device.RenderState.AlphaFunction = CompareFunction.Less; cam.device.RenderState.ReferenceAlpha = 200; fx.CurrentTechnique.Passes[0].Begin(); cam.device.DrawPrimitives(PrimitiveType.TriangleList, 0, noTriangles); fx.CurrentTechnique.Passes[0].End(); } cam.device.RenderState.AlphaBlendEnable = false; cam.device.RenderState.DepthBufferWriteEnable = true; cam.device.RenderState.AlphaTestEnable = false; fx.End(); }
public void DrawGround(Camera camera, bool mirror) { camera.Reflecting = mirror; camera.Snap(); camera.SetTechnique("MultiTextured"); camera.SetParam("xTexture0", Textures[0]); camera.SetParam("xTexture1", Textures[1]); camera.SetParam("xTexture2", Textures[2]); camera.SetParam("xTexture3", Textures[3]); camera.SetParam("xWorld", Matrix.Identity); foreach (EffectPass pass in camera.Technique.Passes) { pass.Apply(); camera.device.Indices = terrainIndexBuffer; camera.device.SetVertexBuffer(terrainVertexBuffer); camera.device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, indices.Length / 3); } }
protected override void Initialize() { Window.Title = "3D Project"; //IsMouseVisible = true; graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 1024; graphics.ApplyChanges(); land = new Ground("x6"); camera = new Camera(); dome = new Sky(); trees = new Forest(); this.Components.Add(new FrameRateCounter(this)); this.Components.Add(new ShowFPS(this)); base.Initialize(); }
public void DrawWater(Camera camera, float time) { camera.SetTechnique("Water"); camera.SetParam("xWorld", Matrix.Identity); camera.SetParam("xView", camera.View); camera.SetParam("xProjection", camera.Projection); camera.SetParam("xReflectionView", camera.Mirror); camera.SetParam("xReflectionMap", reflectionMap); camera.SetParam("xRefractionMap", refractionMap); camera.SetParam("xWaterBumpMap", rippleMap); camera.SetParam("xWaveLength", 0.1f); camera.SetParam("xWaveHeight", 0.3f); camera.SetParam("xCamPos", camera.location); camera.SetParam("xTime", time); camera.SetParam("xWindForce", 0.001f); camera.SetParam("xWindDirection", wind); camera.Effect.CurrentTechnique.Passes[0].Apply(); camera.device.SetVertexBuffer(waterVertexBuffer); camera.device.DrawPrimitives(PrimitiveType.TriangleList, 0, waterVertexBuffer.VertexCount / 3); }
private Plane CreatePlane(float height, Vector3 normal, Camera cam, bool clipSide) { normal.Normalize(); Vector4 planeCoeffs = new Vector4(normal, height); if (clipSide) { planeCoeffs *= -1; } planeCoeffs = Vector4.Transform(planeCoeffs, cam.InverseView()); Plane finalPlane = new Plane(planeCoeffs); return finalPlane; }
public void MapWater(Camera camera) { camera.Reflecting = false; Plane refractionPlane = CreatePlane(waterHeight + 1.5f, Vector3.Down, camera, false); camera.SetParam("ClipPlane0", new Vector4(refractionPlane.Normal, refractionPlane.D)); camera.SetParam("Clipping", true); camera.device.SetRenderTarget(refractionT); camera.device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer | ClearOptions.Stencil, Color.Transparent, 1.0f, 0); DrawGround(camera, false); camera.RevertTarget(); camera.SetParam("Clipping", false); refractionMap = refractionT; }
public void MapMirror(Camera camera, Sky sky) { camera.Reflecting = true; Plane reflectionPlane = CreatePlane(waterHeight - 0.5f, Vector3.Down, camera, true); camera.SetParam("ClipPlane0", new Vector4(reflectionPlane.Normal, reflectionPlane.D)); camera.SetParam("Clipping", true); camera.SetTarget(reflectionT); camera.device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer | ClearOptions.Stencil, Color.SteelBlue, 1.0f, 0); sky.DrawClouds(camera); DrawGround(camera, true); camera.SetParam("Clipping", false); camera.RevertTarget(); reflectionMap = reflectionT; }
public void LoadContent(ContentManager cm, Camera cam) { location = Matrix.Identity; wind = Vector3.Left; Map = cm.Load<Texture2D>(nameOfMap); width = Map.Width; length = Map.Height; rippleMap = cm.Load<Texture2D>("river"); Textures[0] = cm.Load<Texture2D>("grass14"); Textures[1] = cm.Load<Texture2D>("dirt02"); Textures[2] = cm.Load<Texture2D>("stone03"); Textures[3] = cm.Load<Texture2D>("snow09"); refractionT = cam.MakeTarget(); reflectionT = cam.MakeTarget(); LoadHeights(); vertices = SetVertices(); indices = SetIndices(); vertices = CalculateNormals(vertices, indices); SetBuffers(cam.device, vertices, indices); SetWater(cam.device); cam.sealevel = waterHeight; }