1//////////////////////////////////////////////// 2// 3// anti-aliasing 4// 5//////////////////////////////////////////////// 6 7lazyshader 0 "tqaaresolve" [ 8 attribute vec4 vvertex; 9 attribute vec2 vtexcoord0; 10 uniform vec4 quincunx; 11 varying vec2 texcoord0, texcoord1, texcoord2; 12 @(? $tqaaresolvegather [ 13 varying vec2 texcoord3; 14 ]) 15 void main(void) 16 { 17 gl_Position = vvertex; 18 texcoord0 = vtexcoord0; 19 texcoord1 = vtexcoord0 + quincunx.xy; 20 texcoord2 = vtexcoord0 + quincunx.zw; 21 @(? $tqaaresolvegather [ 22 texcoord3 = vtexcoord0 - 0.5; 23 ]) 24 } 25] [ 26 @(gfetchdefs tex2) 27 uniform sampler2DRect tex0, tex1; 28 uniform mat4 reprojectmatrix; 29 uniform vec2 maxvelocity; 30 uniform vec2 colorweight; 31 varying vec2 texcoord0, texcoord1, texcoord2; 32 @(? $tqaaresolvegather [ 33 varying vec2 texcoord3; 34 ]) 35 fragdata(0, fragcolor, vec4) 36 void main(void) 37 { 38 @(gdepthunpack depth [gfetch(tex2, texcoord0)] [ 39 vec4 prevtc = reprojectmatrix * vec4(depth*texcoord0, depth, 1.0); 40 ] [ 41 vec4 prevtc = reprojectmatrix * vec4(texcoord0, depth, 1.0); 42 ]) 43 prevtc.xy /= prevtc.w; 44 vec2 vel = prevtc.xy - texcoord0; 45 46 vec4 color = texture2DRect(tex0, texcoord1); 47 float vscale = color.a*maxvelocity.x*inversesqrt(dot(vel, vel) + 1e-6); 48 vec4 prevcolor = texture2DRect(tex1, texcoord2 + vel*vscale); 49 50 @(? $tqaaresolvegather [ 51 vec4 l0 = textureGather(tex0, texcoord3, 1); 52 vec4 l1 = textureGatherOffset(tex0, texcoord3, ivec2(1, 1), 1); 53 float l2 = texture2DRectOffset(tex0, texcoord0, ivec2(1, -1)).g; 54 float l3 = texture2DRectOffset(tex0, texcoord0, ivec2(-1, 1)).g; 55 vec4 l01min = min(l0, l1), l01max = max(l0, l1); 56 l01min.xy = min(l01min.xy, l01min.zw); 57 l01max.xy = max(l01max.xy, l01max.zw); 58 float lmin = min(min(l01min.x, l01min.y), min(l2, l3)); 59 float lmax = max(max(l01max.x, l01max.y), max(l2, l3)); 60 ] [ 61 float l0 = texture2DRect(tex0, texcoord0 + vec2(-1.0, -0.5)).g; 62 float l1 = texture2DRect(tex0, texcoord0 + vec2( 0.5, -1.0)).g; 63 float l2 = texture2DRect(tex0, texcoord0 + vec2( 1.0, 0.5)).g; 64 float l3 = texture2DRect(tex0, texcoord0 + vec2(-0.5, 1.0)).g; 65 float lmin = min(color.g, min(min(l0, l1), min(l2, l3))); 66 float lmax = max(color.g, max(max(l0, l1), max(l2, l3))); 67 ]) 68 69 float weight = clamp((colorweight.x*max(prevcolor.g - lmax, lmin - prevcolor.g) + colorweight.y) / (lmax - lmin + 1e-4), 0.0, 1.0); 70 fragcolor.rgb = mix(color.rgb, prevcolor.rgb, 0.5 - 0.5*weight); 71 fragcolor.a = color.a; 72 } 73] 74 75smaaopt = [ >= (strstr $smaaopts $arg1) 0 ] 76smaashaders = [ 77 smaapreset = $arg1 78 smaaopts = $arg2 79 exec "config/glsl/smaa.cfg" 80] 81 82fxaaopt = [ >= (strstr $fxaaopts $arg1) 0 ] 83fxaashaders = [ 84 fxaapreset = $arg1 85 fxaaopts = $arg2 86 exec "config/glsl/fxaa.cfg" 87] 88 89