Beispiel #1
0
 /// <summary>
 /// Применение настроек к DirectionalLight
 /// </summary>
 /// <param name="directionalLight"></param>
 public void Fill(DirectionalLight directionalLight)
 {
     directionalLight.Enabled = Enabled;
     directionalLight.DiffuseColor = DiffuseColor;
     directionalLight.SpecularColor = SpecularColor;
     directionalLight.Direction = Direction;
 }
 private void SetParamsFromBasicLight(Microsoft.Xna.Framework.Graphics.DirectionalLight source,
                                      BasicPaletteEffect.BasicDirectionalLight target)
 {
     target.SpecularColor = source.SpecularColor;
     target.Enabled       = source.Enabled;
     target.Direction     = source.Direction;
     target.DiffuseColor  = source.DiffuseColor;
 }
Beispiel #3
0
 internal static Vector3 EnableDefaultLighting(DirectionalLight light0, DirectionalLight light1, DirectionalLight light2)
 {
   light0.Direction = new Vector3(-0.5265408f, -0.5735765f, -0.6275069f);
   light0.DiffuseColor = new Vector3(1f, 0.9607844f, 0.8078432f);
   light0.SpecularColor = new Vector3(1f, 0.9607844f, 0.8078432f);
   light0.Enabled = true;
   light1.Direction = new Vector3(0.7198464f, 0.3420201f, 0.6040227f);
   light1.DiffuseColor = new Vector3(0.9647059f, 0.7607844f, 0.4078432f);
   light1.SpecularColor = Vector3.Zero;
   light1.Enabled = true;
   light2.Direction = new Vector3(0.4545195f, -0.7660444f, 0.4545195f);
   light2.DiffuseColor = new Vector3(0.3231373f, 0.3607844f, 0.3937255f);
   light2.SpecularColor = new Vector3(0.3231373f, 0.3607844f, 0.3937255f);
   light2.Enabled = true;
   return new Vector3(0.05333332f, 0.09882354f, 0.1819608f);
 }
Beispiel #4
0
		public DirectionalLight (EffectParameter directionParameter, EffectParameter diffuseColorParameter, EffectParameter specularColorParameter, DirectionalLight cloneSource)
		{
			this.diffuseColorParameter = diffuseColorParameter;
			this.directionParameter = directionParameter;
			this.specularColorParameter = specularColorParameter;
			if (cloneSource != null) {
				this.diffuseColor = cloneSource.diffuseColor;
				this.direction = cloneSource.direction;
				this.specularColor = cloneSource.specularColor;
				this.enabled = cloneSource.enabled;
			} else {
				this.diffuseColorParameter = diffuseColorParameter;
				this.directionParameter = directionParameter;
				this.specularColorParameter = specularColorParameter;
			}
		}
Beispiel #5
0
 public VFXEffect(Effect cloneSource)
     : base(cloneSource)
 {
     _projection = this.Parameters["Projection"];
     _view = this.Parameters["View"];
     _world = this.Parameters["World"];
     _directionalLight = new DirectionalLight(
         this.Parameters["DirectionalLightDirection"],
         this.Parameters["DirectionalLightDiffuseColor"],
         this.Parameters["DirectionalLightSpecularColor"],
         (DirectionalLight)null);
     _directionalLight.Enabled = true;
     this.Parameters["DiffuseColor"].SetValue(Vector4.Zero);
     this.Parameters["SpecularColor"].SetValue(Vector4.Zero);
     _diffuseColor = this.Parameters["DiffuseColor"];
     _specularColor = this.Parameters["SpecularColor"];
     //this.Parameters["AmbientColor"].SetValue(Vector4.Zero);
     _ambientLightColor = Utils.Vector4toVector3(this.Parameters["AmbientColor"].GetValueVector4());
 }
Beispiel #6
0
        /// <summary>
        /// Sets up the standard key/fill/back lighting rig.
        /// </summary>
        internal static Vector3 EnableDefaultLighting(DirectionalLight light0, DirectionalLight light1, DirectionalLight light2)
        {
            // Key light.
            light0.Direction     = new Vector3(-0.5265408f, -0.5735765f, -0.6275069f);
            light0.DiffuseColor  = new Vector3(1, 0.9607844f, 0.8078432f);
            light0.SpecularColor = new Vector3(1, 0.9607844f, 0.8078432f);
            light0.Enabled       = true;

            // Fill light.
            light1.Direction     = new Vector3(0.7198464f, 0.3420201f, 0.6040227f);
            light1.DiffuseColor  = new Vector3(0.9647059f, 0.7607844f, 0.4078432f);
            light1.SpecularColor = Vector3.Zero;
            light1.Enabled       = true;

            // Back light.
            light2.Direction     = new Vector3(0.4545195f, -0.7660444f, 0.4545195f);
            light2.DiffuseColor  = new Vector3(0.3231373f, 0.3607844f, 0.3937255f);
            light2.SpecularColor = new Vector3(0.3231373f, 0.3607844f, 0.3937255f);
            light2.Enabled       = true;

            // Ambient light.
            return(new Vector3(0.05333332f, 0.09882354f, 0.1819608f));
        }
