Search Unity

[FREE] [OPEN-SOURCE] Outline Effect

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

  1. Martinx09

    Martinx09

    Joined:
    Sep 27, 2013
    Posts:
    22
    Hi, I'm having a problem that I was hoping you guys could help me with,
    I have thousands of gameobjects on my game (I know, it's not the best for optimization),
    but it was working fine before adding the outline effect,
    I tested first adding the outline effect on a world with around 1000 gameobjects,
    and it runs fine (60+ fps), the system is great btw.. worked as I wanted from the get go.

    The problem started when I made a bigger world (around 800.000 objects),
    here fps dropped to 1-2 and I noticed on the profiler that it was due to the outline effect,
    specifically OutlineEffect.OnPreRender(), I disabled the Outline Effect component,
    and performance went up to 500-600 fps.

    What could be the problem and how could I approach it?
     
  2. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Hello, first how are you rendering 800.000 objects at 500 fps? That doesn't sound right.

    Also if you could give me a scene that reproduces this issue, it would be great.
     
    WILEz1975 likes this.
  3. Martinx09

    Martinx09

    Joined:
    Sep 27, 2013
    Posts:
    22
    Hey!

    Not all of them are being rendered, they are all created and existing in the scene,
    but most have their renderer disabled.

    I partially fixed the issue by disabling the outline component on the ones that are not being rendered (this was pretty obvious, sorry about that) still dropped from 600 to around 200 fps though.

    I have a new problem,
    for sprites it doesn't work right when you flip them.
     
  4. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    There's an option to fix the flipping: "Backface culling"
     
  5. Xib

    Xib

    Joined:
    Apr 24, 2017
    Posts:
    7
    Did you try it in Unity 5.6.1 ? It seems to be broken in that version of unity. I tried both the GitHub version and the current Asset Store version.

    It seems to still work on smaller objects but on bigger there are some sides missing depending on what angle you watch from (It's not Backface culling since disabling and enabling does nothing)
     
    Cleversan likes this.
  6. Cleversan

    Cleversan

    Joined:
    Nov 25, 2015
    Posts:
    11
    Yes, there are some issues in Unity 5.6.1 :(
     
  7. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Yeah I can confirm disabling backface culling isn't working, I will take a look
     
  8. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Sorry can't see the image you attached
     
  9. Cleversan

    Cleversan

    Joined:
    Nov 25, 2015
    Posts:
    11
    Ok, one more time Untitled.png
     

    Attached Files:

  10. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Can you also give me an image in 5.5 so I can understand the problem?
     
  11. Cleversan

    Cleversan

    Joined:
    Nov 25, 2015
    Posts:
    11
    Of course - from Unity 5.6.0. Different angle but same building. v560.png
     
  12. Xib

    Xib

    Joined:
    Apr 24, 2017
    Posts:
    7
    In 5.6.1p1 it is slightly better but it still doesn't render the full mesh on the RenderTexture, maybe something with the material generation is off, didn't look to deep into the code of the outline effect.
     
  13. Cleversan

    Cleversan

    Joined:
    Nov 25, 2015
    Posts:
    11
    In 5.6.1p1 it looks exactly same as in 5.6.1f1
     
  14. skipadu

    skipadu

    Joined:
    Jan 19, 2016
    Posts:
    3
    It seems that after I updated Unity to the current latest version ( 5.6.1f1 ) Outline effects are no longer working anywhere in my project. Tried to go "back in time" with version control, so that I'm sure that they were working, but still no luck.
    But the demo scene of the Outline Effect works.

    Not really know what to try next to fix this.

    EDIT: I had "Allow HDR" checked in my Main Camera. When I disabled it (it is also disabled in the demo), it started working.
     
    Last edited: May 20, 2017
    Xib likes this.
  15. Xib

    Xib

    Joined:
    Apr 24, 2017
    Posts:
    7
    Can confirm, HDR breaks the outline effect in the most recent version.

    With HDR enabled on main camera


    With HDR disabled on main camera
     
  16. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Hello guys, I'm trying to replicate this in 5.6.1p1 in the demo but I can't. Please post the platform you're using and the try to replicate the issue using the demo. It would help a lot in fixing the issue.

    Thanks.
     
  17. Anoarith

    Anoarith

    Joined:
    Nov 22, 2013
    Posts:
    2
    Hi ! Thanks a lot for your very usefull plugin !

    I think I just found an issue (and I'm not yet on 5.6) : when I use an object with the script Outline attached to it and the option "Erase Renderer", it doesn't seems to work when the SpriteRenderer of this object have FlipX or FlipY set to true (I checked and it works perfectly when set to false).

    Any idea on how to fix this ? Thanks in advance
     
  18. Xib

    Xib

    Joined:
    Apr 24, 2017
    Posts:
    7
    Made a video showcasing it in the demo scene


    It's basically just enabling and disabling HDR on the main camera. I'm working on Windows and Unity 5.6.1p1

    As you can see, on the Text and transparent cube the outline disappears completely and on the chair it's somehow factured and incomplete.
     
  19. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Thanks guys, this is now fixed in the latest GitHub commit and will be in the asset store soon.
     
  20. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    For flipped sprites, you have to disable "Backface Culling" and you have to do it before you hit play.
     
  21. Cleversan

    Cleversan

    Joined:
    Nov 25, 2015
    Posts:
    11
    Thank you, but unfortunately I have exactly same result (with HDR enabled) :(
     
  22. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Yeah this is so wierd, if you just open the project and run the demo it works!

    It has to do with the project settings, there must be one of them that is causing this...
     
  23. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Ok, so there's this variable in the EditorSettings.asset that is causing this and I have no idea why.

    If you want to fix it change this in your ProjectSettings/EditorSettings.asset file:
    m_DefaultBehaviorMode: 0 to m_DefaultBehaviorMode: 1

    NOTE: You need to enable "Force Text" in Project Settings => Editor => Asset Serialization to be able to edit the file.
     
  24. Cleversan

    Cleversan

    Joined:
    Nov 25, 2015
    Posts:
    11
    I can change it directly in Project Settings => Editor => Default Behaviour Mode, right? 0 is for 3D, 1 is for 2D. Same results for both, even with Unity restarted. It has to be something with Unity 5.6.1. 5.6.0 works fine.
     
  25. Anoarith

    Anoarith

    Joined:
    Nov 22, 2013
    Posts:
    2
    ohhh indeed ! Thank you so much !
     
  26. Xib

    Xib

    Joined:
    Apr 24, 2017
    Posts:
    7
    Can confirm, it's still not working in 5.6.1 it's something different.
     
  27. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    204
    I think I may have borked something in my project (noobie) because the outline is really jagged, like it needs AA. Looking at the screen shots in this thread, the outline appears smooth. Any idea what I might have borked up?

    BTW, absolutely awesome of you to make this available for free. It's an amazing resource for learning, so thanks very much.
     
  28. Xib

    Xib

    Joined:
    Apr 24, 2017
    Posts:
    7
    It's not broken in your project that's how this effect is working, you shouldn't make the outline too thick or you will see ma stairs-corner-thingies. I also use heavy AA and bloom related blurring which is pretty much hiding this issue.
     
    Ben_Iyan likes this.
  29. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    204
    Thanks a lot!
     
  30. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    204
    What settings do you use to minimize the jagged effect? Minimum line thickness is 1, which is where mine is set, so I was wondering what other things you changed.
     
  31. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Yeah, there's not a lot you can do about this, however I'm planning to add a super sampling option that can render outlines without jaggies (but will also have a performance cost)
     
  32. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    204
    That would be awesome! I'm looking forward to trying it and, again, thank you for doing this for us noobs. It is really appreciated.
     
  33. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Yeah I think this is a bug in 5.6.1, I'm going to wait for a few patch releases to see if they fix it because I'm out of ideas.
     
  34. Cleversan

    Cleversan

    Joined:
    Nov 25, 2015
    Posts:
    11
    I will check 5.6.1p2 and let you know if it works.
     
  35. Cleversan

    Cleversan

    Joined:
    Nov 25, 2015
    Posts:
    11
    No improvement in 5.6.1p2 :(
     
  36. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Okay I think I fixed it for real this time. It was an alpha blending issue. Please test the new version: https://github.com/cakeslice/Outline-Effect
     
    Rotary-Heart likes this.
  37. Cleversan

    Cleversan

    Joined:
    Nov 25, 2015
    Posts:
    11
    It works fine again! Thank you very much :)
     
  38. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    813
    I can confirm that this fixes the issue with 5.6.1
     
  39. ikazrima

    ikazrima

    Joined:
    Feb 11, 2014
    Posts:
    320
    Very nice :)

    I have an error though, hope you can help. This is all 1 mesh, but the outline appears only on certain parts of the model.
    upload_2017-6-5_16-10-46.png
     
  40. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Are you sure there's only 1 MeshRenderer in that object? You have to apply the outline to all MeshRenderers for it to work.

    If not, please send a project that reproduces the issue, I'll take a look
     
  41. ikazrima

    ikazrima

    Joined:
    Feb 11, 2014
    Posts:
    320
    Yes there's only one. I'll send a PM.
     
  42. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Alright I figured it out. You used vertex painting on the mesh and the outline buffer shader uses vertex colors to work properly with sprites.

    If you really need vertex painting for some reason you can disable this by removing "* IN.color" in line 75 of OutlineBufferShader.shader and OutlineBufferShaderCullOff.shader
     
    ikazrima likes this.
  43. ikazrima

    ikazrima

    Joined:
    Feb 11, 2014
    Posts:
    320
    Works great, thanks!
     
  44. NextGenVideoGames

    NextGenVideoGames

    Joined:
    Dec 28, 2016
    Posts:
    1
    Thanks for this amazing asset! I have one question though. I have no idea how to program shaders, so wondering if you knew. Is there a way to only display the outline and fill only when the object is behind another? Thanks in advance! :)
     
  45. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Right now this is only possible if you add an Outline component to the object that is in front of it and toggle the option "Erase Renderer". In the demo scene there's an example of this (the cube on top of the right chair)
     
  46. Symphonym

    Symphonym

    Joined:
    Feb 24, 2015
    Posts:
    2
    I have a game in which some areas are completely dark (complete blackness, no light), and when the outlined objects (or parts of it) are in these areas then the outlines doesn't appear. This is easily reproduced by turning ambient lighting to 0 and removing all reflections in the demo scene (disable reflection probe) as well as removing the environmental lighting from the skybox. Any way to make it so that the outlines appears even when the object is in completely dark areas?
     
    Last edited: Jun 9, 2017
  47. Symphonym

    Symphonym

    Joined:
    Feb 24, 2015
    Posts:
    2
    Alright so I solved this after some fiddling, changing the surface shader pass in OutlineBufferShader to this:

    o.Albedo = _Color * alpha;
    o.Alpha = alpha;
    o.Emission = o.Albedo;

    (The only thing I added was the emission line, which makes it self-illuminated and show even in completely dark areas)

    Disclaimer: I'm know very little about shaders and this took me a while to figure out, no idea how this affects the rest of the asset.
     
    cakeslice likes this.
  48. Gronkwena

    Gronkwena

    Joined:
    Feb 20, 2015
    Posts:
    3
    Hi, thanks for making this script, has been very useful for me.
    Just some feedback from a bug I have just come across.

    I reloaded a level and for some reason all the outline effects were broken up and not rendering correctly (see pic). After some investigation, it seemed to be caused by the outline script being attached to an object with a material with a cut-out transparency on it. It was effecting all outlined objects, not just itself. However, it doesn't seem to happen consistently, it took a bit of fiddling to replicate the bug, and the bug didn't happen until today despite the same object having been in the scene for some weeks.

    Not sure exactly what had changed in the scene for it to trigger into being into an issue, but seeing as other people have had similar issues, thought I would report as to how I fixed it.

    A couple of other minor points :-
    1) The outline script seems to react badly if the object has a missing material. This caused me a lot of grief trying to track down (although it seems better now the memory leak issue is fixed)
    2) The performance hit is quite high, having about 30 outlined objects in my scene halves my FPS. Not a major issue for me as FPS is still over 200, but could be a limitation in future.

    Hope this information is useful, thanks again for making the script and releasing it for free at this point. There are similar things on the asset store, but none do what this does for free. :)
     

    Attached Files:

    cakeslice likes this.
  49. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Yes that solution works and should not have any side effects, thanks for sharing!
     
  50. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Thanks for the feedback, if you could give me a project that reproduces the issue it would be great!