Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LuminanceEffect" /> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="luminanceFormat">The luminance format.</param>
        /// <param name="luminanceLogEffect">The luminance log effect.</param>
        /// <exception cref="System.ArgumentNullException">lunkinanceLogShader</exception>
        public LuminanceEffect(ImageEffectContext context, PixelFormat luminanceFormat = PixelFormat.R16_Float, ImageEffectShader luminanceLogEffect = null) : base(context)
        {
            // Check luminance format
            if (luminanceFormat.IsCompressed() || luminanceFormat.IsPacked() || luminanceFormat.IsTypeless() || luminanceFormat == PixelFormat.None)
            {
                throw new ArgumentOutOfRangeException("luminanceFormat", "Unsupported format [{0}] (must be not none, compressed, packed or typeless)".ToFormat(luminanceFormat));
            }
            this.luminanceFormat = luminanceFormat;

            // Use or create a default luminance log effect
            this.luminanceLogEffect = luminanceLogEffect ?? new LuminanceLogEffect(context).DisposeBy(this);

            // Create 1x1 texture
            luminance1x1 = Texture.New2D(GraphicsDevice, 1, 1, 1, luminanceFormat, TextureFlags.ShaderResource | TextureFlags.RenderTarget).DisposeBy(this);

            // Use a multiscaler
            multiScaler = new ImageMultiScaler(context).DisposeBy(this);

            // Readback is always going to be done on the 1x1 texture
            readback = new ImageReadback <Half>(context).DisposeBy(this);
            readback.SetInput(luminance1x1);

            // Blur used before upscaling
            blur        = new GaussianBlur(context).DisposeBy(this);
            blur.Radius = 4;

            DownscaleCount = 6;
            UpscaleCount   = 4;

            EnableAverageLuminanceReadback = true;
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GaussianBlur"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        public GaussianBlur(ImageEffectContext context)
            : base(context)
        {
            // Use shared SharedParameters for blurH and blurV
            blurH = new ImageEffectShader(context, "GaussianBlurEffect", Parameters).DisposeBy(this);
            // Setup specific Horizontal parameter for blurH
            blurH.Parameters.Set(GaussianBlurKeys.VerticalBlur, false);

            blurV = new ImageEffectShader(context, "GaussianBlurEffect", Parameters).DisposeBy(this);
            // Setup specific Vertical parameter for blurV
            blurV.Parameters.Set(GaussianBlurKeys.VerticalBlur, true);

            Radius     = 4;
            SigmaRatio = 2.0f;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ColorTransformGroup"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="colorTransformGroupEffect">The color transform group effect.</param>
        public ColorTransformGroup(ImageEffectContext context, string colorTransformGroupEffect = "ColorTransformGroupEffect")
            : base(context, colorTransformGroupEffect)
        {
            compositeKeys     = new Dictionary <ParameterCompositeKey, ParameterKey>();
            transforms        = new ColorTransformCollection();
            enabledTransforms = new List <ColorTransform>();
            collectTransforms = new List <ColorTransform>();

            transformsParameters = new ParameterCollection();

            gammaTransform = new GammaTransform();

            transformGroupEffect = new ImageEffectShader(context, colorTransformGroupEffect, Parameters);

            // we are adding parameter collections after as transform parameters should override previous parameters
            transformGroupEffect.ParameterCollections.Add(transformsParameters);

            this.context = new ColorTransformContext(this);
        }