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

Edge Detection

Started by sansured Dec 28, 2008 at 2:23 PM 3 replies 4.7k views
Original Post
sansured
sansured
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.
MJP
MJP
The PostProcessing sample in the SDK has an edge detection shader you can look at.
sansured
sansured
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

sansured
sansured
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.
cruZ
cruZ
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.

Topic Locked

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

Sign in to reply to this topic.