PixelShader Class
Provides a managed wrapper around a High Level Shading Language (HLSL) pixel shader.
Namespace: System.Windows.Media.Effects
Assembly: System.Windows (in System.Windows.dll)
The PixelShader type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | Dispatcher | Gets the Dispatcher this object is associated with. (Inherited from DependencyObject.) |
![]() | UriSource | Gets or sets a URI reference to HLSL bytecode in the assembly. |
| Name | Description | |
|---|---|---|
![]() | CheckAccess | Determines whether the calling thread has access to this object. (Inherited from DependencyObject.) |
![]() | ClearValue | Clears the local value of a dependency property. (Inherited from DependencyObject.) |
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetAnimationBaseValue | Returns any base value established for a Silverlight dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | GetValue | Returns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ReadLocalValue | Returns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject.) |
![]() | SetValue | Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
Use the PixelShader class to access precompiled HLSL bytecode in a Silverlight application.
Set the UriSource property to load the shader bytecode.
To create a custom effect, assign the PixelShader to the PixelShader property of a ShaderEffect.
The following example shows an image with and without a shader effect applied to it.
This "invert colors" effect is a custom shader effect. To create your own effect, do the following:
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.
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/InvertColors.ps", 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"
xmlns:shader="clr-namespace:PixelShaderSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
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">
<Image.Effect>
<shader:MyPixelInvertedEffect />
</Image.Effect>
</Image>
</StackPanel>
</UserControl>
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.




