Here is one of the coolest applications of WPF ever: Bling. It’s a completely new way to leverage the WPF platform for high-performance graphics development. Bling experiments with a programming model that combines the ease of programming provided by a retained graphics model with the flexibility and performance provided by custom pixel and vertex shaders. Shaders are expressed in pure C# code rather than HLSL code. At run-time, the C#-encoded shaders are dynamically translated into HLSL code that is then compiled into DirectX 10 shaders. You get the speed of shaders running on the GPU without the HLSL goo, hooray!

Glass shader effect from Bling example project.

Glass shader effect in Bling. It runs really fast.

To give you an idea of what pixel shader code looks like in Bling, here’s a simple lens effect:

// A lens pixel effect.
At = new ButtonBl( canvas )
{
    LeftTop = At,
    Content = "Lens",
    Click = () => UseImage.Effect.Custom = ( input, uv ) =>
    {
        slider.Visibility = true;
        slider.LabelName = "light";
        PointBl v = ( ( uv * UseImage.Size ) - ( thumbA - UseImage.LeftTop ) );
        DoubleBl l = ( v.Length / 100 );
        l = ( l <= 1 ).Condition( l.Pow( 1d + slider.Value ), l );
 
        var n = v.Normalize;
        var clr = input[uv + ( l * n * .1 )];
        var clrB = input[uv - ( l * n * .1 )];
        var antiAlias = 1d - ( ( l - 1 ) / .01 ).Saturate;
 
        return ( l <= 1 ).Condition( l.Lerp( clr, Colors.LightGray ), antiAlias.Lerp( input[uv], Colors.LightGray ) );
    }
}.RightTop;

Here’s what the shader looks like:

Lens pixel shader from Bling example project.

Lens pixel shader in Bling.

In addition, the UI is expressed by sophisticated declarative constraints that maintain dynamic relationships in the UI without event handling. But that’s a topic for another post. Just go download Bling.