ShaderEffect Class

Provides a custom bitmap effect by using a PixelShader.

Namespace:  System.Windows.Media.Effects
Assembly:  System.Windows (in System.Windows.dll)

Public MustInherit Class ShaderEffect _
	Inherits Effect

The ShaderEffect type exposes the following members.

Protected methodShaderEffectInitializes a new instance of the ShaderEffect class.

Protected propertyDdxUvDdyUvRegisterIndexGets or sets a value that indicates the shader register to use for the partial derivatives of the texture coordinates with respect to screen space.
Public propertyDispatcherGets the Dispatcher this object is associated with. (Inherited from DependencyObject.)
Protected propertyEffectMappingWhen overridden in a derived class, transforms mouse input and coordinate systems through the effect. (Inherited from Effect.)
Protected propertyPaddingBottomGets or sets the amount by which the effect's output texture is larger than its input texture along the bottom edge of the effect.
Protected propertyPaddingLeftGets or sets the amount by which the effect's output texture is larger than its input texture along the left edge.
Protected propertyPaddingRightGets or sets the amount by which the effect's output texture is larger than its input texture along the right edge.
Protected propertyPaddingTopGets or sets the amount by which the effect's output texture is larger than its input texture along the top edge.
Protected propertyPixelShaderGets or sets the PixelShader to use for the effect.

Public methodCheckAccessDetermines whether the calling thread has access to this object. (Inherited from DependencyObject.)
Public methodClearValueClears the local value of a dependency property. (Inherited from DependencyObject.)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetAnimationBaseValueReturns any base value established for a Silverlight dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodGetValueReturns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodStatic memberPixelShaderConstantCallbackAssociates a dependency property value with a pixel shader's float constant register.
Protected methodStatic memberPixelShaderSamplerCallback(Int32)Associates a dependency property value with a pixel shader's sampler register.
Protected methodStatic memberPixelShaderSamplerCallback(Int32, SamplingMode)Associates a dependency property value with a pixel shader's sampler register and a SamplingMode.
Public methodReadLocalValueReturns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject.)
Protected methodStatic memberRegisterPixelShaderSamplerProperty(String, Type, Int32)Associates a dependency property with a shader sampler register.
Protected methodStatic memberRegisterPixelShaderSamplerProperty(String, Type, Int32, SamplingMode)Associates a dependency property with a shader sampler register and a sampling mode.
Public methodSetValueSets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Protected methodUpdateShaderValueNotifies the effect that the shader constant or sampler corresponding to the specified dependency property should be updated.

Protected fieldStatic memberPixelShaderPropertyIdentifies the PixelShader dependency property.

Shader effects allow you to add effects to rendered objects such as grayscale, redeye removal, pixel brightness effects, shadows, etc by enabling you to use an algorithm to alter how pixels are displayed.


Silverlight shader effects are rendered in software mode. Any object that applies an effect will also be rendered in software. Performance is degraded the most when using effects on large visuals or animating properties of an effect. This is not to say that you should not use shader effects in this way at all, but you should use caution and test thoroughly to ensure that your users are getting the experience you expect.

The following example shows an image with and without a shader effect applied to it.

Run this sample

This "invert colors" effect is a custom shader effect. To create your own effect, do the following:

  1. Create a shader using High Level Shader Language (HLSL), part of the DirectX SDK, and compile into a .ps file. To compile .ps files, you can directly use the fxc command line tool provided with the DirectX SDK or another tool like Shazzam which gives you a convenient UI for working with the fxc command line tool.

  2. Derive your custom effect from the ShaderEffect class and set the PixelShader property of your custom shader effect to your .ps file.

using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System;

namespace PixelShaderSample

    public class MyPixelInvertedEffect : ShaderEffect

        public MyPixelInvertedEffect()

            // Include your project name and .ps file.
            Uri u = new Uri(@"/PixelShaderSample;component/", UriKind.Relative);

            // Set the PixelShader of the custom shader effect to use your custom .ps file.
            PixelShader myPixelShader = new PixelShader();
            myPixelShader.UriSource = u;
            this.PixelShader = myPixelShader;


3. Apply the custom shader effect to your object (in this case an Image).

    <UserControl x:Class="PixelShaderSample.MainPage"
    Width="400" Height="300">
    <StackPanel Orientation="Horizontal">

        <!-- Image without PixelShader effect on the left and image with
             custom shader on the right. -->
        <Image Height="200" Width="200" Source="tree_blossoms.jpg" Stretch="Fill"/>
        <Image Height="200" Width="200" Source="tree_blossoms.jpg" Stretch="Fill">
                <shader:MyPixelInvertedEffect />


Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions