public void DrawReflectionMap(GameCamera.FreeCamera camera, float time, LightsAndShadows.Shadow shadow, LightsAndShadows.Light light, QuadTree tree) { Plane reflectionPlane = CreatePlane(waterHeight - 0.5f, new Vector3(0, -1, 0), camera.reflectionViewMatrix, true); //device.ClipPlanes[0].Plane = reflectionPlane; //device.ClipPlanes[0].IsEnabled = true; //device.SetRenderTarget(0, reflectionRenderTarget); effect.Parameters["ClipPlane0"].SetValue(new Vector4(reflectionPlane.Normal, reflectionPlane.D)); //effect.Parameters["ClipPlane0"].SetValue(new Vector4(-reflectionPlane.Normal, -reflectionPlane.D)); effect.Parameters["Clipping"].SetValue(true); // Allows the geometry to be clipped for the purpose of creating a refraction map device.SetRenderTarget(reflectionRenderTarget); device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0); sky.DrawSkyDome(camera); // tree.Draw(camera, time, shadow, light); //device.ClipPlanes[0].IsEnabled = false; effect.Parameters["Clipping"].SetValue(false); //device.SetRenderTarget(0, null); device.SetRenderTarget(null); reflectionMap = reflectionRenderTarget; //System.IO.Stream ss = System.IO.File.OpenWrite("C:\Test\Reflection.jpg"); //reflectionRenderTarget.SaveAsJpeg(ss, 500, 500); //ss.Close(); }
/// <summary> /// Constructor of LoadModel class. /// Create <paramref name="Model"/> at <paramref name="Position"/ > with <paramref name="Scale"/> and <paramref name="Rotation"/> /// </summary> /// <param name="Model"></param> /// <param name="Position"></param> /// <param name="Rotation"></param> /// <param name="Scale"></param> /// <param name="graphicsDevice"></param> public LoadModel(Model Model, Vector3 Position, Vector3 Rotation, Vector3 Scale, GraphicsDevice graphicsDevice, LightsAndShadows.Light light) { // Console.WriteLine(Position); this.baseWorld = Matrix.CreateScale(Scale) * Matrix.CreateRotationX(Rotation.X) * Matrix.CreateRotationX(Rotation.Y) * Matrix.CreateRotationX(Rotation.Z) * Matrix.CreateTranslation(Position); shadowCasters = new List<ShadowCasterObject>(); this.Model = Model; modelTransforms = new Matrix[Model.Bones.Count]; Model.CopyAbsoluteBoneTransformsTo(modelTransforms); this.Position = Position; this.Rotation = Rotation; this.playerTarget = Vector3.Zero; this.Scale = Scale; this.graphicsDevice = graphicsDevice; this.light = light; buildBoundingSphere(); CreateBoudingBox(); foreach (ModelMesh mesh in Model.Meshes) { if (!mesh.Name.Contains("Bounding")) foreach (ModelMeshPart meshpart in mesh.MeshParts) { ShadowCasterObject shad = new ShadowCasterObject( //meshpart.VertexDeclaration, meshpart.VertexBuffer, meshpart.VertexOffset, //meshpart.VertexStride, meshpart.IndexBuffer, //meshpart.BaseVertex, meshpart.NumVertices, meshpart.StartIndex, meshpart.PrimitiveCount, modelTransforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(Position)); this.shadowCasters.Add(shad); } } }
//Animated model constructor public LoadModel(Model Model, Vector3 Position, Vector3 Rotation, Vector3 Scale, GraphicsDevice GraphicsDevice, ContentManager Content, LightsAndShadows.Light light) { this.baseWorld = Matrix.CreateScale(Scale) * Matrix.CreateRotationX(Rotation.X) *Matrix.CreateRotationY(Rotation.Y)* Matrix.CreateRotationZ(Rotation.Z)* Matrix.CreateTranslation(Position); shadowCasters = new List<ShadowCasterObject>(); //Console.WriteLine(Position); this.Model = Model; this.graphicsDevice = GraphicsDevice; this.content = Content; this.Position = Position; this.playerTarget = Vector3.Zero; this.Rotation = Rotation; this.Scale = Scale; this.light = light; modelTransforms = new Matrix[Model.Bones.Count]; Model.CopyAbsoluteBoneTransformsTo(modelTransforms); SkinningData skinningData = Model.Tag as SkinningData; if (skinningData == null) throw new InvalidOperationException ("This model does not contain a SkinningData tag."); this.skinningData = Model.Tag as SkinningData; Player = new AnimationPlayer(skinningData); buildBoundingSphereAnimated(); foreach (ModelMesh mesh in Model.Meshes) { if (!mesh.Name.Contains("Bounding")) foreach (ModelMeshPart meshpart in mesh.MeshParts) { ShadowCasterObject shad = new ShadowCasterObject( //meshpart.VertexDeclaration, meshpart.VertexBuffer, meshpart.VertexOffset, //meshpart.VertexStride, meshpart.IndexBuffer, //meshpart.BaseVertex, meshpart.NumVertices, meshpart.StartIndex, meshpart.PrimitiveCount, modelTransforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(Position)); this.shadowCasters.Add(shad); } } }
public void DrawRefractionMap(GameCamera.FreeCamera camera, float time, LightsAndShadows.Shadow shadow, LightsAndShadows.Light light,QuadTree tree) { waterPlane = CreatePlane(waterHeight + 1.5f, new Vector3(0, -1, 0), camera.View, false); //refractionPlane = CreatePlane(30.0045F, new Vector3(0, -1, 0), viewMatrix, false); effect.Parameters["ClipPlane0"].SetValue(new Vector4(waterPlane.Normal, waterPlane.D)); effect.Parameters["Clipping"].SetValue(true); // Allows the geometry to be clipped for the purpose of creating a refraction map device.SetRenderTarget(refractionRenderTarget); device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0); // tree.Draw(camera, time, shadow, light); device.SetRenderTarget(null); effect.Parameters["Clipping"].SetValue(false); // Make sure you turn it back off so the whole scene doesnt keep rendering as clipped refractionMap = refractionRenderTarget; }
public void Draw(GameCamera.FreeCamera camera, float time, LightsAndShadows.Shadow shadow, LightsAndShadows.Light light) { effect.CurrentTechnique = effect.Techniques["MultiTextured"]; //RasterizerState rasterizerState = new RasterizerState(); //rasterizerState.FillMode = FillMode.WireFrame; //Device.RasterizerState = rasterizerState; this.CameraPosition = camera.Position; this.View = camera.View; this.Projection = camera.Projection; ViewFrustrum.Matrix = camera.View * camera.Projection; this.Device.SetVertexBuffer(_buffers.VertexBuffer); this.Device.Indices = _buffers.IndexBuffer; effect.Parameters["xLightPos"].SetValue(light.lightPosChange(time)); effect.Parameters["xLightsWorldViewProjection"].SetValue(shadow.lightsViewProjectionMatrix * Matrix.Identity); effect.Parameters["xWorldViewProjection"].SetValue(shadow.woldsViewProjection * Matrix.Identity); effect.Parameters["shadowTexture"].SetValue(shadow.ShadowMap); effect.Parameters["PCFSamples"].SetValue(shadow.PcfSamples); effect.Parameters["xView"].SetValue(camera.View); effect.Parameters["xProjection"].SetValue(camera.Projection); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); if (IndexCount > 0) Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, _vertices.Vertices.Length, 0, IndexCount); } foreach (EnvBilb pass in envBilbList) { pass.DrawBillboards(camera.View, camera.Projection, camera.Position); } }
public static void setLight(LightsAndShadows.Light light) { _light = light; }