Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

[FREE] [OPEN-SOURCE] Outline Effect

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

  1. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    4,563
    The renderer is underneath the main avatar on a child game object, You'll need to look for the renderer using GetComponentInChildren<SkinnedMeshRenderer>(), assuming you put your script on the game object with the DCA.
     
  2. unity_e37J3FSssmROgA

    unity_e37J3FSssmROgA

    Joined:
    Feb 28, 2018
    Posts:
    4
    It worked! Thank you, Jaimi.
    Here is the code I've used (not sure if its the best):

    Code (CSharp):
    1.  
    2. private void Update()
    3.     {
    4.        
    5.         if (!isUpdated)
    6.         {
    7.  
    8.             if (transform.childCount > 0)
    9.             {
    10.                 foreach (Transform child in transform)
    11.                 {
    12.                     if (child.GetComponent<SkinnedMeshRenderer>() !=  null)
    13.                     {
    14.                         child.gameObject.AddComponent<cakeslice.Outline>();
    15.                         isUpdated = true;
    16.                     }
    17.                 }
    18.  
    19.             }
    20.         }
    21.        
    22.     }
    23.  
     
    Jaimi likes this.
  3. hublard

    hublard

    Joined:
    Aug 19, 2015
    Posts:
    47
    Is it possible to draw outline only when object is behind an other specific sprite like house/wall?

    for example:

    i got a 2d top down game. all objects are sprites. now when a player is behind a house then it should draw the outline of the player behind the house.

    right now when it put script on player. there is always drawn a outline anyway if player is behind an object or not.
     
  4. jexmatex

    jexmatex

    Joined:
    Jun 23, 2016
    Posts:
    36
    Hello,

    Many thanks for this very useful asset,
    does anyone achieve to make it work with HDR activated ?

    thx by advance
     
  5. brunzero

    brunzero

    Joined:
    Jul 10, 2015
    Posts:
    7
    does anyone have any insight on to how i would go about smoothing these lines?
     
  6. seijik42

    seijik42

    Joined:
    Sep 8, 2013
    Posts:
    5
    Thank you for great plugin!
    Currently I'm facing an issue and not sure where to check.

    When I use this with ARKit on mobile, outline effect doesn't appear.

    - Outline effect + ARKit + run on iMac editor: works!
    - Outline effect + example project + run on iPhone: works!
    - Outline effect + ARKit + run on iPhone: No outline

    Has anybody tried this with ARKit?
    I'm a programmer so I can debug myself but no idea where to start first..
    Even no error log is showing.

    Thanks!
     
  7. Setsuki

    Setsuki

    Joined:
    Aug 21, 2012
    Posts:
    23
    Almost perfect, a few quirks here and there that are easy to fix depending on the situation great work!
     
  8. ekergraphics

    ekergraphics

    Joined:
    Feb 22, 2017
    Posts:
    257
    This is a very good outlining asset.

    For reference if anyone wants to use it for VR, it's a bit expensive. In our profiler, it consumes 0.3ms with the effect disabled, and 1.0ms with it enabled on a few objects.
     
  9. m4a44

    m4a44

    Joined:
    Mar 13, 2013
    Posts:
    17
    So, I believe I can help you with supporting single pass stereoscopic rendering (just had the problem where the right eye is offset and had to get it working). And it also looks more performant than the secondary camera technique.

    Instead of using a secondary camera (the "outlineCamera"), I am now using the main camera with an initial CommandBuffer (the one that draws the objects to be outlined).
    mainCam.AddCommandBuffer(CameraEvent.BeforeImageEffects, outlineCommandBuffer);


    That outlineCommandBuffer then draws to a RenderTexture (along side the rest of the main camera's normal rendering) that I then use to apply the rest of the effects in OnRenderImage.

    The only weird thing I saw was that the RenderTexture didn't clear properly, but I fixed that by putting a clear into the buffer at the beginning (after I assigned the RenderTexture).
    outlineCommandBuffer.ClearRenderTarget(true, true, Color.black);


    I hope this helps you and other people.
     
    Last edited: Apr 20, 2018
    ropemonkey and ekergraphics like this.
  10. ekergraphics

    ekergraphics

    Joined:
    Feb 22, 2017
    Posts:
    257
  11. occurrentarts

    occurrentarts

    Joined:
    Apr 29, 2014
    Posts:
    3
    I'm having this issue also in 2018.2.0b2
    It looks like this asset and ARKit's UnityARVideo.cs both use command buffers, could there be a conflict there?
    Or perhaps there's an issue with Metal?

    I get this error
    A null value was found where an object instance was required.
    in xcode when i try and turn on the object outline script with:
    this.gameObject.GetComponent<cakeslice.Outline>().enabled = true;

    which suggests to me that the component is removed when built on iOS.

    Does anyone know why this might be happening?
     
  12. Zulhalsing

    Zulhalsing

    Joined:
    Feb 25, 2017
    Posts:
    1
    Dear sir,

    May I know the possibility to get the information of object outline volume and position array from this asset? Thanks a lot.
     
  13. olekkus

    olekkus

    Joined:
    Nov 21, 2017
    Posts:
    1
    Hi

    I'm using the enable outline effect (with playmaker) on an asset that has no LOD's and it works fine but on an asset that is having LOD component and than use it on LOD0 (the closest will get outline when selected) and the script doesnt seem to react whan willing to disable the outline. enabling works fine tho but disable doesn't work for me with assets with LOD
     
  14. m4a44

    m4a44

    Joined:
    Mar 13, 2013
    Posts:
    17
    If you're referring to the changes I mentioned, they weren't done to the cakeslice outline effect. So I don't have changes to submit.
    The in house outline effect that I'm currently using is far simpler, but used to use the same technique (a secondary camera).
     
  15. XN4k3dBR

    XN4k3dBR

    Joined:
    Sep 15, 2015
    Posts:
    11
    The outline's seem to be rendered ontop of everything else in my scene, see imagem atached.
    Help-me!.
     

    Attached Files:

  16. XOA_Productions

    XOA_Productions

    Joined:
    Nov 27, 2016
    Posts:
    24
    Hey There!

    Really nice outline effect, thank you a lot!
    I've also made a modified version, to use the outline effect to solve the issue of transparent insides of meshes when they are partially in the camera's near clip plane. I wanted to make it look like objects had a texture or color in them, so it's more realistic when my users move their cam through objects:

    clipping.PNG noClipping.PNG

    All this is is a small change in the OutlineBufferShader.shader (but needs a bit more work if you want to use the outline normally as well), if anyone is interested:

    Code (CSharp):
    1. Shader "Hidden/OutlineBufferEffect" {
    2.     Properties
    3.     {
    4.         [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
    5.         _Color ("Tint", Color) = (1,1,1,1)
    6.         [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
    7.     }
    8.  
    9.     SubShader
    10.         {
    11.  
    12.                 Tags
    13.                 {
    14.                     "Queue" = "Transparent"
    15.                     "IgnoreProjector" = "True"
    16.                     "RenderType" = "Transparent"
    17.                     "PreviewType" = "Plane"
    18.                     "CanUseSpriteAtlas" = "True"
    19.                 }
    20.  
    21.                 // Change this stuff in OutlineEffect.cs instead!
    22.                 //ZWrite Off
    23.                 //Blend One OneMinusSrcAlpha
    24.                 Cull Off////[_Culling]
    25.                 Lighting Off
    26.  
    27.                 CGPROGRAM
    28.  
    29.                 #pragma surface surf Lambert vertex:vert nofog noshadow noambient nolightmap novertexlights noshadowmask nometa //keepalpha
    30.                 #pragma multi_compile _ PIXELSNAP_ON
    31.                 #include "UnityCG.cginc"
    32.                 sampler2D _MainTex;
    33.                 fixed4 _Color;
    34.                 float _OutlineAlphaCutoff;
    35.  
    36.                 struct Input
    37.                 {
    38.                     float2 uv_MainTex;
    39.                     float3 vertexNormal;
    40.                     float3 vertexPosition;
    41.                  
    42.  
    43.                  
    44.                     //fixed4 color;
    45.                 };
    46.  
    47.                 void vert(inout appdata_full v, out Input o)
    48.                 {
    49.                     #if defined(PIXELSNAP_ON)
    50.                     v.vertex = UnityPixelSnap(v.vertex);
    51.                     #endif
    52.                  
    53.                     UNITY_INITIALIZE_OUTPUT(Input, o);
    54.                     o.vertexNormal = UnityObjectToWorldNormal(v.normal);
    55.                     o.vertexPosition = mul(unity_ObjectToWorld, v.vertex).xyz; ;
    56.  
    57.                  
    58.                  
    59.                  
    60.                  
    61.                 }
    62.                 bool isFacingForward(float3 vertexNormal, float3 vertexPosition) {
    63.                     return dot(normalize(UnityWorldSpaceViewDir(vertexPosition)), vertexNormal) <= 0;
    64.                 }
    65.  
    66.                 void surf(Input IN, inout SurfaceOutput o)
    67.                 {
    68.                     fixed4 c = tex2D(_MainTex, IN.uv_MainTex);// * IN.color;
    69.                     if (c.a < _OutlineAlphaCutoff ) discard;
    70.  
    71.                     float alpha = c.a * 99999999;
    72.  
    73.                     o.Albedo = _Color * alpha;
    74.  
    75.                     o.Alpha = alpha;
    76.  
    77.                     if (!isFacingForward(IN.vertexNormal, IN.vertexPosition))
    78.                         o.Albedo = fixed4(0,0,0,0);
    79.  
    80.                     o.Emission = o.Albedo;
    81.                 }
    82.  
    83.                 ENDCG
    84.  
    85.                  
    86.             }
    87.      
    88.      
    89.  
    90.     Fallback "Transparent/VertexLit"
    91. }
     
    Last edited: Jun 30, 2018
    IgnisIncendio, Xelnath and tcmeric like this.
  17. BurmesterVR

    BurmesterVR

    Joined:
    Sep 9, 2016
    Posts:
    4
    Hi! Nice asset :)

    Is there any way to make this work with a canvas renderer (in this case, a Raw Image element)... or at least the 'Erase Renderer' part? I'm displaying a top-down othorgraphic view that shows the outlines on various objects, but the camera also has a canvas attached using 'Screen Space - Camera'. The outline shows above my UI elements, one of which is showing a rendertexture view from another camera using RawImage in a UI element in the top right corner. The objects are obscured by the UI element but the outlines are still visible. (See Image) Example.png

    Many thanks for any help!
    Alex.
     
  18. jasonboukheir

    jasonboukheir

    Joined:
    May 3, 2017
    Posts:
    4
    Hi there.

    I'd like to make the color and materials be assigned to the Outline component, rather than the OutlineEffect comonent. Right now I can only fade in/out 3 objects at a time with the 3 colors in the OutlineEffect.

    Is this a bad idea? Any recommendations on achieving independent colors for more than 3 Outlines?

    Thanks.
     
  19. R3aper235

    R3aper235

    Joined:
    Feb 15, 2013
    Posts:
    13
    Hi,
    I have been using this asset in my project and have found out that this causes a huge fps drop in my game on android. I hope it's not only me who is facing this issue. What do you guys think about the mobile performance issues with this effect ?
     
  20. unity_BfhJRB37TPcoUg

    unity_BfhJRB37TPcoUg

    Joined:
    Jun 23, 2018
    Posts:
    2
    Hey there,

    Sorry to bother you guys. But I seem to be getting a little issue here. The Outlines on my sword look a bit off. Sorry for the poor image quality. PS: I have not been using unity long so just getting the ropes.

     
  21. unity_BfhJRB37TPcoUg

    unity_BfhJRB37TPcoUg

    Joined:
    Jun 23, 2018
    Posts:
    2
    Here is a more extreme example of my issue.

    https://imgur.com/a/PGENdsa

     
  22. sandboks

    sandboks

    Joined:
    Oct 21, 2016
    Posts:
    3
    We used this for mobile and it has been simple to implement. We had some inconsitant testing results on whether it is working on iPhone. As it turns out, it works on iPhone running iOS9-10.x - It is not working on iPhone X (2017) running iOS11.X We are not sure if it is GPU or OS. Does anyone know how the renderer works and if we can find a tweak for iPhoneX/iOS11+.
     
  23. kyrchristod

    kyrchristod

    Joined:
    Jul 7, 2018
    Posts:
    1
    Hello. Thank you very much for the asset. It is really useful. I have a problem I hope you could help me with.
    I have two cameras (First / Third Person) and I switch from one to another. I have attached the Outline Effect Script on both of them. Also I have around 20 objects that I wanted to outline so I attached them the Outline Script. I also have attached to these objects another script that on Start and onMouseExit disables the Outline Script and onMouseOver enables it.
    The problem is when I make the camera switch twice, the second time I do it all objects have the Outline Script enabled obviously without the mouse being over them.
    What might be the problem?
    TEMPORARY SOLUTION: I had to set enable to false of the component of the paintings and of the previous active camera and true for the forthcoming active camera. It still has a problem when a painting is outlined and camera changes.
     
    Last edited: Oct 20, 2018
  24. Ziplock9000

    Ziplock9000

    Joined:
    Jan 26, 2016
    Posts:
    155
    Did you find a fix to this problem as I have the same issue.
    I have many objects with the outline script attached and NOT enabled.
    Somehow these scripts become enabled not only at runtime but after the project is stopped and you are in design time.
    Manually setting enabled=false in awake or active is not an option, it's a hack.
    Does anyone know code is making these active?

    Thanks.

    UPDATE

    I found the culprit in OutlineEffects.cs

    Change the following code and comment out the interior:
    Code (CSharp):
    1.  
    2.         private void OnEnable()
    3.         {
    4.             /*
    5.             Outline[] o = FindObjectsOfType<Outline>();
    6.  
    7.             foreach(Outline oL in o)
    8.             {
    9.                 oL.enabled = false;
    10.                 oL.enabled = true;
    11.             }
    12.             */
    13.         }
    It's designed to cascade any enable changes to the main outline effects on the camera down to the outline scripts on the objects. This makes sense if you disable it. But it does not make sense for a lot of other circumstances like highlights starting as disabled.
     
    Last edited: Nov 2, 2018
  25. feldondragon

    feldondragon

    Joined:
    Dec 4, 2018
    Posts:
    4
    Is there any way to Outline working without "shaking" when TAA is ON?
     
  26. feldondragon

    feldondragon

    Joined:
    Dec 4, 2018
    Posts:
    4
    I have same problem - did you solve this? If you do, please share the solution. I'll appreciate that :)
     
  27. sujitmarcus

    sujitmarcus

    Joined:
    Sep 1, 2018
    Posts:
    3
    Awesome.. How Can i use Erase Option? Please help
     
  28. Shabazza

    Shabazza

    Joined:
    Dec 30, 2018
    Posts:
    1
    In Unity 2018.3.0f2 the Line Thickness property does not seem to work. It's always the same, regardless of setting.
    And btw: Thanks for this great script.
    It might be relatively performance intensive, but for my current newbie-project, it works just fine.
     
  29. Maximelene

    Maximelene

    Joined:
    Dec 10, 2014
    Posts:
    1
    I had the same problem, and corrected it by creating a secondary camera in the exact same place as my main camera, without TAA, and putting it as the Source Camera in the Outline Effect script (which stays on the main camera).
     
    Last edited: Jan 23, 2019
  30. son1cman

    son1cman

    Joined:
    Jan 2, 2015
    Posts:
    14
    Hi!! i was wondering a simple hack to draw the outline inside the object pixels and not outside!! Thanks in advanced
     
  31. kris111

    kris111

    Joined:
    Aug 11, 2016
    Posts:
    3
    ivan_tbl wrote:
    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.


    Hello,

    I have the same problem as described by ivan_tbl. When in runtime I check/uncheck Erase Renderer flag, the object erases outline effects of outlined objects located behind. That works fine if there is no texture assigned to the object that erases outline. But when I assign texture and check/uncheck Erase Renderer flag the outline effects doesn't disappear.

    We would appreciate any support. outline error.png
     
  32. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    184
    Hello guys, I've attached the fix for this issue. Just replace the OutlineEffect.cs file with this one.

    Cheers!
     

    Attached Files:

  33. EricLowry

    EricLowry

    Joined:
    Apr 12, 2015
    Posts:
    7
    Hi there,

    I'm working on a project that was just switched to LWRP, and it seems that all outlines have simply disappeared.
    I am at a bit of a loss here because I'm getting no errors or anything, just no outlines :/

    Anyone have an idea of how to deal with this?
    Thanks! =D
     
  34. Zafaron

    Zafaron

    Joined:
    Dec 20, 2018
    Posts:
    7
    Really useful asset, thanks for providing it. Took me a while to realize you were using a different namespace, but everything went smoothly after that :p
     
  35. Numa

    Numa

    Joined:
    Oct 7, 2014
    Posts:
    36
    Hi, thanks for the great plugin!

    In outlineEffect.cs, onPreRender() you check for
    Code (CSharp):
    1. outline.Renderer.sharedMaterials[v].mainTexture != null
    but it looks like this still throws an error if the material doesn't have a main texture? Maybe also check for this?
    Code (CSharp):
    1. outline.Renderer.sharedMaterials[v].HasProperty("_MainTex")
    Cheers
     
    Last edited: Mar 26, 2019
  36. ZhavShaw

    ZhavShaw

    Joined:
    Aug 12, 2013
    Posts:
    121
    Same issue here
     
  37. TheFlyvio

    TheFlyvio

    Joined:
    Jul 23, 2013
    Posts:
    15
    Hello! First of all, thanks for this amazing asset.
    I think I found a bug: when enabling the script OutlineEffect in the camera, it disables and reenables all outlines in the game, even the ones disabled in the first place. A if command will fix this:
    Code (csharp):
    1.  
    2. private void OnEnable()
    3.         {
    4.             Outline[] o = FindObjectsOfType<Outline>();
    5.  
    6.             foreach(Outline oL in o)
    7.             {
    8.               if(oL.enabled) {
    9.                 oL.enabled = false;
    10.                 oL.enabled = true;
    11.               }
    12.             }
    13.         }
    14.  
     
    Last edited: Apr 10, 2019
  38. limyc105077

    limyc105077

    Joined:
    Jul 2, 2017
    Posts:
    3
    Hi Cake Slice! Firstly, I want to thank you for this wonderful asset. Simple and easy to use! I have implemented this asset more or less successfully into my project. However, I have two questions:

    1) Is this asset supported in Unity's lightweight render pipeline? If it does, I added the scripts to the camera and the outlined object, is there something else that needs to be done?

    2) Is there a way to separate outline between game objects? Or is some setting in my project wrong?
     
  39. limyc105077

    limyc105077

    Joined:
    Jul 2, 2017
    Posts:
    3

    I managed to find a way. turns out most of the problems i here can be solved through toggling a few bools in the scripts through the editor. So sorry!
     
  40. limyc105077

    limyc105077

    Joined:
    Jul 2, 2017
    Posts:
    3
    However, I found other problems! Before I continue, I realize and apologize for not stating that my project is 2D based, and my sprites/animations are done using Spine.

    I realize that a second camera (outline camera) is used to render a compiled texture of the gameobjects that has the "outline" script. I do not want my weapon trails to be outlined, so I made the weapon trails using particle system.


    So far I have gotten what I want, except :
    1) I managed to include the particle meshes into the Outline classes. But I prefer if it followed the sprite's alpha. Is there a way to do this?
    2) If the mesh is behind the character, it will still cause the outline to be removed. For the character sprite I modified a standard surface shader to have backface culling (to deal with the flipped sprites). Before when I used the default Spine shader it ignored the mesh and z position of the sprite (so the trail is rendered on top of the sprite, even though it was behind it when viewed from the 3D view). Please let me know how I can overcome this problem.


    I think another way to solve both these problems, is to somehow draw the outlines beforethe rendering of the particles (weapon trails). I used the frame debugger to figure out when it was drawn -- but I really have no idea how to change it. Hoping you could help me with an easier alternative!
     
    Last edited: Apr 15, 2019
  41. CastleSeven

    CastleSeven

    Joined:
    Jan 24, 2018
    Posts:
    1
    FYI I'm pretty sure FindObjectsOfType won't return inactive objects.
     
  42. unity_9pYv4DPIt_U7UQ

    unity_9pYv4DPIt_U7UQ

    Joined:
    Mar 31, 2019
    Posts:
    2
    Hi great asset!

    It is literally the only solution ive found that works to outline a flat mesh where all the normals are in the same direction.

    Im using it to create a "Spell indicator" system... that being said, is there anyway to stop the outline from rendering over all my other objects without having to put the outline script and setting it to erase on literally every GameObject that has a renderer?
     
  43. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    769
    This doesn't seem to work for Unlit textures - the outline does not show on mobile for Vuforia though it works in editor
     
  44. TonyVT-Lab

    TonyVT-Lab

    Joined:
    May 8, 2019
    Posts:
    1
    Did you make it work in LWRP? If so, how?
     
  45. skydestinies

    skydestinies

    Joined:
    Feb 6, 2014
    Posts:
    11
    I would also like to know this. I recently switched to using LWRP and I'd like to know if this outline effect asset is still compatible.
     
  46. 3Dmajid2013

    3Dmajid2013

    Joined:
    Oct 19, 2012
    Posts:
    72
    How i can have multiple Outline with different Colors and Far Camera property ?
     
  47. loliconest

    loliconest

    Joined:
    Sep 21, 2015
    Posts:
    26
    I wish the outline can work without the camera and visible in scene view.
     
  48. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    134
  49. WILEz1975

    WILEz1975

    Joined:
    Mar 23, 2013
    Posts:
    288
    Hi!
    Is it possible to use "Erase Render" objects only if they are in front of the object?
    This is my problem.

    Even if the door is behind, it hides the effect.
    It solves?