关注this question,我正在尝试向GPUImageLookupFilter
添加强度属性。在对强度值进行硬编码时似乎工作得很好,但是将objective-c包装器连接到接口会导致它崩溃。
在main()
实施中,我将gl_FragColor
等式更新为建议:
gl_FragColor = mix(textureColor, vec4(newColor.rgb, textureColor.w), 1.0);
// ^ intensity value
这很有效。然后我尝试将以下部分添加/更新到obj-c包装器:
.h
@interface GPUImageLookupFilter : GPUImageTwoInputFilter
{
GLint intensityUniform;
}
@property(readwrite, nonatomic) CGFloat intensity;
@end
.m
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
NSString *const kGPUImageLookupFragmentShaderString = SHADER_STRING
(
// other unchanged declarations here
uniform float intensity;
void main()
{
// rest of the unchanged main function here
gl_FragColor = mix(textureColor, vec4(newColor.rgb, textureColor.w), intensity);
}
);
#else
NSString *const kGPUImageLookupFragmentShaderString = SHADER_STRING
(
// other unchanged declarations here
uniform float intensity;
void main()
{
// rest of the unchanged main function here
gl_FragColor = mix(textureColor, vec4(newColor.rgb, textureColor.w), intensity);
}
);
#endif
@implementation GPUImageLookupFilter
@synthesize intensity = _intensity;
#pragma mark -
#pragma mark Initialization and teardown
- (id)init;
{
intensityUniform = [filterProgram uniformIndex:@"intensity"];
self.intensity = 1.0;
if (!(self = [super initWithFragmentShaderFromString:kGPUImageLookupFragmentShaderString]))
{
return nil;
}
return self;
}
#pragma mark -
#pragma mark Accessors
- (void)setIntensity:(CGFloat)newValue;
{
_intensity = newValue;
[self setFloat:_intensity forUniform:intensityUniform program:filterProgram];
}
@end
它崩溃了:
*** Assertion failure in -[GPUImageLookupFilter initWithVertexShaderFromString:fragmentShaderFromString:], ...GPUImageFilter.m:94
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Filter shader link failed'
答案 0 :(得分:0)
简单修复,看起来我需要使用lowp float
代替:
uniform lowp float intensity;