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

Shader for Outline Contour Points

Discussion in 'Shaders' started by Futtureman, Jun 22, 2020.

  1. Futtureman

    Futtureman

    Joined:
    Jun 4, 2015
    Posts:
    4
    Hi everyone, I have a project about instance segmentation which requires to create contour around certain objects.
    I am currently using OpenCV for detecting edges for every mesh but it feels like workaround because first I am saving texture as grayscale then find contours with OpenCV from these images like above

    image.png
    I have searched shaders for finding silhouttes and outlines but none of them gives me outline contour world or screenspace points for a mesh and I don't really need visualisation.

    So I need a shader which gives me coordinates of outline contour.
     
  2. pdehn

    pdehn

    Joined:
    Oct 17, 2013
    Posts:
    6
    You could implement an edge detector in a shader instead of OpenCV, but you'll still just have an image in that case. it could be marginally faster though, so maybe still a win.

    How exact do you want to be?

    You could get a MVP matrix off the Camera and MeshRender's Transform, then run all the mesh vertices through that and throw out depth, giving a messy triangle network. You'd then need add some vertices for intersections (e.g. from partial self-occlusion) and filter out interior edges.

    ...I don't think it's possible to do something like that with rendering techniques. You might be able to implement parts of such algorithm using compute shaders (whether it's worthwhile is questionable).