Search Unity

Screen-space outline effect for Unity (FREE)

Discussion in 'Assets and Asset Store' started by Arvtesh, Feb 27, 2020.

  1. wiiwiiwiiwiiwii2001

    wiiwiiwiiwiiwii2001

    Joined:
    Mar 6, 2019
    Posts:
    2
    Thanks a lot for pointing that out, it all now works as intended!
     
    mishakozlov74 likes this.
  2. haydspin

    haydspin

    Joined:
    Feb 5, 2021
    Posts:
    1
    I'm having a few issues with my setup - I don't know if I'm running into limitations of the effect or my setup is wrong. Hopefully someone can help:



    The left plant is a sprite - alpha test works great, outline tightly follows the texture. The right plant is a plane with an alpha clip material with the same texture - alpha test doesn't seem to be working here. The same issue is happening at the bottom of the vending machine, the outline is not following the cutout shape, it's just following the mesh. Lastly, the outline of the vending machine is shaping around the character when occluded (hard to tell, but it's most obvious around the top) instead of just blocking the outline. The last one I'm not sure is just by design of the asset though. I'm using URP Version 11.0.0 and I've attached a screenshot of my render feature settings. I've tried messing with the depth testing and alpha testing flags in the settings and different alpha cutoffs. This is the only asset I've found that even discusses alpha test with outlines, so hopefully I can get it working. Any advice would be very appreciated!

     
  3. Arvtesh

    Arvtesh

    Joined:
    Aug 16, 2014
    Posts:
    94
    The alpha test feature relies on _Cutoff shader param of the material used by the sprite. If the is no such param, it uses Alpha Cutoff value from the Outline Feature settings. Try settings it to different values and see if it helps. If not, please send me a repro project (or the shader) for testing.
     
  4. Arvtesh

    Arvtesh

    Joined:
    Aug 16, 2014
    Posts:
    94
    Hello everyone! A new patch with some bugs fixed and minor improvements is out (v0.8.5). Thanks for your feedback and ideas!

    Added

    • Added support for HDR color pickers (#42).
    Fixed
    • Fixed URP depth testing with MSAA enabled when using OutlineLayerCollection, thanks @AGM-GR for help (#39).
    • Added loop unroll statement to make shaders compatible with some platforms (WebGL 1.0) (#45).
    • Removed BeginSample/EndSample profiler calls when rendering outlines to get rid of the editor errors (#44).
     
    webik150, tonytopper and MadMonkey119 like this.
  5. MadMonkey119

    MadMonkey119

    Joined:
    Dec 20, 2013
    Posts:
    64
    Hello, this is one of the best outline assets I have tried yet, so thanks a lot. However, I do have one problem due to how I utilize the render objects feature of the URP. My view model layer renders at a different FOV than my main camera and due to this the outline is rendered in the incorrect position.



    Is there anyway to support this behaviour? Thanks
     
  6. Arvtesh

    Arvtesh

    Joined:
    Aug 16, 2014
    Posts:
    94
    Hey @MadMonkey119. Thanks for the feedback. I'm afraid there is no easy way to achieve what you want at the moment, as outline feature knows nothing of the camera override settings on Render Objects.
     
    MadMonkey119 likes this.
  7. MadMonkey119

    MadMonkey119

    Joined:
    Dec 20, 2013
    Posts:
    64
    Okay, going to be completely honest. I have no idea what I did but it's working now.

    Edit: Ah okay, as I'm drawing the depth outline on the default layer (weapon excluded) it's outlining the world mesh around the weapon, which sort of works. However, I think this may be the reason the outline has a slight problem. It draws slightly offset within the weapon mesh resulting in a few pixels being exposed outside the mesh which unfortunately doesn't look perfect.

     
    Last edited: Nov 29, 2021
    Arvtesh likes this.
  8. SFXMartinTuor

    SFXMartinTuor

    Joined:
    Mar 25, 2017
    Posts:
    4
    Hello @Arvtesh, I'm a big fan of your asset, thank you very much. I've got a slight issue when running a build on Android. It's all working fine in the frontend, but the log (logcat) gets spammed with warnings and errors:



    The test scene only contains a sphere with standard material applied, one light, and a camera containing the outline effect.

    Versions I'm using:
    Unity 2019.4.19f | Standard Render pipeline
    UnityFx.Outline 0.8.5

    Update:
    I just found out that the errors are dependent on the graphics API: OpenGLES2. As long as Vulkan is set as the primary API, no errors and warnings show up.
     
    Last edited: Dec 28, 2021
  9. Arvtesh

    Arvtesh

    Joined:
    Aug 16, 2014
    Posts:
    94
    Hello @SFXMartinTuor, the library uses R8 (one byte per pixel) format for render textures. It might not be supported on some platforms. I guess this is what happens.
     
    SFXMartinTuor likes this.
  10. JokerDen

    JokerDen

    Joined:
    Apr 9, 2015
    Posts:
    9
    I liked your asset a lot!
    Is it possible by any chance to reduce cost of wide outlines? It is especially crucial for mobile where screen resolution is very unproportional to it performance. Maybe something like render scale.
    For example, any particular reasons that made it hard to implement for URP SDF based outlines with Jump Flood Algorythm?
     
    Last edited: Feb 4, 2022
  11. Arvtesh

    Arvtesh

    Joined:
    Aug 16, 2014
    Posts:
    94
    Hello @JokerDen, I actually didn't look much into other implementation options. The approach taken in the library is more like a brute force. Thank you for the JFA suggestion, I think I should give it a try!
     
    tonytopper likes this.
  12. maayanc

    maayanc

    Joined:
    Jul 14, 2020
    Posts:
    5
    Hi @Arvtesh,

    First of all, I want to thank you for this great asset.
    We tried many outline solutions before, and the quality, and most importantly, the performance, is much better than anything else that we've tried!

    We're trying to figure out some performance issues with lower-end devices that are affected badly by the outline.
    In one of the scenes, we have a few simple meshes outlined (3-5K vertices). Enabling the outline for these objects, drop the FPS from 60 FPS to 40 FPS.
    In another scene, we outline much more instances (x6) of these meshes, but the effect is quite similar, dropping from 60 FPS to 35 FPS.
    It looks like just having the outline renderer feature enabled (we're using URP) causes the FPS to drop in 20 FPS. (checking the frame debugger, the number of draw calls is 4).

    We did another experiment where we deactivated the game object holding the outlined meshes, and the FPS was still the same (~40FPS), although the draw calls were reduced to 3 (no SRP batch call this time). Nothing to outline and still a significant drop in FPS.

    Any idea what can cause this? we tried to modify almost every feature of the outline and/or the renderer to find the root cause but found nothing.

    Any help will be greatly appreciated!
     
  13. Arvtesh

    Arvtesh

    Joined:
    Aug 16, 2014
    Posts:
    94
    Hey @maayanc. The answer to your question depends on the way you mark the objects for outlining.

    If you use layer masks, than number of meshes outlined doesn't matter much, just the outline width. Even if no meshes are rendered? there's till a performance penalty (it's post-effect after all). To disable outline in this case you have to disable the outline feature.

    If you use OutlineLayerCollection and add renderers/game objects for outlining manually, the performance cost might be proportional to the number of the game objects, and disabled renderers should not influence the performance. That said, there's a space for improvements in implementation here. I'll add task into my backlog for this.
     
  14. maayanc

    maayanc

    Joined:
    Jul 14, 2020
    Posts:
    5
    Hi @Arvtesh,

    Thanks for the quick reply!
    I did use a layer mask.
    I tried to replace it with OutlineLayerCollection but I got the same result in terms of performance.
    Just to make, in URP there's no other way than using a renderer feature, right?
    I need to create the OutlineLayerCollection, add then add the game objects programmatically?

    We have another post-processing for bloom, vignette, blur, distort and it barely affects the FPS on these low-end devices (I tried the outline without it, just to make sure this is not a problem of having both renderer features together).
     
  15. alchemist_wurzelpurzel

    alchemist_wurzelpurzel

    Joined:
    Sep 4, 2018
    Posts:
    43
    Hi @Arvtesh and thank you for this amazing asset!

    We would like to use it in Unity 2020.3.17f1 with URP 10.6.0 in combination with RapidIcon Icon Generator to generate Outlines around our Prefabs when generating Icons for them.

    RapidIcon works by spawning the Prefab and a Camera and rendering it into a Texture. To that end, I already modified the RapidIcon source code to be able to choose my own URP Forward Renderer for the spawned camera which works nicely with your Outline Feature on it.

    There is one issue though which I don't know how to fix. In the Texture, there are of course half-transparent pixels at the edges of the prefab. Unfortunately, the Outline is not applied over these pixels and instead treats them as part of the visual (understandably) and only starts further out, creating a visible border between Prefab visual and Outline as can be seen in the attached screenshot.

    Is there any way to work around this issue and have the Outline also paint over half-transparent pixels within the Texture? Using the Alpha Test Render Flag sadly didn't change anything about this behavior.

    Thanks again and keep up the good work!
     

    Attached Files:

  16. webik150

    webik150

    Joined:
    Mar 23, 2013
    Posts:
    62
    Hey @Arvtesh, thank you for this asset.

    I'm trying to edit the shaders so that the Depth test would be inversed (I want to draw outlines only on an object only when it's occluded, specifically so that I can see the player's outline when he gets behind a wall). Unfortunately it turned out not as simple as changing ZTest :D

    Could you point me in the right direction? I'm using URP and I assume I have to modify the OutlineColor.URP shader, but I can't figure out how.

    EDIT: I managed to get the effect I want, but through a very ugly hack. I had to create a custom Lit shader for my player that doesn't write into z-buffer and edit the Outline.URP shader to ZTest Greater instead of LEqual.
     
    Last edited: Apr 23, 2022
  17. lordubbe

    lordubbe

    Joined:
    Feb 7, 2015
    Posts:
    6
    Did you ever figure something out in regards to this? I have problem with alpha on literally everything but a sprite! The only way I can get the outline to respect the alpha is when using a Sprite Renderer component.

    Here's a screenshot of a simple test scene where I imported a texture of a white circle with transparent background, created a material (New Material), and slapped the material on the three objects you see (a sprite, quad and a cube)
    upload_2022-6-14_14-56-18.png

    This package is otherwise perfect, so I am sure it's something simple missing.
     
  18. evantjuh

    evantjuh

    Joined:
    Dec 24, 2015
    Posts:
    1
    Hello,

    This package is awesome, it works very good!

    However, i want to choose different colors on different objects for the outline using the URP. How would i achieve this? Would this require a layer for each color or can i do this easier?
     
    tonytopper likes this.
  19. jayandor

    jayandor

    Joined:
    Oct 3, 2020
    Posts:
    1
    @Arvtesh so the only way I was able to get your package to work was by utilizing a script which is able to add GameObjects to an OutlineLayer (via
    layer.Add(myGameObject)
    ), and this will likely work for me just fine. However, for my own curiosity I'd still like to try to figure out if I can get the OutlineBehaviour component to work. I'm using URP on Unity 2021.3.6 and I believe I've set everything up correctly: I added an OutlineBehaviour component to an object and set the Outline Resources to the built-in OutlineResources.URP asset. I'm 95% sure I have the actual rendering settings correct, as I can get it to render correctly via the script method, just not using the provided OutlineBehaviour component. I've tried setting a Target Camera in OutlineBehaviour and not setting it, using /not using Outline Settings, also using/not using an OutlineEffect component on my main camera, but none of these combinations seem to do anything. It seems the only way I can get anything to show is by specifically using an OutlineEffect component on a camera and using a script to add target objects to the layer set in the camera.

    Any suggestions?
     
  20. razhollander98monkey

    razhollander98monkey

    Joined:
    Jun 7, 2022
    Posts:
    1
    Firstly, thanks for the great the asset!
    When we build the project (on Mac/Android) the following error message is printed, please helppp


    10-23 19:01:16.210 26246 29643 E Unity : ArgumentNullException: Value cannot be null.

    10-23 19:01:16.210 26246 29643 E Unity : Parameter name: shader

    10-23 19:01:16.210 26246 29643 E Unity : at ScreenSpaceOutlines+ViewSpaceNormalsTexturePass..ctor (UnityEngine.Rendering.Universal.RenderPassEvent renderPassEvent, UnityEngine.LayerMask layerMask, UnityEngine.LayerMask occluderLayerMask, ScreenSpaceOutlines+ViewSpaceNormalsTextureSettings settings) [0x00000] in <00000000000000000000000000000000>:0

    10-23 19:01:16.210 26246 29643 E Unity : at ScreenSpaceOutlines.Create () [0x00000] in <00000000000000000000000000000000>:0

    10-23 19:01:16.210 26246 29643 E Unity : at UnityEngine.Rendering.Universal.ScriptableRenderer..ctor (UnityEngine.Rendering.Universal.ScriptableRendererData data) [0x00000] in <00000000000000000000000000000000>:0

    10-23 19:01:16.210 26246 29643 E Unity : at UnityEngine.Rendering.Universal.UniversalRenderer..ctor (UnityEngine.Rendering.Universal.UniversalRendererData data) [0x00000] in <00000000000000000000000000000000>:0

    10-23 19:01:16.210 26246 29643 E Unity : at UnityEngine.Rendering.Universal.UniversalRendererData.Create () [0x00000] in <00000000000000000000000000000000>:0

    10-23 19:01:16.210 26246 29643 E Unity : at UnityEngine.Rendering.Universal.UniversalRenderPipelineAsset.CreateRenderers () [0x0
     
  21. Wanderous

    Wanderous

    Joined:
    Apr 21, 2015
    Posts:
    2
    Got to a solution here, hope this helps anyone who finds themselves in the same spot!

    The problem seems to be that the shaders in use are in a "Hidden" resources folder, that is not included in the build by default. (Probable that my particular interpretation here is bogus, honestly). Since they are "Hidden" you can take the shortcut of creating a bogus material and assigning them to it as a shader, thus telling Unity that it is In Use and needs to be included in the build.

    You can tell Unity to do that, however, in the project settings.

    Look for this buddy on Project Settings >> Graphics

    upload_2022-11-25_17-30-35.png

    ScreenOutlineShaderVariants is a Shader Variant Collection that I made in my Assets/Shaders folder.

    upload_2022-11-25_17-31-18.png

    That did it for me!

     
  22. Coopland

    Coopland

    Joined:
    Mar 6, 2022
    Posts:
    2
    How would you go about changing values from forward renderer data at runtime, like line width, for example
     
  23. Magoga

    Magoga

    Joined:
    Jan 24, 2013
    Posts:
    134
    if you try to use MaterialPropertyBlock to set up "_MainTex" it should work.
    that's because it works with sprite renderer.
    looks like there is the some issues with link textures in temporary buffer.
     
  24. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,445
    Is there a cleaner way of installing than requiring NPM? It's either clone all github source and figure out just what few bits you need, or install a whole new package manager you don't want. Why not a standard Unity Package file for each render pipeline?
     
  25. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    613
    @halley Under Edit > Project Settings, find Package Manager and fill out the following
    A.png

    Then under Window > Package Manager, Select Packages: My Registries
    B.png

    There you will find all Outline packages and a clean way of installing them :)
     
    KarlKarl2000 likes this.
  26. ehabelbwab

    ehabelbwab

    Joined:
    Jul 12, 2019
    Posts:
    2
    Hello There,

    I'm facing a problem with URP version of your outline which is outlines rotated when i tested it on mobiles

    in editor:
    upload_2023-1-2_13-54-53.png


    in mobile:
     

    Attached Files:

  27. robin_baselinez

    robin_baselinez

    Joined:
    Nov 17, 2021
    Posts:
    1
    Hi there, I got interested in this asset because it said VR compatible, but when using it on the Quest 2 with one layer the FPS drops to about 30. With two layers to 20 fps and with three to 15 fps. Is this a known limitation? Are there any ways of improving this?
    Currently using the Built-In without Post Processing.
     
  28. James_Arndt

    James_Arndt

    Unity Technologies

    Joined:
    Jan 4, 2021
    Posts:
    22
    There seems to be a bug with URP 14.0.8 and Unity 2022.3.6f1. When setting the Render Flag property to "Enable Depth Testing" on the Outline Settings asset, the render is corrupted and a warning message pops up in the console.

    upload_2023-9-12_15-35-27.png
     
  29. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    610
    Hello,

    Is this awesome looking asset still active?
    I'd like to use it in my project but when I add it via manifest.json, I get these errors in the latest Unity version 2023.2.2.

    The latest Unity is causing the compilation to fail when there are some "obsolete" API usage and this asset has some of them. Since this is a NPM package, I can't go and edit those obsolete API lines.

    Also, there is one shader related error. Please see the screenshot.

    Can you please help?

    upload_2023-12-23_23-4-0.png
     
    tonytopper likes this.
  30. kilzkoy11

    kilzkoy11

    Joined:
    Mar 28, 2020
    Posts:
    2
    Hi i find this very cool! but i have a problem encountered in this. firstly the shader was optimized in mobile but it got a massive lag spikes when using it. (Built-In)
     
  31. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    610
  32. tonytopper

    tonytopper

    Joined:
    Jun 25, 2018
    Posts:
    226
    Thank you for this package @Arvtesh. You're making up for what I would have hoped was just part of the Unity engine, but hey maybe I expect too much from them.

    I am moving from just using a single layer that I have outlined to an OutlineLayerCollection so I can use the outlining feature in more than one place.

    One suggestion if I may, some basic instructions for using the OutlineLayerCollection API would be great. Maybe I am missing the obvious, but what's the best way to grab the OutlineLayerCollection programmatically and add/remove an object from the list?
     
    Snaipuha likes this.