LWRP - Outline Shader (also edges, not just outer outline)

Hi Guys

In 2019.2 I’m using LWRP and I’m trying to get an affect of a toon like edge/outline

I found various other threads SORT OF what I need, but only a few OLDER ones with actually what I need, but since they are older, I’m not sure how to make it work

Here’s some almost there examples:

But really, those are only OUTLINES, but I also need the edges.

Basically what I need is this:

But no idea how to get this last one working with the latest 2019.2 Unity with LWRP 6.9.
I made a new scene and just chose the default LWRP template, I added a single 1m X 1m cube and assigned a red LWRP Lit shader. Now what? The old post processing stack 2.0 seems to be not available anymore, or they renamed it to Post Processing Volume or Post Processing Layer, not sure whats the difference

If anybody can help me get this going, I’d greatly appreciate it!

Nobody knows or nobody cares?

The most recent Post Processing Stack v2 is available in the Package Manager.
I’m not aware of independent “old” or “new” versions of it other than v1 or the one on github.

And maybe this helps: https://alexanderameye.github.io/edgedetection.html
I didn’t try it yet. Seems a bit complex. But it came up while researching the subject.

The one you are referring works for me, since i’m mostly in SRP.
The keywords that helped me most are “edge detect shader”.

See the official example project here:
https://github.com/Unity-Technologies/LWRP-CustomRendererExamples

It includes a sobel post process that does inner lines.

1 Like

Errrrrr, I’m on 2019.3.0a12…but there’s no LWRP in it in the startup template…
How do I load the example stuff the from the github?

From the top of that project’s description:

Note, Universal RP is the replacement for the LWRP. If you want to use the now deprecated LWRP you can use this older version.

Errrrrrr, so where can we get announcement for this stuff so we all know what is going on?
LWRP just recently came out of preview, and now its already replaced by this new thing “Universal RP”

Does that mean we can now get realtime GI with this Universal RP?

EDIT: And yes, I missed the bit at the top of the page that says “Current Support 2019.3.0a10 with UniversalRP7” Thanks for that tip

1 Like

I have an additional question to this: How do you actually use these for your own project?
I have opened the examples and looked through all the stuff, and tried importing the materials and render settings into my project. I created a new Renderer Feature in my UniversalRenderPipelineAsset_Renderer.asset and under overrides, added the OutlineHull material provided with the examples.
The outline is created in the color I picked, but the outline thickness is way too high, even on the lowest setting.
There must be something wrong, but since there is no explanation whatsoever provided with the example, I have a hard time figuring out what to do. The example provides two methods of creating the outlines, but as a somewhat beginner I have no idea which files belong to which method even…

Edit:
Nevermind I figured it out: The scale for the model I have imported from blender is off… even though it seems to be the right size for the scene, the X,Y and Z scales are each 100 instead of 1. I guess I must have forgotten to apply the scale in Blender at some point.

Nevertheless, since these are low-poly models, it turns out the approach doesn’t work very well for those. The outlines sometimes seem to float some distance away from the actual model and since they’re inverted normals often don’t look very good.
Still looking for a better approach…

The other example in the demo project uses something named “blit”. For now, adding the two “Blit” scripts provided with the example to my project allowed me to create Blits as renderer features and I could use the sobelBlit material to create the outline. However, it creates a funny effect where the objects are outlined properly in the scene view in the editor, but in the actual game window it has the outlines from the editor overlayed on top of the game, which obviously doesn’t make any sense. Even in the Unity demo, the outlines from the editor will show up in the game window. But in the official demo, if I set the game to fullscreen it works properly…
If I maximize the game into fullscreen in my own project, there are no outlines displayed at all. Any ideas what could be causing this and how to fix it?

Edit again:

Ok, it turned that in the UniversalRenderPipelineAsset, you need to enable Depth Texture as well as Opaque Texture. The outlines from the Blit thingy are also influenced by the camera’s clipping plane, that is if the clipping plane is too near, the outlines tend to fade out.
I managed to get it to work now, and even though method 2 produces much nicer outlines, there doesn’t seem to be a way to change their color. It would also be nice if we could lower the opacity on the outlines.

I took a look at the SobelFilter.shader, but I don’t think I’ll be able to find out how to manipulate it to create the effects I want…

Pretty sure this is the shader.
Tried to put it into an HDRP project thinking that’d work fine. Nope. Straight up missing file in the package. Any advice?

Shader error in ‘Unlit/SobelFilter’: failed to open source file: ‘Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl’ at line 19 (on d3d11)

this post toon outline shows through additive particles as if it were in front of them