#include "Defs.fxh" #ifdef _ENTRY_VSDown4xG_PSDown4xG PS3PRAGMA(regcount 48) #endif float4 TexSize; sampler2D TexIn; struct VSInput { float4 vPos : POSITION; float2 vTC : TEXCOORD0; }; /////////////////////////////////////////////////////////////////////////////// // Downsample 2x: jeden sampling bilinear // // +--+--+ +-----+ // | | | | | // +--+--+ => | s | // | | | | | // +--+--+ +-----+ // // środek pixela wynikowego jest dokładnie na rogach pixli wejściowych, offset 0,0 // // identyczne jak copy shader float4 VSDown2x(in VSInput IN, out float2 tc: TEXCOORD0): POSITION { IN.vPos.z=0; tc = IN.vTC; return IN.vPos; } half4 PSDown2x(in half2 tc: TEXCOORD0) : COLOR0 { half4 c0 = tex2D(TexIn, tc); return c0; } /////////////////////////////////////////////////////////////////////////////// // Downsample 4x, box filter: 4 sample bilinear // +--+--+--+--+ +-----------+ // | | | | | | | // +--+--+--+--+ | s s | // | | | | | | | // +--+--+--+--+ => | | // | | | | | | | // +--+--+--+--+ | s s | // | | | | | | | // +--+--+--+--+ +-----------+ // // środek pixela wynikowego jest dokładnie na rogach pixli wejściowych, offset 0,0 // float4 VSDown4xB(in VSInput IN, out float2 tc0: TEXCOORD0, out float2 tc1: TEXCOORD1): POSITION { IN.vPos.z=0; tc0 = IN.vTC - 1 * TexSize.zw; tc1 = IN.vTC + 1 * TexSize.zw; return IN.vPos; } half4 PSDown4xB(in float2 tc0: TEXCOORD0, in float2 tc1: TEXCOORD1, float2 vp: VPOS): COLOR0 { return (tex2D(TexIn, float2(tc0.x, tc0.y)) + tex2D(TexIn, float2(tc1.x, tc0.y)) + tex2D(TexIn, float2(tc0.x, tc1.y)) + tex2D(TexIn, float2(tc1.x, tc1.y))) / 4; } /////////////////////////////////////////////////////////////////////////////// // Downsample 4x, 6x6 gaussian filter: 9 sampli bilinear // // ..1 ..5 .10 .10 ..5 ..1 1:5 1/6 : 5/6 // ..5 .25 .50 .50 .25 ..5 // .10 .50 100 100 .50 .10 // .10 .50 100 100 .50 .10 // ..5 .25 .50 .50 .25 ..5 // ..1 ..5 .10 .10 ..5 ..1 // // t0 [] [] // [] t1 [] // [] [] t2 // +--+--+--+--+--+--+ + + // | | | | | | | // +--+--+--+--+--+--+ +-----------+ // | | | | | | | |t0 (-1.6) | // +--+--+--+--+--+--+ | | // | | | | | | | | | // +--+--+--+--+--+--+ => | t1 | // | | | | | | | | | // +--+--+--+--+--+--+ | | // | | | | | | | | (1.6)t2 | // +--+--+--+--+--+--+ +-----------+ // | | | | | | | // +--+--+--+--+--+--+ + + float4 VSDown4xG(in VSInput IN, out float2 tc0: TEXCOORD0, out float2 tc1: TEXCOORD1, out float2 tc2: TEXCOORD2): POSITION { IN.vPos.z=0; tc0 = IN.vTC - 1.6666f * TexSize.zw; tc1 = IN.vTC; tc2 = IN.vTC + 1.6666f * TexSize.zw; return IN.vPos; } half4 PSDown4xG(in float2 tc0: TEXCOORD0, in float2 tc1: TEXCOORD1, in float2 tc2: TEXCOORD2, in float2 vp: VPOS): COLOR0 { #ifdef DEBUG if(vp.x == 15 && vp.y == 15) return half4(10,0,0,0); #endif #if 1 // głupie optymalizatory return (tex2D(TexIn, float2(tc0.x, tc0.y)) * 9 + tex2D(TexIn, float2(tc1.x, tc0.y)) * 30 + tex2D(TexIn, float2(tc2.x, tc0.y)) * 9 + tex2D(TexIn, float2(tc0.x, tc1.y)) * 30 + tex2D(TexIn, float2(tc1.x, tc1.y)) * 100 + tex2D(TexIn, float2(tc2.x, tc1.y)) * 30 + tex2D(TexIn, float2(tc0.x, tc2.y)) * 9 + tex2D(TexIn, float2(tc1.x, tc2.y)) * 30 + tex2D(TexIn, float2(tc2.x, tc2.y)) * 9) / 256; #else return (((tex2D(TexIn, float2(tc1.x, tc0.y)) + tex2D(TexIn, float2(tc0.x, tc1.y)) + tex2D(TexIn, float2(tc2.x, tc1.y)) + tex2D(TexIn, float2(tc1.x, tc2.y)) + tex2D(TexIn, float2(tc1.x, tc1.y)) * (100./30.)) * (30./9.)) + tex2D(TexIn, float2(tc0.x, tc0.y)) + tex2D(TexIn, float2(tc2.x, tc0.y)) + tex2D(TexIn, float2(tc0.x, tc2.y)) + tex2D(TexIn, float2(tc2.x, tc2.y))) * (9./256); #endif } /////////////////////////////////////////////////////////////////////////////// // Blur 5-tap gaussian 11x11 separable // // +--+--+--+--+--+--+--+--+--+--+ + + // | | | | | | | | | | | // +--+--+--+--+--+--+--+--+--+--+ => +--o środek pixela offset uv: (-.5, .5) // | | | | | | | | | | | |><| // +--+--+--+--+--+--+--+--+--+--+ + +--+ + // // // +--+--+ + + // | | | // +--+--+ // | | | // +--+--+ // | | | // +--+--+ // | | | // +--+--+ +--+ // | | | |><| środek pixela offset uv: (.5, -.5) // +--+--+ => o--+ // | | | // +--+--+ // | | | // +--+--+ // | | | // +--+--+ // | | | // +--+--+ // | | | // +--+--+ + + // // // 1 9 36 84 126 126 84 36 9 1 // 1 9 36 84 126 126 84 36 9 1 // // wagi: // 5 60 126 60 5 / 256 // // uvki // // 1 9 -> 0.9 +- 3.2 // 36 84 -> 0.7 +- 1.6 // 126 126 -> 0.5 0 // dla poziomego blura: (TexSize.z, 0, 0.5 * TexSize.z,-0.5 * TexSize.w) // dla pionowego blura: (0, TexSize.w,-0.5 * TexSize.z, 0.5 * TexSize.w) float4 texel_offset; float4 VSBlur11xG(in VSInput IN, out float4 tc0: TEXCOORD0, out float4 tc1: TEXCOORD1, out float4 tc2: TEXCOORD2): POSITION { IN.vPos.z=0; IN.vTC += texel_offset.zw; tc0.xy = IN.vTC - 3.6 * texel_offset.xy; // między -4.5 a -3.5, w stosunku 1:9 tc0.zw = IN.vTC - 1.8 * texel_offset.xy; // między -2.5 a -1.5, w stosunku 36:84 tc1.xy = IN.vTC; tc1.zw = IN.vTC + 1.8 * texel_offset.xy; tc2.xy = IN.vTC + 3.6 * texel_offset.xy; tc2.zw = 0; return IN.vPos; } half4 PSBlur11xG(in float4 tc0: TEXCOORD0, in float4 tc1: TEXCOORD1, in float4 tc2: TEXCOORD2, float2 vp: VPOS): COLOR0 { half4 r = (tex2D(TexIn, tc0.xy) * 5 + tex2D(TexIn, tc0.zw) * 60 + tex2D(TexIn, tc1.xy) * 126 + tex2D(TexIn, tc1.zw) * 60 + tex2D(TexIn, tc2.xy) * 5) / 256.; return r; } // analogicznie mniejszy rozmiar kernela, mniej tapów // // 1 7 21 35 35 21 7 1 4-tap [9x9] 1:7:7:1 // 1 5 10 10 5 1 3-tap [7x7] 3:10:3 // 1 3 3 1 2-tap [5x5] 1:1 // 1 1 1-tap [3x3] ?? float4 VSBlur9xG(in VSInput IN, out float4 tc0: TEXCOORD0, out float4 tc1: TEXCOORD1): POSITION { IN.vPos.z=0; IN.vTC += texel_offset.zw; tc0.xy = IN.vTC - 2.625 * texel_offset.xy; // między -3.5 a -2.5, w stosunku 1:7 tc0.zw = IN.vTC - 0.875 * texel_offset.xy; // między -1.5 a -0.5, w stosunku 21:35 tc1.xy = IN.vTC + 0.875 * texel_offset.xy; tc1.zw = IN.vTC + 2.625 * texel_offset.xy; return IN.vPos; } half4 PSBlur9xG(in float4 tc0: TEXCOORD0, in float4 tc1: TEXCOORD1): COLOR0 { half4 r = (tex2D(TexIn, tc0.xy) * 1 + tex2D(TexIn, tc0.zw) * 7 + tex2D(TexIn, tc1.xy) * 7 + tex2D(TexIn, tc1.zw) * 1) / 16.; return r; } float4 VSBlur7xG(in VSInput IN, out float4 tc0: TEXCOORD0, out float4 tc1: TEXCOORD1): POSITION { IN.vPos.z=0; IN.vTC += texel_offset.zw; tc0.xy = IN.vTC - 1.6667 * texel_offset.xy; // między -2.5 a -1.5, w stosunku 1:5 tc0.zw = IN.vTC; tc1.xy = IN.vTC + 1.6667 * texel_offset.xy; tc1.zw = 0; return IN.vPos; } half4 PSBlur7xG(in float4 tc0: TEXCOORD0, in float4 tc1: TEXCOORD1): COLOR0 { half4 r = (tex2D(TexIn, tc0.xy) * 3 + tex2D(TexIn, tc0.zw) * 10 + tex2D(TexIn, tc1.xy) * 3) / 16.; return r; } float4 VSBlur5xG(in VSInput IN, out float4 tc0: TEXCOORD0): POSITION { IN.vPos.z=0; IN.vTC += texel_offset.zw; tc0.xy = IN.vTC - 0.75 * texel_offset.xy; // między -1.5 a -0.5, w stosunku 1:3 tc0.zw = IN.vTC + 0.75 * texel_offset.xy; return IN.vPos; } half4 PSBlur5xG(in float4 tc0: TEXCOORD0): COLOR0 { half4 r = (tex2D(TexIn, tc0.xy) + tex2D(TexIn, tc0.zw)) / 2.; return r; } float4 Color; float4 VSCompositeBlur(in VSInput IN, out float2 tc: TEXCOORD0): POSITION { IN.vPos.z=0; tc = IN.vTC; return IN.vPos; } half4 PSCompositeBlur(float2 tc: TEXCOORD0, float2 vp: VPOS) : COLOR0 { float4 tmp = tex2D(TexIn, tc); tmp.a = Color.a; return tmp; }