Adding property to objective-c interface and tweaking existing code
I'm using the GPUImage library in one of my projects and am trying to
tweak a class within it. Unfortunately I have no experience with
objective-c, my tweaked code is compiling but the app crashes when i try
to use my changes.
Basically I'm trying to add an "alpha" property to the
GPUImageToneCurveFilter and I'm using the GPUImageAlphaBlendFilter as a
reference (trying to mimic it). I have attempted to add a property mix and
mix two colors based on that value.
Would appreciate any help in this.
GPUImageToneCurveFilter.h
#import "GPUImageFilter.h"
@interface GPUImageToneCurveFilter : GPUImageFilter
{
GLint mixUniform;
}
@property(readwrite, nonatomic) CGFloat mix;
@end
GPUImageToneCurveFilter.m
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
NSString *const kGPUImageToneCurveFragmentShaderString = SHADER_STRING
(
varying highp vec2 textureCoordinate;
uniform sampler2D inputImageTexture;
uniform sampler2D toneCurveTexture;
uniform lowp float mixturePercent;
void main()
{
lowp vec4 textureColor = texture2D(inputImageTexture,
textureCoordinate);
lowp float redCurveValue = texture2D(toneCurveTexture,
vec2(textureColor.r, 0.0)).r;
lowp float greenCurveValue = texture2D(toneCurveTexture,
vec2(textureColor.g, 0.0)).g;
lowp float blueCurveValue = texture2D(toneCurveTexture,
vec2(textureColor.b, 0.0)).b;
// my additions
vec4 curvedColor = vec4(redCurveValue, greenCurveValue,
blueCurveValue, 1.0);
gl_FragColor = vec4(mix(textureColor.rgb, curvedColor.rgb,
curvedColor.a * mixturePercent), textureColor.a);
//gl_FragColor = vec4(redCurveValue, greenCurveValue,
blueCurveValue, textureColor.a);
}
);
#else
NSString *const kGPUImageToneCurveFragmentShaderString = SHADER_STRING
(
varying vec2 textureCoordinate;
uniform sampler2D inputImageTexture;
uniform sampler2D toneCurveTexture;
uniform float mixturePercent;
void main()
{
vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
float redCurveValue = texture2D(toneCurveTexture,
vec2(textureColor.r, 0.0)).r;
float greenCurveValue = texture2D(toneCurveTexture,
vec2(textureColor.g, 0.0)).g;
float blueCurveValue = texture2D(toneCurveTexture,
vec2(textureColor.b, 0.0)).b;
// my additions
vec4 curvedColor = vec4(redCurveValue, greenCurveValue,
blueCurveValue, 1.0);
gl_FragColor = vec4(mix(textureColor.rgb, curvedColor.rgb,
curvedColor.a * mixturePercent), textureColor.a);
//gl_FragColor = vec4(redCurveValue, greenCurveValue,
blueCurveValue, textureColor.a);
}
);
No comments:
Post a Comment