Beispiel #7
0
        /// <summary>
        /// Looks up shortcut references to our effect parameters.
        /// </summary>
        void CacheEffectParameters(BasicEffect cloneSource)
        {
            #if !PSM
                textureParam                = Parameters["Texture"];
            #else
                textureParam                = Parameters["Texture0"];
            #endif
            diffuseColorParam           = Parameters["DiffuseColor"];
            emissiveColorParam          = Parameters["EmissiveColor"];
            specularColorParam          = Parameters["SpecularColor"];
            specularPowerParam          = Parameters["SpecularPower"];
            eyePositionParam            = Parameters["EyePosition"];
            fogColorParam               = Parameters["FogColor"];
            fogVectorParam              = Parameters["FogVector"];
            worldParam                  = Parameters["World"];
            worldInverseTransposeParam  = Parameters["WorldInverseTranspose"];
            worldViewProjParam          = Parameters["WorldViewProj"];

            light0 = new DirectionalLight(Parameters["DirLight0Direction"],
                                          Parameters["DirLight0DiffuseColor"],
                                          Parameters["DirLight0SpecularColor"],
                                          (cloneSource != null) ? cloneSource.light0 : null);

            light1 = new DirectionalLight(Parameters["DirLight1Direction"],
                                          Parameters["DirLight1DiffuseColor"],
                                          Parameters["DirLight1SpecularColor"],
                                          (cloneSource != null) ? cloneSource.light1 : null);

            light2 = new DirectionalLight(Parameters["DirLight2Direction"],
                                          Parameters["DirLight2DiffuseColor"],
                                          Parameters["DirLight2SpecularColor"],
                                          (cloneSource != null) ? cloneSource.light2 : null);
        }
Beispiel #8
0
        /// <summary>
        /// Looks up shortcut references to our effect parameters.
        /// </summary>
        void CacheEffectParameters(EnvironmentMapEffect cloneSource)
        {
            textureParam                = Parameters["Texture"];
            environmentMapParam         = Parameters["EnvironmentMap"];
            environmentMapAmountParam   = Parameters["EnvironmentMapAmount"];
            environmentMapSpecularParam = Parameters["EnvironmentMapSpecular"];
            fresnelFactorParam          = Parameters["FresnelFactor"];
            diffuseColorParam           = Parameters["DiffuseColor"];
            emissiveColorParam          = Parameters["EmissiveColor"];
            eyePositionParam            = Parameters["EyePosition"];
            fogColorParam               = Parameters["FogColor"];
            fogVectorParam              = Parameters["FogVector"];
            worldParam                  = Parameters["World"];
            worldInverseTransposeParam  = Parameters["WorldInverseTranspose"];
            worldViewProjParam          = Parameters["WorldViewProj"];

            light0 = new DirectionalLight(Parameters["DirLight0Direction"],
                                          Parameters["DirLight0DiffuseColor"],
                                          null,
                                          (cloneSource != null) ? cloneSource.light0 : null);

            light1 = new DirectionalLight(Parameters["DirLight1Direction"],
                                          Parameters["DirLight1DiffuseColor"],
                                          null,
                                          (cloneSource != null) ? cloneSource.light1 : null);

            light2 = new DirectionalLight(Parameters["DirLight2Direction"],
                                          Parameters["DirLight2DiffuseColor"],
                                          null,
                                          (cloneSource != null) ? cloneSource.light2 : null);
        }
Beispiel #9
0
        void CacheEffectParametersFromSkinnedEffect(Microsoft.Xna.Framework.Graphics.SkinnedEffect cloneSource)
        {
            textureParam = Parameters["Texture"];
            diffuseColorParam = Parameters["DiffuseColor"];
            emissiveColorParam = Parameters["EmissiveColor"];
            specularColorParam = Parameters["SpecularColor"];
            specularPowerParam = Parameters["SpecularPower"];
            eyePositionParam = Parameters["EyePosition"];
            fogColorParam = Parameters["FogColor"];
            fogVectorParam = Parameters["FogVector"];
            worldParam = Parameters["World"];
            worldInverseTransposeParam = Parameters["WorldInverseTranspose"];
            ViewProjParam = Parameters["ViewProj"];
            lightWorldViewProjParam = Parameters["LightWorldViewProj"];
            animateLightWorldViewProjParam = Parameters["AnimateLightWorldViewProj"];
            bonesParam = Parameters["Bones"];

            light0 = new DirectionalLight(Parameters["DirLight0Direction"],
                                          Parameters["DirLight0DiffuseColor"],
                                          Parameters["DirLight0SpecularColor"],
                                          (cloneSource != null) ? cloneSource.DirectionalLight0 : null);

            light1 = new DirectionalLight(Parameters["DirLight1Direction"],
                                          Parameters["DirLight1DiffuseColor"],
                                          Parameters["DirLight1SpecularColor"],
                                          (cloneSource != null) ? cloneSource.DirectionalLight1 : null);

            light2 = new DirectionalLight(Parameters["DirLight2Direction"],
                                          Parameters["DirLight2DiffuseColor"],
                                          Parameters["DirLight2SpecularColor"],
                                          (cloneSource != null) ? cloneSource.DirectionalLight2 : null);
        }
Beispiel #10
0
        ///<summary> /// Sets up the standard key/fill/back lighting rig. /// </summary>
        public virtual Vector3 EnableDefaultLighting(DirectionalLight light0, DirectionalLight light1, DirectionalLight light2)
        {
            // Key light.
            light0.Direction = new Vector3(-0.5265408f, -0.5735765f, -0.6275069f);
            light0.DiffuseColor = new Vector3(1, 0.9607844f, 0.8078432f);
            light0.SpecularColor = new Vector3(1, 0.9607844f, 0.8078432f);
            light0.Enabled = true;

            // Fill light.
            light1.Direction = new Vector3(0.7198464f, 0.3420201f, 0.6040227f);
            light1.DiffuseColor = new Vector3(0.9647059f, 0.7607844f, 0.4078432f);
            light1.SpecularColor = Vector3.Zero;
            light1.Enabled = true;

            // Back light.
            light2.Direction = new Vector3(0.4545195f, -0.7660444f, 0.4545195f);
            light2.DiffuseColor = new Vector3(0.3231373f, 0.3607844f, 0.3937255f);
            light2.SpecularColor = new Vector3(0.3231373f, 0.3607844f, 0.3937255f);
            light2.Enabled = true;

            // Ambient light.
            return new Vector3(0.05333332f, 0.09882354f, 0.1819608f);
        }
            public CustomEffect(Effect cloneSource)
                : base(cloneSource)
            {
                world = Parameters["World"];
                view = Parameters["View"];
                projection = Parameters["Projection"];
                worldInvertTranspose = Parameters["WorldInvertTranspose"];

                lightDirection = Parameters["LightDirection"];
                lightDiffuseColor = Parameters["LightDiffuseColor"];
                lightingEnabled = Parameters["LightingEnabled"];

                sunPower = Parameters["SunPower"];
                time = Parameters["Time"];
                skyMap = Parameters["SkyMap"];

                directionalLight0 = new XnaDirectionalLight(lightDirection, lightDiffuseColor, null, null);
                directionalLight1 = new XnaDirectionalLight(null, null, null, null);
                directionalLight2 = new XnaDirectionalLight(null, null, null, null);
            }
