Пример #1
0
 private void DrawRectangle(SharpDX.RectangleF rectangle, Color color, float width, bool inflate = true)
 {
     if (inflate)
     {
         rectangle.Inflate(1, 0);
     }
     Line.DrawLine(color, width, rectangle.TopLeft, rectangle.TopRight, rectangle.BottomRight, rectangle.BottomLeft, rectangle.TopLeft);
 }
Пример #2
0
        /// <summary>Function called to render the sprite data.</summary>
        /// <returns>The presentation interval to use when rendering.</returns>
        protected override int OnRender()
        {
            base.OnRender();

            Renderer.Begin();

            for (int i = 0; i < _handles.Length; ++i)
            {
                DX.RectangleF handleBounds = _handles[i];

                if (handleBounds.IsEmpty)
                {
                    continue;
                }

                // Hilight our active handle.
                if (_activeHandleIndex == i)
                {
                    Renderer.DrawFilledRectangle(handleBounds, new GorgonColor(GorgonColor.RedPure, 0.7f));
                }

                Renderer.DrawRectangle(handleBounds, GorgonColor.Black);
                var inner = new DX.RectangleF(handleBounds.Left + 1, handleBounds.Top + 1, handleBounds.Width - 2, handleBounds.Height - 2);
                Renderer.DrawRectangle(inner, GorgonColor.White);

                if ((i < 4) && (_selected[i]))
                {
                    inner = new DX.RectangleF(handleBounds.Left - 4, handleBounds.Top - 4, handleBounds.Width + 8, handleBounds.Height + 8);
                    Renderer.DrawEllipse(inner, GorgonColor.Black);
                    inner.Inflate(-1, -1);
                    Renderer.DrawEllipse(inner, GorgonColor.White);
                }
            }

            Renderer.End();

            return(1);
        }
