public void Render(View view) { Game1.graphics.GraphicsDevice.BlendState = BlendState.AlphaBlend; Game1.graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default; Game1.graphics.GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp; Game1.graphics.GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; foreach (GameObject3D gameObject in view.GameObject3DList) { Matrix World = gameObject.GetWorldMatrix(); foreach (ModelMesh mesh in gameObject.Model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.TextureEnabled = true; effect.Texture = gameObject.Texture; effect.Projection = view.GetProjectionMatrix(); effect.World = World; effect.View = view.Camera.GetView(); effect.LightingEnabled = true; effect.DirectionalLight0.DiffuseColor = new Vector3(1, 1, 1); effect.AmbientLightColor = new Vector3(lightIntensity, lightIntensity, lightIntensity); effect.DirectionalLight0.Direction = new Vector3(0, 0, 0); effect.DirectionalLight0.SpecularColor = new Vector3(0, 0, 0); effect.FogEnabled = true; Game1.graphics.GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp; } mesh.Draw(); } } }
public void Render(View view, Effect effect) { Game1.graphics.GraphicsDevice.BlendState = BlendState.AlphaBlend; Game1.graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default; Game1.graphics.GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp; Game1.graphics.GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; effect.CurrentTechnique = effect.Techniques[2]; foreach (GameObject3D gameObject in view.GameObject3DList) { Matrix World = gameObject.GetWorldMatrix(); effect.Parameters["world"].SetValue(World); effect.Parameters["view"].SetValue(view.Camera.GetView()); effect.Parameters["projection"].SetValue(view.GetProjectionMatrix()); foreach (ModelMesh mesh in gameObject.Model.Meshes) { int passCount = effect.CurrentTechnique.Passes.Count; for (int i = 0; i < passCount; i++) { // EffectPass.Apply will update the device to // begin using the state information defined in the current pass effect.CurrentTechnique.Passes[i].Apply(); foreach (ModelMeshPart meshPart in mesh.MeshParts) { meshPart.Effect = effect; effect.Parameters["ambientLightColor"].SetValue(new Vector4(lightIntensity, lightIntensity, lightIntensity, lightIntensity)); effect.Parameters["diffuseLightColor"].SetValue(Color.White.ToVector4()); effect.Parameters["specularLightColor"].SetValue(Color.White.ToVector4()); effect.Parameters["ModelTexture"].SetValue(gameObject.Texture); } mesh.Draw(); } } } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); ModelLib.LoadContent(Content, "Models"); TexLib.LoadContent(Content, "Models\\Textures"); soundPlayer.InitSoundLibrary(Content); //view = new View(this.Window.ClientBounds.Width, this.Window.ClientBounds.Height); view = new MazeObjects.Maze(); //view.Add(new GameObjects.GameObject3D(ModelLib.Get("Ball"), TexLib.Get("EyeTex"))); // TODO: use this.Content to load your game content here effect = Content.Load<Effect>("Shaders\\PerPixelLighting"); // cache the effect parameters cameraPositionParameter = effect.Parameters["cameraPosition"]; specularPowerParameter = effect.Parameters["specularPower"]; specularIntensityParameter = effect.Parameters["specularIntensity"]; cameraPositionParameter = effect.Parameters["cameraPosition"]; // // set up some basic effect parameters that do not change during the // course of execution // // set the light colors effect.Parameters["ambientLightColor"].SetValue(new Vector4(255, 255, 255, 0)); effect.Parameters["diffuseLightColor"].SetValue(Color.Red.ToVector4()); effect.Parameters["specularLightColor"].SetValue(Color.White.ToVector4()); // Set the light position to a fixed location. // This will place the light source behind, to the right, and above the // initial camera position. effect.Parameters["lightPosition"].SetValue( new Vector3(0f, 1f, 0f)); effect.Parameters["lightRotation"].SetValue(view.Camera.rotationMatrix); effect.Parameters["FullStrengthDistance"].SetValue(0.5f); effect.Parameters["MaxDistance"].SetValue(1); colChecker = new CollisionChecker(view.GameObject3DList); colChecker.CreateBoxes(); stepCounter = 0; soundPlayer.LoopMusic("BG1"); }