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;
            }
        }
Exemple #2
0
        private void AddTorch (float x, float y) {
            var torch = new LightSource {
                Mode = LightSourceMode.Alpha,
                Position = new Vector2(x, y),
                Color = new Vector4(235 / 255.0f, 95 / 255.0f, 15 / 255f, 0.9f),
                RampStart = 80,
                RampEnd = 250
            };

            Torches.Add(torch);
            ForegroundEnvironment.LightSources.Add(torch);
        }
        private void AddAmbientLight (float x, float y, Bounds? clipBounds = null) {
            var ambient = new LightSource {
                Mode = LightSourceMode.Max,
                Position = new Vector2(x, y),
                NeutralColor = new Vector4(32 / 255f, 32 / 255f, 32 / 255f, 1f),
                Color = new Vector4(1, 1, 1, 0.45f),
                RampStart = 2000,
                RampEnd = 2500,
                ClipRegion = clipBounds
            };

            BackgroundEnvironment.LightSources.Add(ambient);
        }
        protected void UpdateSectorLight (ParticleSystem<Spark>.ParticleCollection particles, LightSource lightSource) {
            int particleCount = 0;

            int rAccumulator = 0, gAccumulator = 0, bAccumulator = 0, aAccumulator = 0;
            Vector2 positionAccumulator = Vector2.Zero;

            Spark particle;

            using (var e = particles.GetEnumerator())
            while (e.GetNext(out particle)) {
                particleCount += 1;

                positionAccumulator += particle.Position;
                var particleColor = particle.GetColor();

                rAccumulator += particleColor.R;
                gAccumulator += particleColor.G;
                bAccumulator += particleColor.B;
                aAccumulator += particleColor.A;
            }

            lightSource.Position = (positionAccumulator / particleCount);

            float fParticleCount255 = particleCount * 255.0f;
            // FIXME: Need to unpremultiply
            lightSource.Color = new Vector4(
                rAccumulator / fParticleCount255,
                gAccumulator / fParticleCount255,
                bAccumulator / fParticleCount255,
                aAccumulator / fParticleCount255
            );

            lightSource.Color.W *= MathHelper.Clamp(particleCount / 20f, 0.1f, 1.0f) * 0.55f;

            lightSource.RampStart = 24 + MathHelper.Clamp(particleCount * 0.25f, 0, 24);
            lightSource.RampEnd = lightSource.RampStart + 32 + MathHelper.Clamp(particleCount * 0.5f, 0, 48);

            lightSource.RampMode = LightSourceRampMode.Exponential;
        }