Is it possible to use OpenGL shaders in iOS using CIKernel ? If not, is there a way to convert between the two ?
Example OpenGL Shader
#extension GL_OES_EGL_image_external : require
precision mediump float;
varying vec2 vTextureCoord;
uniform samplerExternalOES sTexture;
void main() {
vec4 textureColor = texture2D(sTexture, vTextureCoord);
vec4 outputColor;
outputColor.r = (textureColor.r * 0.393) + (textureColor.g * 0.769) + (textureColor.b * 0.189);
outputColor.g = (textureColor.r * 0.349) + (textureColor.g * 0.686) + (textureColor.b * 0.168);
outputColor.b = (textureColor.r * 0.272) + (textureColor.g * 0.534) + (textureColor.b * 0.131);
outputColor.a = 1.0;
gl_FragColor = outputColor;
I am trying to use the same filters for iOS and android. Android already uses OpenGL shaders, so I would like to use the same shaders in my iOS app.
You can, but with a few tweaks.
vTextureCoordandsamplerExternalOESwould be passed into a kernel function as arguments.sTexturetype would be__sample(assuming you're using aCIColorKernelwhich means the kernel can only access the pixel currently being computed)kernel vec4 xyzzy(__sample pixel)- you can't name itmain.texture2Din a color kernel. In the example abovepixelholds the color of the current pixel.gl_FragColor, your kernel function needs to return the color as avec4.If you want to use your code verbatim, you could (at a stretch) consider a Sprite Kit
SKShaderto generate aSKTexturewhich can be rendered as aCGImage.simon