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); }
public override void UpdateParameters(ColorTransformContext context) { base.UpdateParameters(context); // 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) { // Adapt the luminance using Pattanaik's technique var currentAvgLuminance = (float)Math.Max(luminanceResult.AverageLuminance, 0.0001); weightedLuminances[currentWeightedLuminanceIndex] = currentAvgLuminance; currentWeightedLuminanceIndex = (currentWeightedLuminanceIndex + 1) % weightedLuminances.Length; float avgLuminannce = 0.0f; for (int i = 0; i < weightedLuminances.Length; i++) { avgLuminannce += weightedLuminances[i]; } avgLuminannce /= weightedLuminances.Length; // Get current avg luminance // Get adapted luminance var adaptedLum = (float)(previousLuminance + (avgLuminannce - previousLuminance) * (1.0 - Math.Exp(-elapsedTime.TotalSeconds * AdaptationRate))); avgLuminanceLog = (float)Math.Log(adaptedLum, 2); previousLuminance = adaptedLum; //Trace.WriteLine(string.Format("Adapted: {0} Luminance: {1}", adaptedLum, currentAvgLuminance)); if (AutoKeyValue) { 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 var currentOperator = Operator ?? defaultOperator; currentOperator.UpdateParameters(context); // Copy sub parameters from composition to this transform foreach (var parameterValue in currentOperator.Parameters) { var key = parameterValue.Key.ComposeWith("ToneMapOperator"); currentOperator.Parameters.CopySharedTo(parameterValue.Key, key, Parameters); } }
/// <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); }
/// <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 ColorTransform</remarks> public virtual void UpdateParameters(ColorTransformContext context) { }