Example #1
0
        public override void Draw(GameTime gameTime)
        {
            DrawTextures();

            GraphicsDevice.SetRenderTarget(null);

            if (CameraTargetA == null || CameraTargetA.IsContentLost)
            {
                CameraTargetA = new RenderTarget2D(GraphicsDevice, Viewport.Width, Viewport.Height);
            }

            if (CameraTargetB == null || CameraTargetB.IsContentLost)
            {
                CameraTargetB = new RenderTarget2D(GraphicsDevice, Viewport.Width, Viewport.Height);
            }

            if (DistortionMap == null || DistortionMap.IsContentLost)
            {
                DistortionMap = new RenderTarget2D(GraphicsDevice, Viewport.Width, Viewport.Height);
            }

            Projection     = Matrix.CreateOrthographicOffCenter(0, Viewport.Width, Viewport.Height, 0, 0, -1);
            WorldTransform = CreateViewMatrix();

            IEnumerable <VisualEffect> visualEffects = VisualEffects.Where(x => x.ShouldDraw(CameraMap));
            IEnumerable <ScreenShake>  screenShakes  = visualEffects.OfType <ScreenShake>();

            if (screenShakes.Any())
            {
                ScreenShake screenShake = screenShakes.WithMax(effect => effect.Offset.LengthSquared());
                if (screenShake != null)
                {
                    WorldTransform *= Matrix.CreateTranslation(screenShake.Offset.X, screenShake.Offset.Y, 0);
                }
            }

            var gameObjects = GameObjects.Where(x => x.ShouldDraw(CameraMap));
            var tiles       = DrawMap(CameraMap);
            var drawPasses  = gameObjects.Concat(tiles).ToMultiLookup(x => x.GetDrawPasses());

            GraphicsDevice.SetRenderTarget(DistortionMap);

            /*var noise = SpriteLoader.Instance.AddSprite("content/noise");
             * var noiseOffset = Util.AngleToVector(Frame * 0.1f) * 30;
             * noiseOffset = new Vector2(-Frame * 0.2f, -Frame * 0.5f);
             * PushSpriteBatch(samplerState: SamplerState.LinearWrap, blendState: BlendState.Additive);
             * SpriteBatch.Draw(Pixel, DistortionMap.Bounds, new Color(0,64,0));
             * SpriteBatch.Draw(noise.Texture, DistortionMap.Bounds, new Rectangle((int)noiseOffset.X, (int)noiseOffset.Y, DistortionMap.Width, DistortionMap.Height), Color.Red);
             * PopSpriteBatch();*/
            PushSpriteBatch(samplerState: SamplerState.PointWrap, blendState: NonPremultiplied, transform: WorldTransform, projection: Projection);
            drawPasses.DrawPass(this, DrawPass.SeaDistort);
            PopSpriteBatch();

            GraphicsDevice.SetRenderTarget(CameraTargetA);
            //Render Liquid to Target A
            PushSpriteBatch(samplerState: SamplerState.PointWrap, blendState: NonPremultiplied, transform: WorldTransform, projection: Projection);
            drawPasses.DrawPass(this, DrawPass.SeaFloor);
            drawPasses.DrawPass(this, DrawPass.Sea);
            PopSpriteBatch();

            GraphicsDevice.SetRenderTarget(CameraTargetB);
            SwapBuffers();
            PushSpriteBatch(samplerState: SamplerState.PointWrap, blendState: NonPremultiplied, transform: WorldTransform, projection: Projection);
            drawPasses.DrawPass(this, DrawPass.LiquidFloor);
            //Render Target A (Liquid) to Target B (with distortion)
            PushSpriteBatch(samplerState: SamplerState.PointWrap, blendState: NonPremultiplied, transform: Matrix.Identity, shader: Shader, shaderSetup: (matrix, projection) =>
            {
                SetupDistortion(DistortionMap, new Vector2(30f / DistortionMap.Width, 30f / DistortionMap.Height), Matrix.Identity, Matrix.Identity, Projection);
            });
            SpriteBatch.Draw(CameraTargetB, CameraTargetB.Bounds, Color.White);
            //SpriteBatch.Draw(DistortionMap, DistortionMap.Bounds, Color.White);
            PopSpriteBatch();
            drawPasses.DrawPass(this, DrawPass.Liquid);
            //Render Map


            drawPasses.DrawPass(this, DrawPass.Tile);
            drawPasses.DrawPass(this, DrawPass.Item);
            drawPasses.DrawPass(this, DrawPass.EffectLow);
            PushSpriteBatch(blendState: BlendState.Additive);
            drawPasses.DrawPass(this, DrawPass.EffectLowAdditive);
            PopSpriteBatch();
            drawPasses.DrawPass(this, DrawPass.Creature);
            drawPasses.DrawPass(this, DrawPass.Effect);
            PushSpriteBatch(blendState: BlendState.Additive);
            drawPasses.DrawPass(this, DrawPass.EffectAdditive);
            PopSpriteBatch();
            PopSpriteBatch();

            GraphicsDevice.SetRenderTarget(CameraTargetB);
            SwapBuffers();

            //Draw screenflashes
            ColorMatrix color = ColorMatrix.Identity;

            IEnumerable <ScreenFlash> screenFlashes = visualEffects.OfType <ScreenFlash>();

            foreach (ScreenFlash screenFlash in screenFlashes)
            {
                color *= screenFlash.Color;
            }

            //SetupColorMatrix(color, Matrix.Identity, Projection);
            //SetupGlitch(Game.Noise, Matrix.Identity, Projection, Random);
            PushSpriteBatch(samplerState: SamplerState.PointWrap, blendState: NonPremultiplied, shader: Shader, shaderSetup: (transform, projection) =>
            {
                SetupColorMatrix(color, Matrix.Identity, Projection);
            });
            SpriteBatch.Draw(CameraTargetB, CameraTargetB.Bounds, Color.White);
            PopSpriteBatch();

            GraphicsDevice.SetRenderTarget(CameraTargetB);
            SwapBuffers();

            //Draw glitches
            IEnumerable <ScreenGlitch> screenGlitches = visualEffects.OfType <ScreenGlitch>();

            foreach (var glitch in screenGlitches)
            {
                GlitchParams glitchParams = glitch.Glitch;

                PushSpriteBatch(samplerState: SamplerState.PointWrap, blendState: NonPremultiplied, shader: Shader, shaderSetup: (transform, projection) =>
                {
                    SetupGlitch(Game.Noise, glitchParams, Random, Matrix.Identity, Projection);
                });
                SpriteBatch.Draw(CameraTargetB, CameraTargetB.Bounds, Color.White);
                PopSpriteBatch();

                GraphicsDevice.SetRenderTarget(CameraTargetB);
                SwapBuffers();
            }

            //Draw to screen
            GraphicsDevice.SetRenderTarget(null);

            PushSpriteBatch(samplerState: SamplerState.PointWrap, blendState: NonPremultiplied, shader: Shader, shaderSetup: (transform, projection) =>
            {
                SetupColorMatrix(ColorMatrix.Identity, Matrix.Identity, Projection);
            });
            SpriteBatch.Draw(CameraTargetB, CameraTargetB.Bounds, Color.White);
            PopSpriteBatch();

            SpriteReference cursor_tile = SpriteLoader.Instance.AddSprite("content/cursor_tile");

            SetupNormal(Matrix.Identity, Projection);
            //SpriteBatch.Begin(blendState: NonPremultiplied, rasterizerState: RasterizerState.CullNone, samplerState: SamplerState.PointWrap, transformMatrix: WorldTransform);
            PushSpriteBatch(blendState: NonPremultiplied, samplerState: SamplerState.PointWrap, transform: WorldTransform, projection: Projection);

            if (TileCursor.HasValue)
            {
                DrawSprite(cursor_tile, Frame / 8, new Vector2(TileCursor.Value.X * 16, TileCursor.Value.Y * 16), SpriteEffects.None, 0);
            }

            DrawQuests(CameraMap);

            drawPasses.DrawPass(this, DrawPass.UIWorld);

            //SpriteBatch.End();
            PopSpriteBatch();

            //SetupNormal(Matrix.Identity);
            //SpriteBatch.Begin(blendState: NonPremultiplied, rasterizerState: RasterizerState.CullNone, samplerState: SamplerState.PointWrap);

            PushSpriteBatch(blendState: NonPremultiplied, samplerState: SamplerState.PointWrap, projection: Projection);

            DrawQuestText(CameraMap);

            drawPasses.DrawPass(this, DrawPass.UI);

            Menu.Draw(this);

            DrawTooltip();

            PopSpriteBatch();
        }
Example #2
0
 public void SetupColorMatrix(ColorMatrix matrix)
 {
     SetupColorMatrix(matrix, WorldTransform, Projection);
 }
Example #3
0
 public static ColorMatrix Lerp(ColorMatrix a, ColorMatrix b, float s)
 {
     return(new ColorMatrix(Matrix.Lerp(a.Matrix, b.Matrix, s), Vector4.Lerp(a.Add, b.Add, s)));
 }
Example #4
0
 public ColorMatrix Multiply(ColorMatrix other)
 {
     return(Multiply(this, other));
 }
Example #5
0
 public override void OnStackChange(int delta)
 {
     base.OnStackChange(delta);
     if (delta > 0 && Creature is Creature creature)
     {
         var cloak = new Cloak(creature, 30);
         cloak.OnUpdate += c => Cloak.PowerDown(c, 5, ColorMatrix.Greyscale() * ColorMatrix.Tint(Color.SteelBlue), LerpHelper.QuadraticOut, LerpHelper.QuadraticOut, 20);
     }
 }