(Now updated to work up to 5.4.0f3)
As I was working on my project, I was looking into edge detecting and the current image effects edge detection doesn’t offer the ability to change the colours of the edges it detects. Instead it only renders it black.
I’ve edited the shader and editor to add another image effect called Edge Detection Color. It allows you to edit the colour of the edges, changing them from black to any other color, selectable in the editor. The required files are attached to this post.
How to install: Unity Image Effects files are required (Import Unity Effects package)
Put EdgeDetectionColorsEditor file in the Editor/ImageEffects folder,
Put the other two (EdgeDetectColor.cs & EdgeDetectNormalsColor.shader) anywhere else.
Add EdgeDetectionColour to camera through Image Effects > Edge Detection > EdgeDetectionColor / searching for EdgeDetectionColor
Note: only works for triangle depth normals and robert cross depth normals
@pmurph03 this is just want I wanted, but I’m getting an error: “Missing shader in Main Camera when” when I attach the script to my camera, do you have any suggestions as to how I can fix this?
@pmurph03
THANK YOU! This is exactly what i have been looking for. I was using the unity edge detection scrpt, and it wasnt doing the job like i wanted. this is exactly perfect. You are the man!
This is excellent. I was really struggling on how to do this so thank you.
Does anyone know if it is at all possible to either - 1) have the color key off say for instance an objects material color or 2) exclude certain objects from the edge detection effect?
When trying out your scripts, I’m receiving two errors.
Assets/Editor/ImageEffects/EdgeDetectionEditor.cs(8,11): error CS0101: The namespace UnityStandardAssets.ImageEffects' already contains a definition for EdgeDetectionEditor’
NullReferenceException: Object reference not set to an instance of an object
UnityStandardAssets.ImageEffects.EdgeDetectionColor.OnRenderImage (UnityEngine.RenderTexture source, UnityEngine.RenderTexture destination) (at Assets/Scripts/EdgeDetectionColor.cs:81)
Seeing as how i’m trying to learn how shaders and things work, I’m not sure how to go about finding the cause of these issues. The first error really has me confused, since I have searched the EdgeDetectionEditor.cs script and find no instance of “EdgeDetectionEditor” in the script itself. So i’m not sure where it’s finding that definition.
@Rottiger I know it’s been several months since you solved your problem, but do you remember what you did exactly? I have the exact problem you did, and I’ve tried a bunch of different things (including shuffling the shader around) but I can’t seem to fix it. (Also I’m on Unity Personal v5.3.3f1, if that has any significance)
#1. You can’t have two scripts with the same name in your project. Either delete the duplicate or rename one, both the file and the namespace.
#2. Look at line 81 of the script just like the error tells you. Likely you have a missing pointer and the script is trying to utilize some component but you haven’t told it what to use.
I apologize for the lack of support! I didn’t realize that anyone had used this, so I’m very sorry for the late update.
I just quickly updated this shader to work in Unity 5.4.0f3, as well as fixing some bugs that people pointed out. I’ll also update the original post to include more information about proper installation. Original post attachments have also been updated to the latest version.
Hi, I’m unity 5.6 and I kept the EdgeDetection image effect but it has a bad issue: the thickness of lines changes based on screen size.
Does this effect have the same issue?
I believe if you modify the script that goes on the camera to multiply the sample distance based on screen resolution there shouldn’t be a change of percieved thickness based on screen size.
Hi pmurph, I am using Unity 5.6, I added these files in the correct place as well as importing Unity’s image effects but I get the error:
The type or namespace name `PostEffectsBase’ could not be found.
Am I missing something else? This class didn’t seem to be included in Unity’s Effects package.