Is there anything unusual about how the alpha component is handled in a pixel shader? I have a WPF application for which my artist gives me grayscale images for use as a background, and the application paints these images in accordance with the current state. So I wrote a pixel shader (using the WPF pixel shader effects library infrastructure) to use as an effect for an image element. The shader takes color as a parameter, which it converts to HSL so that it can manipulate brightness. Then, for each gray pixel, it calculates a color whose brightness is interpolated between the color parameter and white in proportion to the brightness of the original pixel.
float4 main(float2 uv : TEXCOORD) : COLOR { float4 src = tex2D(implicitInputSampler, uv);
This works fine on pixels where alpha = 1. But where alpha = 0, the resulting pixels are highlighted in white, and do not look like the background of the window. So I made a small change:
float4 main(float2 uv : TEXCOORD) : COLOR { float4 src = tex2D(implicitInputSampler, uv); if (src.a == 0) return src; ...
and now the transparent parts are really transparent. What for? Why did this dst.a = src.a statement dst.a = src.a do this in the first version? Unfortunately, even this is only a partial correction, because it looks like pixels with 0 <alpha; 1 go white.
Does anyone know that I don't understand about alpha?
pixel wpf alphablending pixel-shader
vanmelle
source share