Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Shader for Outline Contour Points

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

  1. Futtureman

    Futtureman

    Joined:
    Jun 4, 2015
    Posts:
    2
    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).
     
unityunity