I am having issues with a pixel shader that turns an image into a grayscale one. The image source is being bound to a url outside of the project. Sometimes the effect is applied properly, other times the image is all white, and sometimes the green channel seems to be screwed up.
Has anyone came across an issue like this?
Thanks in advance
Shader code
sampler2D implicitInput : register(s0);
float factor : register(c0);
float4 main(float2 uv : TEXCOORD) : COLOR
{
float4 color = tex2D(implicitInput, uv);
float gray = color.r * 0.3 + color.g * 0.59 + color.b *0.11;
float4 result;
result.r = (color.r - gray) * factor + gray;
result.g = (color.g - gray) * factor + gray;
result.b = (color.b - gray) * factor + gray;
result.a = color.a;
return result;
}
<Image Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Width="25"
Stretch="Uniform"
Effect="{Binding ConversionState, Converter{StaticResource ImageConvert}}"
Source="{Binding IconPath}" />
I'm using a converter on the effect because I only need the effect applied in certain cases. Even when I hard code the effect the issue still occurs.