# Edge Detection

This topic is 3424 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, i am working on directx's Progressive Mesh example and i am trying to add black edge lines on textured mesh. I guess i need to add cell shader to my project but the problem is i am not good at shaders. Do you have any example code or project that i can learn how to do this. Thanks for your help.

##### Share on other sites
The PostProcessing sample in the SDK has an edge detection shader you can look at.

##### Share on other sites
Yes i already looked at that example but in the postprocess example there are no textures on the mesh. I couldn't figure it out how to draw edge lines on the mesh texture. Here i'll show you what i mean: Screen Shot

##### Share on other sites
From a few days i am trying to solve this problem and here is the result(it is not working)

My shader (according to post process example)

texture  g_txScene;sampler g_samScene =sampler_state{    Texture = <g_txScene>;     AddressU = Clamp;    AddressV = Clamp;    MinFilter = Point;    MagFilter = Linear;    MipFilter = Linear;};float2 PixelKernel[4] ={    { 0,  1},    { 1,  0},    { 0, -1},    {-1,  0}};float2 TexelKernel[4]<	string ConvertPixelsToTexels = "PixelKernel";>;float4 PostProcess3PS( float2 Tex : TEXCOORD0 ) : COLOR0{    float4 Orig = tex2D( g_samScene, Tex );    float4 Sum = 0;    for( int i = 0; i < 4; i++ )    Sum += saturate( 1 - dot( Orig.xyz, tex2D( g_samScene, Tex + TexelKernel ).xyz ) );    return Sum;}technique CelShading{    pass p0    {        VertexShader = null;        PixelShader = compile ps_2_0 PostProcess3PS();    }}

And here are the results: Render Screen

So as you see, i am far away from drawing edge lines on the texture or even detect edges correctly. Does anyone have any idea about what i need to do ? Thanks.

##### Share on other sites
U will need more than one pass to do cell shading. First do the edge detection (a simple sobel filter will do the job) - like in the sdk sample. Then render the model again, this time textured. Finally blend the 2 images together and u should have edges around your textured model. If u use MRT's u can probably spare the separate edge pass and calculate the textured and edge model in a single pass.

• 10
• 18
• 14
• 18
• 15