Skip to content

Commit

Permalink
Resolving duplication issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ben_singer committed Nov 11, 2024
1 parent d0c88c1 commit 83cb000
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 112 deletions.
28 changes: 26 additions & 2 deletions LoFiEffects.WPF/Effects/NegativeEffect.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
using System.Windows.Media.Effects;
using System.Windows.Media;
using System.Windows;
using System.Windows.Media.Effects;

namespace LoFiEffects.WPF.Effects
{
/// <summary>
/// Represents a negative shader effect.
/// </summary>
public class NegativeEffect : SpecklingEffect
public class NegativeEffect : ShaderEffect
{
#region StaticFields

private static readonly PixelShader pixelShader = new() { UriSource = UriHelper.FromResource(@"Effects/Shaders/Negative.ps") };

#endregion

#region Properties

/// <summary>
/// Get or set the input. This is a dependency property.
/// </summary>
public Brush Input
{
get { return (Brush)GetValue(InputProperty); }
set { SetValue(InputProperty, value); }
}

#endregion

#region DependencyProperties

/// <summary>
/// Identifies the NegativeEffect.Input property.
/// </summary>
public static readonly DependencyProperty InputProperty = RegisterPixelShaderSamplerProperty("Input", typeof(NegativeEffect), 0);

#endregion

#region Constructors

/// <summary>
Expand Down
112 changes: 2 additions & 110 deletions LoFiEffects.WPF/Effects/NoiseEffect.cs
Original file line number Diff line number Diff line change
@@ -1,112 +1,18 @@
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Media.Effects;

namespace LoFiEffects.WPF.Effects
{
/// <summary>
/// Represents a noise shader effect.
/// </summary>
public class NoiseEffect : ShaderEffect
public class NoiseEffect : SpecklingEffect
{
#region StaticFields

private static readonly PixelShader pixelShader = new() { UriSource = UriHelper.FromResource(@"Effects/Shaders/Noise.ps") };

#endregion

#region Properties

/// <summary>
/// Get or set the input. This is a dependency property.
/// </summary>
public Brush Input
{
get { return (Brush)GetValue(InputProperty); }
set { SetValue(InputProperty, value); }
}

/// <summary>
/// Get or set the density. Higher values will produce more speckling. This is a dependency property.
/// </summary>
public double Density
{
get { return (double)GetValue(DensityProperty); }
set { SetValue(DensityProperty, value); }
}

/// <summary>
/// Get or set the intensity. Higher values will produce more intense speckling. This is a dependency property.
/// </summary>
public double Intensity
{
get { return (double)GetValue(IntensityProperty); }
set { SetValue(IntensityProperty, value); }
}

/// <summary>
/// Get or set the offset. This value can modified to produce different speckling patterns. This is a dependency property.
/// </summary>
public double Offset
{
get { return (double)GetValue(OffsetProperty); }
set { SetValue(OffsetProperty, value); }
}

/// <summary>
/// Get or set if the effect should be rendered over transparency. This is a dependency property.
/// </summary>
public bool RenderOverTransparent
{
get { return (bool)GetValue(RenderOverTransparentProperty); }
set { SetValue(RenderOverTransparentProperty, value); }
}

/// <summary>
/// Get or set if the effect should be rendered over transparency. This is a dependency property.
/// </summary>
protected double RenderOverTransparentDouble
{
get { return (double)GetValue(RenderOverTransparentDoubleProperty); }
set { SetValue(RenderOverTransparentDoubleProperty, value); }
}

#endregion

#region DependencyProperties

/// <summary>
/// Identifies the NoiseEffect.Input property.
/// </summary>
public static readonly DependencyProperty InputProperty = RegisterPixelShaderSamplerProperty("Input", typeof(NoiseEffect), 0);

/// <summary>
/// Identifies the NoiseEffect.Density property.
/// </summary>
public static readonly DependencyProperty DensityProperty = DependencyProperty.Register("Density", typeof(double), typeof(NoiseEffect), new UIPropertyMetadata(0.3, PixelShaderConstantCallback(0)));

/// <summary>
/// Identifies the NoiseEffect.Intensity property.
/// </summary>
public static readonly DependencyProperty IntensityProperty = DependencyProperty.Register("Intensity", typeof(double), typeof(NoiseEffect), new UIPropertyMetadata(0.8, PixelShaderConstantCallback(1)));

/// <summary>
/// Identifies the NoiseEffect.Offset property.
/// </summary>
public static readonly DependencyProperty OffsetProperty = DependencyProperty.Register("Offset", typeof(double), typeof(NoiseEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(2)));

/// <summary>
/// Identifies the NoiseEffect.RenderOverTransparent property.
/// </summary>
public static readonly DependencyProperty RenderOverTransparentProperty = DependencyProperty.Register("RenderOverTransparent", typeof(bool), typeof(NoiseEffect), new PropertyMetadata(false, new PropertyChangedCallback(OnRenderOverTransparentPropertyChanged)));

/// <summary>
/// Identifies the NoiseEffect.RenderOverTransparentDouble property.
/// </summary>
public static readonly DependencyProperty RenderOverTransparentDoubleProperty = DependencyProperty.Register("RenderOverTransparentDouble", typeof(double), typeof(NoiseEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(3)));

#endregion

#region Constructors

/// <summary>
Expand All @@ -124,19 +30,5 @@ public NoiseEffect()
}

#endregion

#region StaticMethods

private static void OnRenderOverTransparentPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
var noise = obj as NoiseEffect;

if (noise == null)
return;

noise.RenderOverTransparentDouble = (bool)args.NewValue ? 1.0 : 0.0;
}

#endregion
}
}

0 comments on commit 83cb000

Please sign in to comment.