コード例 #1
0
        public void blend(PImage src, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, BlendMode mode)
        {
            var blend = mode switch
            {
                BlendMode.ADD => BlendState.Additive,
                BlendMode.DODGE => new BlendState
                {
                    ColorSourceBlend      = Blend.One,
                    ColorDestinationBlend = Blend.One,
                    ColorBlendFunction    = BlendFunction.Add
                },
                BlendMode.MULTIPLY => new BlendState
                {
                    ColorSourceBlend      = Blend.DestinationColor,
                    ColorDestinationBlend = Blend.Zero,
                    ColorBlendFunction    = BlendFunction.Add
                },
                BlendMode.LIGHTEST => new BlendState
                {
                    ColorSourceBlend      = Blend.One,
                    ColorDestinationBlend = Blend.One,
                    ColorBlendFunction    = BlendFunction.Max
                },
                BlendMode.DARKEST => new BlendState
                {
                    ColorSourceBlend      = Blend.One,
                    ColorDestinationBlend = Blend.One,
                    ColorBlendFunction    = BlendFunction.Min
                },
                BlendMode.SUBTRACT => new BlendState
                {
                    ColorSourceBlend      = Blend.One,
                    AlphaSourceBlend      = Blend.One,
                    ColorDestinationBlend = Blend.One,
                    AlphaDestinationBlend = Blend.One,
                    ColorBlendFunction    = BlendFunction.ReverseSubtract,
                    AlphaBlendFunction    = BlendFunction.ReverseSubtract
                },
                _ => BlendState.NonPremultiplied,
            };

            var aux = graphicsDevice.GetRenderTargets();
            var img = new RenderTarget2D(graphicsDevice, width, height, false, graphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24);

            graphicsDevice.SetRenderTarget(img);
            graphicsDevice.Clear(Color.Transparent);

            spriteBatch.Begin(SpriteSortMode.Immediate);
            spriteBatch.Draw(texture, Vector2.Zero, Color.White);
            spriteBatch.End();

            spriteBatch.Begin(SpriteSortMode.Immediate, blend);
            spriteBatch.Draw(src.texture, new Vector2(dx, dy), new Rectangle(sx, sy, sw, sh), Color.White, 0, Vector2.Zero, new Vector2(dw / (float)sw, dh / (float)sh), SpriteEffects.None, 0);
            spriteBatch.End();

            graphicsDevice.SetRenderTargets(currentTarget);
            texture = img;
        }
コード例 #2
0
 public void mask(PImage img)
 {
     img.loadPixels();
     for (int i = 0; i < pixels.Length; i++)
     {
         var aux = pixels[i];
         aux.A     = img.pixels[i].B;
         pixels[i] = aux;
     }
 }
コード例 #3
0
        public void copy(PImage src, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh)
        {
            var img = new RenderTarget2D(graphicsDevice, width, height, false, graphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24);

            graphicsDevice.SetRenderTarget(img);
            graphicsDevice.Clear(Color.Transparent);

            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
            spriteBatch.Draw(texture, Vector2.Zero, Color.White);
            spriteBatch.Draw(src.texture, new Vector2(dx, dy), new Rectangle(sx, sy, sw, sh), Color.White, 0, Vector2.Zero, new Vector2(dw / (float)sw, dh / (float)sh), SpriteEffects.None, 0);
            spriteBatch.End();

            graphicsDevice.SetRenderTargets(currentTarget);
            texture = img;
        }
コード例 #4
0
 public void background(PImage img)
 {
     background(255);
     image(img, 0, 0, width, height);
 }
コード例 #5
0
 public void image(PImage img, float a, float b) => image(img, a, b, img.width, img.height);
コード例 #6
0
 public void image(PImage img, float a, float b, float c, float d) => DrawImage(img.texture, a, b, c, d, _style.Tint);