+8
Completed

Outline Alternate Method

Brian Hall 10 years ago updated by Raul Vega 7 years ago 18
We have a lot of objects with hard edges that we need outlines on.  For instance, crates of various sizes.  The problem is the Outline feature breaks at the corners. 

I'd like to see an alternate option to the current outline feature that keeps the vertices connected at the corners:

Image 129

Answer

+3
Answer
Completed
As of 1.19, you can now switch between three different outline methods:
  • Vertex normals
  • Vertex colors
  • From origin
The first one is the default behavior we've had before.
The second one will read the vertex colors as directions. I've added a script you can add to your objects, to make their meshes write outline-style normals into the vertex colors. That way, you sacrifice the ability to use vertex colors, but gain the ability to have hard edges together with a continuous outline!
The third one is as the "scaled" method mentioned above - it will move the verts away from the origin.

Hope it helps :)

It's not ideal, but it's a *very* cheap effect, as it's only using readily available data.

The issue is that in shaders, individual vertices don't know whether or not other vertices are in the same location, which is exactly the case on hard edges. Vertices only have a single normal, so, on hard edges, their normal direction is just the one of the triangles it's associated to.

There is no ideal solution, but there are ways of getting the ideal looking one, with some limitations
The first two are solutions on my end, the third is something you can do now already:

1. Be able to switch outline mode to "Scale" instead of "Normal offset". Essentially works by scaling a copy of the object, and reversing its face normals. The limitation with this is of course that it only works on convex objects that are near-spherical or cuboidal. So, in your case, the "Scale" method would work.
2. Use vertex colors as normals. This would require baking normals to the vertex colors, which would be required by asset creators in a program such as Maya. 
3. Make your meshes 100% smoothed - make tiny bevels at hard edges to make them look sharp, while keeping the mesh smoothed, which will make sure the outline is fully connected.

I think #1 and #2 are viable options for me to implement in SF at some point, but #3 should work right now :)
Just for curiosity,
Is it possible to add a color to the outline based on a texture?
+1
Yes, just plug in a texture into the outline color input. Although it will most likely look a bit weird :)
Cool! I tried now!
I want a 2D style with outline. Might work!
+2
I just wanted to chime in as a new purchaser of Shader Forge that I would love to see the "Scale" option you listed above made available!
Just bought Shader Forge today, I too am interested in an alternate outline method such as the "Scale" method mention. Would be great to have that feature implemented :D
+1
I can prioritize this for the next update
That would be fantastic! I think having both of these option will definitely provide much more option to create a cel shaded world or other effects. Thank you! :D
+3
Answer
Completed
As of 1.19, you can now switch between three different outline methods:
  • Vertex normals
  • Vertex colors
  • From origin
The first one is the default behavior we've had before.
The second one will read the vertex colors as directions. I've added a script you can add to your objects, to make their meshes write outline-style normals into the vertex colors. That way, you sacrifice the ability to use vertex colors, but gain the ability to have hard edges together with a continuous outline!
The third one is as the "scaled" method mentioned above - it will move the verts away from the origin.

Hope it helps :)

Awesome! Can't wait to try this out! :D

Hey Joachim,

Could you elaborate about the outline method using vertex color. I can't seem to find that script to add to your objects. :)

It's included in the Shader Forge package

Oh boy, I looked for it before and now I instantly found it of course :) Thanks for answering anyway, works like a charm now!

Hi, I have an Issue, I`d like to try out the Vertex Color variant of the border feature, the problem Is I`m working with double sided meshes (because of collisions) and it seems the script can't handle it. I can't afford to bevel all the meshes though the game is made of simple geometrical shapes, but It's matter of breakeven.
Isn`t there another possible way working it out as a post effect (i.e. like a classical 1px wireframe)?
Thanks! Great Editor!

It is possible to do it with a post effect, but it's not cheap. It would probably involve multi-sampling the depth buffer and write black if the threshold of the depth buffer is larger than some value, and not write anything if it's below.

@Joachim Is it possible to only outline object? The current one is more of a toony look (Vertex Normals) where as I just want a unit select looking shader (like what games like dota have)

+1

Hello,


I'm using the "soft normals to vertex color" script to be able to make a smooth outline even in geometry with hard edges. It is great. But my problem is that I can only use it with the checkbox "generate on awake" enabled because if I close and open unity the vertex info is gone.

I'd like to use the script to bake the soft normals info into vertex color and then remove the script. Is it posible? Am I misunderstanding the "soft normals to vertex color" script purpose?


Thanks a lot