5

I'm using a Sobel filter to draw an outline in a shader. How do I control its thickness? Here's my outlining code:

float3x3 Kx = {
-1, 0, 1,
-2, 0, 2,
-1, 0, 1};

float3x3 Ky = {
1, 2, 1,
0, 0, 0,
-1,-2,-1};

float Lx = 0;
float Ly = 0;    

for (int y = -1; y <= 1; ++y) {
    for (int x = -1; x<= 1; ++x) {
        float2 offset = float2( x, y );
        float3 tex = tex2D(sampler, uv + offset).rgb;
        float luminance = dot(tex, float3(0.3, 0.59, 0.11));

        Lx += luminance * Kx[y+1][x+1];
        Ly += luminance * Ky[y+1][x+1];
    }
}
float color = sqrt(Lx*Lx + Ly*Ly);
return float4( color, color, color, color );
SurvivalMachine
  • 298
  • 1
  • 3
  • 11

1 Answers1

4

I've done this 2 different ways in the past:

  1. Apply a pre-blur to the image before running the Sobel operator on it. This will have the side effect of getting rid of any noise that's smaller than the blur kernel, but it will also thicken the lines you end up drawing, too.
  2. Apply a post-process where you thicken the lines by either stamping a shape at every point that's an edge, or using some sort of dilate process.
user1118321
  • 3,401
  • 11
  • 14