Jump to content
  • Advertisement
Sign in to follow this  
sansured

Edge Detection

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

If you intended to correct an error in the post then please contact us.

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 this post


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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!