是否可以使用OpenGL着色器在iOS中使用CIKernel?如果没有,是否有办法在两者之间进行转换?
示例OpenGL着色器
#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;我正试图为iOS和安卓使用相同的过滤器。安卓已经使用了OpenGL着色器,所以我想在我的iOS应用程序中使用相同的着色器。
发布于 2016-06-25 11:05:17
你可以但只要稍微调整一下就行了。
vTextureCoord和samplerExternalOES将作为参数传递到内核函数中。sTexture类型为__sample (假设您使用的是CIColorKernel,这意味着内核只能访问当前正在计算的像素)kernel vec4 xyzzy(__sample pixel) --您不能将它命名为main。texture2D。在上面的示例中,pixel保存当前像素的颜色。gl_FragColor的值,而是需要以vec4的形式返回颜色。如果您想逐字使用代码,可以考虑使用Sprite Kit SKShader来生成SKTexture,该SKTexture可以呈现为CGImage。
西蒙
https://stackoverflow.com/questions/37921660
复制相似问题