Mercurial > repos > blastem
annotate shaders/ntsc.f.glsl @ 2389:66b3f2eda0c8
Fix regression in savestate loading
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 24 Nov 2023 14:44:01 -0800 |
parents | 49bd818ec9d8 |
children | f1574b22d5d9 |
rev | line source |
---|---|
2329
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 //****************************************************************************** |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 // NTSC composite simulator for BlastEm |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 // Shader by Sik, based on BlastEm's default shader |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 // |
2343
49bd818ec9d8
Updated NTSC shader from Sik
Michael Pavone <pavone@retrodev.com>
parents:
2329
diff
changeset
|
5 // Now with gamma correction (NTSC = 2.5 gamma, sRGB = 2.2 gamma) |
49bd818ec9d8
Updated NTSC shader from Sik
Michael Pavone <pavone@retrodev.com>
parents:
2329
diff
changeset
|
6 // |
2329
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 // It works by converting from RGB to YIQ and then encoding it into NTSC, then |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 // trying to decode it back. The lossy nature of the encoding process results in |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 // the rainbow effect. It also accounts for the differences between H40 and H32 |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 // mode as it computes the exact colorburst cycle length. |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 // |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 // This shader tries to work around the inability to keep track of previous |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 // pixels by sampling seven points (in 0.25 colorburst cycle intervals), that |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 // seems to be enough to give decent filtering (four samples are used for |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 // low-pass filtering, but we need seven because decoding chroma also requires |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 // four samples so we're filtering over overlapping samples... just see the |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 // comments in the I/Q code to understand). |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 //****************************************************************************** |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 uniform mediump float width; |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 uniform sampler2D textures[2]; |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 uniform mediump vec2 texsize; |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 varying mediump vec2 texcoord; |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 // Converts from RGB to YIQ |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 mediump vec3 rgba2yiq(vec4 rgba) |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 { |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 return vec3( |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 rgba[0] * 0.3 + rgba[1] * 0.59 + rgba[2] * 0.11, |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 rgba[0] * 0.599 + rgba[1] * -0.2773 + rgba[2] * -0.3217, |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 rgba[0] * 0.213 + rgba[1] * -0.5251 + rgba[2] * 0.3121 |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 ); |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 } |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 // Encodes YIQ into composite |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 mediump float yiq2raw(vec3 yiq, float phase) |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 { |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 return yiq[0] + yiq[1] * sin(phase) + yiq[2] * cos(phase); |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 } |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 // Converts from YIQ to RGB |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 mediump vec4 yiq2rgba(vec3 yiq) |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 { |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 return vec4( |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 yiq[0] + yiq[1] * 0.9469 + yiq[2] * 0.6236, |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 yiq[0] - yiq[1] * 0.2748 - yiq[2] * 0.6357, |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 yiq[0] - yiq[1] * 1.1 + yiq[2] * 1.7, |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 1.0 |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 ); |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 } |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 void main() |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 { |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 // Use first pair of lines for hard line edges |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 // Use second pair of lines for soft line edges |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 mediump float modifiedY0 = (floor(texcoord.y * texsize.y + 0.25) + 0.5) / texsize.y; |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 mediump float modifiedY1 = (floor(texcoord.y * texsize.y - 0.25) + 0.5) / texsize.y; |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 //mediump float modifiedY0 = (texcoord.y * texsize.y + 0.75) / texsize.y; |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 //mediump float modifiedY1 = (texcoord.y * texsize.y + 0.25) / texsize.y; |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 // Used by the mixing when fetching texels, related to the way BlastEm |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 // handles interlaced mode (nothing to do with composite) |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 mediump float factorY = (sin(texcoord.y * texsize.y * 6.283185307) + 1.0) * 0.5; |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 // Horizontal distance of half a colorburst cycle |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 mediump float factorX = (1.0 / texsize.x) / 170.667 * 0.5 * (width - 27.0); |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 |
2343
49bd818ec9d8
Updated NTSC shader from Sik
Michael Pavone <pavone@retrodev.com>
parents:
2329
diff
changeset
|
68 // sRGB has a gamma of 2.2 while NTSC has a gamma of 2.5 |
49bd818ec9d8
Updated NTSC shader from Sik
Michael Pavone <pavone@retrodev.com>
parents:
2329
diff
changeset
|
69 // Use this value to do gamma correction of every RGB value |
49bd818ec9d8
Updated NTSC shader from Sik
Michael Pavone <pavone@retrodev.com>
parents:
2329
diff
changeset
|
70 mediump float gamma = 2.5 / 2.2; |
49bd818ec9d8
Updated NTSC shader from Sik
Michael Pavone <pavone@retrodev.com>
parents:
2329
diff
changeset
|
71 |
2329
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 // Where we store the sampled pixels. |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 // [0] = current pixel |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 // [1] = 1/4 colorburst cycles earlier |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 // [2] = 2/4 colorburst cycles earlier |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 // [3] = 3/4 colorburst cycles earlier |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 // [4] = 1 colorburst cycle earlier |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 // [5] = 1 1/4 colorburst cycles earlier |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 // [6] = 1 2/4 colorburst cycles earlier |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 mediump float phase[7]; // Colorburst phase (in radians) |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 mediump float raw[7]; // Raw encoded composite signal |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 // Sample all the pixels we're going to use |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 mediump float x = texcoord.x; |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 for (int n = 0; n < 7; n++, x -= factorX * 0.5) { |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 // Compute colorburst phase at this point |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 phase[n] = x / factorX * 3.1415926; |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 // Decode RGB into YIQ and then into composite |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 // Reading two textures is a BlastEm thing :P (the two fields in |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 // interlaced mode, that's taken as-is from the stock shaders) |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 raw[n] = yiq2raw(mix( |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 rgba2yiq(texture2D(textures[1], vec2(x, modifiedY1))), |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 rgba2yiq(texture2D(textures[0], vec2(x, modifiedY0))), |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 factorY |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 ), phase[n]); |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 } |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 // Decode Y by averaging over the the whole sampled cycle (effectively |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 // filtering anything above the colorburst frequency) |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 mediump float y_mix = (raw[0] + raw[1] + raw[2] + raw[3]) * 0.25; |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 // Decode I and Q (see page below to understand what's going on) |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 // https://codeandlife.com/2012/10/09/composite-video-decoding-theory-and-practice/ |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 // |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 // Retrieving I and Q out of the raw signal is done like this |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 // (use sin for I and cos for Q): |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 // |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 // 0.5 * raw[0] * sin(phase[0]) + 0.5 * raw[1] * sin(phase[1]) + |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 // 0.5 * raw[2] * sin(phase[2]) + 0.5 * raw[3] * sin(phase[3]) |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 // |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 // i.e. multiply each of the sampled quarter cycles against the reference |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 // wave and average them (actually double that because for some reason |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 // that's needed to get the correct scale, hence 0.5 instead of 0.25) |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 // |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 // That turns out to be blocky tho, so we opt to filter down the chroma... |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 // which requires doing the above *four* times if we do it the same way as |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 // we did for luminance (note that 0.125 = 1/4 of 0.5): |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 // |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 // 0.125 * raw[0] * sin(phase[0]) + 0.125 * raw[1] * sin(phase[1]) + |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 // 0.125 * raw[2] * sin(phase[2]) + 0.125 * raw[3] * sin(phase[3]) + |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 // 0.125 * raw[1] * sin(phase[1]) + 0.125 * raw[2] * sin(phase[2]) + |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 // 0.125 * raw[3] * sin(phase[3]) + 0.125 * raw[4] * sin(phase[4]) + |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 // 0.125 * raw[2] * sin(phase[2]) + 0.125 * raw[3] * sin(phase[3]) + |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 // 0.125 * raw[4] * sin(phase[4]) + 0.125 * raw[5] * sin(phase[5]) + |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 // 0.125 * raw[3] * sin(phase[3]) + 0.125 * raw[4] * sin(phase[4]) + |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 // 0.125 * raw[5] * sin(phase[5]) + 0.125 * raw[6] * sin(phase[6]) |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 // |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 // There are a lot of repeated values there that could be merged into one, |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 // what you see below is the resulting simplification. |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 mediump float i_mix = |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 0.125 * raw[0] * sin(phase[0]) + |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 0.25 * raw[1] * sin(phase[1]) + |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 0.375 * raw[2] * sin(phase[2]) + |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 0.5 * raw[3] * sin(phase[3]) + |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 0.375 * raw[4] * sin(phase[4]) + |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 0.25 * raw[5] * sin(phase[5]) + |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 0.125 * raw[6] * sin(phase[6]); |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 mediump float q_mix = |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 0.125 * raw[0] * cos(phase[0]) + |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 0.25 * raw[1] * cos(phase[1]) + |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 0.375 * raw[2] * cos(phase[2]) + |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 0.5 * raw[3] * cos(phase[3]) + |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 0.375 * raw[4] * cos(phase[4]) + |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 0.25 * raw[5] * cos(phase[5]) + |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 0.125 * raw[6] * cos(phase[6]); |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 // Convert YIQ back to RGB and output it |
2343
49bd818ec9d8
Updated NTSC shader from Sik
Michael Pavone <pavone@retrodev.com>
parents:
2329
diff
changeset
|
151 gl_FragColor = pow(yiq2rgba(vec3(y_mix, i_mix, q_mix)), |
49bd818ec9d8
Updated NTSC shader from Sik
Michael Pavone <pavone@retrodev.com>
parents:
2329
diff
changeset
|
152 vec4(gamma, gamma, gamma, 1.0)); |
2329
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 // If you're curious to see what the raw composite signal looks like, |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 // comment out the above and uncomment the line below instead |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 //gl_FragColor = vec4(raw[0], raw[0], raw[0], 1.0); |
06d5e9b08bdb
Add NTSC composite shader by Sik
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 } |