Example #1
0
        public override void UpdateParameters(ColorTransformContext context)
        {
            // TODO This could be put as part

            double b = BlackPoint;
            double c = CrossOver;
            double w = WhitePoint;
            double t = Toe;
            double s = Shoulder;

            double k = ((1 - t) * (c - b)) / ((1 - s) * (w - c) + (1 - t) * (c - b));

            var toe = new Vector4(
                (float)((k * (1 - t))),
                (float)(-t),
                (float)(k * (1 - t) * (-b)),
                (float)(c - (1 - t) * b));

            var shoulder = new Vector4(
                (float)(((1 - k) + k * s)),
                (float)(s),
                (float)((1 - k) * (-c) + k * ((1 - s) * w - c)),
                (float)((1 - s) * w - c));

            // Don't call base, as we are rewriting all parameters for the shader
            Parameters.Set(ToneMapMikeDayOperatorShaderKeys.ToeCoeffs, toe);
            Parameters.Set(ToneMapMikeDayOperatorShaderKeys.ShoulderCoeffs, shoulder);
            Parameters.Set(ToneMapMikeDayOperatorShaderKeys.MiddleCrossOver, CrossOver);
        }
Example #2
0
        public override void UpdateParameters(ColorTransformContext context)
        {
            // TODO This could be put as part 

            double b = BlackPoint;
            double c = CrossOver;
            double w = WhitePoint;
            double t = Toe;
            double s = Shoulder;

            double k = ((1 - t) * (c - b)) / ((1 - s) * (w - c) + (1 - t) * (c - b));

            var toe = new Vector4(
                (float)((k * (1 - t))),
                (float)(-t),
                (float)(k * (1 - t) * (-b)),
                (float)(c - (1 - t) * b));

            var shoulder = new Vector4(
                (float)(((1 - k) + k * s)),
                (float)(s),
                (float)((1 - k) * (-c) + k * ((1 - s) * w - c)),
                (float)((1 - s) * w - c));

            // Don't call base, as we are rewriting all parameters for the shader
            Parameters.Set(ToneMapMikeDayOperatorShaderKeys.ToeCoeffs, toe);
            Parameters.Set(ToneMapMikeDayOperatorShaderKeys.ShoulderCoeffs, shoulder);
            Parameters.Set(ToneMapMikeDayOperatorShaderKeys.MiddleCrossOver, CrossOver);
        }
Example #3
0
        public override void UpdateParameters(ColorTransformContext context)
        {
            base.UpdateParameters(context);

            Parameters.Set(VignettingShaderKeys.Amount, Amount);
            Parameters.Set(VignettingShaderKeys.RadiusBegin, Radius);
            Parameters.Set(VignettingShaderKeys.Color, Color.ToColorSpace(context.RenderContext.GraphicsDevice.ColorSpace));
        }
Example #4
0
        public override void UpdateParameters(ColorTransformContext context)
        {
            base.UpdateParameters(context);

            Parameters.Set(VignettingShaderKeys.Amount, Amount);
            Parameters.Set(VignettingShaderKeys.RadiusBegin, Radius);
            Parameters.Set(VignettingShaderKeys.Color, Color.ToColorSpace(context.RenderContext.GraphicsDevice.ColorSpace));
        }
Example #5
0
        public override void UpdateParameters(ColorTransformContext context)
        {
            base.UpdateParameters(context);

            Parameters.Set(VignettingShaderKeys.Amount, Amount);
            Parameters.Set(VignettingShaderKeys.RadiusBegin, Radius);
            Parameters.Set(VignettingShaderKeys.Color, Color);
        }
Example #6
0
        public override void UpdateParameters(ColorTransformContext context)
        {
            base.UpdateParameters(context);

            Parameters.Set(VignettingShaderKeys.Amount, Amount);
            Parameters.Set(VignettingShaderKeys.RadiusBegin, Radius);
            Parameters.Set(VignettingShaderKeys.Color, Color);
        }
Example #7
0
        public override void UpdateParameters(ColorTransformContext context)
        {
            base.UpdateParameters(context);

            if (Operator == null)
            {
                throw new InvalidOperationException("Operator cannot be null on this instance");
            }

            // Update the luminance
            var elapsedTime = timer.Elapsed;

            timer.Restart();

            var luminanceResult = context.SharedParameters.Get(LuminanceEffect.LuminanceResult);

            // Get the average luminance
            float adaptedLum = luminanceResult.AverageLuminance;

            if (TemporalAdaptation)
            {
                // Get adapted luminance
                // From "Perceptual effects in real-time tone mapping" by Grzegorz Krawczyk, Karol Myszkowski, Hans-Peter Seidel, p. 3, Equation 5
                adaptedLum        = (float)(previousLuminance + (luminanceResult.AverageLuminance - previousLuminance) * (1.0 - Math.Exp(-elapsedTime.TotalSeconds * AdaptationRate)));
                previousLuminance = adaptedLum;
            }

            if (AutoKeyValue)
            {
                // From "Perceptual effects in real-time tone mapping" by Grzegorz Krawczyk, Karol Myszkowski, Hans-Peter Seidel, p. 4, Equation 11
                KeyValue = 1.03f - (2.0f / (2.0f + (float)Math.Log10(adaptedLum + 1)));
            }

            // Setup parameters
            Parameters.Set(ToneMapShaderKeys.LuminanceTexture, luminanceResult.LocalTexture);
            Parameters.Set(ToneMapShaderKeys.LuminanceAverageGlobal, (float)Math.Log(adaptedLum, 2));
            Parameters.Set(ToneMapShaderKeys.Exposure, (float)Math.Pow(2.0, Exposure));

            // Update operator parameters
            Operator.UpdateParameters(context);

            // Copy sub parameters from composition to this transform
            foreach (var key in Operator.Parameters.Keys)
            {
                ParameterKey tonemapKey;
                if (!tonemapKeys.TryGetValue(key, out tonemapKey))
                {
                    tonemapKey = key.ComposeWith("ToneMapOperator");
                    tonemapKeys.Add(key, tonemapKey);
                }
                Operator.Parameters.CopySharedTo(key, tonemapKey, Parameters);
            }
        }
