Im trying to make an outline pixel shader that grows inwards depending on the specified thickness.
Here is what Ive tried:
[unroll(MaxVal)]
for (int i = -thickness; i < thickness; i++)
{
[unroll(MaxVal)]
for (int j = -thickness; j < thickness; j++)
{
float2 pixelOffsetUV = uv.xy + float2( i / width, j / height );
float pixelOffset = tex2D(input, pixelOffsetUV).a;
if (pixelOffset <=0.5)
return float4(0, 0, 0, color.a);
}
}
return orginal;
It simply checks the neighbour pixels, and if it finds one whose alpha component is below a specified value, it returns black. It works fine, but it takes forever to compile. I need to have a max thickness of about 100-200, and the above implementation is obviously overkill for this.
What are some other more efficient outline algorithms?
By the way this is strictly 2d (WPF effects), no vertex shaders or geometry attributes,, just a pixel shader.