forked from BradLarson/GPUImage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a false color filter. Incorporated the shadows and highlights f…
…ilter into the showcase.
- Loading branch information
1 parent
6d2b072
commit 8c351ac
Showing
12 changed files
with
177 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#import "GPUImageFilter.h" | ||
|
||
@interface GPUImageFalseColorFilter : GPUImageFilter | ||
{ | ||
GLint firstColorUniform, secondColorUniform; | ||
} | ||
|
||
// The first and second colors specify what colors replace the dark and light areas of the image, respectively. The defaults are (0.0, 0.0, 0.5) amd (1.0, 0.0, 0.0). | ||
@property(readwrite, nonatomic) GPUVector4 firstColor; | ||
@property(readwrite, nonatomic) GPUVector4 secondColor; | ||
|
||
- (void)setFirstColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent; | ||
- (void)setSecondColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#import "GPUImageFalseColorFilter.h" | ||
|
||
NSString *const kGPUFalseColorFragmentShaderString = SHADER_STRING | ||
( | ||
precision lowp float; | ||
|
||
varying highp vec2 textureCoordinate; | ||
|
||
uniform sampler2D inputImageTexture; | ||
uniform float intensity; | ||
uniform vec3 firstColor; | ||
uniform vec3 secondColor; | ||
|
||
const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721); | ||
|
||
void main() | ||
{ | ||
lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); | ||
float luminance = dot(textureColor.rgb, luminanceWeighting); | ||
|
||
gl_FragColor = vec4( mix(firstColor.rgb, secondColor.rgb, luminance), textureColor.a); | ||
} | ||
); | ||
|
||
@implementation GPUImageFalseColorFilter | ||
|
||
@synthesize secondColor = _secondColor; | ||
@synthesize firstColor = _firstColor; | ||
|
||
- (id)init; | ||
{ | ||
if (!(self = [super initWithFragmentShaderFromString:kGPUFalseColorFragmentShaderString])) | ||
{ | ||
return nil; | ||
} | ||
|
||
firstColorUniform = [filterProgram uniformIndex:@"firstColor"]; | ||
secondColorUniform = [filterProgram uniformIndex:@"secondColor"]; | ||
|
||
self.firstColor = (GPUVector4){0.0f, 0.0f, 0.5f, 1.0f}; | ||
self.secondColor = (GPUVector4){1.0f, 0.0f, 0.0f, 1.0f}; | ||
|
||
return self; | ||
} | ||
|
||
|
||
#pragma mark - | ||
#pragma mark Accessors | ||
|
||
- (void)setFirstColor:(GPUVector4)newValue; | ||
{ | ||
_firstColor = newValue; | ||
|
||
[self setFirstColorRed:_firstColor.one green:_firstColor.two blue:_firstColor.three]; | ||
} | ||
|
||
- (void)setSecondColor:(GPUVector4)newValue; | ||
{ | ||
_secondColor = newValue; | ||
|
||
[self setSecondColorRed:_secondColor.one green:_secondColor.two blue:_secondColor.three]; | ||
} | ||
|
||
- (void)setFirstColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent; | ||
{ | ||
GLfloat filterColor[3]; | ||
filterColor[0] = redComponent; | ||
filterColor[1] = greenComponent; | ||
filterColor[2] = blueComponent; | ||
|
||
[GPUImageOpenGLESContext useImageProcessingContext]; | ||
[filterProgram use]; | ||
glUniform3fv(firstColorUniform, 1, filterColor); | ||
} | ||
|
||
- (void)setSecondColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent; | ||
{ | ||
GLfloat filterColor[3]; | ||
filterColor[0] = redComponent; | ||
filterColor[1] = greenComponent; | ||
filterColor[2] = blueComponent; | ||
|
||
[GPUImageOpenGLESContext useImageProcessingContext]; | ||
[filterProgram use]; | ||
glUniform3fv(secondColorUniform, 1, filterColor); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters