- Home /
Edge detect color
I'd like to customize the colored edges of the EdgeDetectEffectNormals script that comes with Unity Pro. What do I need to change in the script / shader to make the edges say, yellow, instead of black?
Answer by Ricardo Arango · Jun 14, 2011 at 04:17 PM
You have to change a few files to get this working:
In EdgeDetectNormalsShader.shader:
1 Define a property that will be exposed in the editor for you to change the color of the edges:
_Color ("Color", color) = (0,0,0,0)
2 Comment the following line in FragRobert:
return edge * lerp(tex2D(_MainTex, i.uv[0].xy), _BgColor, _BgFade);
and add the edge color:
//return edge * lerp(tex2D(_MainTex, i.uv[0].xy), _BgColor, _BgFade);
if(edge > 0)
return lerp(tex2D(_MainTex, i.uv[0].xy), _BgColor, _BgFade);
else
return _Color;
3 Repeat the step for FragThin:
//return edge * lerp(original, _BgColor, _BgFade);
if(edge > 0)
return lerp(original, _BgColor, _BgFade);
else
return _Color;
In EdgeDetectEffectNormalsEditor.js:
1 Add a Serialized propery for the Color value:
var edgesColor : SerializedProperty;
2 Assign the reference in OnEnable:
edgesColor = serObj.FindProperty("edgesColor");
3 Display it in the OnGUI call just after the Background options:
GUILayout.Label ("Edges Color");
EditorGUILayout.PropertyField (edgesColor, new GUIContent ("EdgesColor"));
In EdgeDetectEffectNormals.js:
1 Add a variable to hold the color property:
public var edgesColor : Color = Color.white;
2 Use this variable when OnRenderImage to set the _Color property in the shader:
var edgeCol : Vector4 = edgesColor;
edgeDetectMaterial.SetVector ("_Color", edgeCol);
Thanks Ricardo, I followed your great instructions and now I'm getting this error: "The image effect Camera (EdgeDetectEffectNormals) on Camera is not supported on this platform!" $$anonymous$$y platform settings are set to PC and $$anonymous$$ac Standalone and my graphics card is an ATI Radeon HD 5730 - do you what might be wrong?
I get the same error, along with some other errors including this:
Invalid pass number for Graphics.Blit UnityEngine.Graphics:Blit(Texture, RenderTexture, $$anonymous$$aterial, Int32) EdgeDetectEffectNormals:OnRenderImage(RenderTexture, RenderTexture)
Would greatly ppreciate some help on this!
Ricardo forgot to mention that you have to add this to EdgeDetectNormalsShader.shader in the uniform section:
uniform half4 _Color;
Doubt this is still live, but I had a go at this to no effect. I have the property in the inspector but no update to the shader... Did I miss something?
Would be better to just post the code in entirety. I can't even tell if this is still valid. Or what parts are valid and what parts are not and what code this is being built and if that code has changed or not.
Answer by giulio-pierucci · May 28, 2013 at 11:43 PM
Yes, i'ts alive. I think tha your problem is caused by mode. Applying Ricardo solution, Sobel not get _Color property (Maybe a little old post :) )
You have to add same code to other 2 section:
fragDCheap and fragD
Here the code:
//return Sobel * lerp(tex2D(_MainTex, i.uv[0].xy), _BgColor, _BgFade);
if(Sobel > 0)
return lerp(tex2D(_MainTex, i.uv[0].xy), _BgColor, _BgFade);
else
return _Color;