This is a library of blend modes that can be used with WPF 4.0 (and forward).
4 | 5 |I recently went through and compiled all the HLSL effect (.fx) files into pixel shader (.ps) files. This means that the library is now really a standalone library that you can just easily use in your WPF projects. I don't know why I haven't done this before!
6 | 7 |I have a series of blog posts that describe these blend mode effects ... and which also details the journey in creating the library itself.
8 | 9 |If you happen to use my library, I would love to hear about it. It was a labor of love!
10 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/AverageEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class AverageEffect : BlendModeEffect 9 | { 10 | static AverageEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/AverageEffect.ps"); 13 | } 14 | 15 | public AverageEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/BlendModeEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class BlendModeEffect : ShaderEffect 9 | { 10 | public BlendModeEffect() 11 | { 12 | UpdateShaderValue(AInputProperty); 13 | UpdateShaderValue(BInputProperty); 14 | } 15 | 16 | [System.ComponentModel.BrowsableAttribute(false)] 17 | public Brush AInput 18 | { 19 | get { return (Brush)GetValue(AInputProperty); } 20 | set { SetValue(AInputProperty, value); } 21 | } 22 | public static readonly DependencyProperty AInputProperty = 23 | ShaderEffect.RegisterPixelShaderSamplerProperty 24 | ( 25 | "AInput", 26 | typeof(BlendModeEffect), 27 | 0 28 | ); 29 | 30 | public Brush BInput 31 | { 32 | get { return (Brush)GetValue(BInputProperty); } 33 | set { SetValue(BInputProperty, value); } 34 | } 35 | public static readonly DependencyProperty BInputProperty = 36 | ShaderEffect.RegisterPixelShaderSamplerProperty 37 | ( 38 | "BInput", 39 | typeof(BlendModeEffect), 40 | 1 41 | ); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/ColorBurnEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class ColorBurnEffect : BlendModeEffect 9 | { 10 | static ColorBurnEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/ColorBurnEffect.ps"); 13 | } 14 | 15 | public ColorBurnEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/ColorDodgeEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class ColorDodgeEffect : BlendModeEffect 9 | { 10 | static ColorDodgeEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/ColorDodgeEffect.ps"); 13 | } 14 | 15 | public ColorDodgeEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/ColorEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class ColorEffect : BlendModeEffect 9 | { 10 | static ColorEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/ColorEffect.ps"); 13 | } 14 | 15 | public ColorEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/DarkenEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class DarkenEffect : BlendModeEffect 9 | { 10 | static DarkenEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/DarkenEffect.ps"); 13 | } 14 | 15 | public DarkenEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/DifferenceEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class DifferenceEffect : BlendModeEffect 9 | { 10 | static DifferenceEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/DifferenceEffect.ps"); 13 | } 14 | 15 | public DifferenceEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/ExclusionEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class ExclusionEffect : BlendModeEffect 9 | { 10 | static ExclusionEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/ExclusionEffect.ps"); 13 | } 14 | 15 | public ExclusionEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/GlowEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class GlowEffect : BlendModeEffect 9 | { 10 | static GlowEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/GlowEffect.ps"); 13 | } 14 | 15 | public GlowEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/HardLightEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class HardLightEffect : BlendModeEffect 9 | { 10 | static HardLightEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/HardLightEffect.ps"); 13 | } 14 | 15 | public HardLightEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/HardMixEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class HardMixEffect : BlendModeEffect 9 | { 10 | static HardMixEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/HardMixEffect.ps"); 13 | } 14 | 15 | public HardMixEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/HueEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class HueEffect : BlendModeEffect 9 | { 10 | static HueEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/HueEffect.ps"); 13 | } 14 | 15 | public HueEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/LightenEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class LightenEffect : BlendModeEffect 9 | { 10 | static LightenEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/LightenEffect.ps"); 13 | } 14 | 15 | public LightenEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/LinearBurnEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class LinearBurnEffect : BlendModeEffect 9 | { 10 | static LinearBurnEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/LinearBurnEffect.ps"); 13 | } 14 | 15 | public LinearBurnEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/LinearDodgeEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class LinearDodgeEffect : BlendModeEffect 9 | { 10 | static LinearDodgeEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/LinearDodgeEffect.ps"); 13 | } 14 | 15 | public LinearDodgeEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/LinearLightEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class LinearLightEffect : BlendModeEffect 9 | { 10 | static LinearLightEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/LinearLightEffect.ps"); 13 | } 14 | 15 | public LinearLightEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/LuminosityEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class LuminosityEffect : BlendModeEffect 9 | { 10 | static LuminosityEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/LuminosityEffect.ps"); 13 | } 14 | 15 | public LuminosityEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/MultiplyEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class MultiplyEffect : BlendModeEffect 9 | { 10 | static MultiplyEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/MultiplyEffect.ps"); 13 | } 14 | 15 | public MultiplyEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/NegationEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class NegationEffect : BlendModeEffect 9 | { 10 | static NegationEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/NegationEffect.ps"); 13 | } 14 | 15 | public NegationEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/NormalEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class NormalEffect : BlendModeEffect 9 | { 10 | static NormalEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/NormalEffect.ps"); 13 | } 14 | 15 | public NormalEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/OverlayEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class OverlayEffect : BlendModeEffect 9 | { 10 | static OverlayEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/OverlayEffect.ps"); 13 | } 14 | 15 | public OverlayEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/PhoenixEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class PhoenixEffect : BlendModeEffect 9 | { 10 | static PhoenixEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/PhoenixEffect.ps"); 13 | } 14 | 15 | public PhoenixEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/PinLightEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class PinLightEffect : BlendModeEffect 9 | { 10 | static PinLightEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/PinLightEffect.ps"); 13 | } 14 | 15 | public PinLightEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/ReflectEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class ReflectEffect : BlendModeEffect 9 | { 10 | static ReflectEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/ReflectEffect.ps"); 13 | } 14 | 15 | public ReflectEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/SaturationEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class SaturationEffect : BlendModeEffect 9 | { 10 | static SaturationEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/SaturationEffect.ps"); 13 | } 14 | 15 | public SaturationEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/ScreenEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class ScreenEffect : BlendModeEffect 9 | { 10 | static ScreenEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/ScreenEffect.ps"); 13 | } 14 | 15 | public ScreenEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/SoftLightEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class SoftLightEffect : BlendModeEffect 9 | { 10 | static SoftLightEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/SoftLightEffect.ps"); 13 | } 14 | 15 | public SoftLightEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectFiles/VividLightEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Effects; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | public class VividLightEffect : BlendModeEffect 9 | { 10 | static VividLightEffect() 11 | { 12 | _pixelShader.UriSource = Global.MakePackUri("ShaderSource/VividLightEffect.ps"); 13 | } 14 | 15 | public VividLightEffect() 16 | { 17 | this.PixelShader = _pixelShader; 18 | } 19 | 20 | private static PixelShader _pixelShader = new PixelShader(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/EffectLibrary.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Reflection; 4 | using System.Text; 5 | 6 | namespace BlendModeEffectLibrary 7 | { 8 | internal static class Global 9 | { 10 | public static Uri MakePackUri(string relativeFile) 11 | { 12 | StringBuilder uriString = new StringBuilder(); 13 | #if !SILVERLIGHT 14 | uriString.Append("pack://application:,,,"); 15 | #endif 16 | uriString.Append("/" + AssemblyShortName + ";component/" + relativeFile); 17 | return new Uri(uriString.ToString(), UriKind.RelativeOrAbsolute); 18 | } 19 | 20 | private static string AssemblyShortName 21 | { 22 | get 23 | { 24 | if (_assemblyShortName == null) 25 | { 26 | Assembly a = typeof(Global).Assembly; 27 | 28 | // Pull out the short name. 29 | _assemblyShortName = a.ToString().Split(',')[0]; 30 | } 31 | 32 | return _assemblyShortName; 33 | } 34 | } 35 | 36 | private static string _assemblyShortName; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("MyEffects")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("MyEffects")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2009")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("8aee1ced-bda5-4012-a753-65ecf4fbbd63")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/AverageEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- AverageEffect 4 | // 5 | //-------------------------------------------------------------------------------------- 6 | 7 | sampler2D input : register(s0); 8 | sampler2D blend : register(s1); 9 | 10 | float4 main(float2 uv : TEXCOORD) : COLOR 11 | { 12 | float4 inputColor; 13 | inputColor = tex2D(input, uv); 14 | 15 | float4 blendColor; 16 | blendColor = tex2D(blend, uv); 17 | 18 | 19 | float4 resultColor; 20 | resultColor.a = inputColor.a; 21 | 22 | // un-premultiply the blendColor alpha out from blendColor 23 | blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 24 | 25 | 26 | // apply the blend mode math 27 | resultColor.rgb = (inputColor.rgb + blendColor.rgb) / 2; 28 | 29 | 30 | // re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a 31 | resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a; 32 | 33 | return resultColor; 34 | } 35 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/AverageEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/AverageEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/ColorBurnEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- ColorBurnEffect 4 | // 5 | //-------------------------------------------------------------------------------------- 6 | 7 | sampler2D input : register(s0); 8 | sampler2D blend : register(s1); 9 | 10 | //-------------------------------------------------------------------------------------- 11 | // Pixel Shader 12 | //-------------------------------------------------------------------------------------- 13 | 14 | float4 main(float2 uv : TEXCOORD) : COLOR 15 | { 16 | float4 inputColor; 17 | inputColor = tex2D(input, uv); 18 | 19 | float4 blendColor; 20 | blendColor = tex2D(blend, uv); 21 | 22 | 23 | float4 resultColor; 24 | resultColor.a = inputColor.a; 25 | 26 | // un-premultiply the blendColor alpha out from blendColor 27 | blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 28 | 29 | 30 | // apply the blend mode math 31 | // R = 1 - (1-Base) / Blend 32 | resultColor.rgb = clamp(1 - (1 - inputColor.rgb) / blendColor.rgb, 0, 1); 33 | 34 | 35 | // re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a 36 | resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a; 37 | 38 | return resultColor; 39 | } 40 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/ColorBurnEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/ColorBurnEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/ColorDodgeEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- ColorDodgeEffect 4 | // 5 | //-------------------------------------------------------------------------------------- 6 | 7 | #define BlendColorDodgef(base, blend) ((blend == 1.0) ? blend : min(base / (1.0 - blend), 1.0)) 8 | 9 | sampler2D input : register(s0); 10 | sampler2D blend : register(s1); 11 | 12 | //-------------------------------------------------------------------------------------- 13 | // Pixel Shader 14 | //-------------------------------------------------------------------------------------- 15 | 16 | float4 main(float2 uv : TEXCOORD) : COLOR 17 | { 18 | float4 inputColor; 19 | inputColor = tex2D(input, uv); 20 | 21 | float4 blendColor; 22 | blendColor = tex2D(blend, uv); 23 | 24 | 25 | float4 resultColor; 26 | resultColor.a = inputColor.a; 27 | 28 | // un-premultiply the blendColor alpha out from blendColor 29 | blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 30 | 31 | 32 | // apply the blend mode math 33 | // R = Base / (1-Blend) 34 | resultColor.r = BlendColorDodgef(inputColor.r, blendColor.r); 35 | resultColor.g = BlendColorDodgef(inputColor.g, blendColor.g); 36 | resultColor.b = BlendColorDodgef(inputColor.b, blendColor.b); 37 | 38 | 39 | // re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a 40 | resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a; 41 | 42 | return resultColor; 43 | } 44 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/ColorDodgeEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/ColorDodgeEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/ColorEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- ColorEffect 4 | // 5 | // Color blend mode keeps the brightness of the base color and applies both the hue and 6 | // saturation of the blend color. 7 | // 8 | //-------------------------------------------------------------------------------------- 9 | 10 | sampler2D input : register(s0); 11 | sampler2D blend : register(s1); 12 | 13 | //-------------------------------------------------------------------------------------- 14 | // Pixel Shader 15 | //-------------------------------------------------------------------------------------- 16 | 17 | float3 RGBToHSL(float3 color) 18 | { 19 | float3 hsl; 20 | 21 | float fmin = min(min(color.r, color.g), color.b); 22 | float fmax = max(max(color.r, color.g), color.b); 23 | float delta = fmax - fmin; 24 | float maxplusmin = fmax + fmin; 25 | 26 | // set luminance 27 | hsl.z = maxplusmin / 2.0; 28 | 29 | if (delta == 0.0) 30 | { 31 | // a gray color, set hue and satuation to 0 32 | hsl.x = 0.0; 33 | hsl.y = 0.0; 34 | } 35 | else 36 | { 37 | // not a gray color 38 | 39 | // set saturation 40 | if (hsl.z < 0.5) 41 | hsl.y = delta / (maxplusmin); 42 | else 43 | hsl.y = delta / (2.0 - maxplusmin); 44 | 45 | if (color.r == fmax) 46 | hsl.x = ((color.g - color.b) / delta); 47 | else if (color.g == fmax) 48 | hsl.x = 2.0 + ((color.b - color.r) / delta); 49 | else if (color.b == fmax) 50 | hsl.x = 4.0 + ((color.r - color.g) / delta); 51 | 52 | hsl.x = hsl.x / 6.0; 53 | 54 | if (hsl.x < 0.0) 55 | hsl.x += 1.0; 56 | } 57 | 58 | return hsl; 59 | } 60 | 61 | float HueToRGB(float temp1, float temp2, float temp3) 62 | { 63 | if (temp3 < 0.0) 64 | temp3 += 1.0; 65 | else if (temp3 > 1.0) 66 | temp3 -= 1.0; 67 | 68 | float rgbComponent; 69 | 70 | if ((6.0 * temp3) < 1.0) 71 | rgbComponent = temp1 + (temp2 - temp1) * 6.0 * temp3; 72 | else if ((2.0 * temp3) < 1.0) 73 | rgbComponent = temp2; 74 | else if ((3.0 * temp3) < 2.0) 75 | rgbComponent = temp1 + (temp2 - temp1) * ((2.0 / 3.0) - temp3) * 6.0; 76 | else 77 | rgbComponent = temp1; 78 | 79 | return rgbComponent; 80 | } 81 | 82 | float3 HSLToRGB(float3 hsl) 83 | { 84 | float3 rgb; 85 | 86 | if (hsl.y == 0.0) 87 | { 88 | rgb = float3(hsl.z, hsl.z, hsl.z); 89 | } 90 | else 91 | { 92 | float temp2; 93 | if (hsl.z < 0.5) 94 | temp2 = hsl.z * (1.0 + hsl.y); 95 | else 96 | temp2 = (hsl.y + hsl.z) - (hsl.y * hsl.z); 97 | 98 | float temp1 = 2.0 * hsl.z - temp2; 99 | 100 | rgb.r = HueToRGB(temp1, temp2, hsl.x + (1.0/3.0)); 101 | rgb.g = HueToRGB(temp1, temp2, hsl.x); 102 | rgb.b = HueToRGB(temp1, temp2, hsl.x - (1.0/3.0)); 103 | } 104 | 105 | return rgb; 106 | } 107 | 108 | float3 BlendColor(float3 base, float3 blend) 109 | { 110 | float3 blendHSL = RGBToHSL(blend); 111 | return HSLToRGB(float3(blendHSL.r, blendHSL.g, RGBToHSL(base).b)); 112 | } 113 | 114 | float4 main(float2 uv : TEXCOORD) : COLOR 115 | { 116 | float4 inputColor; 117 | inputColor = tex2D(input, uv); 118 | 119 | float4 blendColor; 120 | blendColor = tex2D(blend, uv); 121 | 122 | 123 | float4 resultColor; 124 | resultColor.a = inputColor.a; 125 | 126 | // un-premultiply the blendColor alpha out from blendColor 127 | blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 128 | 129 | 130 | // apply the blend mode math 131 | resultColor.rgb = BlendColor(inputColor.rgb, blendColor.rgb); 132 | 133 | 134 | // re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a 135 | resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a; 136 | 137 | return resultColor; 138 | } 139 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/ColorEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/ColorEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/DarkenEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- DarkenEffect 4 | // 5 | //-------------------------------------------------------------------------------------- 6 | 7 | sampler2D input : register(s0); 8 | sampler2D blend : register(s1); 9 | 10 | float4 main(float2 uv : TEXCOORD) : COLOR 11 | { 12 | float4 inputColor; 13 | inputColor = tex2D(input, uv); 14 | 15 | float4 blendColor; 16 | blendColor = tex2D(blend, uv); 17 | 18 | 19 | float4 resultColor; 20 | resultColor.a = inputColor.a; 21 | 22 | // un-premultiply the blendColor alpha out from blendColor 23 | blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 24 | 25 | 26 | // apply the blend mode math 27 | if (inputColor.r > blendColor.r) 28 | resultColor.r = blendColor.r; 29 | else 30 | resultColor.r = inputColor.r; 31 | 32 | if (inputColor.g > blendColor.g) 33 | resultColor.g = blendColor.g; 34 | else 35 | resultColor.g = inputColor.g; 36 | 37 | if (inputColor.b > blendColor.b) 38 | resultColor.b = blendColor.b; 39 | else 40 | resultColor.b = inputColor.b; 41 | 42 | 43 | // re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a 44 | resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a; 45 | 46 | return resultColor; 47 | } 48 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/DarkenEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/DarkenEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/DifferenceEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- DifferenceEffect 4 | // 5 | //-------------------------------------------------------------------------------------- 6 | 7 | sampler2D input : register(s0); 8 | sampler2D blend : register(s1); 9 | 10 | float4 main(float2 uv : TEXCOORD) : COLOR 11 | { 12 | float4 inputColor; 13 | inputColor = tex2D(input, uv); 14 | 15 | float4 blendColor; 16 | blendColor = tex2D(blend, uv); 17 | 18 | 19 | float4 resultColor; 20 | resultColor.a = inputColor.a; 21 | 22 | // un-premultiply the blendColor alpha out from blendColor 23 | blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 24 | 25 | 26 | // apply the blend mode math 27 | // R = | Base - Blend | 28 | resultColor.rgb = abs(inputColor.rgb - blendColor.rgb); 29 | 30 | 31 | // re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a 32 | resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a; 33 | 34 | return resultColor; 35 | } 36 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/DifferenceEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/DifferenceEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/ExclusionEffect.fx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/ExclusionEffect.fx -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/ExclusionEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/ExclusionEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/GlowEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- GlowEffect 4 | // 5 | //-------------------------------------------------------------------------------------- 6 | 7 | #define BlendReflectf(base, blend) ((blend == 1.0) ? blend : min(base * base / (1.0 - blend), 1.0)) 8 | 9 | sampler2D input : register(s0); 10 | sampler2D blend : register(s1); 11 | 12 | //-------------------------------------------------------------------------------------- 13 | // Pixel Shader 14 | //-------------------------------------------------------------------------------------- 15 | 16 | float4 main(float2 uv : TEXCOORD) : COLOR 17 | { 18 | float4 inputColor; 19 | inputColor = tex2D(input, uv); 20 | 21 | float4 blendColor; 22 | blendColor = tex2D(blend, uv); 23 | 24 | 25 | float4 resultColor; 26 | resultColor.a = inputColor.a; 27 | 28 | // un-premultiply the blendColor alpha out from blendColor 29 | blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 30 | 31 | 32 | // apply the blend mode math 33 | resultColor.r = BlendReflectf(blendColor.r, inputColor.r); 34 | resultColor.g = BlendReflectf(blendColor.g, inputColor.g); 35 | resultColor.b = BlendReflectf(blendColor.b, inputColor.b); 36 | 37 | 38 | // re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a 39 | resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a; 40 | 41 | return resultColor; 42 | } 43 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/GlowEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/GlowEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/HardLightEffect.fx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/HardLightEffect.fx -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/HardLightEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/HardLightEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/HardMixEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- HardMixEffect 4 | // 5 | //-------------------------------------------------------------------------------------- 6 | 7 | #define BlendColorDodgef(base, blend) ((blend == 1.0) ? blend : min(base / (1.0 - blend), 1.0)) 8 | #define BlendColorBurnf(base, blend) ((blend == 0.0) ? blend : max((1.0 - ((1.0 - base) / blend)), 0.0)) 9 | #define BlendVividLightf(base, blend) ((blend < 0.5) ? BlendColorBurnf(base, (2.0 * blend)) : BlendColorDodgef(base, (2.0 * (blend - 0.5)))) 10 | #define BlendHardMixf(base, blend) ((BlendVividLightf(base, blend) < 0.5) ? 0.0 : 1.0) 11 | 12 | sampler2D input : register(s0); 13 | sampler2D blend : register(s1); 14 | 15 | //-------------------------------------------------------------------------------------- 16 | // Pixel Shader 17 | //-------------------------------------------------------------------------------------- 18 | 19 | float4 main(float2 uv : TEXCOORD) : COLOR 20 | { 21 | float4 inputColor; 22 | inputColor = tex2D(input, uv); 23 | 24 | float4 blendColor; 25 | blendColor = tex2D(blend, uv); 26 | 27 | 28 | float4 resultColor; 29 | resultColor.a = inputColor.a; 30 | 31 | // un-premultiply the blendColor alpha out from blendColor 32 | blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 33 | 34 | 35 | // apply the blend mode math 36 | resultColor.r = BlendHardMixf(inputColor.r, blendColor.r); 37 | resultColor.g = BlendHardMixf(inputColor.g, blendColor.g); 38 | resultColor.b = BlendHardMixf(inputColor.b, blendColor.b); 39 | 40 | 41 | // re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a 42 | resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a; 43 | 44 | return resultColor; 45 | } 46 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/HardMixEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/HardMixEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/HueEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- HueEffect 4 | // 5 | // Hue blend mode creates the result color by combining the luminance and saturation of 6 | // the base color with the hue of the blend color. 7 | // 8 | //-------------------------------------------------------------------------------------- 9 | 10 | sampler2D input : register(s0); 11 | sampler2D blend : register(s1); 12 | 13 | //-------------------------------------------------------------------------------------- 14 | // Pixel Shader 15 | //-------------------------------------------------------------------------------------- 16 | 17 | float3 RGBToHSL(float3 color) 18 | { 19 | float3 hsl; 20 | 21 | float fmin = min(min(color.r, color.g), color.b); 22 | float fmax = max(max(color.r, color.g), color.b); 23 | float delta = fmax - fmin; 24 | float maxplusmin = fmax + fmin; 25 | 26 | // set luminance 27 | hsl.z = maxplusmin / 2.0; 28 | 29 | if (delta == 0.0) 30 | { 31 | // a gray color, set hue and satuation to 0 32 | hsl.x = 0.0; 33 | hsl.y = 0.0; 34 | } 35 | else 36 | { 37 | // not a gray color 38 | 39 | // set saturation 40 | if (hsl.z < 0.5) 41 | hsl.y = delta / (maxplusmin); 42 | else 43 | hsl.y = delta / (2.0 - maxplusmin); 44 | 45 | if (color.r == fmax) 46 | hsl.x = ((color.g - color.b) / delta); 47 | else if (color.g == fmax) 48 | hsl.x = 2.0 + ((color.b - color.r) / delta); 49 | else if (color.b == fmax) 50 | hsl.x = 4.0 + ((color.r - color.g) / delta); 51 | 52 | hsl.x = hsl.x / 6.0; 53 | 54 | if (hsl.x < 0.0) 55 | hsl.x += 1.0; 56 | } 57 | 58 | return hsl; 59 | } 60 | 61 | float HueToRGB(float temp1, float temp2, float temp3) 62 | { 63 | if (temp3 < 0.0) 64 | temp3 += 1.0; 65 | else if (temp3 > 1.0) 66 | temp3 -= 1.0; 67 | 68 | float rgbComponent; 69 | 70 | if ((6.0 * temp3) < 1.0) 71 | rgbComponent = temp1 + (temp2 - temp1) * 6.0 * temp3; 72 | else if ((2.0 * temp3) < 1.0) 73 | rgbComponent = temp2; 74 | else if ((3.0 * temp3) < 2.0) 75 | rgbComponent = temp1 + (temp2 - temp1) * ((2.0 / 3.0) - temp3) * 6.0; 76 | else 77 | rgbComponent = temp1; 78 | 79 | return rgbComponent; 80 | } 81 | 82 | float3 HSLToRGB(float3 hsl) 83 | { 84 | float3 rgb; 85 | 86 | if (hsl.y == 0.0) 87 | { 88 | rgb = float3(hsl.z, hsl.z, hsl.z); 89 | } 90 | else 91 | { 92 | float temp2; 93 | if (hsl.z < 0.5) 94 | temp2 = hsl.z * (1.0 + hsl.y); 95 | else 96 | temp2 = (hsl.y + hsl.z) - (hsl.y * hsl.z); 97 | 98 | float temp1 = 2.0 * hsl.z - temp2; 99 | 100 | rgb.r = HueToRGB(temp1, temp2, hsl.x + (1.0/3.0)); 101 | rgb.g = HueToRGB(temp1, temp2, hsl.x); 102 | rgb.b = HueToRGB(temp1, temp2, hsl.x - (1.0/3.0)); 103 | } 104 | 105 | return rgb; 106 | } 107 | 108 | float3 BlendHue(float3 base, float3 blend) 109 | { 110 | float3 baseHSL = RGBToHSL(base); 111 | return HSLToRGB(float3(RGBToHSL(blend).x, baseHSL.y, baseHSL.z)); 112 | } 113 | 114 | float4 main(float2 uv : TEXCOORD) : COLOR 115 | { 116 | float4 inputColor; 117 | inputColor = tex2D(input, uv); 118 | 119 | float4 blendColor; 120 | blendColor = tex2D(blend, uv); 121 | 122 | 123 | float4 resultColor; 124 | resultColor.a = inputColor.a; 125 | 126 | // un-premultiply the blendColor alpha out from blendColor 127 | blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 128 | 129 | 130 | // apply the blend mode math 131 | resultColor.rgb = BlendHue(inputColor.rgb, blendColor.rgb); 132 | 133 | 134 | // re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a 135 | resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a; 136 | 137 | return resultColor; 138 | } 139 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/HueEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/HueEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/LightenEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- LightenEffect 4 | // 5 | //-------------------------------------------------------------------------------------- 6 | 7 | sampler2D input : register(s0); 8 | sampler2D blend : register(s1); 9 | 10 | float4 main(float2 uv : TEXCOORD) : COLOR 11 | { 12 | float4 inputColor; 13 | inputColor = tex2D(input, uv); 14 | 15 | float4 blendColor; 16 | blendColor = tex2D(blend, uv); 17 | 18 | 19 | float4 resultColor; 20 | resultColor.a = inputColor.a; 21 | 22 | // un-premultiply the blendColor alpha out from blendColor 23 | blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 24 | 25 | 26 | // apply the blend mode math 27 | if (inputColor.r < blendColor.r) 28 | resultColor.r = blendColor.r; 29 | else 30 | resultColor.r = inputColor.r; 31 | 32 | if (inputColor.g < blendColor.g) 33 | resultColor.g = blendColor.g; 34 | else 35 | resultColor.g = inputColor.g; 36 | 37 | if (inputColor.b < blendColor.b) 38 | resultColor.b = blendColor.b; 39 | else 40 | resultColor.b = inputColor.b; 41 | 42 | 43 | // re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a 44 | resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a; 45 | 46 | return resultColor; 47 | } 48 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/LightenEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/LightenEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/LinearBurnEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- LinearBurnEffect 4 | // 5 | //-------------------------------------------------------------------------------------- 6 | 7 | sampler2D input : register(s0); 8 | sampler2D blend : register(s1); 9 | 10 | //-------------------------------------------------------------------------------------- 11 | // Pixel Shader 12 | //-------------------------------------------------------------------------------------- 13 | 14 | float4 main(float2 uv : TEXCOORD) : COLOR 15 | { 16 | float4 inputColor; 17 | inputColor = tex2D(input, uv); 18 | 19 | float4 blendColor; 20 | blendColor = tex2D(blend, uv); 21 | 22 | 23 | float4 resultColor; 24 | resultColor.a = inputColor.a; 25 | 26 | // un-premultiply the blendColor alpha out from blendColor 27 | blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 28 | 29 | 30 | // apply the blend mode math 31 | // R = Base + Blend - 1 32 | resultColor.rgb = clamp(inputColor.rgb + blendColor.rgb - 1, 0, 1); 33 | 34 | 35 | // re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a 36 | resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a; 37 | 38 | return resultColor; 39 | } 40 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/LinearBurnEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/LinearBurnEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/LinearDodgeEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- LinearDodgeEffect 4 | // 5 | //-------------------------------------------------------------------------------------- 6 | 7 | sampler2D input : register(s0); 8 | sampler2D blend : register(s1); 9 | 10 | //-------------------------------------------------------------------------------------- 11 | // Pixel Shader 12 | //-------------------------------------------------------------------------------------- 13 | 14 | float4 main(float2 uv : TEXCOORD) : COLOR 15 | { 16 | float4 inputColor; 17 | inputColor = tex2D(input, uv); 18 | 19 | float4 blendColor; 20 | blendColor = tex2D(blend, uv); 21 | 22 | 23 | float4 resultColor; 24 | resultColor.a = inputColor.a; 25 | 26 | // un-premultiply the blendColor alpha out from blendColor 27 | blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 28 | 29 | 30 | // apply the blend mode math 31 | // R = Base + Blend 32 | resultColor.rgb = inputColor.rgb + blendColor.rgb; 33 | 34 | 35 | // re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a 36 | resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a; 37 | 38 | return resultColor; 39 | } 40 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/LinearDodgeEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/LinearDodgeEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/LinearLightEffect.fx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/LinearLightEffect.fx -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/LinearLightEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/LinearLightEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/LuminosityEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- LuminosityEffect 4 | // 5 | // Luminosity blend mode creates the result color by combining the hue and saturation 6 | // of the base color with the luminance of the blend color. 7 | // 8 | //-------------------------------------------------------------------------------------- 9 | 10 | sampler2D input : register(s0); 11 | sampler2D blend : register(s1); 12 | 13 | //-------------------------------------------------------------------------------------- 14 | // Pixel Shader 15 | //-------------------------------------------------------------------------------------- 16 | 17 | float3 RGBToHSL(float3 color) 18 | { 19 | float3 hsl; 20 | 21 | float fmin = min(min(color.r, color.g), color.b); 22 | float fmax = max(max(color.r, color.g), color.b); 23 | float delta = fmax - fmin; 24 | float maxplusmin = fmax + fmin; 25 | 26 | // set luminance 27 | hsl.z = maxplusmin / 2.0; 28 | 29 | if (delta == 0.0) 30 | { 31 | // a gray color, set hue and satuation to 0 32 | hsl.x = 0.0; 33 | hsl.y = 0.0; 34 | } 35 | else 36 | { 37 | // not a gray color 38 | 39 | // set saturation 40 | if (hsl.z < 0.5) 41 | hsl.y = delta / (maxplusmin); 42 | else 43 | hsl.y = delta / (2.0 - maxplusmin); 44 | 45 | if (color.r == fmax) 46 | hsl.x = ((color.g - color.b) / delta); 47 | else if (color.g == fmax) 48 | hsl.x = 2.0 + ((color.b - color.r) / delta); 49 | else if (color.b == fmax) 50 | hsl.x = 4.0 + ((color.r - color.g) / delta); 51 | 52 | hsl.x = hsl.x / 6.0; 53 | 54 | if (hsl.x < 0.0) 55 | hsl.x += 1.0; 56 | } 57 | 58 | return hsl; 59 | } 60 | 61 | float HueToRGB(float temp1, float temp2, float temp3) 62 | { 63 | if (temp3 < 0.0) 64 | temp3 += 1.0; 65 | else if (temp3 > 1.0) 66 | temp3 -= 1.0; 67 | 68 | float rgbComponent; 69 | 70 | if ((6.0 * temp3) < 1.0) 71 | rgbComponent = temp1 + (temp2 - temp1) * 6.0 * temp3; 72 | else if ((2.0 * temp3) < 1.0) 73 | rgbComponent = temp2; 74 | else if ((3.0 * temp3) < 2.0) 75 | rgbComponent = temp1 + (temp2 - temp1) * ((2.0 / 3.0) - temp3) * 6.0; 76 | else 77 | rgbComponent = temp1; 78 | 79 | return rgbComponent; 80 | } 81 | 82 | float3 HSLToRGB(float3 hsl) 83 | { 84 | float3 rgb; 85 | 86 | if (hsl.y == 0.0) 87 | { 88 | rgb = float3(hsl.z, hsl.z, hsl.z); 89 | } 90 | else 91 | { 92 | float temp2; 93 | if (hsl.z < 0.5) 94 | temp2 = hsl.z * (1.0 + hsl.y); 95 | else 96 | temp2 = (hsl.y + hsl.z) - (hsl.y * hsl.z); 97 | 98 | float temp1 = 2.0 * hsl.z - temp2; 99 | 100 | rgb.r = HueToRGB(temp1, temp2, hsl.x + (1.0/3.0)); 101 | rgb.g = HueToRGB(temp1, temp2, hsl.x); 102 | rgb.b = HueToRGB(temp1, temp2, hsl.x - (1.0/3.0)); 103 | } 104 | 105 | return rgb; 106 | } 107 | 108 | float3 BlendLuminosity(float3 base, float3 blend) 109 | { 110 | float3 baseHSL = RGBToHSL(base); 111 | return HSLToRGB(float3(baseHSL.x, baseHSL.y, RGBToHSL(blend).z)); 112 | } 113 | 114 | float4 main(float2 uv : TEXCOORD) : COLOR 115 | { 116 | float4 inputColor; 117 | inputColor = tex2D(input, uv); 118 | 119 | float4 blendColor; 120 | blendColor = tex2D(blend, uv); 121 | 122 | 123 | float4 resultColor; 124 | resultColor.a = inputColor.a; 125 | 126 | // un-premultiply the blendColor alpha out from blendColor 127 | blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 128 | 129 | 130 | // apply the blend mode math 131 | resultColor.rgb = BlendLuminosity(inputColor.rgb, blendColor.rgb); 132 | 133 | 134 | // re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a 135 | resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a; 136 | 137 | return resultColor; 138 | } 139 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/LuminosityEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/LuminosityEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/MultiplyEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- MultiplyEffect 4 | // 5 | //-------------------------------------------------------------------------------------- 6 | 7 | sampler2D input : register(s0); 8 | sampler2D blend : register(s1); 9 | 10 | float4 main(float2 uv : TEXCOORD) : COLOR 11 | { 12 | float4 inputColor; 13 | inputColor = tex2D(input, uv); 14 | 15 | float4 blendColor; 16 | blendColor = tex2D(blend, uv); 17 | 18 | 19 | float4 resultColor; 20 | resultColor.a = inputColor.a; 21 | 22 | // un-premultiply the blendColor alpha out from blendColor 23 | blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 24 | 25 | 26 | // apply the blend mode math 27 | // R = Base * Blend 28 | resultColor.rgb = blendColor.rgb * inputColor.rgb; 29 | 30 | 31 | // re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a 32 | resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a; 33 | 34 | return resultColor; 35 | } 36 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/MultiplyEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/MultiplyEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/NegationEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- NegationEffect 4 | // 5 | //-------------------------------------------------------------------------------------- 6 | 7 | #define BlendNegation(base, blend) (float3(1.0, 1.0, 1.0) - abs(float3(1.0, 1.0, 1.0) - base - blend)) 8 | 9 | sampler2D input : register(s0); 10 | sampler2D blend : register(s1); 11 | 12 | //-------------------------------------------------------------------------------------- 13 | // Pixel Shader 14 | //-------------------------------------------------------------------------------------- 15 | 16 | float4 main(float2 uv : TEXCOORD) : COLOR 17 | { 18 | float4 inputColor; 19 | inputColor = tex2D(input, uv); 20 | 21 | float4 blendColor; 22 | blendColor = tex2D(blend, uv); 23 | 24 | 25 | float4 resultColor; 26 | resultColor.a = inputColor.a; 27 | 28 | // un-premultiply the blendColor alpha out from blendColor 29 | blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 30 | 31 | 32 | // apply the blend mode math 33 | resultColor.rgb = BlendNegation(inputColor, blendColor); 34 | 35 | 36 | // re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a 37 | resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a; 38 | 39 | return resultColor; 40 | } 41 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/NegationEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/NegationEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/NormalEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- NormalEffect 4 | // 5 | //-------------------------------------------------------------------------------------- 6 | 7 | sampler2D input : register(s0); 8 | sampler2D blend : register(s1); 9 | 10 | //-------------------------------------------------------------------------------------- 11 | // Pixel Shader 12 | //-------------------------------------------------------------------------------------- 13 | 14 | float4 main(float2 uv : TEXCOORD) : COLOR 15 | { 16 | float4 inputColor; 17 | inputColor = tex2D(input, uv); 18 | 19 | float4 blendColor; 20 | blendColor = tex2D(blend, uv); 21 | 22 | inputColor.rgb = (1 - blendColor.a) * inputColor.rgb + blendColor.rgb; 23 | 24 | return inputColor; 25 | } 26 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/NormalEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/NormalEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/OverlayEffect.fx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/OverlayEffect.fx -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/OverlayEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/OverlayEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/PhoenixEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- PhoenixEffect 4 | // 5 | //-------------------------------------------------------------------------------------- 6 | 7 | #define BlendPhoenix(base, blend) (min(base, blend) - max(base, blend) + float3(1.0, 1.0, 1.0)) 8 | 9 | sampler2D input : register(s0); 10 | sampler2D blend : register(s1); 11 | 12 | //-------------------------------------------------------------------------------------- 13 | // Pixel Shader 14 | //-------------------------------------------------------------------------------------- 15 | 16 | float4 main(float2 uv : TEXCOORD) : COLOR 17 | { 18 | float4 inputColor; 19 | inputColor = tex2D(input, uv); 20 | 21 | float4 blendColor; 22 | blendColor = tex2D(blend, uv); 23 | 24 | 25 | float4 resultColor; 26 | resultColor.a = inputColor.a; 27 | 28 | // un-premultiply the blendColor alpha out from blendColor 29 | blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 30 | 31 | 32 | // apply the blend mode math 33 | resultColor.rgb = BlendPhoenix(inputColor, blendColor); 34 | 35 | 36 | // re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a 37 | resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a; 38 | 39 | return resultColor; 40 | } 41 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/PhoenixEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/PhoenixEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/PinLightEffect.fx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/PinLightEffect.fx -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/PinLightEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/PinLightEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/ReflectEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- ReflectEffect 4 | // 5 | //-------------------------------------------------------------------------------------- 6 | 7 | #define BlendReflectf(base, blend) ((blend == 1.0) ? blend : min(base * base / (1.0 - blend), 1.0)) 8 | 9 | sampler2D input : register(s0); 10 | sampler2D blend : register(s1); 11 | 12 | //-------------------------------------------------------------------------------------- 13 | // Pixel Shader 14 | //-------------------------------------------------------------------------------------- 15 | 16 | float4 main(float2 uv : TEXCOORD) : COLOR 17 | { 18 | float4 inputColor; 19 | inputColor = tex2D(input, uv); 20 | 21 | float4 blendColor; 22 | blendColor = tex2D(blend, uv); 23 | 24 | 25 | float4 resultColor; 26 | resultColor.a = inputColor.a; 27 | 28 | // un-premultiply the blendColor alpha out from blendColor 29 | blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 30 | 31 | 32 | // apply the blend mode math 33 | resultColor.r = BlendReflectf(inputColor.r, blendColor.r); 34 | resultColor.g = BlendReflectf(inputColor.g, blendColor.g); 35 | resultColor.b = BlendReflectf(inputColor.b, blendColor.b); 36 | 37 | 38 | // re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a 39 | resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a; 40 | 41 | return resultColor; 42 | } 43 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/ReflectEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/ReflectEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/SaturationEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- SaturationEffect 4 | // 5 | // Saturation blend mode creates the result color by combining the luminance and hue 6 | // of the base color with the saturation of the blend color. 7 | // 8 | //-------------------------------------------------------------------------------------- 9 | 10 | sampler2D input : register(s0); 11 | sampler2D blend : register(s1); 12 | 13 | //-------------------------------------------------------------------------------------- 14 | // Pixel Shader 15 | //-------------------------------------------------------------------------------------- 16 | 17 | float3 RGBToHSL(float3 color) 18 | { 19 | float3 hsl; 20 | 21 | float fmin = min(min(color.r, color.g), color.b); 22 | float fmax = max(max(color.r, color.g), color.b); 23 | float delta = fmax - fmin; 24 | float maxplusmin = fmax + fmin; 25 | 26 | // set luminance 27 | hsl.z = maxplusmin / 2.0; 28 | 29 | if (delta == 0.0) 30 | { 31 | // a gray color, set hue and satuation to 0 32 | hsl.x = 0.0; 33 | hsl.y = 0.0; 34 | } 35 | else 36 | { 37 | // not a gray color 38 | 39 | // set saturation 40 | if (hsl.z < 0.5) 41 | hsl.y = delta / (maxplusmin); 42 | else 43 | hsl.y = delta / (2.0 - maxplusmin); 44 | 45 | if (color.r == fmax) 46 | hsl.x = ((color.g - color.b) / delta); 47 | else if (color.g == fmax) 48 | hsl.x = 2.0 + ((color.b - color.r) / delta); 49 | else if (color.b == fmax) 50 | hsl.x = 4.0 + ((color.r - color.g) / delta); 51 | 52 | hsl.x = hsl.x / 6.0; 53 | 54 | if (hsl.x < 0.0) 55 | hsl.x += 1.0; 56 | } 57 | 58 | return hsl; 59 | } 60 | 61 | float HueToRGB(float temp1, float temp2, float temp3) 62 | { 63 | if (temp3 < 0.0) 64 | temp3 += 1.0; 65 | else if (temp3 > 1.0) 66 | temp3 -= 1.0; 67 | 68 | float rgbComponent; 69 | 70 | if ((6.0 * temp3) < 1.0) 71 | rgbComponent = temp1 + (temp2 - temp1) * 6.0 * temp3; 72 | else if ((2.0 * temp3) < 1.0) 73 | rgbComponent = temp2; 74 | else if ((3.0 * temp3) < 2.0) 75 | rgbComponent = temp1 + (temp2 - temp1) * ((2.0 / 3.0) - temp3) * 6.0; 76 | else 77 | rgbComponent = temp1; 78 | 79 | return rgbComponent; 80 | } 81 | 82 | float3 HSLToRGB(float3 hsl) 83 | { 84 | float3 rgb; 85 | 86 | if (hsl.y == 0.0) 87 | { 88 | rgb = float3(hsl.z, hsl.z, hsl.z); 89 | } 90 | else 91 | { 92 | float temp2; 93 | if (hsl.z < 0.5) 94 | temp2 = hsl.z * (1.0 + hsl.y); 95 | else 96 | temp2 = (hsl.y + hsl.z) - (hsl.y * hsl.z); 97 | 98 | float temp1 = 2.0 * hsl.z - temp2; 99 | 100 | rgb.r = HueToRGB(temp1, temp2, hsl.x + (1.0/3.0)); 101 | rgb.g = HueToRGB(temp1, temp2, hsl.x); 102 | rgb.b = HueToRGB(temp1, temp2, hsl.x - (1.0/3.0)); 103 | } 104 | 105 | return rgb; 106 | } 107 | 108 | float3 BlendSaturation(float3 base, float3 blend) 109 | { 110 | float3 baseHSL = RGBToHSL(base); 111 | return HSLToRGB(float3(baseHSL.x, RGBToHSL(blend).y, baseHSL.z)); 112 | } 113 | 114 | float4 main(float2 uv : TEXCOORD) : COLOR 115 | { 116 | float4 inputColor; 117 | inputColor = tex2D(input, uv); 118 | 119 | float4 blendColor; 120 | blendColor = tex2D(blend, uv); 121 | 122 | 123 | float4 resultColor; 124 | resultColor.a = inputColor.a; 125 | 126 | // un-premultiply the blendColor alpha out from blendColor 127 | blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 128 | 129 | 130 | // apply the blend mode math 131 | resultColor.rgb = BlendSaturation(inputColor.rgb, blendColor.rgb); 132 | 133 | 134 | // re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a 135 | resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a; 136 | 137 | return resultColor; 138 | } 139 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/SaturationEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/SaturationEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/ScreenEffect.fx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/ScreenEffect.fx -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/ScreenEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/ScreenEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/SoftLightEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- SoftLightEffect 4 | // 5 | //-------------------------------------------------------------------------------------- 6 | 7 | #define BlendSoftLightf(base, blend) ((blend < 0.5) ? (2.0 * base * blend + base * base * (1.0 - 2.0 * blend)) : (sqrt(base) * (2.0 * blend - 1.0) + 2.0 * base * (1.0 - blend))) 8 | 9 | sampler2D input : register(s0); 10 | sampler2D blend : register(s1); 11 | 12 | float4 main(float2 uv : TEXCOORD) : COLOR 13 | { 14 | float4 inputColor; 15 | inputColor = tex2D(input, uv); 16 | 17 | float4 blendColor; 18 | blendColor = tex2D(blend, uv); 19 | 20 | 21 | float4 resultColor; 22 | resultColor.a = inputColor.a; 23 | 24 | // un-premultiply the blendColor alpha out from blendColor 25 | blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 26 | 27 | 28 | // apply the blend mode math 29 | resultColor.r = BlendSoftLightf(inputColor.r, blendColor.r); 30 | resultColor.g = BlendSoftLightf(inputColor.g, blendColor.g); 31 | resultColor.b = BlendSoftLightf(inputColor.b, blendColor.b); 32 | 33 | 34 | // re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a 35 | resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a; 36 | 37 | return resultColor; 38 | } 39 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/SoftLightEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/SoftLightEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/VividLightEffect.fx: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // 3 | // WPF ShaderEffect HLSL -- VividLightEffect 4 | // 5 | //-------------------------------------------------------------------------------------- 6 | 7 | #define BlendColorDodgef(base, blend) ((blend == 1.0) ? blend : min(base / (1.0 - blend), 1.0)) 8 | #define BlendColorBurnf(base, blend) ((blend == 0.0) ? blend : max((1.0 - ((1.0 - base) / blend)), 0.0)) 9 | #define BlendVividLightf(base, blend) ((blend < 0.5) ? BlendColorBurnf(base, (2.0 * blend)) : BlendColorDodgef(base, (2.0 * (blend - 0.5)))) 10 | 11 | sampler2D input : register(s0); 12 | sampler2D blend : register(s1); 13 | 14 | //-------------------------------------------------------------------------------------- 15 | // Pixel Shader 16 | //-------------------------------------------------------------------------------------- 17 | 18 | float4 main(float2 uv : TEXCOORD) : COLOR 19 | { 20 | float4 inputColor; 21 | inputColor = tex2D(input, uv); 22 | 23 | float4 blendColor; 24 | blendColor = tex2D(blend, uv); 25 | 26 | 27 | float4 resultColor; 28 | resultColor.a = inputColor.a; 29 | 30 | // un-premultiply the blendColor alpha out from blendColor 31 | blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 32 | 33 | 34 | // apply the blend mode math 35 | resultColor.r = BlendVividLightf(inputColor.r, blendColor.r); 36 | resultColor.g = BlendVividLightf(inputColor.g, blendColor.g); 37 | resultColor.b = BlendVividLightf(inputColor.b, blendColor.b); 38 | 39 | 40 | // re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a 41 | resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a; 42 | 43 | return resultColor; 44 | } 45 | -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/ShaderSource/VividLightEffect.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cplotts/WPFSLBlendModeFx/c4f0ff0039a759078f46d41d5356fabed14f352e/WPFBlendModeEffectLibrary/ShaderSource/VividLightEffect.ps -------------------------------------------------------------------------------- /WPFBlendModeEffectLibrary/WPFBlendModeEffectLibrary.csproj.vspscc: -------------------------------------------------------------------------------- 1 | "" 2 | { 3 | "FILE_VERSION" = "9237" 4 | "ENLISTMENT_CHOICE" = "NEVER" 5 | "PROJECT_FILE_RELATIVE_PATH" = "" 6 | "NUMBER_OF_EXCLUDED_FILES" = "0" 7 | "ORIGINAL_PROJECT_FILE_PATH" = "" 8 | "NUMBER_OF_NESTED_PROJECTS" = "0" 9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER" 10 | } 11 | -------------------------------------------------------------------------------- /WPFSLBlendModeFx.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 11.00 2 | # Visual Studio 2010 3 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E86BFE46-0740-4037-B4E7-19F563310102}" 4 | ProjectSection(SolutionItems) = preProject 5 | BackgroundEffectBehavior.png = BackgroundEffectBehavior.png 6 | BlendModes.psd = BlendModes.psd 7 | BlendModes2.psd = BlendModes2.psd 8 | BlendModesOpacityTester.psd = BlendModesOpacityTester.psd 9 | H.design = H.design 10 | HelloWorld.design = HelloWorld.design 11 | HelloWorldColorBurn600.png = HelloWorldColorBurn600.png 12 | HOnImage.png = HOnImage.png 13 | HOnImage600.png = HOnImage600.png 14 | HOnImageColorBurn.png = HOnImageColorBurn.png 15 | HOnImageColorBurn600.png = HOnImageColorBurn600.png 16 | HOnImageColorBurn600NoCigar.png = HOnImageColorBurn600NoCigar.png 17 | HOnImageColorBurn600Success.png = HOnImageColorBurn600Success.png 18 | PhotoshopMathFP.hlsl = PhotoshopMathFP.hlsl 19 | EndProjectSection 20 | EndProject 21 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ColorPicker", "ColorPicker\ColorPicker.csproj", "{ED67A75F-5F76-43A8-9CD0-171212D599CB}" 22 | EndProject 23 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPFBlendModeEffectLibrary", "WPFBlendModeEffectLibrary\WPFBlendModeEffectLibrary.csproj", "{25F23180-F1BE-42F2-A58E-7F77BB03A987}" 24 | EndProject 25 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPFTestHarness", "WPFTestHarness\WPFTestHarness.csproj", "{C174652D-C12B-445D-8F80-10DF64FDB92A}" 26 | EndProject 27 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.DwayneNeed", "Microsoft.DwayneNeed\Microsoft.DwayneNeed.csproj", "{80A10B86-6615-4440-93B0-C943DF5B8693}" 28 | EndProject 29 | Global 30 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 31 | Debug|Any CPU = Debug|Any CPU 32 | Release|Any CPU = Release|Any CPU 33 | EndGlobalSection 34 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 35 | {ED67A75F-5F76-43A8-9CD0-171212D599CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {ED67A75F-5F76-43A8-9CD0-171212D599CB}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {ED67A75F-5F76-43A8-9CD0-171212D599CB}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {ED67A75F-5F76-43A8-9CD0-171212D599CB}.Release|Any CPU.Build.0 = Release|Any CPU 39 | {25F23180-F1BE-42F2-A58E-7F77BB03A987}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 40 | {25F23180-F1BE-42F2-A58E-7F77BB03A987}.Debug|Any CPU.Build.0 = Debug|Any CPU 41 | {25F23180-F1BE-42F2-A58E-7F77BB03A987}.Release|Any CPU.ActiveCfg = Release|Any CPU 42 | {25F23180-F1BE-42F2-A58E-7F77BB03A987}.Release|Any CPU.Build.0 = Release|Any CPU 43 | {C174652D-C12B-445D-8F80-10DF64FDB92A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 44 | {C174652D-C12B-445D-8F80-10DF64FDB92A}.Debug|Any CPU.Build.0 = Debug|Any CPU 45 | {C174652D-C12B-445D-8F80-10DF64FDB92A}.Release|Any CPU.ActiveCfg = Release|Any CPU 46 | {C174652D-C12B-445D-8F80-10DF64FDB92A}.Release|Any CPU.Build.0 = Release|Any CPU 47 | {80A10B86-6615-4440-93B0-C943DF5B8693}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 48 | {80A10B86-6615-4440-93B0-C943DF5B8693}.Debug|Any CPU.Build.0 = Debug|Any CPU 49 | {80A10B86-6615-4440-93B0-C943DF5B8693}.Release|Any CPU.ActiveCfg = Release|Any CPU 50 | {80A10B86-6615-4440-93B0-C943DF5B8693}.Release|Any CPU.Build.0 = Release|Any CPU 51 | EndGlobalSection 52 | GlobalSection(SolutionProperties) = preSolution 53 | HideSolutionNode = FALSE 54 | EndGlobalSection 55 | EndGlobal 56 | -------------------------------------------------------------------------------- /WPFSLBlendModeFx.vssscc: -------------------------------------------------------------------------------- 1 | "" 2 | { 3 | "FILE_VERSION" = "9237" 4 | "ENLISTMENT_CHOICE" = "NEVER" 5 | "PROJECT_FILE_RELATIVE_PATH" = "" 6 | "NUMBER_OF_EXCLUDED_FILES" = "0" 7 | "ORIGINAL_PROJECT_FILE_PATH" = "" 8 | "NUMBER_OF_NESTED_PROJECTS" = "0" 9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT" 10 | } 11 | -------------------------------------------------------------------------------- /WPFTestHarness/App.xaml: -------------------------------------------------------------------------------- 1 |