Search code examples
objective-cgpuimage

GPUImage and Shader Compile Errors


I'm implementing a custom filter creating two strings one as a vertex shader and the other one as a fragment one.

I'm in the early stage and I was just trying to compile and run a program with custom shaders just copying the one used in GPUImage.

Here the shaders:

    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;
}
);

However whenever I initialize a filter with such shaders my app crash with this log.

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)

The shaders are correct to me since are just cut and copy of other working shaders included in the GPUImage projects.

The call inside the code to the two shaders above is as following:

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

My goal is to blend two videos that's why two textures are present in the shaders.


Solution

  • Based on the comment by OP,

    here is the call: customFilter = [[GPUImageFilter alloc] initWithVertexShaderFromString:@"CustomShaderV" fragmentShaderFromString:@"CustomShaderF"];

    the error was that the variable name was quoted and being used as a string. Fix was:

    Change that to: [[GPUImageFilter alloc] initWithVertexShaderFromString:CustomShaderV fragmentShaderFromString:CustomShaderF];