[2864] | 1 | struct v2p |
---|
| 2 | { |
---|
[2865] | 3 | float2 c: TEXCOORD0; // center |
---|
| 4 | float2 lt: TEXCOORD1; // left top |
---|
| 5 | float2 rb: TEXCOORD2; // right bottom |
---|
| 6 | float2 rt: TEXCOORD3; // right top |
---|
| 7 | float2 lb: TEXCOORD4; // left bottom |
---|
| 8 | float4 lr: TEXCOORD5; // left / right |
---|
| 9 | float4 tb: TEXCOORD6; // top / bottom |
---|
| 10 | }; |
---|
[2864] | 11 | |
---|
[2867] | 12 | // the barrier for detecting a discontinuity |
---|
[2884] | 13 | uniform float4 e_barrier = float4(5e-5, 5e-5, 0, 0); // x = normal, y = depth |
---|
[2867] | 14 | // the weights for normal / depth discontinuity |
---|
[2891] | 15 | uniform float4 e_weights = float4(0.5f, 0.5f, 1.0f, 1.0f); // x = normal, y = depth |
---|
| 16 | //uniform float4 e_weights = float4(1.0f, 1.0f, 1.0f, 1.0f); // x = normal, y = depth |
---|
| 17 | uniform float4 e_kernel = float4(0.5f, 1.0f, 1.0f, 1.0f); |
---|
[2864] | 18 | |
---|
| 19 | |
---|
[2865] | 20 | float4 main(v2p IN, |
---|
| 21 | uniform sampler2D colors, |
---|
| 22 | uniform sampler2D normals |
---|
| 23 | ): COLOR |
---|
[2864] | 24 | { |
---|
[2867] | 25 | //return tex2D(colors, IN.c.xy); |
---|
[2884] | 26 | |
---|
[2865] | 27 | // normal discontinuity filter |
---|
| 28 | float3 nc = (float3)tex2D(normals, IN.c.xy); |
---|
[2864] | 29 | |
---|
[2865] | 30 | float4 nd; |
---|
| 31 | nd.x = dot(nc, float3(tex2D(normals, IN.lt.xy))); |
---|
| 32 | nd.y = dot(nc, float3(tex2D(normals, IN.rb.xy))); |
---|
| 33 | nd.z = dot(nc, float3(tex2D(normals, IN.rt.xy))); |
---|
| 34 | nd.w = dot(nc, float3(tex2D(normals, IN.lb.xy))); |
---|
[2864] | 35 | |
---|
[2891] | 36 | nd -= e_barrier.x; |
---|
[2868] | 37 | nd = step((float4)0.0f, nd); |
---|
[2864] | 38 | |
---|
| 39 | float ne = saturate(dot(nd, e_weights.x)); |
---|
| 40 | |
---|
[2884] | 41 | // construct opposite coordinates |
---|
[2865] | 42 | float4 lrr = IN.lr.wzyx; |
---|
| 43 | float4 tbr = IN.tb.wzyx; |
---|
[2864] | 44 | |
---|
[2865] | 45 | // depth filter: compute gradient difference: |
---|
| 46 | // (c - sample) + (c - opposite sample) |
---|
[2864] | 47 | |
---|
[2865] | 48 | float4 dc = float4(tex2D(colors, IN.c).w); |
---|
[2864] | 49 | |
---|
[2865] | 50 | float pos_lt = (float)tex2D(colors, IN.lt.xy).w; |
---|
| 51 | float pos_rb = (float)tex2D(colors, IN.rb.xy).w; |
---|
[2864] | 52 | |
---|
[2865] | 53 | float pos_lb = (float)tex2D(colors, IN.lb.xy).w; |
---|
| 54 | float pos_rt = (float)tex2D(colors, IN.rt.xy).w; |
---|
[2864] | 55 | |
---|
[2865] | 56 | float pos_l = (float)tex2D(colors, IN.lr.xy).w; |
---|
| 57 | float pos_r = (float)tex2D(colors, lrr.xy).w; |
---|
[2864] | 58 | |
---|
[2865] | 59 | float pos_t = (float)tex2D(colors, IN.tb.xy).w; |
---|
| 60 | float pos_b = (float)tex2D(colors, tbr.xy).w; |
---|
[2864] | 61 | |
---|
[2865] | 62 | float4 dd; |
---|
[2864] | 63 | |
---|
[2865] | 64 | dd.x = pos_lt + pos_rb; |
---|
| 65 | dd.y = pos_lb + pos_rt; |
---|
| 66 | dd.z = pos_l + pos_r; |
---|
| 67 | dd.w = pos_t + pos_b; |
---|
[2864] | 68 | |
---|
[2865] | 69 | dd = abs(2.0f * dc - dd) - e_barrier.y; |
---|
[2884] | 70 | dd = step(dd, (float4)0.0f); |
---|
[2866] | 71 | |
---|
[2865] | 72 | float de = saturate(dot(dd, e_weights.y)); |
---|
| 73 | |
---|
| 74 | // weight: 0 = no aa, 1 = full antialiasing |
---|
| 75 | float w = (1.0f - de * ne) * e_kernel.x; |
---|
| 76 | |
---|
| 77 | // smoothed color |
---|
| 78 | // (a - c) * w + c = a * w + c * (1 - w) |
---|
| 79 | float2 offset = IN.c.xy * (1.0f - w); |
---|
| 80 | |
---|
[2884] | 81 | float4 s0 = tex2Dlod(colors, float4(offset + IN.lt.xy * w, 0, 0)); |
---|
| 82 | float4 s1 = tex2Dlod(colors, float4(offset + IN.rb.xy * w, 0, 0)); |
---|
| 83 | float4 s2 = tex2Dlod(colors, float4(offset + IN.rt.xy * w, 0, 0)); |
---|
| 84 | float4 s3 = tex2Dlod(colors, float4(offset + IN.lb.xy * w, 0, 0)); |
---|
[2865] | 85 | |
---|
[2891] | 86 | float4 sc = tex2Dlod(colors, float4(IN.c.xy, 0, 0)); |
---|
[2884] | 87 | |
---|
[2891] | 88 | return (s0 + s1 + s2 + s3 + sc) * 0.2f; |
---|
| 89 | //return (s0 + s1 + s2 + s3) * 0.25f; |
---|
[2868] | 90 | //return float4(w); |
---|
[2865] | 91 | } |
---|