ProjectArcade

Форк
0
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

19
float4 applyFXAA(float2 fragCoord)
20
{
21
	float4 color;
22
	float2 inverseVP = GetInvResolution();
23
	float3 rgbNW = SampleLocation((fragCoord + float2(-1.0, -1.0)) * inverseVP).xyz;
24
	float3 rgbNE = SampleLocation((fragCoord + float2(1.0, -1.0)) * inverseVP).xyz;
25
	float3 rgbSW = SampleLocation((fragCoord + float2(-1.0, 1.0)) * inverseVP).xyz;
26
	float3 rgbSE = SampleLocation((fragCoord + float2(1.0, 1.0)) * inverseVP).xyz;
27
	float3 rgbM  = SampleLocation(fragCoord  * inverseVP).xyz;
28
	float3 luma = float3(0.299, 0.587, 0.114);
29
	float lumaNW = dot(rgbNW, luma);
30
	float lumaNE = dot(rgbNE, luma);
31
	float lumaSW = dot(rgbSW, luma);
32
	float lumaSE = dot(rgbSE, luma);
33
	float lumaM  = dot(rgbM,  luma);
34
	float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
35
	float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
36

37
	float2 dir;
38
	dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
39
	dir.y =  ((lumaNW + lumaSW) - (lumaNE + lumaSE));
40

41
	float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) *
42
						(0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);
43

44
	float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);
45
	dir = min(float2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),
46
			max(float2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),
47
			dir * rcpDirMin)) * inverseVP;
48

49
	float3 rgbA = 0.5 * (
50
		SampleLocation(fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz +
51
		SampleLocation(fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);
52
	float3 rgbB = rgbA * 0.5 + 0.25 * (
53
		SampleLocation(fragCoord * inverseVP + dir * -0.5).xyz +
54
		SampleLocation(fragCoord * inverseVP + dir * 0.5).xyz);
55

56
	float lumaB = dot(rgbB, luma);
57
	if ((lumaB < lumaMin) || (lumaB > lumaMax))
58
		color = float4(rgbA, 1.0);
59
	else
60
		color = float4(rgbB, 1.0);
61
	return color;
62
}
63

64
void main()
65
{
66
	SetOutput(applyFXAA(GetCoordinates() * GetResolution()));
67
}
68

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.