Search Unity

Outline from shader peeks through adjacent objects

Discussion in 'Editor & General Support' started by delzhand, Feb 17, 2013.

  1. delzhand

    delzhand

    Joined:
    Jul 20, 2012
    Posts:
    26
    I have a problem I'm not quite sure how to describe, so I hope these pictures will help. I have two adjacent object. They're aligned so their edges meet to a reasonable degree (it's not perfect because they're hexagon and floating point math can only be so precise). But they are the exact same object, at the exact same scale, with the exact same y position.

    They're using the same material and shader, and this isn't something that can be changed - they're blocks of a map editor, and a map could be comprised of hundreds of these blocks, having a different material and/or shader for each item would be a nightmare. The shader is Toony-LightedOutline, and I've modified Toony-BasicOutline so that it works with an orthographic camera by changing

    o.pos.xy += offset * o.pos.z * _Outline;

    to

    o.pos.xy += offset * .004 * 10;

    at line 33. I've confirmed that the same issue exists when using the unmodified shader in perspective mode, so I don't think that's relevant.

    Here's the issue:



    The outline for the closer hex is visible in front of the rear one. The "sides" of the hexagon are split from the top in my modeling program, so the vertex normals are all perpedicular, meaning that extruding the vertices along the normal for the outline shader shouldn't increase their Y position.



    At first I suspected it might be z-fighting, but the effect is consistent as I move the camera around. I'm stumped!
     
  2. delzhand

    delzhand

    Joined:
    Jul 20, 2012
    Posts:
    26
    A second minor tweak to Toony-BasicOutline solved the problem! I added o.pos.z += .00002; to the vertex shader. Basically after the vertexes are extruded, this drops them down an almost imperceptible amount. I had to tweak the value to find the lowest number that worked, but I'm no longer seeing outlines where I don't expect them.