Skip to main content
GameDev.net gamedev.net
🔒 Locked

Thicker Outline for Toon Shader

Started by richardmonette May 14, 2009 at 1:29 PM 2 replies 2.6k views
Original Post
richardmonette
richardmonette
I am currently working on a cartoon style shader in HLSL which uses Sobel edge detection to draw outlines around my models. This is working well, but I would like to make the outlines much, much thicker than they are currently. If I make the kernel larger the lines get a bit thicker but for the extremely thick lines I require the kernel size would ruin performance. Can anyone recommend a good strategy for creating thicker lines?
Krypt0n
Krypt0n
keep the small kernel and afterwards do some 'postprocess' passes that expand the lines.

of you want thiker lines, you might get away with rendeirng into a smaller buffer and then stretch it over the full resolution rendertarget, that way you'd process less fargment shaders but get thicker lines automatically.
richardmonette
richardmonette
Found a decent solution that can produce thicker outlines while still using only a 3x3 kernel.

Basically I create the offsets for the kernel like this:


const float texelSize = 1.0f / 512.0f;
const float2 kernelOffsets[NUM] = {
float2(-texelSize, texelSize),
float2( 0.00 , texelSize),
float2( texelSize, texelSize),
float2(-texelSize, 0.00 ),
float2( 0.0, 0.0),
float2( texelSize, texelSize ),
float2(-texelSize,-texelSize),
float2( 0.00 , -texelSize),
float2( texelSize,-texelSize),
}
[\code]

So all I really needed to do was change the texel size so increase the distance of the sampling.

For example, 1.0f/256.0f (even though the texture is still 512x512 produces roughly a doubly thick line.
Jason Z
Jason Z
You could potentially do some type of a dilation filter on the outlines as well, but you would have to be careful to only expand the outline in the correct direction... (i.e. only expand outward instead of inward).
Jason Zink :: DirectX MVP   Direct3D 11 engine on CodePlex: Hieroglyph 3 Direct3D Books: 

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.