forked from BradLarson/GPUImage
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request BradLarson#31 from alariccole/master
Haze filter addition
- Loading branch information
Showing
7 changed files
with
128 additions
and
1 deletion.
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
2 changes: 1 addition & 1 deletion
2
examples/FilterShowcase/FilterShowcase/ShowcaseFilterViewController.h
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,27 @@ | ||
#import "GPUImageFilter.h" | ||
|
||
/* | ||
* The haze filter can be used to remove or haze (similar to a UV filter) | ||
* | ||
* @author Alaric Cole | ||
* @creationDate 03/10/12 | ||
* | ||
*/ | ||
|
||
@interface GPUImageHazeFilter : GPUImageFilter | ||
{ | ||
GLint distanceUniform; | ||
GLint slopeUniform; | ||
} | ||
|
||
/* | ||
* Strength of the color applied. Default 0. Values between -.3 and .3 are best | ||
*/ | ||
@property(readwrite, nonatomic) CGFloat distance; | ||
|
||
/* | ||
* Amount of color change. Default 0. Values between -.3 and .3 are best | ||
*/ | ||
@property(readwrite, nonatomic) CGFloat slope; | ||
|
||
@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,78 @@ | ||
#import "GPUImageHazeFilter.h" | ||
|
||
NSString *const kGPUImageHazeFragmentShaderString = SHADER_STRING | ||
( | ||
varying highp vec2 textureCoordinate; | ||
|
||
uniform sampler2D inputImageTexture; | ||
|
||
uniform lowp float distance; | ||
uniform highp float slope; | ||
|
||
void main() | ||
{ | ||
//todo reconsider precision modifiers | ||
highp vec4 color = vec4(1.0);//todo reimplement as a parameter | ||
|
||
highp float d = textureCoordinate.y * slope + distance; | ||
|
||
highp vec4 c = texture2D(inputImageTexture, textureCoordinate) ; // consider using unpremultiply | ||
|
||
|
||
c = (c - d * color) / (1.0 -d); | ||
|
||
gl_FragColor = c; //consider using premultiply(c); | ||
|
||
|
||
} | ||
); | ||
|
||
|
||
|
||
|
||
|
||
@implementation GPUImageHazeFilter | ||
|
||
@synthesize distance = _distance; | ||
@synthesize slope = _slope; | ||
#pragma mark - | ||
#pragma mark Initialization and teardown | ||
|
||
- (id)init; | ||
{ | ||
if (!(self = [super initWithFragmentShaderFromString:kGPUImageHazeFragmentShaderString])) | ||
{ | ||
return nil; | ||
} | ||
|
||
distanceUniform = [filterProgram uniformIndex:@"distance"]; | ||
slopeUniform = [filterProgram uniformIndex:@"slope"]; | ||
|
||
self.distance = 0.2; | ||
self.slope = 0.0; | ||
return self; | ||
} | ||
|
||
#pragma mark - | ||
#pragma mark Accessors | ||
|
||
- (void)setDistance:(CGFloat)newValue; | ||
{ | ||
_distance = newValue; | ||
|
||
[GPUImageOpenGLESContext useImageProcessingContext]; | ||
[filterProgram use]; | ||
glUniform1f(distanceUniform, _distance); | ||
} | ||
|
||
- (void)setSlope:(CGFloat)newValue; | ||
{ | ||
_slope = newValue; | ||
|
||
[GPUImageOpenGLESContext useImageProcessingContext]; | ||
[filterProgram use]; | ||
glUniform1f(slopeUniform, _slope); | ||
} | ||
|
||
@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