- Home /
Inner shadow on procedural 2D surface
I have arbitrary 2D shapes that are created at runtime by slicing other shapes. They are often very close to eachother and need the "shading" inside the mesh.
I have spent hours on end finding out a way to write this shader. Been searching the web for people doing something close to this and found none.
I guess I need a shader that gets all the mesh triangle edges and find the border of the mesh by removing those lines with an opposite line. And then somehow shade pixels based on their proximity to this border. But this sounds very heavy to me and I don't know if its even possible :S
Or maybe I'll procedurally create a purely visual mesh in 3D to get the distinction between my meshes I want (in addition to an invisible simple 2D mesh for further cutting).
I'm open to any suggestions, thanks in advance!
Note: - Very low poly shapes. - Camera is static, Orthographic, Side-view - Mobile (Android) - Meshes are created by user slicing meshes.
EDIT: spelling
Answer by Phong · May 26, 2013 at 08:18 PM
Have you considered using the "colors" channel in the mesh? RageSpline uses this technique to put outlines around its spline based shapes. Its very easy to write a shader that uses colors in the mesh. You probably need to create an extra row of vertices slightly inset from the edge. Then give the edge vertices a dark color and the inset vertices a light color and write your shader to use these vertices.
I will try this out, thanks. I would prefer a pure shader solution, but I guess there is a reason I can't find any trace of it anywhere :)
There are some outline shaders on the Unity Wiki site
http://wiki.unity3d.com/index.php/Shaders
I think I looked at them once but wasn't happy with the performance/appearance. The nice thing about the colors is it is VERY fast and can look great!
Ye, no. Those shaders won't cut it. $$anonymous$$ost of them don't even work on 2D shapes because they use normals to expand. What I would do in that case would be to shrink my mesh. But i have concave meshes as well and would also like it to be a smooth transition. But I think I can make something nice with the inset verts and with vertex-coloring.