Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Submesh border?

Discussion in 'Shaders' started by Seraphim-Whiteless, Jan 17, 2020.

  1. Seraphim-Whiteless

    Seraphim-Whiteless

    Joined:
    Jun 23, 2014
    Posts:
    197
    Hi everyone!

    Having mesh with dynamic submeshes.
    Not textured. Only colored meshes.

    How can i mark submesh border points?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    What do you mean by "mark submesh border points"? Are you asking for a way to draw a line of some kind where two submeshes meet? And presumably, because you're asking this in the shader subforum, you're also asking how to do this with a shader.

    The answer is you can't. It's impossible to mark the border between submeshes with a shader since shaders don't know about submeshes. Realistically, a shader only ever knows about a single vertex or a single pixel at a time. Even tessellation & geometry shaders only know about a single input triangle at a time. And that's for a single mesh; even if there was a way to know about more than just a triangle at a time, as far as a GPU is concerned each submesh is a completely separate thing. The "sub" part of the submesh is purely a CPU side construct.

    So, solutions:
    1. On the border between your submeshes, manually build a line strip submesh in c#.
    2. Use a custom post process edge detection shader.
    3. Mark the edge vertices with some kind of vertex property when constructing the mesh and use a custom shader that draws a line there (see wireframe shaders).