public Lighting(World world)
        {
            this.world = world;

            pSunColor = Shaders.Common.Parameters["vSunColor"];
            pSunVector = Shaders.Common.Parameters["vSunVector"];
            pAmbientColor = Shaders.Common.Parameters["vAmbientColor"];
            pAmbientLight = Shaders.Common.Parameters["fAmbient"];
            pNumberOfLights = Shaders.Common.Parameters["iNumLights"];
            pSunIntensity = Shaders.Common.Parameters["fSunIntensity"];
            pFogColor = Shaders.Common.Parameters["vFogColor"];

            //Shaders.Common.Parameters["tCloudShadowMap"].SetValue(world.Game.Content.Load<Texture2D>(@"textures\sky\clouds"));

            Random r = new Random();
            if (lights[0] == null)
            {
                for (int i = 0; i < lights.Length; i++)
                {
                    Vector3 color = new Vector3(r.Next(1000) / 1000.0f, r.Next(1000) / 1000.0f, r.Next(1000) / 1000.0f);
                    lights[i] = new PointLight(Vector3.Zero, color, Shaders.Common.Parameters["lights"].Elements[i]);
                }
            }

            // setup the shadowmap render target
            GraphicsDevice g = world.GraphicsDevice;
            PresentationParameters pp = world.GraphicsDevice.PresentationParameters;
            int shadowWidth = pp.BackBufferWidth;
            int shadowHeight = pp.BackBufferHeight;

            smapTarget = new RenderTarget2D(g, shadowWidth, shadowHeight, 1, SurfaceFormat.Single);
            smapStencilBuffer = new DepthStencilBuffer(g, shadowWidth, shadowHeight, g.DepthStencilBuffer.Format);
        }
 public virtual void SetEffectParameters(BasicEffect e, World world)
 {
     e.LightingEnabled = true;
     e.DiffuseColor = diffuseColor;
     e.SpecularColor = specularColor;
     e.SpecularPower = 20;
     e.AmbientLightColor = ambientColor;
     e.PreferPerPixelLighting = false;
     e.DirectionalLight0.Enabled = true;
     e.DirectionalLight0.Direction = -world.Lighting.SunVector;
     e.DirectionalLight0.SpecularColor = Vector3.One * world.Lighting.SunIntensity;
     e.DirectionalLight0.DiffuseColor = world.Lighting.SunColor * world.Lighting.SunIntensity;
     
     e.DirectionalLight1.Enabled = true;
     e.DirectionalLight1.DiffuseColor = world.Lighting.AmbientColor * (1-world.Lighting.SunIntensity) / 10;
     e.DirectionalLight1.Direction = world.Lighting.SunVector;
     e.Alpha = alpha;
 }
Exemplo n.º 3
0
        private void SetupWC(Viewport vp)
        {
            wc.Clear();
            Sim.Environment.World world = manager.UI.Sim.World;
            wc.Disable(manager.UI);
            Rectangle  wcArea  = new Rectangle(0, 0, vp.Width / 2, vp.Height / 3);
            ControlMat wcSpace = new ControlMat(wcArea, 7, 1, 2, ControlMat.FillOrder.RowsFirst);
            int        i       = 0;

            wc.Add(new Label("Weather Options", wcSpace.Spaces[i++], Label.Fit.AlignCenter));

            ToggleButton rain = new ToggleButton("Active", wcSpace.Spaces[i++]);

            rain.Use += delegate() { world.Weather.Active = !world.Weather.Active; };
            wc.Add(rain);

            Slider turbSlider = new Slider("Turbulence", wcSpace.Spaces[i++], 0, 30);

            turbSlider.SetValue(Sim.Settings.Graphics.Default.WindTurbulence);
            turbSlider.Use += delegate(float v) { Sim.Settings.Graphics.Default.WindTurbulence = v; };
            wc.Add(turbSlider);

            Slider windX = new Slider("Wind X", wcSpace.Spaces[i++], -75.0f, 75.0f);

            windX.SetValue(Sim.Settings.Graphics.Default.WindX);
            windX.Use += delegate(float v) { Sim.Settings.Graphics.Default.WindX = v; };
            wc.Add(windX);

            Slider windZ = new Slider("Wind Z", wcSpace.Spaces[i++], -75.0f, 75.0f);

            windZ.SetValue(Sim.Settings.Graphics.Default.WindZ);
            windZ.Use += delegate(float v) { Sim.Settings.Graphics.Default.WindZ = v; };
            wc.Add(windZ);

            Slider overcast = new Slider("Overcast", wcSpace.Spaces[i++], 1, 5);

            overcast.SetValue(Sim.Settings.Graphics.Default.Overcast);
            overcast.Use += delegate(float v) { Sim.Settings.Graphics.Default.Overcast = v; Shaders.Common.Parameters["overcast"].SetValue(v); };
            wc.Add(overcast);
        }
        protected override void Initialize()
        {
            int w = Graphics.GraphicsDevice.DisplayMode.Width;
            int h = GraphicsDevice.DisplayMode.Height;
            System.Console.WriteLine("blah: " + w + h);

            SetResolution();

            Shaders.LoadContent(GraphicsDevice, Content);
            Fonts.LoadContent(Content);
            Textures.LoadHeightmaps(GraphicsDevice);
            Models.LoadContent(Content);

            world = new World(this);
            ui = new UserInterface(this);

            Components.Add(ui);
            Components.Add(world);

            ppManager = new PostProcessManager();

            base.Initialize();
        }
        public virtual void Draw(Sim.Interface.Camera cam, World world, GraphicsDevice g)
        {
            SetRenderStates(g);

            Matrix[] transforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(transforms);

            foreach (ModelMesh mesh in model.Meshes)
            {
                g.Indices = mesh.IndexBuffer;

                for (int i = 0; i < mesh.MeshParts.Count; i++)
                {
                    ModelMeshPart meshPart = mesh.MeshParts[i];

                    g.Vertices[0].SetSource(mesh.VertexBuffer, meshPart.StreamOffset, meshPart.VertexStride);
                    g.VertexDeclaration = meshPart.VertexDeclaration;

                    BasicEffect effect = meshPart.Effect as BasicEffect;
                    
                    

                    SetEffectParameters(effect, world);

                    effect.World =
                        transforms[mesh.ParentBone.Index] *
                        Matrix.CreateScale(scale) *
                        rotMat * 
                        Matrix.CreateTranslation(position);
                    effect.View = cam.View;
                    effect.Projection = cam.Projection;
                }
                mesh.Draw();
            }

            ResetRenderStates(g);
        }
 public WorldScreen(ScreenManager manager)
     : base(manager)
 {
     Initialize();
     this.world = manager.UI.Sim.World;
 }
