1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 23:52:26 +00:00

Attempted very basic vectorisation, plus some minor other clean-ups.

This commit is contained in:
Thomas Harte 2015-09-02 17:17:22 -04:00 committed by Thomas Harte
parent f60ba4f487
commit 0d6094d842

View File

@ -195,7 +195,7 @@ const char *vertexShader =
"srcCoordinatesVarying[5] = srcCoordinatesVarying[2] - vec2(0.1 / textureSize.x, 0.0);\n" "srcCoordinatesVarying[5] = srcCoordinatesVarying[2] - vec2(0.1 / textureSize.x, 0.0);\n"
"srcCoordinatesVarying[6] = srcCoordinatesVarying[2] + vec2(0.1 / textureSize.x, 0.0);\n" "srcCoordinatesVarying[6] = srcCoordinatesVarying[2] + vec2(0.1 / textureSize.x, 0.0);\n"
"lateralVarying = lateral + 1.0707963267949;\n" "lateralVarying = lateral + 1.0707963267949;\n"
"phase = srcCoordinates.x;\n" "phase = srcCoordinates.x * 6.283185308;\n"
"gl_Position = vec4(position.x * 2.0 - 1.0, 1.0 - position.y * 2.0 , 0.0, 1.0);\n" // + position.x / 131.0 "gl_Position = vec4(position.x * 2.0 - 1.0, 1.0 - position.y * 2.0 , 0.0, 1.0);\n" // + position.x / 131.0
"}\n"; "}\n";
@ -214,57 +214,46 @@ const char *fragmentShader =
"uniform sampler2D texID;\n" "uniform sampler2D texID;\n"
"uniform float alpha;\n" "uniform float alpha;\n"
"\n" "\n"
"float angles[5];\n"
"\n"
"float sample(float c, float angle)\n" "float sample(float c, float angle)\n"
"{\n" "{\n"
"float y = 0.1 + (mod(c * 128.0, 8.0) / 8.0) * 0.9;\n" "float y = 0.1 + (mod(c * 128.0, 8.0) / 8.0) * 0.9;\n"
"float rawCh = (c * 16.0);\n" "float rawCh = (c * 16.0);\n"
"float ch = mod(rawCh, 16.0);\n" "float aOffset = 2.0 * 3.141592654 * floor(mod(rawCh, 16.0)) / 17.0;\n"
"float aOffset = 2.0 * 3.141592654 * (ch - mod(ch, 1.0)) / 17.0;\n"
"return y + step(1.0, rawCh) * (0.1 * sin(angle + aOffset));\n" "return y + step(1.0, rawCh) * (0.1 * sin(angle + aOffset));\n"
"}\n" "}\n"
"\n" "\n"
"void main(void)\n" "void main(void)\n"
"{\n" "{\n"
"float samples[7];\n" "vec4 samples[2];\n"
"float angles[7], i[5], q[5];\n" "float angles[7];\n"
"\n" "\n"
"angles[0] = mod(phase + 0.6, 1.0) * 2.0 * 3.141592654;\n" "angles[2] = mod(phase, 6.283185308);\n"
"angles[1] = mod(phase + 0.8, 1.0) * 2.0 * 3.141592654;\n"
"angles[2] = mod(phase, 1.0) * 2.0 * 3.141592654;\n"
"angles[3] = mod(phase + 0.2, 1.0) * 2.0 * 3.141592654;\n"
"angles[4] = mod(phase + 0.4, 1.0) * 2.0 * 3.141592654;\n"
"angles[5] = mod(phase + 0.9, 1.0) * 2.0 * 3.141592654;\n"
"angles[6] = mod(phase + 0.1, 1.0) * 2.0 * 3.141592654;\n"
"\n" "\n"
"samples[0] = sample(texture(texID, srcCoordinatesVarying[0]).r, angles[0]);\n" "angles[0] = angles[2] + 3.7699111848;\n"
"samples[1] = sample(texture(texID, srcCoordinatesVarying[1]).r, angles[1]);\n" "angles[1] = angles[2] + 5.0265482464;\n"
"samples[2] = sample(texture(texID, srcCoordinatesVarying[2]).r, angles[2]);\n" "angles[3] = angles[2] + 1.2566370616;\n"
"samples[3] = sample(texture(texID, srcCoordinatesVarying[3]).r, angles[3]);\n" "angles[4] = angles[2] + 2.5132741232;\n"
"samples[4] = sample(texture(texID, srcCoordinatesVarying[4]).r, angles[4]);\n" "angles[5] = angles[2] + 5.6548667772;\n"
"samples[5] = sample(texture(texID, srcCoordinatesVarying[5]).r, angles[5]);\n" "angles[6] = angles[2] + 0.6283185308;\n"
"samples[6] = sample(texture(texID, srcCoordinatesVarying[6]).r, angles[6]);\n"
"float y = (samples[0] + samples[1] + samples[2] + samples[3] + samples[4]) / 5.0;\n"
"\n" "\n"
"i[0] = (samples[1] - y) * sin(angles[1]);\n" "samples[0] = vec4(sample(texture(texID, srcCoordinatesVarying[0]).r, angles[0]),"
"i[1] = (samples[5] - y) * sin(angles[5]);\n" " sample(texture(texID, srcCoordinatesVarying[1]).r, angles[1]),"
"i[2] = (samples[2] - y) * sin(angles[2]);\n" " sample(texture(texID, srcCoordinatesVarying[2]).r, angles[2]),"
"i[3] = (samples[6] - y) * sin(angles[6]);\n" " sample(texture(texID, srcCoordinatesVarying[3]).r, angles[3]));\n"
"i[4] = (samples[3] - y) * sin(angles[3]);\n" "samples[1] = vec4(sample(texture(texID, srcCoordinatesVarying[4]).r, angles[4]),"
"float iSum = (i[0] + i[1] + i[2] + i[3] + i[4]) * 1.1914;\n" " sample(texture(texID, srcCoordinatesVarying[5]).r, angles[5]),"
" sample(texture(texID, srcCoordinatesVarying[6]).r, angles[6]),"
" 1.0);\n"
"float y = dot(vec4(0.2, 0.2, 0.2, 0.2), samples[0]) + dot(vec4(0.2, 0.0, 0.0, 0.0), samples[1]);\n"
"\n" "\n"
"q[0] = (samples[1] - y) * cos(angles[1]);\n" "samples[0] -= vec4(y, y, y, y);\n"
"q[1] = (samples[5] - y) * cos(angles[5]);\n" "samples[1] -= vec4(y, y, y, y);\n"
"q[2] = (samples[2] - y) * cos(angles[2]);\n"
"q[3] = (samples[6] - y) * cos(angles[6]);\n"
"q[4] = (samples[3] - y) * cos(angles[3]);\n"
"float qSum = (q[0] + q[1] + q[2] + q[3] + q[4]) * 1.0452;\n"
"\n" "\n"
"float i = dot(vec4(0.0, sin(angles[1]), sin(angles[2]), sin(angles[3])), samples[0]) + dot(vec4(0.0, sin(angles[5]), sin(angles[6]), 0.0), samples[1]);"
"float q = dot(vec4(0.0, cos(angles[1]), cos(angles[2]), cos(angles[3])), samples[0]) + dot(vec4(0.0, cos(angles[5]), cos(angles[6]), 0.0), samples[1]);"
"\n" "\n"
"fragColour = vec4( y + 0.965 * iSum + 0.621 * qSum, " "const mat3 yiqToRGB = mat3(1.0, 1.149701, 0.6490692, 1.0, -0.3240608, -0.6762444, 1.0, -1.3176884, 1.7799756);\n"
"y - 0.272 * iSum - 0.647 * qSum, " "fragColour = vec4( yiqToRGB * vec3(y, i, q),"
"y - 1.106 * iSum + 1.703 * qSum, "
"1.0);\n" "1.0);\n"
"}\n"; "}\n";