Beispiel #12
0
 private void CacheEffectParameters(BasicEffect cloneSource)
 {
   this.textureParam = this.Parameters["Texture"];
   this.diffuseColorParam = this.Parameters["DiffuseColor"];
   this.emissiveColorParam = this.Parameters["EmissiveColor"];
   this.specularColorParam = this.Parameters["SpecularColor"];
   this.specularPowerParam = this.Parameters["SpecularPower"];
   this.eyePositionParam = this.Parameters["EyePosition"];
   this.fogColorParam = this.Parameters["FogColor"];
   this.fogVectorParam = this.Parameters["FogVector"];
   this.worldParam = this.Parameters["World"];
   this.worldInverseTransposeParam = this.Parameters["WorldInverseTranspose"];
   this.worldViewProjParam = this.Parameters["WorldViewProj"];
   this.light0 = new DirectionalLight(this.Parameters["DirLight0Direction"], this.Parameters["DirLight0DiffuseColor"], this.Parameters["DirLight0SpecularColor"], cloneSource != null ? cloneSource.light0 : (DirectionalLight) null);
   this.light1 = new DirectionalLight(this.Parameters["DirLight1Direction"], this.Parameters["DirLight1DiffuseColor"], this.Parameters["DirLight1SpecularColor"], cloneSource != null ? cloneSource.light1 : (DirectionalLight) null);
   this.light2 = new DirectionalLight(this.Parameters["DirLight2Direction"], this.Parameters["DirLight2DiffuseColor"], this.Parameters["DirLight2SpecularColor"], cloneSource != null ? cloneSource.light2 : (DirectionalLight) null);
 }
