It's my impression (and the answer to this question seems to confirm it) that I can subclass from GPUImageTwoPassFilter to effectively run two fragment shaders in succession on an image but keep all the code and such confined into a single class. However, in my experimentation, it doesn't appear that the second fragment shader is ever compiled, much less executed; the example below builds and runs without complaint. The resulting image looks the same as if only the first fragment shader were run in a single-shader class.
What could be going wrong here? It doesn't help that all the examples I can find in the GPUImage code base that subclass GPUImageTwoPassFilter are simply using the same fragment shader program for each pass (as in GPUImageGaussianBlurFilter).
#import "BFTwoPassTest.h"
NSString *const kBFTwoPassTestFirstFragmentShaderString = SHADER_STRING
(
varying highp vec2 textureCoordinate;
uniform sampler2D inputImageTexture;
void main()
{
lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
gl_FragColor = vec4(1.0, textureColor.g, textureColor.b, 1.0);
}
);
NSString *const kBFTwoPassTestSecondFragmentShaderString = SHADER_STRING
(
varying highp vec2 textureCoordinate;
uniform sampler2D inputImageTexture;
void main()
{
This should be an obvious syntax error.
}
);
@implementation BFTwoPassTest
- (id)init {
self = [self initWithFirstStageFragmentShaderFromString:kBFTwoPassTestFirstFragmentShaderString secondStageFragmentShaderFromString:kBFTwoPassTestSecondFragmentShaderString];
if (self) {
}
return self;
}
@end
Oops, there was a bug on line 55 of GPUImageTwoPassFilter.m. The following line:
if (!(self = [self initWithFirstStageVertexShaderFromString:kGPUImageVertexShaderString firstStageFragmentShaderFromString:firstStageFragmentShaderString secondStageVertexShaderFromString:kGPUImageVertexShaderString secondStageFragmentShaderFromString:firstStageFragmentShaderString]))
should have been
if (!(self = [self initWithFirstStageVertexShaderFromString:kGPUImageVertexShaderString firstStageFragmentShaderFromString:firstStageFragmentShaderString secondStageVertexShaderFromString:kGPUImageVertexShaderString secondStageFragmentShaderFromString:secondStageFragmentShaderString]))
Thanks for pointing this out, which should be fixed in the repository now. However, in the future may I suggest posting specific framework issues like this to the GitHub issues page for the project instead of here?