Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    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,024
    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:
    24
    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:
    6
    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:
    13
    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:
    250
    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:
    12
    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
    goliathmb and ekergraphics like this.
  10. ekergraphics

    ekergraphics

    Joined:
    Feb 22, 2017
    Posts:
    250
  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:
    12
    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:
    23
    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
    Xelnath and tcmeric like this.
  17. BurmesterVR

    BurmesterVR

    Joined:
    Sep 9, 2016
    Posts:
    1
    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:
    2
    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. Einst31n

    Einst31n

    Joined:
    Feb 15, 2013
    Posts:
    8
    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?