GPUImage和着色器编译错误

时间:2013-11-24 17:07:03

标签: objective-c gpuimage

我正在实现一个自定义过滤器,创建两个字符串,一个作为顶点着色器,另一个作为片段一个。

我处于早期阶段,我只是试图编译并运行一个带有自定义着色器的程序,只需复制GPUImage中使用的程序。

这些着色器:

    NSString *const CustomShaderV = SHADER_STRING
(
 attribute vec4 position;
 attribute vec4 inputTextureCoordinate;
 attribute vec4 inputTextureCoordinate2;

 varying vec2 textureCoordinate;
 varying vec2 textureCoordinate2;

 void main()
 {
     gl_Position = position;
     textureCoordinate = inputTextureCoordinate.xy;
     textureCoordinate2 = inputTextureCoordinate2.xy;
 }
 );

NSString *const CustomShaderF = SHADER_STRING
(

 varying highp vec2 textureCoordinate;
 varying highp vec2 textureCoordinate2;

 uniform sampler2D inputImageTexture;
 uniform sampler2D inputImageTexture2;
 uniform highp float bVal;
 uniform highp float hVal;
 uniform highp float sVal;

 void main()
{
    lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
    lowp vec4 alphaColor = texture2D(inputImageTexture2, textureCoordinate2);
    lowp vec4 outputColor;

    outputColor = textureColor;

    gl_FragColor =  outputColor;
}
);

但是每当我使用这样的着色器初始化过滤器时,我的应用程序都会崩溃。

2013-11-24 17:58:40.243[865:60b] Shader compile log:
ERROR: 0:1: 'CustomShaderV' : syntax error syntax error
2013-11-24 17:58:40.245[865:60b] Failed to compile vertex shader
2013-11-24 17:58:40.248[865:60b] Shader compile log:
ERROR: 0:1: 'CustomShaderF' : syntax error syntax error
2013-11-24 17:58:40.249[865:60b] Failed to compile fragment shader
2013-11-24 17:58:40.250[865:60b] Program link log: ERROR: One or more attached shaders not successfully compiled
2013-11-24 17:58:40.252[865:60b] Fragment shader compile log: (null)
2013-11-24 17:58:40.253[865:60b] Vertex shader compile log: (null)

着色器对我来说是正确的,因为它只是剪切和复制GPUImage项目中包含的其他工作着色器。

上面两个着色器的代码内部调用如下:

 customFilter = [[GPUImageFilter alloc] initWithVertexShaderFromString:@"CustomShaderV" fragmentShaderFromString:@"CustomShaderF"];

我的目标是混合两个视频,这就是着色器中存在两个纹理的原因。

1 个答案:

答案 0 :(得分:2)

基于OP的评论,

  

这里是调用:customFilter = [[GPUImageFilter alloc] initWithVertexShaderFromString:@“CustomShaderV”fragmentShaderFromString:@“CustomShaderF”];

错误是变量 name 被引用并用作字符串。修复是:

  

将其更改为:[[GPUImageFilter alloc] initWithVertexShaderFromString:CustomShaderV fragmentShaderFromString:CustomShaderF];