Beispiel #13
0
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Overlay component, used to draw the pause menu and game over menu
            overlayComponent = new OverlayComponent(Game, spriteBatch);
            Game.Components.Add(overlayComponent);

            projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                GraphicsDevice.Viewport.AspectRatio, 0.1f, 50000);

            directionalLight = new DirectionalLight(
                new Vector3(-1.25f, -2f, 5.0f), // Direction
                new Vector3(.1f, .1f, .1f),//new Vector3(.15f, .14f, .29f), // Ambient
                new Vector3(.46f, .33f, .75f)); // Diffuse

            Game.AddService(typeof(DirectionalLight), directionalLight);

            #region Level terrain generation

            int heightMapSize = terrainSegmentsCount * terrainSegmentSize + 1;
            float halfHeightMapSize = heightMapSize / 2f;
            HeightMap heightmapGenerator = new HeightMap(heightMapSize);
            var heightMap = heightmapGenerator.Generate();

            var roadMap = new float[heightMapSize, heightMapSize];
            raceTrack = new RaceTrack(heightMapSize, terrainScale);

            navMesh = new NavMesh(GraphicsDevice, raceTrack.Curve, //1500, roadWidth, terrainScale);
                750, roadWidth, terrainScale);

            Vector3 lastPosition = raceTrack.Curve.GetPoint(.01f) / terrainScale;

            for (float t = 0; t < 1; t += .0002f)
            {
                var e = raceTrack.Curve.GetPoint(t) / terrainScale;

                for (float j = -roadFalloff; j <= roadFalloff; j++)
                {
                    var pos = e + j * Vector3.Normalize(Vector3.Cross(lastPosition - e, Vector3.Up));

                    // Indices
                    int x = (int)(pos.X + halfHeightMapSize),
                        z = (int)(pos.Z + halfHeightMapSize);

                    float height = e.Y;

                    if (Math.Abs(j) <= roadWidth)
                    {
                        heightMap[x, z] = height;
                        roadMap[x, z] = 1;
                    }
                    else
                    {
                        float amount = (Math.Abs(j) - roadWidth) / (roadFalloff - roadWidth);
                        heightMap[x, z] = MathHelper.Lerp(height,
                            heightMap[x, z], amount);
                        roadMap[x, z] = amount / 10f;
                    }
                }
                lastPosition = e;
            }

            heightmapGenerator.Smoothen();
            heightmapGenerator.Perturb(30f);

            for (int i = 0; i < 5; i++)
            {
                heightmapGenerator.Smoothen();
            }

            terrainEffect = content.Load<Effect>(@"Effects\TerrainShading");

            //terrainEffect.Parameters["TextureMap0"].SetValue(content.Load<Texture2D>(@"Terrain\sand"));
            #region TEXTURE RENDERING

            //var unprocessedGrassTexture = content.Load<Texture2D>(@"Terrain\grass");
            //var grassTexture = new RenderTarget2D(GraphicsDevice, unprocessedGrassTexture.Width, unprocessedGrassTexture.Height);

            //GraphicsDevice.SetRenderTarget(grassTexture);
            //spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
            //spriteBatch.Draw(unprocessedGrassTexture, new Rectangle(0, 0, unprocessedGrassTexture.Width, unprocessedGrassTexture.Height), Color.White);
            //spriteBatch.Draw(content.Load<Texture2D>(@"Particles\fire"), new Rectangle(0, 0, unprocessedGrassTexture.Width, unprocessedGrassTexture.Height), Color.White);
            //spriteBatch.End();
            //GraphicsDevice.SetRenderTarget(null);

            //terrainEffect.Parameters["TextureMap1"].SetValue(grassTexture);

            #endregion
            terrainEffect.Parameters["TextureMap0"].SetValue(content.Load<Texture2D>(@"Terrain\road"));
            terrainEffect.Parameters["TextureMap1"].SetValue(content.Load<Texture2D>(@"Terrain\grass"));
            terrainEffect.Parameters["TextureMap2"].SetValue(content.Load<Texture2D>(@"Terrain\rock"));
            terrainEffect.Parameters["TextureMap3"].SetValue(content.Load<Texture2D>(@"Terrain\snow"));
            terrainEffect.Parameters["RoadNormalMap"].SetValue(content.Load<Texture2D>(@"Terrain\road_n"));
            terrainEffect.Parameters["Projection"].SetValue(projectionMatrix);

            // Creates a terrainmodel around Vector3.Zero
            terrainSegments = new TerrainModel[terrainSegmentsCount, terrainSegmentsCount];

            float terrainStart = -.5f * heightMapSize;

            for (int z = 0; z < terrainSegmentsCount; z++)
            {
                for (int x = 0; x < terrainSegmentsCount; x++)
                {
                    terrainSegments[x, z] = new TerrainModel(GraphicsDevice,
                        terrainSegmentSize, terrainSegmentsCount, terrainStart,
                        x * terrainSegmentSize, z * terrainSegmentSize,
                        terrainScale, heightMap, roadMap, terrainEffect, directionalLight);
                }
            }

            #endregion

            #region Car

            Car = MakeCar();
            gameInstance.AddService(typeof(Car), Car);
            Player localPlayer = gameInstance.GetService<ServerClient>().LocalPlayer;
            gameInstance.GetService<CarControlComponent>().Cars[localPlayer] = Car;
            gameInstance.AddService(typeof(Player), localPlayer);

            #endregion

            #region Lights

            // Load model to represent our lightsources
            var pointLightModel = content.Load<Model>(@"Models\light");

            //spotLightModel = content.Load<Model>(@"Models\Cone");

            Vector3 pointLightOffset = new Vector3(0, 250, 0);

            var cr = new CurveRasterization(raceTrack.Curve, 50);

            float colorOffset = 0f;

            foreach (var point in cr.Points)
            {
                Random r = UniversalRandom.GetInstance();

                Vector3 color = new Vector3(0f,0f,0f);
                PointLight pl = new PointLight(point.Position + pointLightOffset +
                    Vector3.Transform(50 * Vector3.Up, Matrix.CreateRotationZ(MathHelper.TwoPi * (float)UniversalRandom.GetInstance().NextDouble())),
                    color, 450)
                {
                    Model = pointLightModel,
                    ColorTimeOffset = colorOffset
                };

                pointLights.Add(pl);
                GraphicalObjects.Add(pl);

                colorOffset += 100 / cr.Points.Count;
            }

            #endregion

            dustEmitter = new ParticleEmitter(dustSystem, 150, Car.Position);

            #region SkySphere

            skyBoxModel = content.Load<Model>(@"Models/skybox");
            skyBoxEffect = content.Load<Effect>(@"Effects/SkyBox");

            skyMap = new TextureCube(GraphicsDevice, 2048, false, SurfaceFormat.Color);
            string[] cubemapfaces = { @"SkyBoxes/PurpleSky/skybox_right1",
                @"SkyBoxes/PurpleSky/skybox_left2",
                @"SkyBoxes/PurpleSky/skybox_top3",
                @"SkyBoxes/PurpleSky/skybox_bottom4",
                @"SkyBoxes/PurpleSky/skybox_front5",
                @"SkyBoxes/PurpleSky/skybox_back6_2"
            };

            //cubeMap = new TextureCube(GraphicsDevice, 1024, false, SurfaceFormat.Color);
            //string[] cubemapfaces = {
            //    @"SkyBoxes/StormyDays/stormydays_ft",
            //    @"SkyBoxes/StormyDays/stormydays_bk",
            //    @"SkyBoxes/StormyDays/stormydays_up",
            //    @"SkyBoxes/StormyDays/stormydays_dn",
            //    @"SkyBoxes/StormyDays/stormydays_rt",
            //    @"SkyBoxes/StormyDays/stormydays_lf"
            //};

            //cubeMap = new TextureCube(GraphicsDevice, 1024, false, SurfaceFormat.Color);
            //string[] cubemapfaces = {
            //    @"SkyBoxes/Miramar/miramar_ft",
            //    @"SkyBoxes/Miramar/miramar_bk",
            //    @"SkyBoxes/Miramar/miramar_up",
            //    @"SkyBoxes/Miramar/miramar_dn",
            //    @"SkyBoxes/Miramar/miramar_rt",
            //    @"SkyBoxes/Miramar/miramar_lf"
            //};

            for (int i = 0; i < cubemapfaces.Length; i++)
                LoadCubemapFace(skyMap, cubemapfaces[i], (CubeMapFace)i);

            skyBoxEffect.Parameters["SkyboxTexture"].SetValue(skyMap);

            foreach (var mesh in skyBoxModel.Meshes)
                foreach (var part in mesh.MeshParts)
                    part.Effect = skyBoxEffect;

            #endregion

            #region Weather

            thunderBoltGenerator = new ThunderBoltGenerator(gameInstance, thunderParticleSystem);
            gameInstance.Components.Add(thunderBoltGenerator);

            #endregion

            #region GameObjects

            OakTree.LoadMaterial(content);
            BirchTree.LoadMaterial(content);
            Stone.LoadMaterial(content);

            int numObjects = 75;

            for (int i = 0; i < numObjects; i++)
            {

                var t = navMesh.triangles[UniversalRandom.GetInstance().Next(navMesh.triangles.Length)];
                float v = (float)UniversalRandom.GetInstance().NextDouble();

                //float u = (float) (UniversalRandom.GetInstance().NextDouble() - 1/2f);
                //if (u < 0)
                //    u -= .5f;
                //else
                //    u += 1.5f;

                float u = 0;
                if (UniversalRandom.GetInstance().NextDouble() <= .5)
                    u = -.5f - .3f * (float)(-UniversalRandom.GetInstance().NextDouble());
                else
                    u = (float)(1.5f + .3f * UniversalRandom.GetInstance().NextDouble());

                var pos = (t.vertices[0] + u * t.ab + v * t.ac) / terrainScale;
                //var treePos = new Vector3(-halfHeightMapSize + (float)UniversalRandom.GetInstance().NextDouble() * (heightMapSize-50), 0,
                //    -halfHeightMapSize + (float)UniversalRandom.GetInstance().NextDouble() * (heightMapSize-50));

                float X = pos.X + heightMapSize / 2f,
                    Z = pos.Z +heightMapSize / 2f;

                float Xlerp = X % 1f,
                    Zlerp = Z % 1f;

                int x0 = (int)X,
                    z0 = (int)Z,
                    x1 = x0 + 1,
                    z1 = z0 + 1;

                float height;
                float k;
                if (Xlerp + Zlerp > 1)
                {
                    float h1 = MathHelper.Lerp(heightMap[x0, z1], heightMap[x1, z1], Xlerp);
                    float h2 = MathHelper.Lerp(heightMap[x1, z0], heightMap[x1, z1], Zlerp);
                    k = h2 / h1;
                    height = MathHelper.Lerp(h1, h2, .5f);
                }
                else
                {
                    float h1 = MathHelper.Lerp(heightMap[x0, z0], heightMap[x1, z0], Xlerp),
                        h2 = MathHelper.Lerp(heightMap[x0, z0], heightMap[x0, z1], Zlerp);
                    k = h2 / h1;
                    height = MathHelper.Lerp(h1, h2, .5f);
                }
                pos.Y = height - 0.002f;

                if (k > 1.02 ) continue;

                GameObject obj;
                switch(UniversalRandom.GetInstance().Next(0, 3))
                {
                case 0:
                    obj = new OakTree(gameInstance);
                    obj.Scale = 3 + 3 * (float)UniversalRandom.GetInstance().NextDouble();
                    FireflyCandidates.Add(obj);
                    break;
                case 1:
                    obj = new BirchTree(gameInstance);
                    obj.Scale = 3 + 3 * (float)UniversalRandom.GetInstance().NextDouble();
                    FireflyCandidates.Add(obj);
                    break;
                default:
                    obj = new Stone(gameInstance);
                    obj.Scale = 0.5f + (float)(.25 * UniversalRandom.GetInstance().NextDouble());
                    break;
                }

                obj.Position = terrainScale * pos;
                obj.Rotation = new Vector3(0, MathHelper.Lerp(0, MathHelper.Pi * 2, (float)UniversalRandom.GetInstance().NextDouble()), 0);

                GraphicalObjects.Add(obj);
                ShadowCasterObjects.Add(obj);
            }

            for (int i = 0; i < FireflyCandidates.Count; i+=5)
            {
                ParticleEmitter emitter = new ParticleEmitter(fireflySystem, 80, FireflyCandidates[i].Position);
                emitter.Origin = FireflyCandidates[i].Position + Vector3.Up * 500;
                fireflyEmitter.Add(emitter);
            }

            #endregion

            //foreach (GameObject obj in GraphicalObjects)
            //{
            //    pointLights.Add(new PointLight(obj.Position + Vector3.Up * 500, new Vector3(0.7f, 0.7f, 0.7f), 450)
            //    {
            //        Model = pointLightModel
            //    });
            //}
            //GraphicalObjects.AddRange(pointLights);

            //List<FireObject> list = new List<FireObject>();
            //foreach (PointLight p in pointLights)
            //{
            //    FireObject obj = new FireObject(gameInstance, content, p.Position, p.Position + Vector3.Up * 10);
            //    list.Add(obj);

            //}
            //pointLights.AddRange(list);
            //GraphicalObjects.AddRange(list);

            #region Cameras

            var input = gameInstance.GetService<InputComponent>();

            gameInstance.GetService<CameraComponent>().AddCamera(new DebugCamera(new Vector3(-11800, 3000, -8200), input));
            Camera c;
            gameInstance.GetService<CameraComponent>().AddCamera(c = new ThirdPersonCamera(Car, input));
            gameInstance.GetService<CameraComponent>().CurrentCamera = c;

            #endregion

            #region DynamicEnvironment

            // TODO: CARMOVE
            environmentCubeMap = new RenderTargetCube(this.GraphicsDevice, 256, true, SurfaceFormat.Color, DepthFormat.Depth16);
            Car.EnvironmentMap = skyMap;

            #endregion

            #region PostProcess

            postProcessingComponent = new PostProcessingComponent(Game);
            Game.Components.Add(postProcessingComponent);

            postProcessTexture = new RenderTarget2D(GraphicsDevice,
                GraphicsDevice.Viewport.Width,
                GraphicsDevice.Viewport.Height,
                true, SurfaceFormat.Color, DepthFormat.Depth24);

            #endregion

            // Adding a prelighingrenderer as a service
            prelightingRenderer = new PrelightingRenderer(GraphicsDevice, content);
            Game.AddService(typeof(PrelightingRenderer), prelightingRenderer);

            #region ShadowMapEffect

            shadowMapEffect = content.Load<Effect>(@"Effects\ShadowMap");

            #endregion

            #region Gameplay Trigger Manager (with sample)

            /// <summary>
            /// Gets the triggermanager
            /// Add new PositionTrigger
            /// Hook up to listener => when hit, use the thunderBoltGenerator and spawn a flash
            /// Adds it to triggers.
            /// </summary>

            //var triggerManager = gameInstance.GetService<TriggerManager>();

            //int noOfCheckpoints = 10;
            //for (int i = 0; i < noOfCheckpoints; i++)
            //{
            //    var trigger = new PositionTrigger(raceTrack.CurveRasterization, (int)(((float)i / noOfCheckpoints) * raceTrack.CurveRasterization.Points.Count), true, true);
            //    string cp = "Checkpoint " + i;
            //    trigger.Triggered += (sender, e) =>
            //    {
            //        Console.WriteLine(cp);
            //    };
            //    triggerManager.Triggers.Add("checkpoint"+i, trigger);
            //}

            #endregion

            #region Game Mode
            if (gameInstance.GetService<ServerClient>().connected)
            {
                foreach (var player in gameInstance.GetService<ServerClient>().Players.Values)
                {
                    gameInstance.GetService<CarControlComponent>().AddCar(player, null, this);
                }
                var carList = gameInstance.GetService<CarControlComponent>().Cars.OrderBy(pc => pc.Key.ID).Select(pc => pc.Value).ToList();
                SetCarsAtStart(carList);
            }

            int cp = 6;
            if (gameModeChoice == GameModeChoice.SimpleRace)
                this.mode = new SimpleRaceMode(gameInstance, 3, cp, raceTrack, Car);
            else if (gameModeChoice == GameModeChoice.Multiplayer)
                this.mode = new MultiplayerRaceMode(gameInstance, 3, cp, raceTrack, Car);
            else
                throw new Exception("Stop choosing weird game modes");

            gameInstance.AddService(typeof(GameplayMode), mode);

            #endregion

            #region Checkpoint lights
            for (int i=0; i<cp; i++) {
                var point = raceTrack.GetCurveRasterization(cp).Points[i];

                var pl = new CheckpointLight(point.Position + 500 * Vector3.Up)
                {
                    Model = pointLightModel
                };
                pointLights.Add(pl);
                GraphicalObjects.Add(pl);

                #region Fire
                int halfnumberoffire = 5;

                for (int o = -halfnumberoffire + 1; o < halfnumberoffire; o++)
                {
                    Vector3 side = Vector3.Cross(Vector3.Normalize(raceTrack.Curve.GetPoint((i) / (float)cp + .001f) - point.Position), Vector3.Up);

                    var fire = new FireObject(content, fireSystem, fireSmokeSystem, point.Position + side * 100 * o -
                        Vector3.Up * 400 +
                        Vector3.Up * 650 * (float)Math.Cos(o/(float)halfnumberoffire), Vector3.Up * 10);
                    pointLights.Add(fire);
                    GraphicalObjects.Add(fire);
                }
                #endregion
            }
            #endregion

            #region BackgroundSound
            loopSoundManager.AddNewSound("forestambient");
            #endregion

            prelightingRenderer.GameObjects = GraphicalObjects;

            init = true;
        }
            public CustomEffect(Effect cloneSource)
                : base(cloneSource)
            {
                world = Parameters["World"];
                view = Parameters["View"];
                projection = Parameters["Projection"];
                eyePosition = Parameters["EyePosition"];

                fogEnabled = Parameters["FogEnabled"];
                fogStart = Parameters["FogStart"];
                fogEnd = Parameters["FogEnd"];
                fogColor = Parameters["FogColor"];

                diffuseColor = Parameters["DiffuseColor"];
                emissiveColor = Parameters["EmissiveColor"];
                specularColor = Parameters["SpecularColor"];
                specularPower = Parameters["SpecularPower"];

                ambientLightColor = Parameters["AmbientLightColor"];

                dirLight0Direction = Parameters["DirLight0Direction"];
                dirLight0DiffuseColor = Parameters["DirLight0DiffuseColor"];
                dirLight0SpecularColor = Parameters["DirLight0SpecularColor"];

                dirLight1Direction = Parameters["DirLight1Direction"];
                dirLight1DiffuseColor = Parameters["DirLight1DiffuseColor"];
                dirLight1SpecularColor = Parameters["DirLight1SpecularColor"];

                dirLight2Direction = Parameters["DirLight2Direction"];
                dirLight2DiffuseColor = Parameters["DirLight2DiffuseColor"];
                dirLight2SpecularColor = Parameters["DirLight2SpecularColor"];

                minAlpha = Parameters["MinAlpha"];
                maxAlpha = Parameters["MaxAlpha"];
                distanceAlphaFactor = Parameters["DistanceAlphaFactor"];

                normalMap = Parameters["NormalMap"];
                sampleOffset = Parameters["SampleOffset"];
                textureSize = Parameters["TextureSize"];
                textureScale = Parameters["TextureScale"];

                directionalLight0 = new XnaDirectionalLight(
                    dirLight0Direction,
                    dirLight0DiffuseColor,
                    dirLight0SpecularColor, null);
                directionalLight1 = new XnaDirectionalLight(
                    dirLight1Direction,
                    dirLight1DiffuseColor,
                    dirLight1SpecularColor, null);
                directionalLight2 = new XnaDirectionalLight(
                    dirLight2Direction,
                    dirLight2DiffuseColor,
                    dirLight2SpecularColor, null);
            }
        /// <summary>
        /// プロパティからのアクセスに使用する EffectParameter の取得と初期化を行います。
        /// </summary>
        void InitializeParameters()
        {
            view = backingEffect.Parameters["View"];
            projection = backingEffect.Parameters["Projection"];

            ambientLightColor = backingEffect.Parameters["AmbientLightColor"];
            directionalLight0 = new DirectionalLight(
                backingEffect.Parameters["DirLight0Direction"],
                backingEffect.Parameters["DirLight0DiffuseColor"],
                backingEffect.Parameters["DirLight0SpecularColor"],
                null);
            directionalLight1 = new DirectionalLight(
                backingEffect.Parameters["DirLight1Direction"],
                backingEffect.Parameters["DirLight1DiffuseColor"],
                backingEffect.Parameters["DirLight1SpecularColor"],
                null);
            directionalLight2 = new DirectionalLight(
                backingEffect.Parameters["DirLight2Direction"],
                backingEffect.Parameters["DirLight2DiffuseColor"],
                backingEffect.Parameters["DirLight2SpecularColor"],
                null);

            fogEnabled = backingEffect.Parameters["FogEnabled"];
            fogStart = backingEffect.Parameters["FogStart"];
            fogEnd = backingEffect.Parameters["FogEnd"];
            fogColor = backingEffect.Parameters["FogColor"];

            diffuseColor = backingEffect.Parameters["DiffuseColor"];
            alpha = backingEffect.Parameters["Alpha"];
            emissiveColor = backingEffect.Parameters["EmissiveColor"];
            specularColor = backingEffect.Parameters["SpecularColor"];
            specularPower = backingEffect.Parameters["SpecularPower"];

            // View の設定時に [M41, M42, M43] を EyePosition へ設定します。
            // このため、専用のプロパティによるアクセスを提供しません。
            // BasicEffect でも EyePosition は定義済みで、Fog の制御で使用しますが、
            // 同様の方法で EyePosition を View から設定しているのではないか、と・・・。
            eyePosition = backingEffect.Parameters["EyePosition"];
        }
