I have a shader SelectionEffect.fx effect like this:
sampler2D Input1 : register(S0);
float4 main(float2 uv : TEXCOORD) : COLOR
{
float4 color;
color = tex2D(Input1, uv);
if ((color.r != 1.0f) && (color.g != 1.0f) && (color.b != 1.0f)) {
color.r = 1.0;
color.g = 0.0;
color.b = 0.0;
//color.a = 0.9;
}
return color;
}
Compiled as SelectionEffect.ps and added his .cs class file, of course.
It's used to change the color of the object to red only, when I select it (activate a property according in the object), instead of assigned a tempoaraneally red color to the object.
I would to use this solution that is faster, i have 50-100 thousand objects.
So,to assign this effect at the object that i have already added to canvas is only:
((System.Windows.Shapes.Path)shape.Visual).Effect = new MyShaders.SelectionEffect();
to remove it:
((System.Windows.Shapes.Path)shape.Visual).Effect = null;
Please note that in the example I'm applyed this "effect" to one object pro time, so, it's intended that i would change color of the only object that have "effect" applyed in that moment and not to the anothers.
Using:
((System.Windows.Shapes.Path)shape.Visual).Stroke = new SolidColorBrush(Colors.Red);
is slow.