Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Source project to the 2011 Siggraph Object Outlines Effect

Discussion in 'Image Effects' started by brad_gopositron, Jul 21, 2016.

  1. brad_gopositron

    brad_gopositron

    Joined:
    Jul 21, 2016
    Posts:
    3
    Just wondering if anyone at Unity can share the selected object outlines effect as shown in pages 46-47 here:

    http://beta.unity3d.com/talks/Siggraph2011_SpecialEffectsWithDepth_WithNotes.pdf

    We need it for a project where we only want certain objects selected to have the outline effect, and I haven't had much luck with my own implementations with shaders and post processing effects. Thanks in advance to anyone who can help!
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,000
  3. brad_gopositron

    brad_gopositron

    Joined:
    Jul 21, 2016
    Posts:
    3
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    Funny enough I implemented almost exactly the system described in that talk for our games specifically because it doesn't work as a post process. I'm working on a PSVR game and full screen post process effects are generally avoided as much as possible.

    I can't share the source directly but here's the short version:

    A script that either adds a command buffer or, perhaps more simply, uses OnRenderObject() and DrawMeshNow() to re-render the object you want highlighted. I went with command buffers instead of OnRenderObject as it gave a little more control. Alternatively you can just have a second mesh renderer you turn on and off that uses the "outline" material set instead of the normal material for that object. Even more alternatively you can append extra materials to a renderer's sharedMaterials list and it'll draw the mesh an additional time for every extra material! I would probably have used that last method had I know about it originally (and I still might go back and change it to use that).

    A shader that takes _CameraDepthTexture and samples the pixel around it and does a depth test. You can look at various sobel filters for the implementation of getting outlines from depth, and you can look at Unity's built in particle shaders for examples on sampling the depth texture from a normal mesh rather than in a camera image effect.

    Now there are a few things to be aware of. Because this method uses the depth buffer it doesn't highlight objects that are flush or close to a wall / floor / etc. it also won't highlight objects that are behind walls. The outline is actually an innerline so you can't have big glows around objects and thin objects start to become solid colors.

    The post process style version of these effects benefit from being able to choose different kinds of behaviors. For my purposes working on a VR game most of the "benefits" of the post process method, especially being able to draw through walls, wasn't actually useful so the benefits didn't outweigh the costs.
     
  5. brad_gopositron

    brad_gopositron

    Joined:
    Jul 21, 2016
    Posts:
    3

    Thanks for the informative post! I hadn't thought about using OnRenderObject, and I am also working on a VR game so this method would work. I was playing with command buffers as well and was wondering if that was a better way to go. Thanks again for replying on some methods of achieving this, it will certainly help!
     
  6. Torigas

    Torigas

    Joined:
    Jan 1, 2014
    Posts:
    63
    It would still be awesome if the Unity people could release that project. Some of the effects would be great to learn from.
     
  7. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,000
  8. colin299

    colin299

    Joined:
    Sep 2, 2013
    Posts:
    176
    if you can doing VR(performance is important), and you need a per object outline, why not just using a 2 pass extrude outline shader? you can just switch material between "normal" & "normal+outline" when needed
    I did use this method of outline, you can see the result below(not selection outline, but the method is the same)