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?

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);

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 :slight_smile: )

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;