iosopengl-escikernel

iOS using OpenGL shaders in CIKernel


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.


Solution

  • You can, but with a few tweaks.

    If you want to use your code verbatim, you could (at a stretch) consider a Sprite Kit SKShader to generate a SKTexture which can be rendered as a CGImage.

    simon