Example #8
0
        /// <inheritdoc/>
        protected override void InitializeCore()
        {
            base.InitializeCore();

            transformGroupEffect = new ImageEffectShader(colorTransformGroupEffectName);
            transformGroupEffect.SharedParameterCollections.Add(Parameters);
            transformGroupEffect.Initialize(Context);

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

            this.transformContext = new ColorTransformContext(this);
        }
Example #9
0
        public override void UpdateParameters(ColorTransformContext context)
        {
            base.UpdateParameters(context);

            Parameters.Set(FilmGrainShaderKeys.Amount, Amount * 4 * 0.02f);
            Parameters.Set(FilmGrainShaderKeys.GrainSize, GrainSize);
            Parameters.Set(FilmGrainShaderKeys.LuminanceFactor, LuminanceFactor);
            if (Animate)
            {
                time += 0.1f;
                if (time > 100f) time = 1f;
            }
            Parameters.Set(FilmGrainShaderKeys.Time, time);
        }
Example #10
0
        public override void UpdateParameters(ColorTransformContext context)
        {
            base.UpdateParameters(context);

            Parameters.Set(FilmGrainShaderKeys.Amount, Amount * 4 * 0.02f);
            Parameters.Set(FilmGrainShaderKeys.GrainSize, GrainSize);
            Parameters.Set(FilmGrainShaderKeys.LuminanceFactor, LuminanceFactor);
            if (Animate)
            {
                time += 0.1f;
                if (time > 100f)
                {
                    time = 1f;
                }
            }
            Parameters.Set(FilmGrainShaderKeys.Time, time);
        }
Example #11
0
        public override void UpdateParameters(ColorTransformContext context)
        {
            base.UpdateParameters(context);

            if (Operator == null)
            {
                throw new InvalidOperationException("Operator cannot be null on this instance");
            }

            // Update the luminance
            var elapsedTime = timer.Elapsed;
            timer.Restart();

            var luminanceResult = context.SharedParameters.Get(LuminanceEffect.LuminanceResult);

            var avgLuminanceLog = 0.18f; // TODO: Add a parmetrized average luminance
            if (luminanceResult.LocalTexture != null)
            {
                // Get adapted luminance
                // From "Perceptual effects in real-time tone mapping" by Grzegorz Krawczyk, Karol Myszkowski, Hans-Peter Seidel, p. 3, Equation 5
                var adaptedLum = (float)(previousLuminance + (luminanceResult.AverageLuminance - previousLuminance) * (1.0 - Math.Exp(-elapsedTime.TotalSeconds * AdaptationRate)));
                avgLuminanceLog = (float)Math.Log(adaptedLum, 2);
                previousLuminance = adaptedLum;

                if (AutoKeyValue)
                {
                    // From "Perceptual effects in real-time tone mapping" by Grzegorz Krawczyk, Karol Myszkowski, Hans-Peter Seidel, p. 4, Equation 11
                    KeyValue = 1.03f - (2.0f / (2.0f + (float)Math.Log10(adaptedLum + 1)));
                }
            }

            // Setup parameters
            Parameters.Set(ToneMapShaderKeys.LuminanceTexture, luminanceResult.LocalTexture);
            Parameters.Set(ToneMapShaderKeys.LuminanceAverageGlobal, avgLuminanceLog);

            // Update operator parameters
            Operator.UpdateParameters(context);

            // Copy sub parameters from composition to this transform
            foreach (var key in Operator.Parameters.Keys)
            {
                ParameterKey tonemapKey;
                if (!tonemapKeys.TryGetValue(key, out tonemapKey))
                {
                    tonemapKey = key.ComposeWith("ToneMapOperator");
                    tonemapKeys.Add(key, tonemapKey);
                }
                Operator.Parameters.CopySharedTo(key, tonemapKey, Parameters);
            }
        }
Example #12
0
 /// <summary>
 /// Updates the parameters for this transformation.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <remarks>This method is called just before rendering the ColorTransformGroup that is holding this ColorTransformBase</remarks>
 public virtual void UpdateParameters(ColorTransformContext context)
 {
 }
Example #13
0
 /// <summary>
 /// Updates the parameters for this transformation.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <remarks>This method is called just before rendering the ColorTransformGroup that is holding this ColorTransformBase</remarks>
 public virtual void UpdateParameters(ColorTransformContext context)
 {
 }