aboutsummaryrefslogtreecommitdiffstats
path: root/assets/shaders/glsl330/fuck.fs
blob: 5a4f63c94a3ec96d0360809b909baafdb45a2131 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#version 330

// This is a fuck shader. It is very fuck.

in vec2 fragTexCoord;

out vec4 fragColor;

uniform sampler2D texture0;
uniform vec4 colDiffuse;

const float PI = 3.1415926535;
const float aperture = 290.0;
const float renderWidth = 16;
const float renderHeight = 12;
const float gamma = 0.6;
const float numColors = 3.0;

float offset[3] = float[](0.0, 1.3846153846, 3.2307692308);
float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703);

void main()
{
  float apertureHalf = 0.5*aperture*(PI/180.0);
  float maxFactor = sin(apertureHalf);

  vec2 uv = vec2(0);
  vec2 xy = 2.0*fragTexCoord.xy - 1.0;
  float d = length(xy);

  if (d < (2.0 - maxFactor))
  {
    d = length(xy*maxFactor);
    float z = sqrt(1.0 - d*d);
    float r = atan(d, z)/PI;
    float phi = atan(xy.y, xy.x);

    uv.x = r*cos(phi) + 0.5;
    uv.y = r*sin(phi) + 0.5;
  }
  else
  {
    uv = fragTexCoord.xy;
  }

  vec4 color = texture(texture0, uv);

  color += texture(texture0, fragTexCoord + 0.001);
  color += texture(texture0, fragTexCoord + 0.003);
  color += texture(texture0, fragTexCoord + 0.005);
  color += texture(texture0, fragTexCoord + 0.007);
  color += texture(texture0, fragTexCoord + 0.009);
  color += texture(texture0, fragTexCoord + 0.011);

  color += texture(texture0, fragTexCoord - 0.001);
  color += texture(texture0, fragTexCoord - 0.003);
  color += texture(texture0, fragTexCoord - 0.005);
  color += texture(texture0, fragTexCoord - 0.007);
  color += texture(texture0, fragTexCoord - 0.009);
  color += texture(texture0, fragTexCoord - 0.011);

  color.rgb = vec3((color.r + color.g + color.b)/3.0);
  color = color/9.5;

  float x = 1.0/renderWidth;
  float y = 1.0/renderHeight;

  vec4 horizEdge = vec4(0.0);
  horizEdge -= texture(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
  horizEdge -= texture(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y   ))*2.0;
  horizEdge -= texture(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
  horizEdge += texture(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
  horizEdge += texture(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y   ))*2.0;
  horizEdge += texture(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;

  vec4 vertEdge = vec4(0.0);
  vertEdge -= texture(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0;
  vertEdge -= texture(texture0, vec2(fragTexCoord.x    , fragTexCoord.y - y))*2.0;
  vertEdge -= texture(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0;
  vertEdge += texture(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0;
  vertEdge += texture(texture0, vec2(fragTexCoord.x    , fragTexCoord.y + y))*2.0;
  vertEdge += texture(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0;

  vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb));

  vec3 texelColor = ((color + texture(texture0, uv)) * weight[0]).rgb + edge;

  for (int i = 1; i < 3; i++)
  {
    texelColor += texture(texture0, fragTexCoord + vec2(offset[i])/renderWidth, 0.0).rgb*weight[i];
    texelColor += texture(texture0, fragTexCoord - vec2(offset[i])/renderWidth, 0.0).rgb*weight[i];
  }

  texelColor = pow(texelColor, vec3(gamma, gamma, gamma));
  texelColor = texelColor*numColors;
  texelColor = floor(texelColor);
  texelColor = texelColor/numColors;
  texelColor = pow(texelColor, vec3(1.0/gamma));

  fragColor = vec4(texelColor, 1.0);
}