Skip to content

Commit

Permalink
Add fxaa
Browse files Browse the repository at this point in the history
  • Loading branch information
frangarcj committed Nov 20, 2016
1 parent c51d9c4 commit 74b8d87
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 6 deletions.
9 changes: 3 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 64 additions & 0 deletions shaders/fxaa_f.cg
Original file line number Diff line number Diff line change
@@ -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);
}


}
33 changes: 33 additions & 0 deletions shaders/fxaa_v.cg
Original file line number Diff line number Diff line change
@@ -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;

}

0 comments on commit 74b8d87

Please sign in to comment.