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

[FREE] [OPEN-SOURCE] Outline Effect

Discussion in 'Assets and Asset Store' started by cakeslice, Mar 28, 2015.

  1. reinfeldx

    reinfeldx

    Joined:
    Nov 23, 2013
    Posts:
    164
    Sorry for flooding the thread here, but I ran into something else:



    I'm using the outlines to give an environment a wireframe look, but when my player exits the room I set up, I'm getting unexpected behavior. Despite being separate objects, when the walls overlap from the players point of view, the doorway's outline shows gaps as a result of the interior walls. A neat effect, but it's the opposite of what I need. The outlines made by Unity's legacy toon shader (while ugly and inferior) leave overlapping outlines like my doorway here intact.

    Anything I can do about this?
     
  2. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Please send me a project that reproduces the issue and I'll take a look!
     
  3. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    No this is just the way the effect works, it creates a single outline around multiple objects.
     
  4. reinfeldx

    reinfeldx

    Joined:
    Nov 23, 2013
    Posts:
    164
    Gotcha. Assuming there's not a way I can hack the effect, I'll probably have to forego using it for my walls. It's great for other things though!
     
  5. StephenRJudge27

    StephenRJudge27

    Joined:
    Sep 2, 2015
    Posts:
    24
    Would it be possible to add a feature where the reverse side of the mesh is visible?
     
  6. wampastompa

    wampastompa

    Joined:
    Apr 19, 2014
    Posts:
    6
    Hey! Very cool asset, I'm impressed!

    There's one issue that's keeping me from using this, though. I'd like to use it to show which character is selected in my scene, but the characters need to be able to be flipped horizontally. It seems like the outline disappears on 2D sprites if the horizontal scale is negative or if the sprite is rotated 180 along the y axis. This can be replicated easily in the demo scene.

    Any idea on how to make the outlines work when the sprite is flipped?

    Thanks!
     
  7. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Hello guys, you're welcome!

    To do this go to OutlineBufferShader.shader and uncomment the "Cull Off" line (44)

    EDIT: Now you just have to toggle "Backface Culling" to false in the image effect (before playing the scene)
     
    Last edited: Jul 3, 2017
  8. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    VR is now supported! Check it out: github.com/cakeslice/Outline-Effect
     
    Last edited: Apr 1, 2017
    faduci, SAOTA and Alverik like this.
  9. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    Thanks! Will test it tonight!
     
  10. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Download the latest version from GitHub, it should work!
     
  11. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    Yup, they finally aligned! ;) Now, I just have a question: Sometimes when an outline area (in this case a plane/box) is inside another object like a treasure chest (or sometimes partially inside another object) the outline plane just starts to look torn or broken. I remember I alleviated that issue by change some setting in the OutlineEffect script (but that was weeks ago so I can't recall). Still even that way some corners still looked a bit like "chipped" or cracked (with missing bits). Is there a way to deal with that issue?

    Anyway, it's kinda late here now, so I'll see if I can get you some screenshots tomorrow, so you can see what I mean. Anyway, thanks for the update :)
     
  12. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Alright send me the screenshots, I'll take a look.

    You're welcome! :)
     
  13. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    Here's the screenshot of how it looks:


    It gets better if I lower the alpha cutout in the effect.
     
  14. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    813
    Is there anyway to make this work without a directional light?
     
  15. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    I'm not sure what is causing that to happen, can you send me a project that replicates the issue?
     
    Alverik likes this.
  16. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    It's supposed to work, make sure you have the latest version.

    Also if that doesn't work please send me a project that replicates the issue.
     
  17. SAOTA

    SAOTA

    Joined:
    Feb 9, 2015
    Posts:
    220
    It works in Multi-Pass VR. Not so much with Single Pass.

    If anyone wants to try.
    Here are some readings.

    https://forum.unity3d.com/threads/s...srefraction-effect-of-effects-package.418239/
    https://forum.unity3d.com/threads/single-pass-stereo-with-imageeffectopaque-onrenderimage.406918/
    https://docs.unity3d.com/Manual/SinglePassStereoRendering.html

    *edit almost there by changing Line 163 in OutlineShader to

    Code (CSharp):
    1.         half4 originalPixel = tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(input.uv, _MainTex_ST));
    Thanks Cakeslice.
     
    Last edited: Apr 3, 2017
    RusVoin and punk like this.
  18. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    813
    After more testing it seems like the test scene that I have had some issues with camera effects that made the outline not work without a directional light. I will try to clean the scene and send it over just in case.
     
  19. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Super sexy.

    I discovered your outline effect a while back, but back then it wasn't really suited for my project, and I tried to adapt another effect to fit my project. Unity 5.5 broke that effect and it had a number of limitations that I wasn't sure how to fix. However with your latest additions I was able to just drop your effect directly into my project and replace the old effect in 10 minutes.

    One question though. Is it possible to make the "erase renderer" behaviour a global setting? I haven't really looked at your code yet, and I'm not even sure I want outlines to show through objects or not in my project, I'm just asking in advance. :)

    Currently to stop outlines from showing through I would have to add the Outline component to every other object in the scene and tell it to erase renderer, right?
     
  20. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Yes, currently it's the only way. To add a global setting, I would need to use the depth buffer of the main camera when rendering to the outline buffer.

    I will add that to my todo list but can't make any promises.
     
  21. Blueskai

    Blueskai

    Joined:
    Jul 25, 2014
    Posts:
    16
    A bug that i found, if the sprite is rotated 180 degress on the Y axis or just flipped on X axis (x = -1), or just flipped on X axis (in spriterenderer options) then the outline disappears
     
  22. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    This is not a bug, it's just backface culling. The latest version on GitHub has an option to disable it (called "Backface Culling")
     
  23. Blueskai

    Blueskai

    Joined:
    Jul 25, 2014
    Posts:
    16
    very much thank you :D you put a lot of effort and time into this, you should get more recognition
     
  24. Blueskai

    Blueskai

    Joined:
    Jul 25, 2014
    Posts:
    16
    is there a way to make the outline be behind other sprite layers? because they are always rendered on top
     
  25. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Yes, you have to toggle the "Erase Renderer" option (using the Outline component) on the object you want to be on top of the outline
     
  26. VrTechEx

    VrTechEx

    Joined:
    Aug 4, 2013
    Posts:
    40
    When the sprite turn -1 in localscale, the outline is flipped to the other side... any solutions? Thank you !! I used backface culling but nothing happened !?
     
    Last edited: Apr 15, 2017
  27. batteryyrettab

    batteryyrettab

    Joined:
    Sep 20, 2013
    Posts:
    7
    Wow! Just wanted to say thank you so much for your time and effort (and willingness to share it for free)! This is a great effect and works really well. Just reading this thread shows you're really up on supporting it too. Thanks again - it's much appreciated!
     
    cakeslice likes this.
  28. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    Sorry for the late reply. I've been kinda busy so I'll try to make a repo project whenever I actually find some free time. (plus it's not too critical right now cause lowering the alpha cutout makes the problem mostly disappear).
     
  29. Andrei_S

    Andrei_S

    Joined:
    Oct 31, 2012
    Posts:
    11
    I had this same problem. Using the outline effect on GearVR, the effect just don't appear when there is no Directional Light or the Direction Light is set to Baked.

    Also, when there is a Realtime Directional Light, the effect looks a bit offset to the right. Screenshots from the GearVR:
    Screenshot1.png Screenshot2.png
     
  30. tcmeric

    tcmeric

    Joined:
    Dec 21, 2016
    Posts:
    190
    Thanks to the OP for this nice little package. I created a short tutorial about setting it up. It covers just the basics but it does the job I think. In the second half of my tutorial, I show how to use it with playmaker actions that I wrote for this asset. You can download the playmaker actions for free (under MIT license).

    Outline Effect playmaker actions: https://github.com/dumbgamedev/outlineEffect_Playmaker

     
    Last edited: Apr 19, 2017
    Alverik and cakeslice like this.
  31. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Sorry but I can't replicate this, can you send me a project with the problem?
     
  32. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Thanks for the feedback, will look into it
     
  33. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Thank you guys!
     
    tcmeric and Alverik like this.
  34. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Hmm, I just realized that this effect is crazy expensive. I'm using it in an RPG and if I have 30-40 items on the ground it more than doubles my drawcalls. If I go into the dungeon and there's 30-ish enemies around my drawcalls go from 800 to over 3000 which seems to indicate it's even more expensive on skinned meshes than on normal meshes.

    I'm not sure if this makes the effect unusable for me or not yet. Currently I just highlight everything that the player can interact with when I press the ALT-key, but I haven't decided exactly how I want to use it yet. I don't think I'm going to have enemies be highlighted for example so that would reduce the performance impact quite a bit, but I'm thinking I could end up with a lot more than 30-40 items on the ground at the same time.

    I thought this was a post processing effect where the performance impact only depended on your resolution, but I guess I have no clue how it works or how post processing effects work. :p I will compare it to the outline effect that I deleted when I started using this one to compare performance.
     
  35. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    You probably know why this effect creates so many draw calls? I'm guessing it has to do with the approach chosen?

    At first I thought this effect created 30-50 draw calls per mesh, but then I realized that my zombies which I were testing had a separate eye mesh (just 2 quads) and the main body mesh. Removing the outline component from the eyes didn't change the outline at all, but removed 20 draw calls per zombie. I then went into your demo scene and tested with gamma/linear, forward/deferred, hdr on/off and none of that made a difference, I did this just to make sure my project settings didn't affect the result. I then tested with a simple cube and with the chairs you included in the demo scene. It seems that the amount of drawl calls is tied to mesh complexity in a way I do not understand. If you have a single mesh like my zombie with arms, legs, head etc. (I tried with just a normal mesh renderer and not a skinned mesh renderer) the outline adds 20 draw calls and I can visually see in the frame debugger that the same mesh is drawn 20 times, if I do the same to a cube it only adds 2 draw calls.

    I love the look of this effect, but currently it's just too expensive for me.

    I compared it to my original glow (based on this one http://xroft666.blogspot.no/2015/07/glow-highlighting-in-unity.html) and it only adds 1 draw call per mesh at all times. And when I have it enabled for 30-40 items and 30-40 zombies the difference is unplayable performance vs barely noticeable. This effect uses command buffers and not a separate camera from what I can tell.

    I'm clueless as to how either of these effects work, I'm just trying to find a solid glow/outline I can use for many different projects. I don't think the other asset can have different colored outlines showing at the same time though, a potentially big drawback.

    There's also this guy who makes a ton of really cool stuff for Unity:


    He has both a double camera outline and a command buffer outline in his project and while both of them work perfectly in his example scene they actually crash Unity for me if I try to use them in a different project. :p And it seems his approach requires a custom material or custom shader property to work which makes it a bit more cumbersome to use. It supports unlimited glow colors at the same time though.

    Sorry, this is maybe not all that related to your asset, I just wanted to mention it.
     
    Last edited: Apr 22, 2017
    Alverik and tcmeric like this.
  36. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    I know that guy, he has some great effect examples in his youtube channel (better than anything you'll find anywhere else). In the same outline glow project he has a command buffer version that doesn't require the custom shader (as far as I remember). It does look like an effect he made for a Jam, though, so not sure it's polished enough for all game types (and it doesn't work on VR so, it's a no go for me).
     
  37. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Yes, this whole thing made me want to see if I can make my own outline/glow and his tutorial is as good an introduction as I could hope for. I've always been intimidated by shaders, but this effect seems rather approachable compared to more advanced stuff, it's just that there's so many different approaches. :p

    The unique thing about this outline effect and maybe what makes it so expensive compared to the others is that it creates an actual outline around the mesh, all the other effects I've tried just blur the object itself to create a glow. I prefer the outline approach. The outline is also alpha blended and not additive. I have no clue if it's easy to adapt the other effects to not be additive, but I prefer the alpha blended look because my game is both bright and dark. An additive glow/outline disappears when it's bright and becomes too bright when it's dark. :p

    I'll give it a go. And if cakeslice has any insight that would be welcome as well, the best thing would of course be that I didn't have to make anything myself. :D But I don't want to hijack this thread so I'll leave and experiment some on my own.
     
  38. TiaJC

    TiaJC

    Joined:
    Apr 2, 2017
    Posts:
    1
    There was an error when using it in my project “In order to call GetTransformInfoExpectUpToDate, RendererUpdateManager.UpdateAll must be called first.”,help me
     
  39. joeri_07

    joeri_07

    Joined:
    Dec 18, 2015
    Posts:
    45
    Awesome script!

    But it doesn't seem to be working when the "outline" script is added on an object with a network identity.. Can somebody confirm this?

    EDIT: It isn't working if the camera with the outline-effect script is added to the Player prefab object attached to the Network Manager.

    Thnx!
     
    Last edited: May 2, 2017
  40. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Please send me a unity project that reproduces the issue so I can take a look
     
  41. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Why would you need the camera on the Player prefab? Regardless, if you send me a unity project with the issue I will take a look
     
  42. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Thank you for the extensive performance analysis, I will see if I can do something about it
     
  43. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    565
    Where is the documentation ? I'd like to know exactly what each option does and the performance impact.

    For example, what is "Fill Amount" ?
     
    JLowther likes this.
  44. joeri_07

    joeri_07

    Joined:
    Dec 18, 2015
    Posts:
    45
    Hi,

    When a camera is following a multiplayer player 1st person / 3th person, shouldn't the camera be connected to that player GameObject?

    Here's a simple project with the bug: https://github.com/JoeriBultheel/outlineExample

    Click on the scene 'Game' to start. Everything seems to be working, with an outline-effect component on the camera of 'myPlayer' and outline component on the objects.

    Now click on the 'Lobby' scene and start. The 'Game' scene is initialised by the networkManager, and although the 'player-networked' prefab has an outline-effect component, i'm not seeing the effect take place when looking at the objects.

    Thnx !
     
  45. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    565
    This effect interferes with 2D collider collisions... Any idea why?
     
  46. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    This is because you have 2 cameras active (on each player) at the same time, the effect only works on a single camera. I suggest you use a single camera for the local player and move it to other players if you want a spectator mode.
     
  47. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    As usual, please send a project that reproduces the issue.
     
  48. joeri_07

    joeri_07

    Joined:
    Dec 18, 2015
    Posts:
    45
    I'm afraid that's not the problem. Try deleting the -already present- myplayer gameobject in the 'game' scene, and run the game again from the 'lobby' scene. Now the only camera in that scene is the one of the spawned player, but the problem persists. No outline anywhere...

    thnx for the help! really want to get this working :)
     
  49. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    You were right, get the latest version on GitHub for the fix.
     
  50. joeri_07

    joeri_07

    Joined:
    Dec 18, 2015
    Posts:
    45
    Works!

    You are awesome.
     
    cakeslice likes this.