示例#1
0
 /// <summary>
 /// Removes a light's binding from the shadow map, disabling it from casting shadows.
 /// </summary>
 /// <param name="light">The light to unregister / unbind.</param>
 public void UnregisterLight(ShadowCastingLight light)
 {
     if (light.shadow_map_slot < 0 || light.shadow_map_slot > MAX_SHADOW_MAPS)
     {
         Debug.LogError("Error freeing shadow map slot.");
     }
     FreeShadowMap(light.shadow_map_slot);
     light.shadow_map_slot = -1;
 }
示例#2
0
    /// <summary>
    /// Sets up a light, assigning / binding it to a slot (row) in the shadow map.
    /// </summary>
    /// <param name="light">The light to register / bind.</param>
    public void RegisterLight(ShadowCastingLight light)
    {
        int slot = AllocateShadowMap();

        if (slot != -1)
        {
            light.shadow_map_slot = slot;
        }
        else
        {
            #if UNITY_EDITOR
            Debug.LogError("Too many shadow casting lights in the scene!");
            #endif
        }
    }
示例#3
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
                Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            this.KeyboardInput.Update();
            this.MouseInput.Update();

            if (this.KeyboardInput.Click(Keys.OemTilde))
            {
                this.detailView = !this.detailView;
            }

            if (this.KeyboardInput.Click(Keys.Tab))
            {
                this.currentSceneIndex  = (this.currentSceneIndex + 1) % this.scenes.Length;
                this.renderSystem.Scene = this.scenes[this.currentSceneIndex];
            }

            if (this.KeyboardInput.Click(Keys.F))
            {
                this.IsFixedTimeStep = !this.IsFixedTimeStep;
            }

            if (this.KeyboardInput.Click(Keys.OemPlus))
            {
                this.viewIndex = (this.viewIndex + 1) % this.viewOptions;
            }
            else if (this.KeyboardInput.Click(Keys.OemMinus))
            {
                this.viewIndex = (this.viewIndex + this.viewOptions - 1) % this.viewOptions;
            }

            if (this.KeyboardInput.Click(Keys.LeftControl))
            {
                this.renderSystem.EnableFXAA = !this.renderSystem.EnableFXAA;
            }

            // HACK: dropping some lights
            var selectedScene = this.scenes[this.currentSceneIndex];

            if (this.KeyboardInput.Click(Keys.Q))
            {
                var color = ColorUtilities.PickRandomColor();
                var light = new PointLight(this.camera.Position, color, 10, 1.0f);
                selectedScene.PointLights.Add(light);
            }

            if (this.KeyboardInput.Click(Keys.LeftAlt))
            {
                var light = new ShadowCastingLight(this.GraphicsDevice, this.camera.Position, this.camera.LookAt, Color.White);
                selectedScene.ShadowCastingLights.Add(light);
            }

            if (this.KeyboardInput.Click(Keys.H))
            {
                selectedScene.Sunlights.ForEach(x => x.Move(this.camera.Position, this.camera.LookAt));
            }

            this.cameraController.Update(gameTime.ElapsedGameTime);

            this.renderSystem.Scene.Update(gameTime.ElapsedGameTime);

            base.Update(gameTime);
        }
示例#4
0
        public void Update(PerspectiveCamera camera, Seconds elapsed)
        {
            if (this.started == false)
            {
                return;
            }

            this.CutsceneSystem.Update(camera, elapsed);

            if (this.accumulator == 0)
            {
                this.ambientLight = this.SceneBuilder.BuildSponzaAmbientLight();
                this.sunlight     = this.SceneBuilder.BuildSponzaSunLight();
                this.PointLight   = this.SceneBuilder.BuildFirePlace();

                this.SceneBuilder.BuildStainedGlass();
                this.SceneBuilder.BuildBulletHoles();

                this.SceneBuilder.BuildCutScene();


                this.ambientLight.Color = Color.Black;
                this.sunlight.Move(this.sunlight.Position, new Vector3(-10.0f, this.sunlight.LookAt.Y, this.sunlight.LookAt.Z));

                this.ambientLight.Color = Color.Black;
                this.sunlight.Move(this.sunlight.Position, new Vector3(-10.0f, this.sunlight.LookAt.Y, this.sunlight.LookAt.Z));
                //MediaPlayer.Play(this.song);
            }

            if (this.accumulator < new Seconds(1))
            {
                this.PointLight.Color = Color.IndianRed * this.accumulator;
            }

            this.accumulator += elapsed;

            var warmup = new Seconds(7);

            if (this.accumulator > warmup)
            {
                var since = this.accumulator - warmup;

                var desiredOff2 = MathHelper.Clamp(since / 1, 0.0f, 9.25f);
                this.off2 = MathHelper.Lerp(this.off2, desiredOff2, 0.05f);
                this.sunlight.Move(this.sunlight.Position, new Vector3(-10.0f + this.off2, this.sunlight.LookAt.Y, this.sunlight.LookAt.Z));

                var off = MathHelper.Clamp(since / 23.0f, 0f, 0.4f);
                this.ambientLight.Color = new Color(off, off, off);
            }

            var secondState = new Seconds(26);

            if (this.accumulator > secondState)
            {
                if (this.shadowCastingLight == null)
                {
                    this.shadowCastingLight = this.SceneBuilder.BuildLionSpotLight();
                }

                var since = this.accumulator - secondState;
                var off   = MathHelper.Clamp(since / 2.0f, 0f, 0.8f);
                this.shadowCastingLight.Color = Color.White * off;
            }

            var fadeOut = new Seconds(28);

            if (this.accumulator > fadeOut)
            {
                var left = MathHelper.Clamp((this.accumulator - fadeOut) / 3.0f, 0, 1);
                MediaPlayer.Volume = 1.0f - left;
            }

            Debug.WriteLine(this.accumulator);
        }