Beispiel #16
0
        /// <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);

            // TODO: use this.Content to load your game content here

            // Add objects and lights to the ObjectManager and LightManager
            // respectively. The ObjectManager accepts objects in several forms:
            //
            //   -As SceneObjects, which can be dynamic (movable) or static and are
            //    created from XNA Models or custom vertex / index buffer.
            //
            //   -As XNA Models, which can only be static.
            //

            voxelManager.AddVoxelType("Models/cobblestone", 10000);
            voxelManager.FinishInit(Content, GraphicsDevice, sceneInterface);

            //Window.Title = Window.Title + " - Instanced Object Count: " + (instancesPerContainerObject * containerObjects.Length);

            // LightRigs contain many lights and light groups.
            LightRig rig = new LightRig();

            // Ambient lights uniformly illuminate the scene.
            AmbientLight ambientlight = new AmbientLight();
            ambientlight.Enabled = true;
            ambientlight.DiffuseColor = new Vector3(0.8f, 0.98f, 0.99f);
            ambientlight.Intensity = 0.5f;

            // Directional lights illuminate the scene from a specific direction, similar to sunlight.
            DirectionalLight sunlight = new DirectionalLight();
            sunlight.Enabled = true;
            sunlight.DiffuseColor = new Vector3(1.0f, 0.97f, 0.77f);
            sunlight.Intensity = 2.6f;
            sunlight.Direction = new Vector3(-0.60f, -0.73f, -0.32f);
            sunlight.ShadowType = ShadowType.AllObjects;
            sunlight.ShadowQuality = 1.0f;
            sunlight.ShadowPrimaryBias = 1.0f;
            sunlight.ShadowSecondaryBias = 0.04f;

            DirectionalLight sunlightB = new DirectionalLight();
            sunlightB.Enabled = true;
            sunlightB.DiffuseColor = new Vector3(0.0f, 0.97f, 0.77f);
            sunlightB.Intensity = 2.6f;
            sunlightB.Direction = new Vector3(0.60f, -0.73f, -0.32f);
            sunlightB.ShadowType = ShadowType.AllObjects;
            sunlightB.ShadowQuality = 1.0f;
            sunlightB.ShadowPrimaryBias = 1.0f;
            sunlightB.ShadowSecondaryBias = 0.04f;

            // Add the lights to a group.
            LightGroup group = new LightGroup();
            group.Add(ambientlight);
            group.Add(sunlight);
            group.Add(sunlightB);

            // Add the group to the light rig and commit the changes.
            rig.LightGroups.Add(group);
            rig.CommitChanges();

            // Submit the light rig to the light manager.
            sceneInterface.LightManager.Submit(rig);

            // Setup the scene settings.
            environment = new SceneEnvironment();
            environment.VisibleDistance = 250;
            environment.FogEnabled = true;
            environment.FogColor = new Vector3(0.5f, 0.5f, 0.5f);
            environment.FogStartDistance = 200;
            environment.FogEndDistance = 250;
            environment.ShadowFadeStartDistance = 200;
            environment.ShadowFadeEndDistance = 250;
            environment.ShadowCasterDistance = 250;

            // Apply the user preferences (example - not required).
            sceneInterface.ApplyPreferences(preferences);
        }
