C# SharpDX how to render outline ?

Recommended Posts

I am trying to render outline for my mesh. I basicly re-render the mesh without texture and put color. My problem is I want to show the outline topmost. When I clear depthview after rendering outline mesh my outline stays background of target mesh but also background of other meshes. I want to show outline top of other meshes but behind of my target mesh ? Is that possible ? If I clear depthview for mesh and outline at this time my mesh will be top of other meshes which I do not want.

Share this post


Link to post
Share on other sites

The way i've done outline rendering before is to do an additional pass of the scene geometry. Enable front face culling, and in this particular pass's vertex shader you'd offset the vertice positions in the direction of the normal (making this secondary mesh layer larger).

Than in the pixel shader you can keep it simple, and just return black or something. This should give you the outline you're looking for. You'll have to do additional checks, and calculations if you want the mesh the mouse is hovering above to be the only one that is outlined, like inverse ray projecting (picking).

Here is the URL i've used before to implement it. It should be pretty easy to translate this from XNA to D3D.  

http://rbwhitaker.wikidot.com/toon-shader

You can also do a sobel operation as a post-processing step to achieve an outline around your meshes. Though imho, it looks to clean for toon renders, but for selection outlining it might be perfect for you

Share this post


Link to post
Share on other sites
35 minutes ago, markypooch said:

The way i've done outline rendering before is to do an additional pass of the scene geometry. Enable front face culling, and in this particular pass's vertex shader you'd offset the vertice positions in the direction of the normal (making this secondary mesh layer larger).

Than in the pixel shader you can keep it simple, and just return black or something. This should give you the outline you're looking for. You'll have to do additional checks, and calculations if you want the mesh the mouse is hovering above to be the only one that is outlined, like inverse ray projecting (picking).

Here is the URL i've used before to implement it. It should be pretty easy to translate this from XNA to D3D.  

http://rbwhitaker.wikidot.com/toon-shader

You can also do a sobel operation as a post-processing step to achieve an outline around your meshes. Though imho, it looks to clean for toon renders, but for selection outlining it might be perfect for you

I render it by clearing  context.ClearDepthStencilView(depthView, DepthStencilClearFlags.Depth, 1.0f, 0); And also I did it larger but I did those already problem is when I have a mesh backwards front mesh's outline stays backward other mesh here is the result and issue : https://www.youtube.com/watch?v=4bcdfndc3sQ&feature=youtu.be

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now