- 最后登录
- 2014-10-23
- 注册时间
- 2011-7-19
- 阅读权限
- 90
- 积分
- 81303
- 纳金币
- -1
- 精华
- 11
|
Shader "Hidden/Edge Detect Normals" {
Properties {
_MainTex ("Base (RGB)", RECT) = "white" {}
_NormalsTexture ("Normals", RECT) = "white" {}
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
Fog { Mode off }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
uniform samplerRECT _MainTex;
uniform samplerRECT _NormalsTexture;
uniform float4 _MainTex_***lSize;
s***ct v2f {
float4 pos : POSITION;
float2 uv[3] : TEXCOORD0;
};
v2f vert( appdata_img v )
{
v2f o;
o.pos = mul (glstate.matrix.mvp, v.vertex);
float2 uv = MultiplyUV( glstate.matrix.texture[0], v.texcoord );
o.uv[0] = uv;
o.uv[1] = uv + float2(-_MainTex_***lSize.x, -_MainTex_***lSize.y);
o.uv[2] = uv + float2(+_MainTex_***lSize.x, -_MainTex_***lSize.y);
return o;
}
half4 frag (v2f i) : COLOR
{
half4 original = texRECT(_MainTex, i.uv[0]);
// three samples from normals+depth buffer
half4 normalD1 = texRECT(_NormalsTexture, i.uv[0]);
half4 normalD2 = texRECT(_NormalsTexture, i.uv[1]);
half4 normalD3 = texRECT(_NormalsTexture, i.uv[2]);
// normals filter
half3 n1 = normalD1.rgb*2-1;
half3 n2 = normalD2.rgb*2-1;
half3 n3 = normalD3.rgb*2-1;
half2 ndiff;
ndiff.x = dot( n1, n2 );
ndiff.y = dot( n1, n3 );
ndiff -= 0.9;
ndiff = ndiff > half2(0,0) ? half2(1,1) : half2(0,0);
half ndiff1 = ndiff.x * ndiff.y;
original.rgb *= ndiff1;
// depth filter
float2 zdiff;
zdiff.x = normalD1.a - normalD2.a;
zdiff.y = normalD1.a - normalD3.a;
zdiff = abs( zdiff ) - 0.05;
zdiff = zdiff > half2(0,0) ? half2(0,0) : half2(1,1);
original *= zdiff.x*zdiff.y;
return original;
}
ENDCG
}
}
Fallback off
} |
|