mirror of
https://github.com/TomHarte/CLK.git
synced 2025-04-06 10:38:16 +00:00
Fixed YIQ conversion and made sampling pattern slightly more rational.
This commit is contained in:
parent
80cf3d9301
commit
39027b675d
@ -191,16 +191,20 @@ static NSString *const vertexShader =
|
||||
"\n"
|
||||
"void main (void)\n"
|
||||
"{\n"
|
||||
"srcCoordinatesVarying[2] = vec2(srcCoordinates.x / textureSize.x, (srcCoordinates.y + 0.5) / textureSize.y);\n"
|
||||
"srcCoordinatesVarying[0] = srcCoordinatesVarying[2] - vec2(0.4 / textureSize.x, 0.0);\n"
|
||||
"srcCoordinatesVarying[1] = srcCoordinatesVarying[2] - vec2(0.2 / textureSize.x, 0.0);\n"
|
||||
"srcCoordinatesVarying[4] = srcCoordinatesVarying[2] + vec2(0.4 / textureSize.x, 0.0);\n"
|
||||
"srcCoordinatesVarying[3] = srcCoordinatesVarying[2] + vec2(0.2 / 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[3] = vec2(srcCoordinates.x / textureSize.x, (srcCoordinates.y + 0.5) / textureSize.y);\n"
|
||||
"\n"
|
||||
"srcCoordinatesVarying[0] = srcCoordinatesVarying[3] - vec2(0.4 / textureSize.x, 0.0);\n"
|
||||
"srcCoordinatesVarying[1] = srcCoordinatesVarying[3] - vec2(0.2 / textureSize.x, 0.0);\n"
|
||||
"srcCoordinatesVarying[2] = srcCoordinatesVarying[3] - vec2(0.1 / textureSize.x, 0.0);\n"
|
||||
"\n"
|
||||
"srcCoordinatesVarying[4] = srcCoordinatesVarying[3] + vec2(0.1 / textureSize.x, 0.0);\n"
|
||||
"srcCoordinatesVarying[5] = srcCoordinatesVarying[3] + vec2(0.2 / textureSize.x, 0.0);\n"
|
||||
"srcCoordinatesVarying[6] = srcCoordinatesVarying[3] + vec2(0.4 / textureSize.x, 0.0);\n"
|
||||
"\n"
|
||||
"lateralVarying = lateral + 1.0707963267949;\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
|
||||
"\n"
|
||||
"gl_Position = vec4(position.x * 2.0 - 1.0, 1.0 - position.y * 2.0 + position.x / 131.0, 0.0, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
// TODO: this should be factored out and be per project
|
||||
@ -223,9 +227,9 @@ static NSString *const fragmentShader =
|
||||
"vec4 samples[2];\n"
|
||||
"vec4 angles[2];\n"
|
||||
"\n"
|
||||
"vec4 angle = vec4(mod(phase, 6.283185308));\n"
|
||||
"angles[0] = angle + vec4(3.7699111848, 5.0265482464, 0.0, 1.2566370616);\n"
|
||||
"angles[1] = angle + vec4(2.5132741232, 5.6548667772, 0.6283185308, 0.0);\n"
|
||||
"vec4 angle = vec4(phase);\n"
|
||||
"angles[0] = angle + vec4(-2.5132741232, -1.2566370616, -0.6283185308, 0.0);\n"
|
||||
"angles[1] = angle + vec4(0.6283185308, 1.2566370616, 2.5132741232, 0.0);\n"
|
||||
"\n"
|
||||
"samples[0] = vec4("
|
||||
" sample(srcCoordinatesVarying[0], angles[0].x),"
|
||||
@ -236,18 +240,18 @@ static NSString *const fragmentShader =
|
||||
" sample(srcCoordinatesVarying[4], angles[1].x),"
|
||||
" sample(srcCoordinatesVarying[5], angles[1].y),"
|
||||
" sample(srcCoordinatesVarying[6], angles[1].z),"
|
||||
" 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"
|
||||
" 0.0);\n"
|
||||
"float y = dot(vec4(0.2, 0.2, 0.0, 0.2), samples[0]) + dot(vec4(0.0, 0.2, 0.2, 0.0), samples[1]);\n"
|
||||
"\n"
|
||||
"samples[0] -= vec4(y);\n"
|
||||
"samples[1] -= vec4(y);\n"
|
||||
"\n"
|
||||
"float i = dot(vec4(0.0, sin(angles[0].y), sin(angles[0].z), sin(angles[0].w)), samples[0]) + dot(vec4(0.0, sin(angles[1].y), sin(angles[1].z), 0.0), samples[1]);"
|
||||
"float q = dot(vec4(0.0, cos(angles[0].y), cos(angles[0].z), cos(angles[0].w)), samples[0]) + dot(vec4(0.0, cos(angles[1].y), cos(angles[1].z), 0.0), samples[1]);"
|
||||
"float i = dot(vec4(0.0, sin(angles[0].y), sin(angles[0].z), sin(angles[0].w)), samples[0]) + dot(vec4(sin(angles[1].x), sin(angles[1].y), 0.0, 0.0), samples[1]);\n"
|
||||
"float q = dot(vec4(0.0, cos(angles[0].y), cos(angles[0].z), cos(angles[0].w)), samples[0]) + dot(vec4(cos(angles[1].x), cos(angles[1].y), 0.0, 0.0), samples[1]);\n"
|
||||
"\n"
|
||||
"const mat3 yiqToRGB = mat3(1.0, 1.149701, 0.6490692, 1.0, -0.3240608, -0.6762444, 1.0, -1.3176884, 1.7799756);\n"
|
||||
"fragColour = vec4( yiqToRGB * vec3(y, i, q),"
|
||||
"1.0);\n"
|
||||
"// now i and q are in the range [-0.5, 0.5], so i needs to be multiplied by 1.1914 and q by 1.0452\n"
|
||||
"const mat3 yiqToRGB = mat3(1.0, 1.0, 1.0, 1.1389784, -0.3240608, -1.3176884, 0.6490692, -0.6762444, 1.7799756);\n"
|
||||
"fragColour = vec4( yiqToRGB * vec3(y, i, q), 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
#if defined(DEBUG)
|
||||
|
Loading…
x
Reference in New Issue
Block a user