Esempio n. 1
0
        public override void LoadContent()
        {
            LightmapMaterials = new DefaultMaterialSet(Game.Services);

            // Since the spiral is very detailed
            LightingEnvironment.DefaultSubdivision = 128f;

            Environment = new LightingEnvironment();

            Renderer = new LightingRenderer(Game.Content, Game.RenderCoordinator, LightmapMaterials, Environment);

            var light = new LightSource {
                Position  = new Vector2(64, 64),
                Color     = new Vector4(1f, 1f, 1f, 1),
                RampStart = 50,
                RampEnd   = 275,
            };

            Lights.Add(light);
            Environment.LightSources.Add(light);

            var rng = new Random(1234);

            for (var i = 0; i < 25; i++)
            {
                light = new LightSource {
                    Position  = new Vector2(64, 64),
                    Color     = new Vector4((float)rng.NextDouble(0.1f, 1.0f), (float)rng.NextDouble(0.1f, 1.0f), (float)rng.NextDouble(0.1f, 1.0f), 1.0f),
                    RampStart = rng.NextFloat(24, 40),
                    RampEnd   = rng.NextFloat(140, 160),
                    RampMode  = LightSourceRampMode.Exponential
                };

                Lights.Add(light);
                Environment.LightSources.Add(light);
            }

            const int spiralCount = 1800;
            float     spiralRadius = 0, spiralRadiusStep = 330f / spiralCount;
            float     spiralAngle = 0, spiralAngleStep = (float)(Math.PI / (spiralCount / 36f));
            Vector2   previous = default(Vector2);

            for (int i = 0; i < spiralCount; i++, spiralAngle += spiralAngleStep, spiralRadius += spiralRadiusStep)
            {
                var current = new Vector2(
                    (float)(Math.Cos(spiralAngle) * spiralRadius) + (Width / 2f),
                    (float)(Math.Sin(spiralAngle) * spiralRadius) + (Height / 2f)
                    );

                if (i > 0)
                {
                    Environment.Obstructions.Add(new LightObstructionLine(
                                                     previous, current
                                                     ));
                }

                previous = current;
            }
        }
Esempio n. 2
0
        public override void LoadContent()
        {
            LightmapMaterials = new DefaultMaterialSet(Game.Services);

            Environment = new LightingEnvironment();

            TestImage = Game.Content.Load <Texture2D>("ramp_test_image");

            RampTexture = Game.Content.Load <Texture2D>("LightGradients");

            Environment.LightSources.AddRange(new[] {
                new LightSource {
                    Position  = new Vector2(128, 128),
                    Color     = Vector4.One,
                    RampStart = 32,
                    RampEnd   = 128,
                    RampMode  = LightSourceRampMode.Linear
                },
                new LightSource {
                    Position  = new Vector2(400, 128),
                    Color     = Vector4.One,
                    RampStart = 32,
                    RampEnd   = 128,
                    RampMode  = LightSourceRampMode.Exponential
                },
                new LightSource {
                    Position    = new Vector2(128, 400),
                    Color       = Vector4.One,
                    RampStart   = 32,
                    RampEnd     = 128,
                    RampMode    = LightSourceRampMode.Linear,
                    RampTexture = RampTexture
                },
                new LightSource {
                    Position    = new Vector2(400, 400),
                    Color       = Vector4.One,
                    RampStart   = 32,
                    RampEnd     = 128,
                    RampMode    = LightSourceRampMode.Exponential,
                    RampTexture = RampTexture
                }
            });

            Renderer = new LightingRenderer(Game.Content, Game.RenderCoordinator, LightmapMaterials, Environment);
        }
 public SparkUpdater(LightingEnvironment lightingEnvironment)
 {
     LightingEnvironment = lightingEnvironment;
     LineWriter          = new CroppedListLineWriter();
 }
Esempio n. 4
0
        public override void LoadContent()
        {
            LightmapMaterials = new DefaultMaterialSet(Game.Services);

            LightingEnvironment.DefaultSubdivision = 512f;

            BackgroundEnvironment = new LightingEnvironment();
            ForegroundEnvironment = new LightingEnvironment();

            BackgroundRenderer = new LightingRenderer(Game.Content, Game.RenderCoordinator, LightmapMaterials, BackgroundEnvironment);
            ForegroundRenderer = new LightingRenderer(Game.Content, Game.RenderCoordinator, LightmapMaterials, ForegroundEnvironment);

            // Add a global sun
            AddAmbientLight(746, -300);

            // Add clipped suns for areas with weird shadowing behavior
            AddAmbientLight(746, 200, new Bounds(
                                new Vector2(38, 33),
                                new Vector2(678, 678)
                                ));

            AddAmbientLight(740, 240, new Bounds(
                                new Vector2(805, 34),
                                new Vector2(1257, 546)
                                ));

            AddAmbientLight(741, 750, new Bounds(
                                new Vector2(0, 674),
                                new Vector2(1257, 941)
                                ));

            AddAmbientLight(741, 1025, new Bounds(
                                new Vector2(0, 941),
                                new Vector2(1257, 1250)
                                ));

            GenerateObstructionsFromTiles();

            Layers[0] = Game.Content.Load <Texture2D>("layers_bg");
            Layers[1] = Game.Content.Load <Texture2D>("layers_fg");
            Layers[2] = Game.Content.Load <Texture2D>("layers_chars");
            Layers[3] = Game.Content.Load <Texture2D>("layers_torches");

            MaskedForegroundMaterial = LightmapMaterials.ScreenSpaceLightmappedBitmap.SetStates(blendState: BlendState.Additive);

            ParticleRenderer = new ParticleRenderer(LightmapMaterials)
            {
                Viewport = new Bounds(Vector2.Zero, new Vector2(Width, Height))
            };

            Spark.Texture = Game.Content.Load <Texture2D>("spark");

            ParticleRenderer.Systems = new[] {
                Sparks = new ParticleSystem <Spark>(
                    new DotNetTimeProvider(),
                    BackgroundEnvironment
                    )
            };

            SparkLights = new ParticleLightManager <Spark>(
                Sparks,
                new[] { BackgroundEnvironment, ForegroundEnvironment },
                UpdateSectorLight
                );
        }