Variable Width Outline Effect Around a Texture in 2D

741 Views Asked by At

I am looking to create a glsl shader program that will give me a variable width outline around an arbitrary 2d texture as shown in the picture. Is this a reasonable job for the GPU? I've looked at edge-detection approaches but those would only reasonably provide a few pixels border. I want arbitrary width. Is this doable?

enter image description here

1

There are 1 best solutions below

0
Daniel Bauer On

One approach would be to render the object to a texture with a bit larger scale and color it all the way your outline color should be. Then you render it to another texture as it should be displayed. In a third render pass you could then combine the 2 textures by choosing the outline texture, when the color-texture is empty and else the color texture. This could be an expensive process, but it obviously depends on the scope of your project if that impacts performance too much. Image of three-Step image process