Edge Detection with Deferred Rendering?

Hi guys

I’m using the TriangleDepthNormals Edge Detection camera post effect. However last night I modified my shaders in my project to utilize deferred rendering, which yields very nice results for edge detection in a short range.

Unfortunately, my ground, which is just a flat plane has it’s edge detection messed up at a distance (at the length of a default unity plane). The solution I’m hoping for is one of three:

  1. Is it possible to have the edge detection cutoff after a specified distance?
  2. Is it possible to have edge detection behave with deferred rendering?
  3. Is it possible to use layers to exclude the ground from the edge detection?

I’ve been looking around for a solution but haven’t much luck at finding any information relating edge detection to deferred randering.

Also something to note is most of the models I’m using do not like using normals to calculate edges, so I’m relying heavily on the depth detection.

I ended up experimenting and changing how the EdgeDetectNormals shader functions. I saw that it would draw a line if either the depth or the normal where over the threshold. I changed it so that both the normal and the depth had to be over the threshold to draw a line; it’s produced much nicer effects.

FROM:

inline half CheckSame (half2 centerNormal, float centerDepth, half4 theSample)
	{
		// difference in normals
		// do not bother decoding normals - there's no need here
		half2 diff = abs(centerNormal - theSample.xy) * _Sensitivity.y;
		half isSameNormal = (diff.x + diff.y) * _Sensitivity.y < 0.1;
		// difference in depth
		float sampleDepth = DecodeFloatRG (theSample.zw);
		float zdiff = abs(centerDepth-sampleDepth);
		// scale the required threshold by the distance
		half isSameDepth = zdiff * _Sensitivity.x < 0.09 * centerDepth;

		// return:
		// 1 - if normals and depth are similar enough
		// 0 - otherwise
		
		return isSameNormal * isSameDepth;
	}	

TO:

inline half CheckSame (half2 centerNormal, float centerDepth, half4 theSample)
	{
		// difference in normals
		// do not bother decoding normals - there's no need here
		half2 diff = abs(centerNormal - theSample.xy) * _Sensitivity.y;
		half isSameNormal = (diff.x + diff.y) * _Sensitivity.y < 0.1;
		// difference in depth
		float sampleDepth = DecodeFloatRG (theSample.zw);
		float zdiff = abs(centerDepth-sampleDepth);
		// scale the required threshold by the distance
		half isSameDepth = zdiff * _Sensitivity.x < 0.09 * centerDepth;

		// return:
		// 1 - if normals and depth are similar enough
		// 0 - otherwise
		
		return saturate(isSameNormal + isSameDepth);
	}	

It works, but there still might yet be some unforeseen effects that I may encounter later on.