//sampler2D s_distort; sampler2D s_depthNormal; // float2 e_barrier = {0.8, 0.5}; // x = norm(~.8f), y = depth(~.5f) float2 e_weights = {0.8, 0.8}; // x = norm, y = depth float e_kernel = 0.5; // x = norm float2 QuadScreenSize = {640, 360}; struct vertexOutput { float4 Position : POSITION; float2 tc0 : TEXCOORD0; // Centre float2 tc1 : TEXCOORD1; // Left Top float2 tc2 : TEXCOORD2; // Right Bottom float2 tc3 : TEXCOORD3; // Right Top float2 tc4 : TEXCOORD4; // Left Bottom float4 tc5 : TEXCOORD5; // Left / Right float4 tc6 : TEXCOORD6; // Top / Bottom }; vertexOutput postprocessAntiAliasingVP(float4 Position : POSITION, float2 TexCoord : TEXCOORD0) { vertexOutput OUT; float2 texelSize = 1.0 / QuadScreenSize; OUT.Position = Position; OUT.tc0 = TexCoord; OUT.tc1 = TexCoord + float2(-texelSize.x, texelSize.y); OUT.tc2 = TexCoord + float2( texelSize.x,-texelSize.y); OUT.tc3 = TexCoord + float2( texelSize.x, texelSize.y); OUT.tc4 = TexCoord + float2(-texelSize.x,-texelSize.y); OUT.tc5 = float4(TexCoord, TexCoord) + float4(-texelSize.x, 0.0f , texelSize.x, 0.0f); OUT.tc6 = float4(TexCoord, TexCoord) + float4( 0.0f, texelSize.y , 0.0f,-texelSize.y); return OUT; } half3 DecodeNormal(half2 _xy) { half3 normal = half3(_xy, 0); normal.z = sqrt(1 - ((_xy.x * _xy.x) + (_xy.y * _xy.y))); return normal; } half4 postprocessAntiAliasingFP(vertexOutput I) : COLOR { half3 dnm0 = tex2D(s_depthNormal, I.tc0).xyw; half3 dnm1 = tex2D(s_depthNormal, I.tc1).xyw; half3 dnm2 = tex2D(s_depthNormal, I.tc2).xyw; half3 dnm3 = tex2D(s_depthNormal, I.tc3).xyw; half3 dnm4 = tex2D(s_depthNormal, I.tc4).xyw; // Normal discontinutiy filter half3 nc = half3(DecodeNormal(dnm0.xy)); half4 nd; nd.x = dot(nc, half3(DecodeNormal(dnm1.xy))); nd.y = dot(nc, half3(DecodeNormal(dnm2.xy))); nd.z = dot(nc, half3(DecodeNormal(dnm3.xy))); nd.w = dot(nc, half3(DecodeNormal(dnm4.xy))); nd -= e_barrier.x; nd = step(0.h, nd); half ne = saturate(dot(nd, e_weights.x)); // Opposite coords // float4 tc5r = I.tc5.wzyx; // float4 tc6r = I.tc6.wzyx; // Depth filter: compute gradiental difference: // (c-sample1)+(c-sample1_opposite) half4 dc = dnm0.z; half4 dd; dd.x = dnm1.z + dnm2.z; dd.y = dnm3.z + dnm4.z; dd.z = (half)tex2D(s_depthNormal, I.tc5.xy).a + (half)tex2D(s_depthNormal, I.tc5.zw).a; dd.w = (half)tex2D(s_depthNormal, I.tc6.xy).a + (half)tex2D(s_depthNormal, I.tc6.zw).a; dd = abs(2 * dc.z - dd) - e_barrier.y; dd = step(dd, 0); half de = saturate(dot(dd, e_weights.y)); // Weight half w = (1 - de * ne) * e_kernel; // 0 - no aa, 1 = full aa // Smoothed Colour // (a-c)*w + c = a*w + c(1-w) float2 offset = I.tc0 * (1-w); // half4 s0 = tex2D(s_screenImage, offset + I.tc1 * w); // half4 s1 = tex2D(s_screenImage, offset + I.tc2 * w); // half4 s2 = tex2D(s_screenImage, offset + I.tc3 * w); // half4 s3 = tex2D(s_screenImage, offset + I.tc4 * w); return half4(w ,0.h, 0.h, 0.h); //return s0 * (1.0 - w); // return (s0 + s1 + s2 + s3)/4.h; //return 1.h - w; } // Technique technique postProcessAntiAliasing { pass p0 { VertexProgram = compile vp30 postprocessAntiAliasingVP(); FragmentProgram = compile fp40 postprocessAntiAliasingFP(); DepthTestEnable = false; DepthMask = false; BlendEnable = false; } }