# Edge Detection

This topic is 3334 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.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.16704462468624115, "perplexity": 3231.9188622476554}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2018-09/segments/1518891812938.85/warc/CC-MAIN-20180220110011-20180220130011-00252.warc.gz"}