Mercurial > repos > blastem
annotate shaders/crt.f.glsl @ 1542:112c7af033ff nuklear_ui
nuklear_ui has been merged to default and is now closed
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 25 Mar 2018 12:03:01 -0700 |
parents | 7da675d0c512 |
children | f3cca4b3f17a |
rev | line source |
---|---|
1392
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #version 110 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 /* Subtle CRT shader usable in fullscreen - Anaël Seghezzi [anael(at)maratis3d.com] |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 This shader is free software distributed under the terms of the GNU General Public |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 License version 3 or higher. This gives you the right to redistribute and/or |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 modify the program as long as you follow the terms of the license. See the file |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 COPYING for full license details. |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 */ |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 #define M_PI 3.14159265358979323846 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 uniform sampler2D textures[2]; |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 uniform float width, height; |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 varying vec2 texcoord; |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 varying vec2 screencoord; |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 float nrand(vec2 n) { |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 return fract(sin(dot(n.xy, vec2(12.9898, 78.233))) * 43758.5453); |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 } |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 float scanline(vec2 texco) |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 { |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 return (1.0 - abs(cos(texco.y * 512.0 * M_PI))); |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 } |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 vec2 sharp_coord(vec2 texco, vec2 dim, vec2 sharpness) |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 { |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 vec2 texcoif = texco * dim; |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 vec2 texcoi = floor(texcoif); |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 vec2 mu = (texcoif - 0.5) - texcoi; |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 vec2 mub = pow(abs(mu) * 2.0, sharpness) * sign(mu) * 0.5; |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 return (texcoi + mub + 0.5) / dim; |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 } |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 void main() |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 { |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 float v = 1.0 / 512.0; |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 float yforce = 0.175; |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 float vign = length(screencoord); |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 // monitor deformation |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 vec2 monitorcoord = (screencoord + screencoord * vign * 0.025); |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 if (monitorcoord.x < -1.0 || monitorcoord.y < -1.0 || monitorcoord.x > 1.0 || monitorcoord.y > 1.0) { |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 gl_FragColor = vec4(0.0); |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 return; |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 } |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 vec2 texco = monitorcoord * vec2(width/1024.0, height/-1024.0) + vec2(width/1024.0, height/1024.0); |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 // mask |
1439
7da675d0c512
Small fix submitted by Anaël Seghezzi to his subtle crt shader
Michael Pavone <pavone@retrodev.com>
parents:
1392
diff
changeset
|
53 float maskx = 1.0 - pow(abs(monitorcoord.x), 200.0); |
7da675d0c512
Small fix submitted by Anaël Seghezzi to his subtle crt shader
Michael Pavone <pavone@retrodev.com>
parents:
1392
diff
changeset
|
54 float masky = 1.0 - pow(abs(-monitorcoord.y), 200.0); |
1392
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 float mask = clamp(maskx * masky, 0.0, 1.0); |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 // sharp texcoord |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 vec2 texco_sharp0 = sharp_coord(texco, vec2(512.0, 512.0), vec2(4.0, 8.0)); |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 vec2 texco_sharp1 = sharp_coord(texco - vec2(0.0, 1.0 / 1024.0), vec2(512.0, 512.0), vec2(4.0, 8.0)); |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 vec4 src0 = texture2D(textures[0], texco_sharp0); |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 vec4 src1 = texture2D(textures[1], texco_sharp1); |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 // interlace mix |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 float interlace = cos((texco.y * 1024.0) * M_PI); |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 vec4 src_mix = mix(src0, src1, interlace * 0.5 + 0.5); |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 // blur |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 vec4 src_blur = mix(texture2D(textures[0], texco), texture2D(textures[1], texco), 0.5); |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 #ifdef NO_SCANLINE |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 gl_FragColor = (src_mix * 0.95 + (src_blur * (1.6 - vign * 0.4) * 0.1)) * mask; |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 #else |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 // multisample scanline with grain |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 // TODO: offset grain with time (needs a "frame" uniform) |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 float cosy; |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 cosy = scanline(texco + vec2(0.125, v * (nrand(texcoord + vec2(0.0, 1.0)) * 0.25) + 0.3333)); |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 cosy += scanline(texco + vec2(0.25, v * (nrand(texcoord + vec2(0.0, 2.0)) * 0.25) + 0.25)); |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 cosy += scanline(texco + vec2(0.50, v * (nrand(texcoord + vec2(0.0, 3.0)) * 0.25) + 0.6666)); |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 cosy += scanline(texco + vec2(0.75, v * (nrand(texcoord + vec2(0.0, 4.0)) * 0.25) + 0.75)); |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 cosy *= 0.25; |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 // final scanline + burn |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 gl_FragColor = ((src_mix * ((1.0 - yforce) + cosy * yforce)) + (src_blur * (1.6 - vign * 0.4) * 0.1)) * mask; |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 #endif |
4942da159194
Added a "subtle" CRT shader contributed by Anael Seghezzi
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 } |