Пример #3
0
        /// <summary>
        /// Function to initialize the effects and the effect compositor.
        /// </summary>
        private static void InitializeEffects()
        {
            // The blur effect.
            _blurEffect = new Gorgon2DGaussBlurEffect(_renderer)
            {
                PreserveAlpha = true
            };
            _blurEffect.Precache();

            // The grayscale effect.
            _grayScaleEffect = new Gorgon2DGrayScaleEffect(_renderer);

            // The posterize effect.
            _posterizeEffect = new Gorgon2DPosterizedEffect(_renderer)
            {
                Bits = 10
            };

            // The 1 bit effect.
            _1BitEffect = new Gorgon2D1BitEffect(_renderer)
            {
                Threshold           = new GorgonRangeF(0.5f, 1.0f),
                ConvertAlphaChannel = false
            };

            // The burn effect.
            _burnEffect = new Gorgon2DBurnDodgeEffect(_renderer)
            {
                UseDodge = false
            };

            // The dodge effect.
            _dodgeEffect = new Gorgon2DBurnDodgeEffect(_renderer)
            {
                UseDodge = true
            };

            // The invert effect.
            _invertEffect = new Gorgon2DInvertEffect(_renderer);

            // The sharpen effect.
            _sharpenEffect = new Gorgon2DSharpenEmbossEffect(_renderer)
            {
                UseEmbossing = false,
                Amount       = 1.0f
            };
            // The emboss effect.
            _embossEffect = new Gorgon2DSharpenEmbossEffect(_renderer)
            {
                UseEmbossing = true,
                Amount       = 1.0f
            };

            // The sobel edge detection effect.
            _sobelEffect = new Gorgon2DSobelEdgeDetectEffect(_renderer)
            {
                LineThickness = 2.5f,
                EdgeThreshold = 0.80f
            };

            // An old film effect.
            _oldFilmEffect = new Gorgon2DOldFilmEffect(_renderer)
            {
                ScrollSpeed = 0.05f
            };
            // A HDR bloom effect.
            _bloomEffect = new Gorgon2DBloomEffect(_renderer)
            {
                Threshold      = 1.11f,
                BloomIntensity = 35.0f,
                BlurAmount     = 6.0f,
                ColorIntensity = 1.15f
            };
            // A chromatic aberration effect.
            _chromatic = new Gorgon2DChromaticAberrationEffect(_renderer)
            {
                Intensity = 0.25f
            };

            _compositor = new Gorgon2DCompositor(_renderer);
            // Set up each pass for the compositor.
            // As you can see, we're not strictly limited to using our 2D effect objects, we can define custom passes as well.
            // And, we can also define how existing effects are rendered for things like animation and such.
            _compositor.EffectPass("Chromatic Aberration", _chromatic)
            .EffectPass("1-Bit Color", _1BitEffect)
            .EffectPass("Blur", _blurEffect)
            .EffectPass("Grayscale", _grayScaleEffect)
            .EffectPass("Posterize", _posterizeEffect)
            .EffectPass("Burn", _burnEffect)
            .EffectPass("Dodge", _dodgeEffect)
            .EffectPass("Invert", _invertEffect)
            .EffectPass("Sharpen", _sharpenEffect)
            .EffectPass("Emboss", _embossEffect)
            .EffectPass("Bloom", _bloomEffect)
            .Pass(new Gorgon2DCompositionPass("Sobel Edge Detection", _sobelEffect)
            {
                BlendOverride = GorgonBlendState.Default,
                ClearColor    = GorgonColor.White
            })
            .RenderPass("Sobel Blend Pass",
                        (sobelTexture, pass, passCount, size) =>
            {
                // This is a custom pass that does nothing but rendering.  No effect is applied here, just straight rendering to
                // the currently active render target.
                var rectPosition = new DX.RectangleF(0, 0, size.Width, size.Height);
                var texCoords    = new DX.RectangleF(0, 0, 1, 1);
                _renderer.DrawFilledRectangle(rectPosition, GorgonColor.White, _images[_currentImage], texCoords);
                _renderer.DrawFilledRectangle(rectPosition, GorgonColor.White, sobelTexture, texCoords);
            })
            .Pass(new Gorgon2DCompositionPass("Olde Film", _oldFilmEffect)
            {
                BlendOverride = GorgonBlendState.Additive,
                RenderMethod  = (prevEffect, passIndex, passCount, size) =>
                {
                    // Here we can override the method used to render to the effect.
                    // In this case, we're animating our old film content to shake and darken at defined intervals.
                    // If we do not override this, the compositor would just blit the previous texture to the
                    // current render target.
                    var rectPosition  = new DX.RectangleF(0, 0, size.Width, size.Height);
                    var texCoords     = new DX.RectangleF(0, 0, 1, 1);
                    GorgonColor color = GorgonColor.White;

                    if ((GorgonTiming.SecondsSinceStart % 10) >= 4)
                    {
                        rectPosition.Inflate(GorgonRandom.RandomSingle(1, 5), GorgonRandom.RandomSingle(1, 5));
                        float value = GorgonRandom.RandomSingle(0.5f, 0.89f);
                        color       = new GorgonColor(value, value, value, 1.0f);
                    }

                    _renderer.DrawFilledRectangle(rectPosition, color, prevEffect, texCoords);
                }
            })
            .InitialClearColor(GorgonColor.White)
            .FinalClearColor(GorgonColor.White);

            _compositor.Passes["Chromatic Aberration"].Enabled = false;
            _compositor.Passes["Bloom"].Enabled       = false;
            _compositor.Passes["Posterize"].Enabled   = false;
            _compositor.Passes["Grayscale"].Enabled   = false;
            _compositor.Passes["1-Bit Color"].Enabled = false;
            _compositor.Passes["Emboss"].Enabled      = false;
            _compositor.Passes["Dodge"].Enabled       = false;
            _compositor.Passes["Olde Film"].Enabled   = false;
        }