Friday, December 17, 2010

WPF - DrawingContext and ShaderEffect

DrawingContext does not support ShaderEffect.

Using DrawingContext in OnRender() method of adorner, we can Push effect using PushEffect() method. But the strange thing is that DrawingContext.PushEffect() does not support ShaderEffect. All it supports is BitmapEffect :(. It seems to be a missing piece of functionality of conversion of all shaders to ShaderEffect.

So if you don't want to use BitmapEffect as it is obsolete now then DrawingContext wouldn't be of much use to you. There seems to be no other option though, e.g. we want to push effect to adorner, the only option available is to push BitmapEffect. Even PushEffect is decorated with ObsoleteAttribute in DrawingContext class.

I have discussed about adorners here:

If you want to study about ShaderEffect, you can refer this post:

Now you must be wondering why we are so much interested in having ShaderEffect with DrawingContext. The reason is the performance benefits with ShaderEffect compared to BitmapEffect. ShaderEffect uses pixel shaders in graphics processor (GPU). So it pushes the work outside the regular CPU. BitmapEffect provides a software solution to provide similar effects but it does not use new features of graphics processor.


Unknown said...

Amen, brother. I ran into exactly the same thing. I spent all morning working on a nice Emboss effect for a watermark that I wanted to paste over my application when the license wasn't valid. To my horror when I got to the point of connecting it to the adorner for the client area, I find that only Bitmap Effects can be pushed. I'm crushed, a whole morning wasted.

Guilherme said...


dim vc as new visualcontext
dim dc as DrawingContext = vc.renderopen


dc.drawimage ()

vc.effect = new effect


it's work !