[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 | |
---|
[2865] | 12 | //uniform sampler2D s_distort; |
---|
| 13 | uniform float4 e_barrier = float4(5e-5, 5e-5, 0, 0); |
---|
| 14 | uniform float4 e_weights = float4(1.0f, 1.0f, 1.0f, 1.0f); // x = normal, y = depth |
---|
| 15 | uniform float4 e_kernel = float4(0.3f, 1.0f, 1.0f, 1.0f); // x = normal, y = depth |
---|
[2864] | 16 | |
---|
| 17 | |
---|
[2865] | 18 | float4 main(v2p IN, |
---|
| 19 | uniform sampler2D colors, |
---|
| 20 | uniform sampler2D normals |
---|
| 21 | ): COLOR |
---|
[2864] | 22 | { |
---|
[2865] | 23 | // normal discontinuity filter |
---|
| 24 | float3 nc = (float3)tex2D(normals, IN.c.xy); |
---|
[2864] | 25 | |
---|
[2865] | 26 | float4 nd; |
---|
| 27 | nd.x = dot(nc, float3(tex2D(normals, IN.lt.xy))); |
---|
| 28 | nd.y = dot(nc, float3(tex2D(normals, IN.rb.xy))); |
---|
| 29 | nd.z = dot(nc, float3(tex2D(normals, IN.rt.xy))); |
---|
| 30 | nd.w = dot(nc, float3(tex2D(normals, IN.lb.xy))); |
---|
[2864] | 31 | |
---|
| 32 | nd -= e_barrier.x; |
---|
[2866] | 33 | nd = step(0.0f, nd); |
---|
[2864] | 34 | |
---|
| 35 | float ne = saturate(dot(nd, e_weights.x)); |
---|
| 36 | |
---|
[2865] | 37 | // opposite coordinates |
---|
| 38 | float4 lrr = IN.lr.wzyx; |
---|
| 39 | float4 tbr = IN.tb.wzyx; |
---|
[2864] | 40 | |
---|
[2865] | 41 | // depth filter: compute gradient difference: |
---|
| 42 | // (c - sample) + (c - opposite sample) |
---|
[2864] | 43 | |
---|
[2865] | 44 | float4 dc = float4(tex2D(colors, IN.c).w); |
---|
[2864] | 45 | |
---|
[2865] | 46 | float pos_lt = (float)tex2D(colors, IN.lt.xy).w; |
---|
| 47 | float pos_rb = (float)tex2D(colors, IN.rb.xy).w; |
---|
[2864] | 48 | |
---|
[2865] | 49 | float pos_lb = (float)tex2D(colors, IN.lb.xy).w; |
---|
| 50 | float pos_rt = (float)tex2D(colors, IN.rt.xy).w; |
---|
[2864] | 51 | |
---|
[2865] | 52 | float pos_l = (float)tex2D(colors, IN.lr.xy).w; |
---|
| 53 | float pos_r = (float)tex2D(colors, lrr.xy).w; |
---|
[2864] | 54 | |
---|
[2865] | 55 | float pos_t = (float)tex2D(colors, IN.tb.xy).w; |
---|
| 56 | float pos_b = (float)tex2D(colors, tbr.xy).w; |
---|
[2864] | 57 | |
---|
[2865] | 58 | float4 dd; |
---|
[2864] | 59 | |
---|
[2865] | 60 | dd.x = pos_lt + pos_rb; |
---|
| 61 | dd.y = pos_lb + pos_rt; |
---|
| 62 | dd.z = pos_l + pos_r; |
---|
| 63 | dd.w = pos_t + pos_b; |
---|
[2864] | 64 | |
---|
[2865] | 65 | dd = abs(2.0f * dc - dd) - e_barrier.y; |
---|
[2866] | 66 | dd = step(dd, 0.0f); |
---|
| 67 | |
---|
[2865] | 68 | float de = saturate(dot(dd, e_weights.y)); |
---|
| 69 | |
---|
| 70 | // weight: 0 = no aa, 1 = full antialiasing |
---|
| 71 | float w = (1.0f - de * ne) * e_kernel.x; |
---|
| 72 | |
---|
| 73 | // smoothed color |
---|
| 74 | // (a - c) * w + c = a * w + c * (1 - w) |
---|
| 75 | float2 offset = IN.c.xy * (1.0f - w); |
---|
| 76 | |
---|
| 77 | float4 s0 = tex2D(colors, offset + IN.lt.xy * w); |
---|
| 78 | float4 s1 = tex2D(colors, offset + IN.rb.xy * w); |
---|
| 79 | float4 s2 = tex2D(colors, offset + IN.rt.xy * w); |
---|
| 80 | float4 s3 = tex2D(colors, offset + IN.lb.xy * w); |
---|
| 81 | |
---|
| 82 | return (s0 + s1 + s2 + s3) / 4.0f; |
---|
| 83 | //return float4(w); |
---|
| 84 | } |
---|