From 74b8d87d34afe96883c2c1508489ee604451aa64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Jos=C3=A9=20Garc=C3=ADa=20Garc=C3=ADa?= Date: Sun, 20 Nov 2016 23:58:47 +0100 Subject: [PATCH] Add fxaa --- .travis.yml | 9 +++---- shaders/fxaa_f.cg | 64 +++++++++++++++++++++++++++++++++++++++++++++++ shaders/fxaa_v.cg | 33 ++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 shaders/fxaa_f.cg create mode 100644 shaders/fxaa_v.cg diff --git a/.travis.yml b/.travis.yml index b9a0fb2..5a5e54d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,13 +4,10 @@ language: c before_install: - sudo apt-get install qemu-kvm qemu qemu-user-static - - git clone https://github.com/vitadev/vdpm - - cd vdpm - - cp config.sample config - - ./bootstrap-vitasdk.sh - - export VITASDK=/usr/local/vitasdk + - curl https://github.com/repos/vitasdk/autobuilds/releases | grep browser_download_url | grep linux | head -n 1 | cut -d '"' -f 4 | xargs wget + - tar xjf *.tar.bz2 + - export VITASDK=$PWD/vitasdk - export PATH=$VITASDK/bin:$PATH - - cd .. - wget https://releases.linaro.org/15.02/components/toolchain/binaries/arm-linux-gnueabihf/gcc-linaro-4.9-2015.02-3-x86_64_arm-linux-gnueabihf.tar.xz - tar xf gcc-linaro-4.9-2015.02-3-x86_64_arm-linux-gnueabihf.tar.xz - export PATH=$(pwd)/gcc-linaro-4.9-2015.02-3-x86_64_arm-linux-gnueabihf/bin:$PATH diff --git a/shaders/fxaa_f.cg b/shaders/fxaa_f.cg new file mode 100644 index 0000000..398efe6 --- /dev/null +++ b/shaders/fxaa_f.cg @@ -0,0 +1,64 @@ +#define FXAA_REDUCE_MIN (1.0/256.0) +#define FXAA_REDUCE_MUL (1.0/8.0) +#define FXAA_SPAN_MAX 8.0 +#define FXAA_SUBPIX_SHIFT (1.0/8.0) + +struct input +{ + float2 video_size; + float2 texture_size; + float2 output_size; + float frame_count; + float frame_direction; + float frame_rotation; +}; + + +struct out_vertex { + float4 position : POSITION; + float2 texCoord : TEXCOORD0; + float4 vpos : TEXCOORD1; +}; + +/* FRAGMENT SHADER */ +float4 main(in out_vertex VAR, uniform input IN, uniform sampler2D decal : TEXUNIT0) : COLOR +{ + //yes Cg is THIS retarded, passing position as texturecoord + VAR.vpos /= VAR.vpos.w; + + float2 inverse_resolution=1/IN.video_size.xy; + float4 coords; + coords.xy = VAR.texCoord; + coords.zw = coords.xy - (inverse_resolution.xy * (0.5 + FXAA_SUBPIX_SHIFT)); + float3 rgbNW = tex2D(decal, (VAR.texCoord + float2(-1.0,-1.0)) * inverse_resolution).xyz; + float3 rgbNE = tex2D(decal, (VAR.texCoord + float2(1.0,-1.0)) * inverse_resolution).xyz; + float3 rgbSW = tex2D(decal, (VAR.texCoord + float2(-1.0,1.0)) * inverse_resolution).xyz; + float3 rgbSE = tex2D(decal, (VAR.texCoord + float2(1.0,1.0)) * inverse_resolution).xyz; + float3 rgbM = tex2D(decal, VAR.texCoord ).xyz; + float3 luma = float3(0.299, 0.587, 0.114); + float lumaNW = dot(rgbNW, luma); + float lumaNE = dot(rgbNE, luma); + float lumaSW = dot(rgbSW, luma); + float lumaSE = dot(rgbSE, luma); + float lumaM = dot(rgbM, luma); + float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE))); + float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE))); + float2 dir; + dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE)); + dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE)); + float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL),FXAA_REDUCE_MIN); + float rcpDirMin = 1.0/(min(abs(dir.x), abs(dir.y)) + dirReduce); + dir = min(float2( FXAA_SPAN_MAX, FXAA_SPAN_MAX),max(float2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),dir * rcpDirMin)) * inverse_resolution; + + float3 rgbA = 0.5 * (tex2D(decal, VAR.texCoord + dir * (1.0/3.0 - 0.5)).xyz + + tex2D(decal, VAR.texCoord + dir * (2.0/3.0 - 0.5)).xyz); + float3 rgbB = rgbA * 0.5 + 0.25 * (tex2D(decal, VAR.texCoord * inverse_resolution + dir * - 0.5).xyz + tex2D(decal, VAR.texCoord + dir * 0.5).xyz); + float lumaB = dot(rgbB, luma); + if((lumaB < lumaMin) || (lumaB > lumaMax)) { + return float4(rgbA,1.0); + } else { + return float4(rgbB,1.0); + } + + +} diff --git a/shaders/fxaa_v.cg b/shaders/fxaa_v.cg new file mode 100644 index 0000000..16edfd7 --- /dev/null +++ b/shaders/fxaa_v.cg @@ -0,0 +1,33 @@ +struct input +{ + float2 video_size; + float2 texture_size; + float2 output_size; + float frame_count; + float frame_direction; + float frame_rotation; +}; + + +struct out_vertex { + float4 position : POSITION; + float2 texCoord : TEXCOORD0; + float4 vpos : TEXCOORD1; +}; + +/* VERTEX_SHADER */ +void main +( + float4 aPosition, + float2 aTexcoord, + uniform input IN, + uniform float4x4 wvp, + out out_vertex OUT +) +{ + OUT.position = mul(aPosition, wvp); + + OUT.texCoord = aTexcoord; + OUT.vpos = OUT.position; + +}