Beispiel #17
0
        void SetDirectionalLight(DirectionalLightModel model, DirectionalLight light)
        {
            light.Enabled = model.Enabled;

            if (model.Enabled)
            {
                light.Direction = model.Direction;
                light.DiffuseColor = model.DiffuseColor;
                light.SpecularColor = model.SpecularColor;
            }
        }
        /// <summary>
        /// Looks up shortcut references to our effect parameters.
        /// </summary>
        void CacheEffectParameters(SkinnedEffect cloneSource)
        {
            textureParam                = Parameters["Texture"];
            diffuseColorParam           = Parameters["DiffuseColor"];
            emissiveColorParam          = Parameters["EmissiveColor"];
            specularColorParam          = Parameters["SpecularColor"];
            specularPowerParam          = Parameters["SpecularPower"];
            eyePositionParam            = Parameters["EyePosition"];
            fogColorParam               = Parameters["FogColor"];
            fogVectorParam              = Parameters["FogVector"];
            worldParam                  = Parameters["World"];
            worldInverseTransposeParam  = Parameters["WorldInverseTranspose"];
            worldViewProjParam          = Parameters["WorldViewProj"];
            bonesParam                  = Parameters["Bones"];
            shaderIndexParam            = Parameters["ShaderIndex"];

            light0 = new DirectionalLight(Parameters["DirLight0Direction"],
                                          Parameters["DirLight0DiffuseColor"],
                                          Parameters["DirLight0SpecularColor"],
                                          (cloneSource != null) ? cloneSource.light0 : null);

            light1 = new DirectionalLight(Parameters["DirLight1Direction"],
                                          Parameters["DirLight1DiffuseColor"],
                                          Parameters["DirLight1SpecularColor"],
                                          (cloneSource != null) ? cloneSource.light1 : null);

            light2 = new DirectionalLight(Parameters["DirLight2Direction"],
                                          Parameters["DirLight2DiffuseColor"],
                                          Parameters["DirLight2SpecularColor"],
                                          (cloneSource != null) ? cloneSource.light2 : null);
        }
