Hello, I am wondering

Shader “Hidden/EdgeDetectGeometry” {
Properties {
_MainTex (“Base (RGB)”, 2D) = “” {}
_Color (“Color”, color) = (0,0,0,1)
}

// Shader code pasted into all further CGPROGRAM blocks	
CGINCLUDE

#include "UnityCG.cginc"

struct v2f {
	float4 pos : POSITION;
	float2 uv[5] : TEXCOORD0;
};

sampler2D _MainTex;
uniform half4 _MainTex_TexelSize;
sampler2D _CameraDepthNormalsTexture;

uniform half4 sensitivity; 
uniform half4 _BgColor;
uniform half _BgFade;
uniform float4 _Color;

inline half CheckSame (half2 centerNormal, float centerDepth, half4 sample)
{
	// difference in normals
	// do not bother decoding normals - there's no need here
	half2 diff = abs(centerNormal - sample.xy) * sensitivity.y;
	half isSameNormal = (diff.x + diff.y) * sensitivity.y < 0.1;
	// difference in depth
	float sampleDepth = DecodeFloatRG (sample.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;
}	
		
v2f vertThin( appdata_img v )
{
	v2f o;
	o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
	

	
	float2 uv = v.texcoord.xy;
	o.uv[0] = uv;
	
	// On D3D when AA is used, the main texture & scene depth texture
	// will come out in different vertical orientations.
	// So flip sampling of depth texture when that is the case (main texture
	// texel size will have negative Y)
	
	#if SHADER_API_D3D9
	if (_MainTex_TexelSize.y < 0)
		uv.y = 1-uv.y;
	#endif
	
	o.uv[1] = uv;
	o.uv[4] = uv;
			
	// offsets for two additional samples
	o.uv[2] = uv + float2(-_MainTex_TexelSize.x, -_MainTex_TexelSize.y);
	o.uv[3] = uv + float2(+_MainTex_TexelSize.x, -_MainTex_TexelSize.y);
	o.pos.z +=0.1f;
	
	return o;
}	  


half4 fragThin (v2f i) : COLOR
{
	half4 original = tex2D(_MainTex, i.uv[0]);
	
	half4 center = tex2D (_CameraDepthNormalsTexture, i.uv[1]);
	half4 sample1 = tex2D (_CameraDepthNormalsTexture, i.uv[2]);
	half4 sample2 = tex2D (_CameraDepthNormalsTexture, i.uv[3]);
	
	// encoded normal
	half2 centerNormal = center.xy;
	// decoded depth
	float centerDepth = DecodeFloatRG (center.zw);
	
	half edge = 1.0;
	
	edge *= CheckSame(centerNormal, centerDepth, sample1);
	edge *= CheckSame(centerNormal, centerDepth, sample2);
		
	//return edge * lerp(original, _BgColor, _BgFade);
	if(edge > 0)
	    return lerp(original, _BgColor, _BgFade);
	else
	    return _Color;
}

ENDCG 

Subshader {

Pass {

  ZTest Always
  Cull Back 
  ZWrite On
  Fog { Mode off }      

  CGPROGRAM
  #pragma vertex vertThin
  #pragma fragment fragThin
  ENDCG

}

}

Fallback off

} // shader\

Hello, I used shader in the unity3d.
But, I have some wrong this shader just for me.
When I used this shader, you can show under the img.
125alt text125

But, I want to make like a under the picture.
these two plane show line.

95alt text95

How can i fix this shader. If you can know, let me know plz.
Thank for reading. And I’m sorry I can’t write English very well.

Your images are broken, so hard to understand what you are wanting.

1 Answer

1

I’m also working on depth effects in the unity3d.

I can’t see your images, but I also have a problem with “lines”

In my case, switching camera.depthTextureMode from Depth to DepthNormals caused the problem, because the unity3d stores Depth in nonlinear floating point and DepthNormals in fixed point format, which immediately breaks down if your far plane is larger than a room. For instance, with a far plane of 1300 meters the smallest delta you’re getting is 5 meters.

This wrecks SAO effects, among other things. My present task is to fix this. Which means I’m getting paid to cry at my desk.

[27063-depth+is+smoother+than+depthnormals.jpg|27063]

I've accepted your answer on this Well Old QA as its the most informed (and only) answer. If you find a solution to your problem and care to share, perhaps create a new, more direct question of your own and put the answer in. Up to you, of course.