Hi! This works a lot of the time, but not if your outline color is black, for example. It’s definitely the easiest solution if you have brightly colored outlines.
Had to do a bit of extra work to get this working with my setup (URP, OpenVR+SteamVR, Unity 2019.4.18f1). In my case, the shader was working in the scene view, but not in the game view. For some reason, the depth texture wasn't enabled on my camera, even though it's enabled on the render pipeline feature. To get it to work, I had to manually set Depth Texture to Enabled on my Camera.
Uff, one left to go - optimizing. I didn't even initially intended to do these in particular (I mean outlines) but they are just too well thought and presented. Thanks!
Add OutlinesInclude Scripts have a error.Undeclared identidler'NormalSobel_half'at line 203.idon't know what happen?Thank you are vedio.my english is bad.
Hi! No problem. This is because of your graph's precision setting. In the graph settings, set your precision to "single" or "float" and it should work.
Hey Ned thanks for all your tutorials ! I tried this in unity 2022 and I get an error when compiling the OutlinesInclude hlsl in a custom fonction in shader graph that said I have undeclared identifier (NormalSobel_half), any ideas how to fix ?
renaming the function will cause an error later on in the last unlit graph step, setting the precision to single in all functions actually fixed it for me
Amazing tutorials, I'm learning so much. Would there be a way to do color outlining even without the camera being ready ? For example if I'm using textures made of two color, could we do the outline color algorithm on this texture only and blend it to the other part of the shader ?
I keep getting the error: undeclared identifier 'NormalSobel_float'. It used to say NormalSobel_half but then I changed it to single but it´s still not fixed. How do I change it to float?
@@justpncil I don't have much experience with 2022 yet, so I'm not sure what might be happening. I'm actually on vacation right now, but I will see if there's a simple fix when I'm back! Until then, I would just try different combinations of "_float" and "_half" at the end of the function with different precision settings. Also, make sure the function name in the custom function is just "NormalSobel" without the suffix.
I don't have "New Depth Normals Feature" in UniversalRenderPipelineAsset_Renderer, only Screen Space Ambient and Render Objects. What did I do wrong? And how to create .hlsl file in Unity?
Hi! You need to download the DepthNormalsFeature.cs from the required scripts section in video description. You can't create a .hlsl file in Unity. You have to open File Explorer and create a .txt file in your Assets folder, then change the extension to .hlsl.
Hello Ned, Amazing tutorial. For other people that use the render feature with the transparent material make the render feature process after rendering transparents instead of after Opaque or you'll get an Outline that is rendered based on Last Frame Depth. Much Love !
Sorry I've returned to this a bit later but I had a question regarding lit materials and the outline. You said the default lit material would have issues, but custom ones dont? I wrote my own cell shader based off the pbr lit node, and was hoping to use outlines with it. How would you go about making the corrections so its not lit without doing the extra transparent pass, or do u just suggest doing it that way.
Hi! Really, the only reason there’s a problem with the lit shader is because you can’t modify it. A custom shader should have no issues as long as you implement a depth only and depth normals pass. Just include the Outlines.hlsl file in your shader and call the sobel functions. You’ll also need to recreate the fine tuning and threshold logic. No extra outline pass required. As for SSAO, I’m sorry can you refresh my memory about the issue? I think this system should work fine with it, it just generates an extra depth normals pass since I wrote this before Unity had implemented their own.
@@NedMakesGames Oh okay thank you so much, if you think the SSAO should work then it probably wont be an issue One more question I did have. For custom lighting its easier to do forward. However I'm running into an issue where I'd like to use deferred for the environment, but custom lighting for specific objects like characters. Deferred is making my forward rendered objects invisible. Is there a way to force forward / custom lit objects to render in deferred? Setting it to transparent seemed to do the trick but, I lose out on SSAO. Is it not possible to have the renderer process forward objects in deferred the same it does in forward?
@@Memeieli Please let me know if SSAO causes any issues and I’ll see if I can help out. I’m planning to update this tutorial, so I’ll keep this in mind. As for deferred rendering, according to this page, you should be able to have forward rendered objects docs.unity3d.com/Packages/com.unity.render-pipelines.universal@12.0/manual/rendering/deferred-rendering-path.html In fact, custom shaders are forward rendered by default. I haven’t had a chance to work with the URP deferred renderer so I can’t give any tips unfortunately. It seems like it might be important to set certain shader tags, so maybe that’s all you have to do.
@@NedMakesGames Thanks I will! And omg thank you. The pass tag needed was "LightMode" = "UniversalForwardOnly" Now I in theory should be allowed to render a lot of lights for the environment but still allow a few cell shaded characters on screen!
Hello, Ned. This isn't quite what I'm looking for, unfortunately =/ I have a randomly generated mesh for terrain. This terrain is 99% rock and I want to follow the edge with grass. There's other ways I could go about it, but I was wondering if you knew of any way to do this with shader graph. I was able to make a shader graph with both elements, but they tile horizontally and the grass does not follow the edge. Thanks!
Hi! I might be misinterpreting your problem, but I think the easiest way to do this is bake this data into your terrain mesh. For instance, have the red channel of the vertex colors act as a "grass mask." If it's one, draw grass! Otherwise, draw dirt. This will be pretty easy to implement in the shader graph (once you've got your dirt and grass shaders, of course).
Is there any way to make the lines look consistent between camera angles? My outline looks really good upclose, but if i pull the camera back, it starts filling in more parts of the model with black
This happens because, as an object takes up fewer pixels, the differences between those pixels increase. Have you tried adjusting the normals near/far depth thresholds? That usually helps, but takes a lot of tweaking to get perfect.
I'll come back to this tomorrow. You need to voice your variable values as well. Any chance we'll see a tutorial for 2021 Unity? It has it's own sort of issues. I could barely find the graph mapping.
Thanks for the tutorial. I've been trying to follow along but my shapes are just the solid colour of my outline. Tweaking the thickness doesn't appear to be helping. Any thoughts of the top of your head?
Hi, thanks for watching! I would guess that there's a bug in either your sobel edge detection or the nodes that blend it with the "regular" color. I would first try routing the outlines graph directly into base color. If you still can't see outlines, double check your HLSL file and the fine tuning nodes after your custom function. Feel free to post a screenshot and I can take a look!
Hey! I just followed the tutorial (very well done Ned!) and I had the same issue, I managed to notice that the Blend node in the Outline graph was still set to Mode - Multiply, it has to be set to Overwrite! Hope that helps!
Hi! The outline shader works very well, but I'm having troubles with objects that use an Alpha. Ex: my foliage and bushes. The Outline appears on both the mesh and the foliage. Is it possible to remove/hide the outline on the mesh of the leaves? Thank you!
Hi! Thank you for watching, and I'm glad it works relatively well. Unfortunately, this is not an easy fix. To give the whole story... I think this is because of the way the depth normals texture is created in my tutorials. It uses a replacement shader, which unfortunately does not do any alpha clipping. This makes alpha cut out materials fully opaque to the depth-normals renderer. URP's built-in depth normals texture will work, however, since it uses a different technique (which does alpha clip). So the easiest way to fix this problem is to use it instead of the custom depth normals from the tutorial. Whether or not this is possible for you depends on which version of Unity you're using: 2021.2+ for unlit shader graphs and 2020.3+ otherwise. You'll need to change "EdgeDetectionOutlinesInclude.hlsl" a bit to use the new depth texture. First add #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" near the top of the file. You can remove #include "DecodeDepthNormals.hlsl" and TEXTURE2D(_DepthNormalsTexture); SAMPLER(sampler_DepthNormalsTexture); Then, in "GetDepthAndNormal," delete the function body and replace it with: normal = SampleSceneNormals(uv); depth = 0; Finally, to make sure that depth normals are generated, add a "ScreenSpaceAmbientOcclusion" feature to your renderer, set to depth-normals mode. One last thing: don't try to use the "optimized" outlines from the next tutorial in this series. URP's depth-normals texture doesn't encode pure depth, so it won't work with that technique.
Running into some trouble getting this to work in my hdrp project. I'm getting the error that unity_CameraProjection in OutlinesInclude.hlsl isn't declared... New to hlsl files, but isn't that a built-in unity shader graph variable? Including UnityShaderVariables.cginc isn't fixing it either
Hi! I don’t have any experience with HDRP, so I can’t really help. But the built in values I use in URP are most likely different. You’ll have to read the HDRP source to find where the camera projection info is stored.
I have some trouble with the front edges not showing up but I'm pretty sure it has nothing to do with the graphs themselves. Any idea where my problem could lie? Aside from that everything looks fine but anything normal related doesn't do anything
Hi! I'm not sure what you mean by "front edges." Can you upload a screenshot to imgur, Discord, or somewhere else so I can take a look? If you're not getting depth-normal outlines, your depth normals feature might not be set up correctly. You can check by opening the frame debugger (in Window -> Analysis) and see if the DepthNormalsFeature pass shows up in there.
i get this error in the shader graph in Outlines shader. "variable '_ViewDirectionFromScreenUVCustomFunction_bunchofhexadecimal_Out_2' used without having been completely initialized". Same goes to the CalculateDepthNormal function but with Depth_1 instead. May I know what went wrong?
@@hmchiew5245 Hey, sorry for the late response. I didn't get a notification for your comment for some reason. I would guess that the Out and Depth variables in those custom functions have not been set to something before returning. I'd check your script against the references in the video description to see if there's a typo or missing line.
I'm trying to get these outlines on objects that are transparent but as soon as I set "Surface Type" to "Transparent" the outlines stop appearing no matter what inputs I try-also the outline layers flow works for me but as soon as I add transparency to the lit shader it stops rendering the outlines. Any ideas why this is happening? Otherwise I'll just hope you continue this series with a transparent outline video like you mentioned in another comment-thanks for the great tutorial!
Hi! Yeah, these outlines don't work with transparency. Blended transparent objects don't write to the depth buffer, so they won't appear in the depth or depth normals textures. There's no easy way to fix this. Generally, you need to render another set of depth and depth normals textures for each transparent object, but there are some tricks in specific cases. You can get this system working with cut out transparency in 2021.2 though. It's kind of a long explanation so I'll copy a post from my Discord at the end of this comment. But yes, I am planning a new series on outlines which would tackle transparency. Thank you for your patience! I think this is because of the way the depth normals texture is created in my tutorials. It uses a replacement shader, so in-shader vertex animation will not be reflected in the depth normals texture. The same thing happens with alpha clipping. URP's built-in depth normals texture will work, however, since it uses a different technique. So the easiest way to fix this problem is to use it instead of the custom depth normals from the tutorial. Whether or not this is possible for you depends on which version of Unity you're using: 2021.2+ for unlit shader graphs and 2020.3+ otherwise. You'll need to change "EdgeDetectionOutlinesInclude.hlsl" a bit to use the new depth texture. First add #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" near the top of the file. You can remove #include "DecodeDepthNormals.hlsl" and TEXTURE2D(_DepthNormalsTexture); SAMPLER(sampler_DepthNormalsTexture); Then, in GetDepthAndNormal, delete the function body and replace it with: normal = SampleSceneNormals(uv); depth = 0; Finally, to make sure that depth normals are generated, add a "ScreenSpaceAmbientOcclusion" feature to your renderer, set to depth-normals mode. One last thing: Notice that depth is always set to zero in GetDepthAndNormal... this is because URP's depth normals texture does not include depth info. It's alright since we can still get depth information from the depth texture, but this does break outlines from the final optimized tutorial (th-cam.com/video/8Xq7tU5QN1Q/w-d-xo.html). However, you'll be sharing the texture with the SSAO feature, so you may still come out ahead.
@@NedMakesGames Thank you for your answer! I have an other Problem. My Lines are more like stairs. And I lose the anti aliasing option in the graphics settings. Have you an idea at whitch step I might have scrued up?
@@robotoaster5099 Hmm this system should still work with antialiasing. Does ARFoundation ever disable the option? I haven't worked with it before, so I'm not sure how it works.
@@NedMakesGames I am also not shure. I just started with unity. In the Camera I found the option to turn on AA and it already looks better. The AA settings und Project Settings > Quality are gone when I add an URP. Keep up the great work! Your videos help a lot!
Works like a charm, thank you! However, is there any way to make the base colour transparent? I tried changing the final graph to use alpha, but that seems to remove most of the outlines.
Hi! Thank you for watching! Unfortunately outlines don't work well with transparency in general. I'm planning to find a good fix for this when I make more outlines videos, hopefully soon!
This tutorial is great, but i would really like and really need a new tutorial with this kind of outline if it is possible to be improved, like the visibility of the outlines from the interior in some angles or the clear visibility of small objects from distance etc.
Hi, thank you for watching! I'm not completely happy with the completed system either, and am planning a new outlines series which should tackle some of these issues.
Hi, in Unity 2022.1.14f1 I've fixed the precision errors by forcing the custom nodes to Single precision, but I get the error "Shader error in 'Master': redefinition of 'DecodeFloatRG' in the DecodeDepthNormals.hlsl file. line 28 on the downloaded file. The rest of the shader seems to finally be functional for me except for that error turning everything pink.
That would suggest to me that URP has it's own definition of "DecodeFloatRG" built in to Shader Graph shaders in 2022. You might be able to just delete that function from the DecodeDepthNormals.hlsl file.
@@NedMakesGames that unfortunately doesn't fix the issue for me, instead, it throws an error saying "DecodeFloatRG" is an unknown identifier because obviously the function has been deleted. it's still pink :( renaming the method doesn't do anything either, although Unity *does* have a DecodeFloatRG built-in function. It's in the docs. (but for cginc files..)
You can get rid of unity throwing errors if you rename all istances of "DecodeFloatRG", "DecodeDepthNormal" and "SomeDecodeViewNormalStereo", there is also one instance of "DecodeDepthNormal" in the OutlinesInclude file, you have to change that as well. Tho this still doesn't solve the issue, causing the object to be fully pink
I now bring a working solution, after doing that you gotta go into the shader graph > graph settings > active targets > + > universal, when you re-apply the material it works (tho the outline seems to still behave quite weirdly, i can't manage to get a clean result, changing AcuteStartDot means that more or less of the object has outlines, but i can't manage to make all of it have outlines)
Hi! You can set the outline color on the material using material.SetColor("_OutlineColor"). You'll have to set the "reference name" of the outline color property to "_OutlineColor." Check out this video to for an example: th-cam.com/video/IfFVjxPOrrY/w-d-xo.html
I followed the entire process and the outline works great. However the edges which are overlayed on-top of mesh polygons don't show an outline i.e. only the "outside edges" show an outline. Somewhat like 7:07. As a result, when two objects are infront of each other, they start blending. Edit: This happens only in the orthographic view. Also, something interesting I noticed is that if I tilt the object slightly, the outline appears.
Hi! This seems to be due to the normals being too similar for the edge detection algorithm to find. That's why when you tilt an object (causing the normals to adjust), outlines appear. You could try decreasing the normal threshold or relying more on depth edge detection.
@@NedMakesGames Thanks, to be precise I wanted something to use for my "mini-map". I wanted the objects to stand out even if they're on top of each other.
@@najmfayaz5972 Oh I see! You might try hull outlines. It doesn't rely on normal differences and, if you have simple models, should look just as good. I have a tutorial here: th-cam.com/video/1QPA3s0S3Oo/w-d-xo.html
I confess I don't understand it because it's too complex for me, but if I copy the video exactly, I get lots of error messages like : "Shader error in 'Sub Graphs/Master': undeclared identifier 'DepthSobel_half' at line 266 (on d3d11)" "Shader error in 'Shader Graphs/Master': undeclared identifier 'ViewDirectionFromScreen_float' at line 338 (on d3d11)" "Shader error in 'Shader Graphs/SimpleOutlinePerObject': undeclared identifier 'ViewDirectionFromScreen_float' at line 337 (on d3d11)" and a few others like it. and my difficulty in understanding English doesn't help me
Change the precision setting of the DepthSobel custom function node to single. As for the other errors, it seems you have misspelled the function name which you can find in the OutlinesInclude.hlsl script. Change 'ViewDirectionFromScreen' to 'ViewDirectionFromScreenUV' in the custom function node. Hope this helps.
Oh that's strange! Is your outline color blue? Sometimes outlines get a little wonky in the scene view, but if it looks OK in the game view, you should be good.
@@NedMakesGames you can! ...well, more or less. Since renderer features can be enabled/disabled at runtime, you can write a super simple MonoBehaviour with a serialized field of type ScriptableRendererFeature (requires the URP namespace), assign a renderer feature of your choice in the inspector and simply call SetActive on the renderer feature you've assigned. For example, in Awake and OnDisable to have the renderer feature only be active during runtime
@@Asier0070 Thank you, I plan to! I made a video about changes to the shader graph in 2020.2, which may help you out: th-cam.com/video/QDbWAZzw1dU/w-d-xo.html
Sorry about that! Have you watched the previous videos in this series? There’s links in the video description. In this video, I tried to focus on new code and concepts, so I’d encourage you to work through the other videos if it’s going too fast. What’s giving you trouble? Thanks for the feedback though. This was my first time covering a variation on a previous tutorial, so I had to experiment with the format.
Hi! There are two ways you can fix this. Either change your graph's precision (in the graph inspector) from "half" to "single," or rename the "DepthSobel_float" to "DepthSobel_half."
if you apply black outlines in the diffuse node and then the corect outline color in emissive, you
Hi! This works a lot of the time, but not if your outline color is black, for example. It’s definitely the easiest solution if you have brightly colored outlines.
i def needed this in more ways than one. Love your tutorials
What an interesting technique for achieving outlines! Will be giving this a go next time I need an outline shader, A+ tutorial
Your tutorials are always awesome, waiting for this channel to blow up
Had to do a bit of extra work to get this working with my setup (URP, OpenVR+SteamVR, Unity 2019.4.18f1). In my case, the shader was working in the scene view, but not in the game view. For some reason, the depth texture wasn't enabled on my camera, even though it's enabled on the render pipeline feature. To get it to work, I had to manually set Depth Texture to Enabled on my Camera.
I'm glad you got it working! You can select "Use Pipeline Settings" for it to default to whatever is selected in the settings asset.
Uff, one left to go - optimizing. I didn't even initially intended to do these in particular (I mean outlines) but they are just too well thought and presented. Thanks!
Thank you again! There's a lot to outlines, so I hope you can learn something from implementing them even if you don't end up using them in a project.
Add OutlinesInclude Scripts have a error.Undeclared identidler'NormalSobel_half'at line 203.idon't know what happen?Thank you are vedio.my english is bad.
Hi! No problem.
This is because of your graph's precision setting. In the graph settings, set your precision to "single" or "float" and it should work.
Hey Ned thanks for all your tutorials !
I tried this in unity 2022 and I get an error when compiling the OutlinesInclude hlsl in a custom fonction in shader graph that said I have undeclared identifier (NormalSobel_half), any ideas how to fix ?
In OutlinesInclude.hlsl file rename the function from NormalSobel_float() to NormalSobel_half(). That will fix the error.
renaming the function will cause an error later on in the last unlit graph step, setting the precision to single in all functions actually fixed it for me
Amazing tutorials, I'm learning so much. Would there be a way to do color outlining even without the camera being ready ? For example if I'm using textures made of two color, could we do the outline color algorithm on this texture only and blend it to the other part of the shader ?
I keep getting the error: undeclared identifier 'NormalSobel_float'. It used to say NormalSobel_half but then I changed it to single but it´s still not fixed. How do I change it to float?
Hi! Single precision should look for "_float" functions... What version of Unity are you using?
@@NedMakesGames Hi! I am using version 2022.1.9f1
@@justpncil I don't have much experience with 2022 yet, so I'm not sure what might be happening. I'm actually on vacation right now, but I will see if there's a simple fix when I'm back!
Until then, I would just try different combinations of "_float" and "_half" at the end of the function with different precision settings. Also, make sure the function name in the custom function is just "NormalSobel" without the suffix.
Spelling error
@@itsfonx Good catch
I don't have "New Depth Normals Feature" in UniversalRenderPipelineAsset_Renderer, only Screen Space Ambient and Render Objects. What did I do wrong?
And how to create .hlsl file in Unity?
Hi!
You need to download the DepthNormalsFeature.cs from the required scripts section in video description.
You can't create a .hlsl file in Unity. You have to open File Explorer and create a .txt file in your Assets folder, then change the extension to .hlsl.
@@NedMakesGames thank you very much!
Hello Ned, Amazing tutorial. For other people that use the render feature with the transparent material make the render feature process after rendering transparents instead of after Opaque or you'll get an Outline that is rendered based on Last Frame Depth. Much Love !
Thank you very much! I’m sorry about that bug. I’m just curious, what version of Unity are you using?
@@NedMakesGames 2020.3
Sorry I've returned to this a bit later but I had a question regarding lit materials and the outline. You said the default lit material would have issues, but custom ones dont?
I wrote my own cell shader based off the pbr lit node, and was hoping to use outlines with it. How would you go about making the corrections so its not lit without doing the extra transparent pass, or do u just suggest doing it that way.
Also the issue regarding SSAO and the outlines, is there a way to fix this at all?
Hi! Really, the only reason there’s a problem with the lit shader is because you can’t modify it. A custom shader should have no issues as long as you implement a depth only and depth normals pass. Just include the Outlines.hlsl file in your shader and call the sobel functions. You’ll also need to recreate the fine tuning and threshold logic. No extra outline pass required.
As for SSAO, I’m sorry can you refresh my memory about the issue? I think this system should work fine with it, it just generates an extra depth normals pass since I wrote this before Unity had implemented their own.
@@NedMakesGames Oh okay thank you so much, if you think the SSAO should work then it probably wont be an issue
One more question I did have. For custom lighting its easier to do forward. However I'm running into an issue where I'd like to use deferred for the environment, but custom lighting for specific objects like characters.
Deferred is making my forward rendered objects invisible. Is there a way to force forward / custom lit objects to render in deferred?
Setting it to transparent seemed to do the trick but, I lose out on SSAO. Is it not possible to have the renderer process forward objects in deferred the same it does in forward?
@@Memeieli Please let me know if SSAO causes any issues and I’ll see if I can help out. I’m planning to update this tutorial, so I’ll keep this in mind.
As for deferred rendering, according to this page, you should be able to have forward rendered objects docs.unity3d.com/Packages/com.unity.render-pipelines.universal@12.0/manual/rendering/deferred-rendering-path.html
In fact, custom shaders are forward rendered by default. I haven’t had a chance to work with the URP deferred renderer so I can’t give any tips unfortunately. It seems like it might be important to set certain shader tags, so maybe that’s all you have to do.
@@NedMakesGames Thanks I will! And omg thank you. The pass tag needed was "LightMode" = "UniversalForwardOnly"
Now I in theory should be allowed to render a lot of lights for the environment but still allow a few cell shaded characters on screen!
Hello, Ned. This isn't quite what I'm looking for, unfortunately =/ I have a randomly generated mesh for terrain. This terrain is 99% rock and I want to follow the edge with grass. There's other ways I could go about it, but I was wondering if you knew of any way to do this with shader graph. I was able to make a shader graph with both elements, but they tile horizontally and the grass does not follow the edge. Thanks!
Hi! I might be misinterpreting your problem, but I think the easiest way to do this is bake this data into your terrain mesh. For instance, have the red channel of the vertex colors act as a "grass mask." If it's one, draw grass! Otherwise, draw dirt. This will be pretty easy to implement in the shader graph (once you've got your dirt and grass shaders, of course).
Is there any way to make the lines look consistent between camera angles? My outline looks really good upclose, but if i pull the camera back, it starts filling in more parts of the model with black
This happens because, as an object takes up fewer pixels, the differences between those pixels increase. Have you tried adjusting the normals near/far depth thresholds? That usually helps, but takes a lot of tweaking to get perfect.
I'll come back to this tomorrow. You need to voice your variable values as well.
Any chance we'll see a tutorial for 2021 Unity?
It has it's own sort of issues. I could barely find the graph mapping.
Yeah just stuff in different places. (And a few hiccups.)
This worked beautifully. Thank You.
@@Serpent_Greenhorn Hey, I'm glad it's working! I plan to update these for 2021 and 2022 once I complete my current series. Hopefully early next year.
Thanks for the tutorial. I've been trying to follow along but my shapes are just the solid colour of my outline. Tweaking the thickness doesn't appear to be helping. Any thoughts of the top of your head?
Hi, thanks for watching! I would guess that there's a bug in either your sobel edge detection or the nodes that blend it with the "regular" color. I would first try routing the outlines graph directly into base color. If you still can't see outlines, double check your HLSL file and the fine tuning nodes after your custom function. Feel free to post a screenshot and I can take a look!
Hey! I just followed the tutorial (very well done Ned!) and I had the same issue, I managed to notice that the Blend node in the Outline graph was still set to Mode - Multiply, it has to be set to Overwrite! Hope that helps!
Hi! The outline shader works very well, but I'm having troubles with objects that use an Alpha. Ex: my foliage and bushes. The Outline appears on both the mesh and the foliage. Is it possible to remove/hide the outline on the mesh of the leaves? Thank you!
Hi! Thank you for watching, and I'm glad it works relatively well. Unfortunately, this is not an easy fix. To give the whole story...
I think this is because of the way the depth normals texture is created in my tutorials. It uses a replacement shader, which unfortunately does not do any alpha clipping. This makes alpha cut out materials fully opaque to the depth-normals renderer.
URP's built-in depth normals texture will work, however, since it uses a different technique (which does alpha clip). So the easiest way to fix this problem is to use it instead of the custom depth normals from the tutorial. Whether or not this is possible for you depends on which version of Unity you're using: 2021.2+ for unlit shader graphs and 2020.3+ otherwise.
You'll need to change "EdgeDetectionOutlinesInclude.hlsl" a bit to use the new depth texture. First add
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
near the top of the file. You can remove
#include "DecodeDepthNormals.hlsl"
and
TEXTURE2D(_DepthNormalsTexture); SAMPLER(sampler_DepthNormalsTexture);
Then, in "GetDepthAndNormal," delete the function body and replace it with:
normal = SampleSceneNormals(uv);
depth = 0;
Finally, to make sure that depth normals are generated, add a "ScreenSpaceAmbientOcclusion" feature to your renderer, set to depth-normals mode.
One last thing: don't try to use the "optimized" outlines from the next tutorial in this series. URP's depth-normals texture doesn't encode pure depth, so it won't work with that technique.
@@NedMakesGames Thank you very much! It works perfectly. Can't wait for new tutorials!
@@julienrochefort326 I’m glad to hear that fixed it! Thank you!
Running into some trouble getting this to work in my hdrp project. I'm getting the error that unity_CameraProjection in OutlinesInclude.hlsl isn't declared... New to hlsl files, but isn't that a built-in unity shader graph variable? Including UnityShaderVariables.cginc isn't fixing it either
Hi! I don’t have any experience with HDRP, so I can’t really help. But the built in values I use in URP are most likely different. You’ll have to read the HDRP source to find where the camera projection info is stored.
I have some trouble with the front edges not showing up but I'm pretty sure it has nothing to do with the graphs themselves. Any idea where my problem could lie? Aside from that everything looks fine but anything normal related doesn't do anything
Hi! I'm not sure what you mean by "front edges." Can you upload a screenshot to imgur, Discord, or somewhere else so I can take a look?
If you're not getting depth-normal outlines, your depth normals feature might not be set up correctly. You can check by opening the frame debugger (in Window -> Analysis) and see if the DepthNormalsFeature pass shows up in there.
i get this error in the shader graph in Outlines shader. "variable '_ViewDirectionFromScreenUVCustomFunction_bunchofhexadecimal_Out_2' used without having been completely initialized". Same goes to the CalculateDepthNormal function but with Depth_1 instead. May I know what went wrong?
btw i'm using unity version 2020.3.2f1 lts
@@hmchiew5245 Hey, sorry for the late response. I didn't get a notification for your comment for some reason.
I would guess that the Out and Depth variables in those custom functions have not been set to something before returning. I'd check your script against the references in the video description to see if there's a typo or missing line.
I'm trying to get these outlines on objects that are transparent but as soon as I set "Surface Type" to "Transparent" the outlines stop appearing no matter what inputs I try-also the outline layers flow works for me but as soon as I add transparency to the lit shader it stops rendering the outlines. Any ideas why this is happening? Otherwise I'll just hope you continue this series with a transparent outline video like you mentioned in another comment-thanks for the great tutorial!
Hi! Yeah, these outlines don't work with transparency.
Blended transparent objects don't write to the depth buffer, so they won't appear in the depth or depth normals textures. There's no easy way to fix this. Generally, you need to render another set of depth and depth normals textures for each transparent object, but there are some tricks in specific cases.
You can get this system working with cut out transparency in 2021.2 though. It's kind of a long explanation so I'll copy a post from my Discord at the end of this comment.
But yes, I am planning a new series on outlines which would tackle transparency. Thank you for your patience!
I think this is because of the way the depth normals texture is created in my tutorials. It uses a replacement shader, so in-shader vertex animation will not be reflected in the depth normals texture. The same thing happens with alpha clipping.
URP's built-in depth normals texture will work, however, since it uses a different technique. So the easiest way to fix this problem is to use it instead of the custom depth normals from the tutorial. Whether or not this is possible for you depends on which version of Unity you're using: 2021.2+ for unlit shader graphs and 2020.3+ otherwise.
You'll need to change "EdgeDetectionOutlinesInclude.hlsl" a bit to use the new depth texture. First add #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" near the top of the file. You can remove #include "DecodeDepthNormals.hlsl" and TEXTURE2D(_DepthNormalsTexture); SAMPLER(sampler_DepthNormalsTexture);
Then, in GetDepthAndNormal, delete the function body and replace it with:
normal = SampleSceneNormals(uv);
depth = 0;
Finally, to make sure that depth normals are generated, add a "ScreenSpaceAmbientOcclusion" feature to your renderer, set to depth-normals mode.
One last thing: Notice that depth is always set to zero in GetDepthAndNormal... this is because URP's depth normals texture does not include depth info. It's alright since we can still get depth information from the depth texture, but this does break outlines from the final optimized tutorial (th-cam.com/video/8Xq7tU5QN1Q/w-d-xo.html). However, you'll be sharing the texture with the SSAO feature, so you may still come out ahead.
Great tutorial! Does this work with ARFoundation? My screen is just black.
Nvm you have to add an ARBackgroundRenderer to your URPAsset_Renderer
@@robotoaster5099 I'm glad to hear it was a simple fix! Thanks for watching!
@@NedMakesGames Thank you for your answer! I have an other Problem. My Lines are more like stairs. And I lose the anti aliasing option in the graphics settings. Have you an idea at whitch step I might have scrued up?
@@robotoaster5099 Hmm this system should still work with antialiasing. Does ARFoundation ever disable the option? I haven't worked with it before, so I'm not sure how it works.
@@NedMakesGames I am also not shure. I just started with unity. In the Camera I found the option to turn on AA and it already looks better. The AA settings und Project Settings > Quality are gone when I add an URP. Keep up the great work! Your videos help a lot!
Works like a charm, thank you!
However, is there any way to make the base colour transparent? I tried changing the final graph to use alpha, but that seems to remove most of the outlines.
Hi! Thank you for watching!
Unfortunately outlines don't work well with transparency in general. I'm planning to find a good fix for this when I make more outlines videos, hopefully soon!
This tutorial is great, but i would really like and really need a new tutorial with this kind of outline if it is possible to be improved, like the visibility of the outlines from the interior in some angles or the clear visibility of small objects from distance etc.
Hi, thank you for watching! I'm not completely happy with the completed system either, and am planning a new outlines series which should tackle some of these issues.
Hi, in Unity 2022.1.14f1 I've fixed the precision errors by forcing the custom nodes to Single precision, but I get the error "Shader error in 'Master': redefinition of 'DecodeFloatRG' in the DecodeDepthNormals.hlsl file. line 28 on the downloaded file. The rest of the shader seems to finally be functional for me except for that error turning everything pink.
That would suggest to me that URP has it's own definition of "DecodeFloatRG" built in to Shader Graph shaders in 2022. You might be able to just delete that function from the DecodeDepthNormals.hlsl file.
@@NedMakesGames that unfortunately doesn't fix the issue for me, instead, it throws an error saying "DecodeFloatRG" is an unknown identifier because obviously the function has been deleted. it's still pink :( renaming the method doesn't do anything either, although Unity *does* have a DecodeFloatRG built-in function. It's in the docs. (but for cginc files..)
me too, did you figure it out?
You can get rid of unity throwing errors if you rename all istances of "DecodeFloatRG", "DecodeDepthNormal" and "SomeDecodeViewNormalStereo", there is also one instance of "DecodeDepthNormal" in the OutlinesInclude file, you have to change that as well.
Tho this still doesn't solve the issue, causing the object to be fully pink
I now bring a working solution, after doing that you gotta go into the shader graph > graph settings > active targets > + > universal, when you re-apply the material it works (tho the outline seems to still behave quite weirdly, i can't manage to get a clean result, changing AcuteStartDot means that more or less of the object has outlines, but i can't manage to make all of it have outlines)
Is there any way to change the outline color by script at runtime? I have tried but I have not found a solution
Hi! You can set the outline color on the material using material.SetColor("_OutlineColor"). You'll have to set the "reference name" of the outline color property to "_OutlineColor." Check out this video to for an example: th-cam.com/video/IfFVjxPOrrY/w-d-xo.html
@@NedMakesGames Hi Ned! Thank you for the advice, now it works perfectly 😊
I followed the entire process and the outline works great.
However the edges which are overlayed on-top of mesh polygons don't show an outline i.e. only the "outside edges" show an outline. Somewhat like 7:07. As a result, when two objects are infront of each other, they start blending.
Edit: This happens only in the orthographic view. Also, something interesting I noticed is that if I tilt the object slightly, the outline appears.
Hi! This seems to be due to the normals being too similar for the edge detection algorithm to find. That's why when you tilt an object (causing the normals to adjust), outlines appear.
You could try decreasing the normal threshold or relying more on depth edge detection.
@@NedMakesGames Thanks, to be precise I wanted something to use for my "mini-map". I wanted the objects to stand out even if they're on top of each other.
@@najmfayaz5972 Oh I see! You might try hull outlines. It doesn't rely on normal differences and, if you have simple models, should look just as good. I have a tutorial here: th-cam.com/video/1QPA3s0S3Oo/w-d-xo.html
Why don't you change the thickness of the line based on how far away the camera is?
Hi! You definitely can, but it changes the art style. Sometimes you want lines with constant thickness, like a coloring book.
I confess I don't understand it because it's too complex for me, but if I copy the video exactly, I get lots of error messages like :
"Shader error in 'Sub Graphs/Master': undeclared identifier 'DepthSobel_half' at line 266 (on d3d11)"
"Shader error in 'Shader Graphs/Master': undeclared identifier 'ViewDirectionFromScreen_float' at line 338 (on d3d11)"
"Shader error in 'Shader Graphs/SimpleOutlinePerObject': undeclared identifier 'ViewDirectionFromScreen_float' at line 337 (on d3d11)"
and a few others like it.
and my difficulty in understanding English doesn't help me
Change the precision setting of the DepthSobel custom function node to single. As for the other errors, it seems you have misspelled the function name which you can find in the OutlinesInclude.hlsl script. Change 'ViewDirectionFromScreen' to 'ViewDirectionFromScreenUV' in the custom function node. Hope this helps.
Is it possible to replace base color with a texture?
Hi! Yes, you can use whatever logic you'd like in your shader as long as you blend the Outline subgraph into it.
@@NedMakesGames Figured it out. Thank you for the amazing tutorials
when i go near an object with the outline shader, my camera turns blue, only in the scene view tho
Oh that's strange! Is your outline color blue? Sometimes outlines get a little wonky in the scene view, but if it looks OK in the game view, you should be good.
@@NedMakesGames its completely fine in the game view, its just annoying to be in the scene view and it gets blue
@@isntityoshi5657 yeah, it would be nice if you could turn renderer features off for the scene view.
@@NedMakesGames you can! ...well, more or less. Since renderer features can be enabled/disabled at runtime, you can write a super simple MonoBehaviour with a serialized field of type ScriptableRendererFeature (requires the URP namespace), assign a renderer feature of your choice in the inspector and simply call SetActive on the renderer feature you've assigned. For example, in Awake and OnDisable to have the renderer feature only be active during runtime
I dont have the Graph Inspector in the Shadergraph wtf
It’s only there in 2020.2. In previous versions, you have to edit things in the dropdown or gear menus on the nodes themselves.
@@NedMakesGames Oh ok thank you i get a bit lost on that part because of that 😅 Keep doing this videos they are very helpful
@@Asier0070 Thank you, I plan to!
I made a video about changes to the shader graph in 2020.2, which may help you out: th-cam.com/video/QDbWAZzw1dU/w-d-xo.html
@@NedMakesGames Nice! I will check it out thanks 😊
I've tried this literally for 3 hours straight and it just does not work right. You kind of go too fast and skip some steps. Very frusterating
Sorry about that! Have you watched the previous videos in this series? There’s links in the video description. In this video, I tried to focus on new code and concepts, so I’d encourage you to work through the other videos if it’s going too fast. What’s giving you trouble?
Thanks for the feedback though. This was my first time covering a variation on a previous tutorial, so I had to experiment with the format.
❤️❤️❤️❤️❤️❤️
Why is everybody fast forwarding their tutorials....
There are other tutrorials in the series who explain the proecess he mentioned it at the beginning
Nice video, but in the future you should go slower.
Thank you, I appreciate the feedback!
too fast
Hey sorry! TH-cam has a speed setting you can access from the gear, maybe that will help? Thank you for the feedback though.
I got the error: "Shader error in 'Master': undeclared identifier 'DepthSobel_half' at line 269 (on d3d11)" is there a way to solve this?
Hi! There are two ways you can fix this. Either change your graph's precision (in the graph inspector) from "half" to "single," or rename the "DepthSobel_float" to "DepthSobel_half."