private static Vector2 ScreenToPixel(ILightmapPass pass, Vector2 v)
        {
            v.X = ((1 + v.X) / 2) * pass.Viewport.Width + pass.Viewport.X;
            v.Y = ((1 - v.Y) / 2) * pass.Viewport.Height + pass.Viewport.Y;

            return v;
        }
        /// <summary>
        /// Draws all lights and hulls to the current render target
        /// </summary>
        /// <param name="pass">The pass.</param>
        /// <param name="lights">The lights.</param>
        /// <param name="hulls">The hulls.</param>
        public void DrawLightmap(ILightmapPass pass, IList<ILight> lights, IList<IHull> hulls)
        {
            // Krypton Draws Here
            foreach (var light in lights)
            {
                this.device.Clear(ClearOptions.Stencil, Color.Black, 0, 0);

                light.Draw(this.lightmapEffect, pass, this.drawBuffer, hulls);
            }
        }
示例#3
0
        /// <summary>
        /// Draws the light with shadows from the hulls
        /// </summary>
        /// <param name="lightmapEffect">The lightmap effect.</param>
        /// <param name="helper">The helper.</param>
        /// <param name="hulls">The hulls.</param>
        public void Draw(LightmapEffect lightmapEffect, ILightmapPass lightmapPass, ILightmapDrawBuffer helper, IEnumerable<IHull> hulls)
        {
            lightmapEffect.Effect.GraphicsDevice.ScissorRectangle = lightmapPass.GetScissor(this);

            // lightmapEffect.Effect.GraphicsDevice.ScissorRectangle = new Rectangle(0, 0, 200, 200);

            // 1) Clear hull buffers
            helper.Clear();

            // 2) Prepare to draw hulls
            foreach (var hull in hulls.Where(x => Vector2.DistanceSquared(this.Position, x.Position) < this.RadiusSquared + x.RadiusSquared))
            {
                hull.Draw(helper);
            }

            // 3) Set lightmapEffect stuff
            lightmapEffect.LightPosition = this.Position;
            lightmapEffect.LightTexture = this.Texture;
            lightmapEffect.LightInesityFactor = this.IntensityFactor;

            switch (this.ShadowType)
            {
                case ShadowType.Illuminated:
                    lightmapEffect.CurrentTechnique = lightmapEffect.IlluminatedShadowTechnique;
                    break;
                case ShadowType.Occluded:
                    lightmapEffect.CurrentTechnique = lightmapEffect.OccludedShadowTechnique;
                    break;
                default:
                    lightmapEffect.CurrentTechnique = lightmapEffect.SolidShadowTechnique;
                    break;
            }

            // 4) Draw hulls for each shadow pass
            foreach (var pass in lightmapEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                helper.Draw();
            }

            // 5) Draw light for each light pass
            lightmapEffect.CurrentTechnique = lightmapEffect.LightTechnique;

            foreach (var pass in lightmapEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                helper.DrawClippedFov(this.Position, this.Rotation, this.Radius * 2, this.Color, this.Fov);
            }

            // 6) Clear the target's alpha chanel
            lightmapEffect.CurrentTechnique = lightmapEffect.AlphaClearTechnique;

            //lightmapEffect.Effect.GraphicsDevice.ScissorRectangle = lightmapEffect.Effect.GraphicsDevice.Viewport.Bounds;

            foreach (var pass in lightmapEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                helper.DrawUnitQuad();
            }
        }
 /// <summary>
 /// Called before starting the pass, and before the viewport and matrix have been set.
 /// </summary>
 /// <param name="pass">The pass.</param>
 protected void OnPassStart(ILightmapPass pass)
 {
     var handler = this.PassStart;
     if (handler != null)
     {
         handler(pass);
     }
 }
 /// <summary>
 /// Called before drawing the pass, but after the viewport and matrix have been set.
 /// </summary>
 /// <param name="pass">The pass.</param>
 protected void OnPassRunning(ILightmapPass pass)
 {
     var handler = this.PassRunning;
     if (handler != null)
     {
         handler(pass);
     }
 }
 /// <summary>
 /// Called after drawing is complete.
 /// </summary>
 /// <param name="pass">The pass.</param>
 protected void OnPassComplete(ILightmapPass pass)
 {
     var handler = this.PassComplete;
     if (handler != null)
     {
         handler(pass);
     }
 }