I am trying to create a PixelShader similar to Photoshop’s Adjustment Layer. Invert is a simple example where it generates a negative image (return 1 – pixel).
The problem I have is you attach the Effect to a UIElement and the pixels used are from the UIElement (Fill color for a Rectangle, Source for an Image). What I would like is the pixels to be from below the UIElement (other shapes, images etc.). If the UIElement that has the effect is moved it uses the pixels below its new bounding box.
Is there some option that a UIElement has that allows this? Or some UIElement/Control that is like a pass through control and uses its source from the pixels below? The only option I see is to render an image below the bounding box and set that as the Source. But managing that when it moves or another element is inserted below the Effects seem expensive. All my objects are added to a Canvas so objects can be inserted, deleted, and moved.
Thanks.
//----------------------------------------
// Pixel Shader
//----------------------------------------
sampler2D implicitInput : register(s0);
float4 main(float2 uv : TEXCOORD) : COLOR
{
float4 imagePixel = tex2D(implicitInput, uv);
imagePixel.g = 1 - imagePixel.g;
imagePixel.b = 1 - imagePixel.b;
imagePixel.r = 1 - imagePixel.r;
return imagePixel;
}
<!—I don’t want to have a Source but want the data used below the bounding box
<Image Name="MyInvertEffect" Width="400" Height="400"
Source="/Images/BlackWihiteGray.png"
Effect="{StaticResource invertEffect}"
>
</Image>