Beispiel #19
0
 private static void EnableDirectionalLight(DirectionalLight directionalLight, Light light, float specularFraction)
 {
     directionalLight.Enabled = true;
     directionalLight.DiffuseColor = light.color * light.intensity * 2;
     directionalLight.Direction = light.transform.forward;
     directionalLight.SpecularColor = light.color * specularFraction;
 }
Beispiel #20
0
 private void CacheEffectParameters(EnvironmentMapEffect cloneSource)
 {
   this.textureParam = this.Parameters["Texture"];
   this.environmentMapParam = this.Parameters["EnvironmentMap"];
   this.environmentMapAmountParam = this.Parameters["EnvironmentMapAmount"];
   this.environmentMapSpecularParam = this.Parameters["EnvironmentMapSpecular"];
   this.fresnelFactorParam = this.Parameters["FresnelFactor"];
   this.diffuseColorParam = this.Parameters["DiffuseColor"];
   this.emissiveColorParam = this.Parameters["EmissiveColor"];
   this.eyePositionParam = this.Parameters["EyePosition"];
   this.fogColorParam = this.Parameters["FogColor"];
   this.fogVectorParam = this.Parameters["FogVector"];
   this.worldParam = this.Parameters["World"];
   this.worldInverseTransposeParam = this.Parameters["WorldInverseTranspose"];
   this.worldViewProjParam = this.Parameters["WorldViewProj"];
   this.light0 = new DirectionalLight(this.Parameters["DirLight0Direction"], this.Parameters["DirLight0DiffuseColor"], (EffectParameter) null, cloneSource != null ? cloneSource.light0 : (DirectionalLight) null);
   this.light1 = new DirectionalLight(this.Parameters["DirLight1Direction"], this.Parameters["DirLight1DiffuseColor"], (EffectParameter) null, cloneSource != null ? cloneSource.light1 : (DirectionalLight) null);
   this.light2 = new DirectionalLight(this.Parameters["DirLight2Direction"], this.Parameters["DirLight2DiffuseColor"], (EffectParameter) null, cloneSource != null ? cloneSource.light2 : (DirectionalLight) null);
 }
 bool SetBasicDirectionaLightParameter(
     XnaDirectionalLight xnaDirectionalLight,
     ref WcDirectionalLight wcDirectionalLight)
 {
     if (wcDirectionalLight.Enabled)
     {
         xnaDirectionalLight.DiffuseColor = wcDirectionalLight.DiffuseColor;
         xnaDirectionalLight.SpecularColor = wcDirectionalLight.SpecularColor;
         xnaDirectionalLight.Direction = wcDirectionalLight.Direction;
         xnaDirectionalLight.Enabled = true;
         return true;
     }
     else
     {
         xnaDirectionalLight.Enabled = false;
         return false;
     }
 }
