Sign in to follow this  

Non-uniform Shape Scaling

This topic is 3661 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

While i am doing this with directX it is the math and algorithems i am struggling with. My objective is a per-pixel outline shader. IE:- An object is rendered and then i render its outline (like a cartoon style) and the outline is a set thickness NO MATTER HOW FAR AWAY THE OBJECT IS. My first method that did this rendered a wireframe (with front face culling) on top so only the outer wire was visable. After turning antialaising on this gave a 1-pixel width outline that was depth independant. With this method i could not change the width of the outline. My second the method (yes - we are nearly at the question now!) rendered the model twice - once normally then again with a depth dependant scale factor with front dace culling on and the colour forced to black. This worked and gave me the option to tinker with the outline thickness but unfortunatly there are many artifacts. I will show and example below. Blue teapot = Second method. Red teapot = First method. Yellow teapot = No outline method. Up close - Close up Notice the lack of outline on the inside of the blue teapots spout and handle. I beleive this is due to the teapot not being a uniform shape and thus the scaling of the model is uneven. Its is even worse when far away:- Far Away To preserve the outline width when far away the scale factor on the outline model must be bigger. Therefor the artifacts are much worse. And finally my question! Is there a mathmatical way to avoid this? I have been thinking about it for a while now and all i can come up with is keeping all models uniform (ie spheres and cubes etc). It might be that only shapes with voids in their profile (like a donut) or concave profile (like the letter c) have this problem as otherwise the shape is a solid block with no overhangs to show up the scaleing artifacts. An imediate fix is to simply use the same scale factor but i really want to have a uniform outline. My scale factor as applied to each vertex in turn is: originalPosition * (1.0f + (0.01f * dist) ) where dist = distance to the vertex currently being looked at. Any input is welcomed. Regards galapogos

Share this post


Link to post
Share on other sites
Yeah, you're pretty much always going to have problems with the second technique if you rely on scaling the whole object at once.

The way you should be doing it is using a vertex shader on the black outline model to push the verticies out in the direction of the surface normal.

Share this post


Link to post
Share on other sites
There is a way to 'grow' the object in a smarter way than just scaling it, but it's still not perfect. If you scale the vertices along their normals, they'll go the right way in the convex case, and will behave independently of their distance from the origin.

Judging from the cel-shading, you're using shaders already and have the normals running through the pipeline, so if you don't mind adding a line or two to your vertex shader, it's worth a shot.

Share this post


Link to post
Share on other sites

This topic is 3661 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.

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

Sign in to follow this