Search Unity

[FREE] [OPEN-SOURCE] Outline Effect

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

  1. Thibaud_SERRE

    Thibaud_SERRE

    Joined:
    Jun 15, 2017
    Posts:
    4
    Hi Cakeslice, first of all great job on this Asset, for the moment the best for me, easy to use, HDR and mobile friendly. Perfect.

    I juste came across some kind of issues, when using Vuforia the ProjectSetting.asset files is modified and seems to make your asset unusable.

    Another little thing is when a Camera start with a rotation a 180 in Y the Outline does not work, I need to start the Camera at 0.0.0 and then rotate the camera for the Outline to work.

    The two issues are in the same project but different scenes, so maybe the two issues are related ?

    I will try to reproduce the issue in a different project and send it to you, but if you or anyone here is aware of this kind of issues and the solutions related please let me know :)

    Oh and I am working on Unity 5.5.2f1 so I can not download your latest release :/ I've downloaded the asset the 19/07/2017 (can't find the exact version number)

    Edit : Both of the problem has been fixed by choosing OpenGLES3 in the PlayerSettings APIs. Thank's again for the great asset, work perfectly fine!
     
    Last edited: Aug 24, 2017
    ina likes this.
  2. WaveKid

    WaveKid

    Joined:
    Mar 5, 2015
    Posts:
    1
    Hey Thanks for this asset its really handy!

    I've had one problem that I've fixed myself. I'm using Unity 2017.1.0f3 (latest release build).
    I noticed I started to get crashes in the editor due to memory leakage. I did some investigating and it was to do with materials in the scene increasing.
    I found in the OutlineEffect.cs that you m = new Material() is used when it doesn't have to be because you already have these materials created. So I just removed the New Material part.

    upload_2017-8-24_14-0-7.png

    Hope this has helped anyone else that had the same problem!
     
    Knarhoi and FaberVi like this.
  3. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    You're welcome :)

    Basically, to draw the outlines I render each object to a buffer using a different shader (OutlineBufferShader).

    You would have to change that shader to include your vertex movement for it to work.
     
  4. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Thanks, glad you got it working!
     
  5. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Thanks for the feedback.

    The reason why I do this, is to support materials that use cutout textures. Since it's causing memory leaks I will try to find another way...
     
    WaveKid likes this.
  6. Efril

    Efril

    Joined:
    Aug 31, 2013
    Posts:
    82
    It seems it is not working when camera set to render only specific layer. Objects set to this layer not outlined. Chair1.PNG Chair2.PNG
     
  7. Efril

    Efril

    Joined:
    Aug 31, 2013
    Posts:
    82
    Ok, I found why this happen. Outline.originalLayer is never set to any value and always 0. It is used in pre render handler to check which game objects to render.
    So replacing this line in OnPreRender method:
    Code (CSharp):
    1. if(outline != null && l == (l | (1 << outline.originalLayer)))
    with
    Code (CSharp):
    1. if (outline != null && l == (l | (1 << outline.gameObject.layer)))
    makes it work for me.
     
    Marvoc likes this.
  8. FaberVi

    FaberVi

    Joined:
    Nov 11, 2014
    Posts:
    146
    I have this problem on Oculus (i use VRTK for oculus, htc vive and all headset.. VRTK for VR are must have.)..

    The first mistake is that I should only highlight the edges and not the whole object, other things in the viewer the left lens looks exactly what I took in the screenshot, in the right lens the effect is moved to the right of the object by actually doing bad if you try to look with both eyes. Does this plugin do not support VR?
     

    Attached Files:

  9. FaberVi

    FaberVi

    Joined:
    Nov 11, 2014
    Posts:
    146
    The bug is the stereo rendering mode in "SinglePass".. If the settings change everything returns to work properly. You can edit the shader for support Single Pass Rendering?

    Or is this the issue? : https://issuetracker.unity3d.com/is...getwidth-in-singlepassrendering-with-htc-vive

    It would be great to run this plugin in single pass mode, performance in VR would definitely be better.

    I also edit this code (check null) for fixed rare errors on activating outline object:

    Code (CSharp):
    1.                             if(mL)
    2.                             {
    3.                                 if(mL.sharedMesh != null)
    4.                                 {
    5.                                     for (int i = 1; i < mL.sharedMesh.subMeshCount; i++)
    6.                                         commandBuffer.DrawRenderer(outline.GetComponent<Renderer>(), m, i, 0);
    7.                                 }
    8.                                
    9.                             }
    10.                             SkinnedMeshRenderer sMR = outline.GetComponent<SkinnedMeshRenderer>();
    11.                             if(sMR)
    12.                             {
    13.                                 if (sMR.sharedMesh != null)
    14.                                 {
    15.                                     for (int i = 1; i < sMR.sharedMesh.subMeshCount; i++)
    16.                                         commandBuffer.DrawRenderer(outline.GetComponent<Renderer>(), m, i, 0);
    17.                                 }
    18.                             }
     
    Last edited: Sep 15, 2017
  10. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    I have the same issue in Single pass stereo VR (Unity 2017.1). The objects get covered completely. Though, I can't say much about how it looks in the headset, since I don't have a headset myself (but I saw the error through a teamviewer video call with a teammate). Anyway, I'd appreciate it if anyone has any idea what it could be.
     
    FaberVi likes this.
  11. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    You're right, thanks for the fix!
     
  12. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Yeah, sorry guys but this effect does not support VR in single pass mode. If someone knows how it can be implemented, please help!

    Also, @D3m0n thanks for the null checks, I forgot about them!
     
    Alverik likes this.
  13. Efril

    Efril

    Joined:
    Aug 31, 2013
    Posts:
    82
    @cakeslice is it possible to have outlines with color 1 rendered in front of outlines with color 0 and outlines with color 2 rendered in front of outlines with color 1? In the attached screenshot Outline component enabled on both ship compartment game object and boiler game object but only ship compartment actually outlined.
    Outline.png
     
    Last edited: Sep 18, 2017
  14. xoidberg

    xoidberg

    Joined:
    Aug 21, 2015
    Posts:
    1
    Asset is working great. Thank you for that!
    It would really be nice to have more than 3 outline colors :)
     
    FaberVi likes this.
  15. FaberVi

    FaberVi

    Joined:
    Nov 11, 2014
    Posts:
    146
    @cakeslice yeah, an List or Array it would be better!
     
  16. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    I was recently looking at the shaders and I think the limit is due to the way the shader is coded. The shader would need to be modified to get it to work with more colors... Or a different approach would be necessary (like material swap, or some other form of highlighting which affects the object's meshes if their outline component is active)...
     
    Last edited: Sep 21, 2017
  17. Blacksky33

    Blacksky33

    Joined:
    Oct 5, 2016
    Posts:
    1
    Got an issue with the new build, i put the fix form Efril:
    NullReferenceException: Object reference not set to an instance of an object
    cakeslice.OutlineEffect.OnPreRender () (at Assets/OutlineEffect/OutlineEffect.cs:186)
     
  18. viveleroi

    viveleroi

    Joined:
    Jan 2, 2017
    Posts:
    91
    What's the recommended way to disable/turn off an outline? I was originally setting GetComponent<Outline>().enabled = false, but that likely means I can't use the "erase renderer" option which I need.
     
  19. danBourquin

    danBourquin

    Joined:
    Nov 16, 2016
    Posts:
    34
    Hey! Thank you so much for this stuff. It's very usefull!
    I have a small question. Maybe I missed something but is there a way to not render the outline when another gameobject is on front? I mean I woul'd like to have the outline on a tree but if the player is between the camera and the tree he would hide the outline part behind him.
    Like this chest on World of Warcraft where the soldier mask some part of the chest outline:
     
  20. morphinegames

    morphinegames

    Joined:
    Mar 13, 2015
    Posts:
    33
    Hey guys - I needed to add more than 3 colors to this and I went through the code and figured out what was going on and modified it to support up to 7 custom colors. I'm not 100% sure on everything that this shader is doing, but I did realize that it's doing a bitmap to determine which color to shade and it's currently using the r g and b values. Previously the shader was looking to see if the r, g, or b was set and it would pick the color based on that, I added checks for the following pairs as well, r + g, r + b, g + b, and r + g + b effectively yielding 4 more colors to choose from.

    I could go further I believe and use the alpha component to increase this number further, but I"m concerned the number of comparisons in the shader will be too high and I don't personally need that right now. If I end up increasing it, I will post the additions here.

    The ZIP attached has the modifications and should be a drop in replacement for the asset store one. I believe that submitting this is OK since the owner has made the project open source, but if he wants me to delete this post I will.


     

    Attached Files:

  21. morphinegames

    morphinegames

    Joined:
    Mar 13, 2015
    Posts:
    33
    Aww heck, I'm going to go full bore and do all 16 - 1 combinations (0000 has special meaning) and while I'm at it optimize the # of comparisons

    EDIT: turns out that the shader uses the alpha channel, so max is 7 in the current setup
     
    Last edited: Sep 29, 2017
    Alverik likes this.
  22. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    Wow, well, 7 is plenty enough, it's a great upgrade for the shader and system in general. Only needs to be tested for performance, I guess? Just wish someone could help me getting it to work in Single Pass Stereo rendering... lol...
     
  23. morphinegames

    morphinegames

    Joined:
    Mar 13, 2015
    Posts:
    33
    I don't know very much about shaders at all, but I'm pretty good at code so was able to figure out how to add 4 more colors. Regarding Single Pass Stereo - I wouldn't even know where to begin.

    I profiled the shader before and after the color additions and while I'm sure there is some change in performance, I couldn't detect it on my rig which is super beefy. It really boils down to a couple more shader properties and a few more if statements - although I hear branches in shaders are bad...
     
  24. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    197
    Sorry for the wait guys, I have been very busy!

    Sorry but no, there is not outline "order" since it's based on the image drawn not individual objects.
    As for the bug, you can send me a project that reproduces the issue and I will take a look.

    What do you want to achieve exactly?

    You can add an outline to the player and use the "Erase Renderer" option (wouldn't outline the player just make it erase outlines)

    Of course it's okay any help is appreciated, thanks!
    Everyone is always asking for more colors but I never went with this solution because I'm afraid it will be too expensive performance wise. I'm now considering just making it an option.
    As for the alpha, it's used for the opacity of the outline.
     
  25. morphinegames

    morphinegames

    Joined:
    Mar 13, 2015
    Posts:
    33
    Maybe just include two separate unitypackages within the one, one with full 7 and one with 3. I don't really know how to profile shaders, so I'm not sure about how expensive it is, but it hasn't affected the framerate in my desktop game. Mobile might be different story though.
     
  26. morphinegames

    morphinegames

    Joined:
    Mar 13, 2015
    Posts:
    33
    OK guys, so I found that I did end up needing more than 7. I was able to get this working by modifying the scripts a little bit to support 2+ instances of the OutlineEffect. Granted, this isn't going to be wise on mobile, but the effect can be pretty lean on desktop and my game isn't intense anyways, so I have the budget.

    The way it works is as follows, from top to bottom the OutlineEffect color index will be the absolute index, so for example, if I want to have a White box in the picture below, the color on the object's Outline will be 7. 0-6 is the first OutlineEffect and the second OutlineEffect takes over 7-13. The third would be 14-20 and on and on.

    I tested this with 3 so far and lots of objects on screen and as you can see in the pic my frame rate is still doing well. FYI - the blue boxes at the very right are a test of a 3rd OutlineEffect and they have their color set to 14.

     

    Attached Files:

    RodrigoSeVeN, FaberVi and Alverik like this.
  27. FaberVi

    FaberVi

    Joined:
    Nov 11, 2014
    Posts:
    146
    Is it possible to create a "mask" object behind which the outline can not be seen if it is active?
     
  28. brennan_agm

    brennan_agm

    Joined:
    Oct 12, 2017
    Posts:
    2
    Is there a way to make the highlight fade out from the center?
     
  29. Nikolay1243

    Nikolay1243

    Joined:
    Jul 2, 2013
    Posts:
    9
    This doesnt work if you set "AddLinesBetweenColors" on and color index higher than 2

    Fix is in OutlineShader to comment out line 99-101
    /*if ((red && blue) || (green && blue) || (red && green))
    return float4(0,0,0,0);
    else*/

    which is a half fix because now they dont internally draw outlines
     
    Last edited: Oct 18, 2017
  30. Nikolay1243

    Nikolay1243

    Joined:
    Jul 2, 2013
    Posts:
    9
    Ok, found the solution...basically the

    Code (CSharp):
    1. IEnumerable<OutlineEffect> effects = Camera.allCameras.AsEnumerable()
    2.                 .SelectMany(c => c.GetComponents<OutlineEffect>())
    3.                 .Where(e => e != null);
    was adding the outline component to all the outline effects which is obviously wrong if you want multiple different outlineEffect components
     
  31. aralambomahay

    aralambomahay

    Joined:
    Apr 12, 2017
    Posts:
    10
    Thanks for this asset, it's incredible.
    I have looked into your shader (OutlineShader) and I don't understand the way you did to assign color on the 2nd pass.
    Code (CSharp):
    1. if (sample1.r > h || sample2.r > h || sample3.r > h || sample4.r > h)
    2.                 {
    3.                     outline = _LineColor1 * _LineIntensity * _LineColor1.a;
    4.                     if (outsideDark)
    5.                         originalPixel *= 1 - _LineColor1.a;
    6.                     hasOutline = true;
    7.                 }
    8.                 else if (sample1.g > h || sample2.g > h || sample3.g > h || sample4.g > h)
    9.                 {
    10.                     outline = _LineColor2 * _LineIntensity * _LineColor2.a;
    11.                     if (outsideDark)
    12.                         originalPixel *= 1 - _LineColor2.a;
    13.                     hasOutline = true;
    14.                 }
    15.                 else if (sample1.b > h || sample2.b > h || sample3.b > h || sample4.b > h)
    16.                 {
    17.                     outline = _LineColor3 * _LineIntensity * _LineColor3.a;
    18.                     if (outsideDark)
    19.                         originalPixel *= 1 - _LineColor3.a;
    20.                     hasOutline = true;
    21.                 }
     
  32. callen

    callen

    Joined:
    Dec 31, 2013
    Posts:
    33
    Thanks for releasing this effect for free! Unfortunately for me, it is not working out well. Is there anything I can do to fix this issue? See image below:

    https://imgur.com/a/jQw02 (Sorry the image won't display inline for me, the link is breaking...)

    Maybe there is something weird with the mesh geometry on this seashell, but I have a few other objects that are showing the same effect. I've tried messing with all the settings but nothing seems to remedy it. Any advice? Thanks!

    UPDATE: I've mostly fixed the issue shown above. I switched to using a different outline shader which seems simpler, but I did have to add a "ZTest Always" to the first pass to remove similar artifacts. So maybe there's also a solution for this shader with ZTest, but I am using the other due to its simplicity
     
    Last edited: Oct 27, 2017
  33. Ozer_Jigme

    Ozer_Jigme

    Joined:
    Nov 2, 2016
    Posts:
    12
    This is such a cool asset and freeeee!

    A couple of questions for cakeslice or any other wizards here:

    - Is there a way to stop the outline from merging between different objects?
    - a way to vary the width based on distance from the camera?

    Thanks in advance! I'd happily pay $10 for these features. It's the best looking outline I've found on the asset store.
     
  34. Nikolay1243

    Nikolay1243

    Joined:
    Jul 2, 2013
    Posts:
    9
    To stop the outline from merging between different object you have to use different color indexes(not colours) in the OutlineEffect component... So for example you can have all three(or 7 with the extension) be the exact same color but your outline objects use different outline indexes.
     
    Alverik likes this.
  35. ivan_tbl

    ivan_tbl

    Joined:
    Sep 20, 2017
    Posts:
    5
    Awesome asset. Thank you.

    But, I have a small problem.

    When I add a png as a texture, the Erase Renderer option stops working. Once the outline is there, it won't go away.
    But if I manually remove the png during play mode, all goes back to working perfectly.

    Thanks in advance to anyone that can help me out with this.
     
  36. viveleroi

    viveleroi

    Joined:
    Jan 2, 2017
    Posts:
    91
    I have world objects like trees, rocks, etc. When the player targets one with a tool, the outline effect should be visible. However, visually it appears over all other objects. Since there's no "sort order"/render layer, you've recommended that the "erase renderer" be used. From my research it sounds like I need to add an erase renderer to every *other* object (that's not being highlighted).

    It's been a few months so I apologize, but i believe my issue was that I can't turn off the outline effect for a specific element without also killing its ability to be an "erase renderer".
     
    Ozer_Jigme likes this.
  37. fleischverpackung

    fleischverpackung

    Joined:
    Feb 23, 2016
    Posts:
    18
    Hi guys,

    I have multiple objects with the outline effect and want to disable and enable them via script.
    Thing is I am unable to access the outline component during runtime.
    I do find the gameobject, but I can't enable or disable the component itself, or change the color parameter.

    Any hints on how to access this?
    merci
     
  38. ivan_tbl

    ivan_tbl

    Joined:
    Sep 20, 2017
    Posts:
    5
    I'm using a Raycaster to pick which object I want.

    Then i'll toggle the Erase Renderer like this:
    Code (CSharp):
    1. GameObject currentSelection;
    2.  
    3. currentSelection = cameraRaycaster.hit.collider.gameObject;
    4.  
    5. currentSelection.GetComponent<Outline>().eraseRenderer = true;
    The problem I'm having is that since that object has a png texture, it stopped erasing the renderer (it works perfectly if I remove the texture from the object, though)
     
  39. yurilin1

    yurilin1

    Joined:
    May 22, 2013
    Posts:
    102
    help.png
    I found when the mesh outline component's color is the same (for example = 0)
    When they collided, the shader only shades one outline around them but not their intersected section.
    As the shader only got 3 colors, many outlines would face such problem.
    Would you help to change this setting or fix it?
    Thanks!

    The object1 and object2 got the same outline color.
    The object 3 and object2 got the different outline color.

    objects are script generated mesh with standard material and shader.
     
    Last edited: Dec 22, 2017
  40. FullHeartGames

    FullHeartGames

    Joined:
    Jul 21, 2015
    Posts:
    18
    Thanks awesome asset! I am having an issue though, I was playing with and realized it grey's out my material that is on my object. Now I removed all the outline scripts from camera and objects but many objects are still grayed out in game view? Please help..

    upload_2017-12-27_12-26-0.png
     

    Attached Files:

  41. FullHeartGames

    FullHeartGames

    Joined:
    Jul 21, 2015
    Posts:
    18
  42. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    This is super cool! Thanks alot @cakeslice for sharing this and everyone else for improving upon it. Artists like myself would be lost without ya! Gotta love this community!

    sharin' is carin'
     
  43. ThunderSoul

    ThunderSoul

    Joined:
    Sep 28, 2016
    Posts:
    63
    This doesn't seem to work... I created a fresh 3D cube, dragged "Outline.cs" script, and that's it, nothing happens. I don't have documentation for this so I'm not sure this is enough... The asset also says it's highly customizable but I don't see any customization anywhere... Am I doing something wrong or is this asset bummed out with the release of Unity3D 2017? Thanks!
     
  44. morphinegames

    morphinegames

    Joined:
    Mar 13, 2015
    Posts:
    33
    Add OutlineEffect component to the main camera in your scene. I was literally using this today in 2017.3 and it works fine
     
  45. FullHeartGames

    FullHeartGames

    Joined:
    Jul 21, 2015
    Posts:
    18
    Still need help^^
     
  46. betahelix

    betahelix

    Joined:
    Jan 16, 2018
    Posts:
    1
    Is it possible for the outline effect to ignore elements that are on a culling mask that is hidden to the primary camera?

    Edit: Nevermind. This can be solved by setting Outline.originalLayer to the correct layer, or by changing line 180 in OutlineEffect:
    Code (csharp):
    1. if (outline != null && l == (l | (1 << outline.gameObject.layer)))
     
    Last edited: Jan 16, 2018
  47. Zidan2k9

    Zidan2k9

    Joined:
    Feb 25, 2014
    Posts:
    1
    Does this asset support multiple cameras?
     
  48. unity_e37J3FSssmROgA

    unity_e37J3FSssmROgA

    Joined:
    Feb 28, 2018
    Posts:
    4
    Any idea on how to use it with UMA2 - Unity Multipurpose Avatar? When I try to add Outline script to character, it gives "Adding component failed", because it asks for a Renderer, which is not shown on the game object created when using UMA2.
     
  49. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    You should add it after the renderer is created. Hook into the OnCharacterCreated event, and add the component in the event handler.
     
  50. unity_e37J3FSssmROgA

    unity_e37J3FSssmROgA

    Joined:
    Feb 28, 2018
    Posts:
    4
    Oh, right, I see the event handler.

    Sorry for this beginner question, but how I make the reference to the gameobject that has the renderer?

    I created a simple script with "gameObject.AddComponent<cakeslice.Outline>();" and attached to the event handler called "Character Created (UMAData)" but looks like Im not indicating the right gameObject.