Beispiel #22
0
        public DirectionalLight(EffectParameter directionParameter, EffectParameter diffuseColorParameter, EffectParameter specularColorParameter, DirectionalLight cloneSource)
        {
            if (cloneSource != null)
            {
                this.diffuseColorParameter  = cloneSource.diffuseColorParameter;
                this.directionParameter     = cloneSource.directionParameter;
                this.specularColorParameter = cloneSource.specularColorParameter;

                this.diffuseColor  = cloneSource.diffuseColor;
                this.direction     = cloneSource.direction;
                this.specularColor = cloneSource.specularColor;
                this.enabled       = cloneSource.enabled;
            }
            else
            {
                this.diffuseColorParameter  = diffuseColorParameter;
                this.directionParameter     = directionParameter;
                this.specularColorParameter = specularColorParameter;
            }
        }
Beispiel #23
0
        protected override void LoadContent()
        {
            base.LoadContent();

            Vector2 size = GetScreenPosition(new Vector2(0.5f, 0.6f));
            Bounds = new Rectangle(0, 0, (int)size.X, (int)size.Y);

            List<Tuple<String, GameState>> itemInfo = new List<Tuple<string, GameState>>();
            itemInfo.Add(new Tuple<String, GameState>("Back", GameState.MainMenu));
            itemInfo.Add(new Tuple<String, GameState>("Start", GameState.Gameplay));

            foreach (var info in itemInfo)
            {
                MenuItem item = new StateActionMenuItem(info.Item1, info.Item2);
                item.Background = ButtonBackground;
                item.Font = MenuFont;
                item.FontColor = ItemColor;
                item.FontColorSelected = ItemColorSelected;
                item.SetWidth(ButtonBackground.Bounds.Width);
                AddMenuItem(item);
            }

            directionalLight = new DirectionalLight(
                new Vector3(-1.25f, -2f, 5.0f), // Direction
                new Vector3(.1f, .1f, .1f),//new Vector3(.15f, .14f, .29f), // Ambient
                new Vector3(1f, 1f, 1f)); // Diffuse

            MakeCar();
            cameraPosition = new Vector3(0, 100f, 300f);

            projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 0.01f, 500f);

            if (availableColors.Exists(c => c == GameSettings.Default.CarColor)) {
                diffuseColor = GameSettings.Default.CarColor;
            }
        }
Beispiel #24
0
 private static void EnableDirectionalLight(DirectionalLight directionalLight, Light light)
 {
     directionalLight.Enabled = true;
     directionalLight.DiffuseColor = light.color * light.intensity * 2;
     directionalLight.Direction = light.transform.forward;
 }
    /// <summary>Compares two directional lights against each other</summary>
    /// <param name="left">Left directional light that will be compared</param>
    /// <param name="right">Reft directional light that will be compared</param>
    /// <returns>True if both directional lights have identical properties</returns>
    private static bool areEqual(
#if XNA_4
      DirectionalLight left, DirectionalLight right