Exemplo n.º 7
0
        private void SetupGC(Viewport vp)
        {
            gc.Clear();


            Sim.Environment.World world   = manager.UI.Sim.World;
            Rectangle             gcArea  = new Rectangle(0, 0, vp.Width / 3, (int)(vp.Height / 1.5f));
            ControlMat            gcSpace = new ControlMat(gcArea, 16, 1, 2, ControlMat.FillOrder.RowsFirst);
            int i = 0;

            gc.Add(new Label("Drawing Options", gcSpace.Spaces[i++], Label.Fit.AlignCenter));

            Spinner <FillMode> gcFillSpinner = new Spinner <FillMode>("Fill Mode", gcSpace.Spaces[i++]);

            gcFillSpinner.Add(FillMode.Solid);
            gcFillSpinner.Add(FillMode.WireFrame);
            gcFillSpinner.Add(FillMode.Point);
            gcFillSpinner.Use += delegate() { world.FillMode = gcFillSpinner.GetSelected(); };
            gc.Add(gcFillSpinner);
            gc.Disable(manager.UI);

            Sim.Settings.Graphics gs = Sim.Settings.Graphics.Default;

            gc.Add(new Button("Sky", gcSpace.Spaces[i ++], delegate() { world.Sky.Visible = !world.Sky.Visible; }));
            gc.Add(new Button("Terrain", gcSpace.Spaces[i ++], delegate() { world.Terrain.Visible = !world.Terrain.Visible; }));
            gc.Add(new Button("Water", gcSpace.Spaces[i ++], delegate() { world.Water.Visible = !world.Water.Visible; }));
            gc.Add(new Button("Axes", gcSpace.Spaces[i ++], delegate() { world.DrawAxes = !world.DrawAxes; }));
            gc.Add(new Button("Vegetation", gcSpace.Spaces[i ++], delegate() { world.Vegetation.Visible = !world.Vegetation.Visible; }));
            gc.Add(new Button("AI Nodes", gcSpace.Spaces[i ++], delegate() { world.Terrain.DrawNodes = !world.Terrain.DrawNodes; }));
            gc.Add(new Button("Terrain Normals", gcSpace.Spaces[i ++], delegate() { world.Terrain.DrawNormals = !world.Terrain.DrawNormals; }));
            gc.Add(new Button("Detail Texturing", gcSpace.Spaces[i ++], delegate() {
                gs.TerrainDetail = !gs.TerrainDetail;
                world.Terrain.Effect.Parameters["bDetailEnabled"].SetValue(gs.TerrainDetail);
            }));
            gc.Add(new Button("Bump Mapping", gcSpace.Spaces[i ++], delegate() {
                gs.BumpEnabled = !gs.BumpEnabled;
                world.Terrain.Effect.Parameters["bBumpEnabled"].SetValue(gs.BumpEnabled);
            }));
            gc.Add(new Button("Shadow Mapping", gcSpace.Spaces[i ++], delegate() {
                gs.ShadowsEnabled = !gs.ShadowsEnabled;
                Shaders.Common.Parameters["bShadowsEnabled"].SetValue(gs.ShadowsEnabled);
            }));
            gc.Add(new Button("Bloom", gcSpace.Spaces[i ++], delegate()
            {
                gs.BloomEnabled = !gs.BloomEnabled;
            }));

            Slider biSlider = new Slider("Bloom Intes.", gcSpace.Spaces[i++], 0, 10);

            biSlider.SetValue(1.25f);
            biSlider.Use += delegate(float v) { manager.UI.Sim.PostProcessManager.Bloom.SetIntensity(v); };
            gc.Add(biSlider);

            Slider btSlider = new Slider("Bloom Thres.", gcSpace.Spaces[i++], 0, 1);

            btSlider.SetValue(0.6f);
            btSlider.Use += delegate(float v) { manager.UI.Sim.PostProcessManager.Bloom.SetThreshold(v); };
            gc.Add(btSlider);

            Slider bbSlider = new Slider("Bloom Blur", gcSpace.Spaces[i++], 0, 20);

            bbSlider.SetValue(8);
            bbSlider.Use += delegate(float v) { manager.UI.Sim.PostProcessManager.Bloom.SetBlur(v); };
            gc.Add(bbSlider);
        }