ProjectArcade
67 строк · 2.3 Кб
1// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2// Version 2, December 2004
3
4// Copyright (C) 2013 mudlord
5
6// Everyone is permitted to copy and distribute verbatim or modified
7// copies of this license document, and changing it is allowed as long
8// as the name is changed.
9
10// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11// TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12
13// 0. You just DO WHAT THE FUCK YOU WANT TO.
14
15#define FXAA_REDUCE_MIN (1.0/ 128.0)
16#define FXAA_REDUCE_MUL (1.0 / 8.0)
17#define FXAA_SPAN_MAX 8.0
18
19float4 applyFXAA(float2 fragCoord)
20{
21float4 color;
22float2 inverseVP = GetInvResolution();
23float3 rgbNW = SampleLocation((fragCoord + float2(-1.0, -1.0)) * inverseVP).xyz;
24float3 rgbNE = SampleLocation((fragCoord + float2(1.0, -1.0)) * inverseVP).xyz;
25float3 rgbSW = SampleLocation((fragCoord + float2(-1.0, 1.0)) * inverseVP).xyz;
26float3 rgbSE = SampleLocation((fragCoord + float2(1.0, 1.0)) * inverseVP).xyz;
27float3 rgbM = SampleLocation(fragCoord * inverseVP).xyz;
28float3 luma = float3(0.299, 0.587, 0.114);
29float lumaNW = dot(rgbNW, luma);
30float lumaNE = dot(rgbNE, luma);
31float lumaSW = dot(rgbSW, luma);
32float lumaSE = dot(rgbSE, luma);
33float lumaM = dot(rgbM, luma);
34float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
35float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
36
37float2 dir;
38dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
39dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
40
41float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) *
42(0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);
43
44float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);
45dir = min(float2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),
46max(float2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),
47dir * rcpDirMin)) * inverseVP;
48
49float3 rgbA = 0.5 * (
50SampleLocation(fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz +
51SampleLocation(fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);
52float3 rgbB = rgbA * 0.5 + 0.25 * (
53SampleLocation(fragCoord * inverseVP + dir * -0.5).xyz +
54SampleLocation(fragCoord * inverseVP + dir * 0.5).xyz);
55
56float lumaB = dot(rgbB, luma);
57if ((lumaB < lumaMin) || (lumaB > lumaMax))
58color = float4(rgbA, 1.0);
59else
60color = float4(rgbB, 1.0);
61return color;
62}
63
64void main()
65{
66SetOutput(applyFXAA(GetCoordinates() * GetResolution()));
67}
68