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.
Merge pull request BradLarson#2133 from r3mus/master
Added 3 new filters, some corrections to readme for vignette and highlight/shadow
- Loading branch information
Showing
7 changed files
with
574 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// GPUImageHighlightShadowTintFilter.h | ||
// | ||
// | ||
// Created by github.com/r3mus on 8/14/15. | ||
// | ||
// | ||
|
||
#import "GPUImageFilter.h" | ||
|
||
@interface GPUImageHighlightShadowTintFilter : GPUImageFilter | ||
{ | ||
GLint shadowTintIntensityUniform, highlightTintIntensityUniform, shadowTintColorUniform, highlightTintColorUniform; | ||
} | ||
|
||
// The shadowTint and highlightTint colors specify what colors replace the dark and light areas of the image, respectively. The defaults for shadows are black, highlighs white. | ||
@property(readwrite, nonatomic) GLfloat shadowTintIntensity; | ||
@property(readwrite, nonatomic) GPUVector4 shadowTintColor; | ||
@property(readwrite, nonatomic) GLfloat highlightTintIntensity; | ||
@property(readwrite, nonatomic) GPUVector4 highlightTintColor; | ||
|
||
- (void)setShadowTintColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent; | ||
- (void)setHighlightTintColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent; | ||
|
||
@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,136 @@ | ||
// | ||
// GPUImageHighlightShadowTintFilter.m | ||
// | ||
// Created by github.com/r3mus on 8/14/15. | ||
// | ||
// | ||
|
||
#import "GPUImageHighlightShadowTintFilter.h" | ||
|
||
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE | ||
NSString *const kGPUHighlightShadowTintFragmentShaderString = SHADER_STRING | ||
( | ||
precision lowp float; | ||
|
||
varying highp vec2 textureCoordinate; | ||
|
||
uniform sampler2D inputImageTexture; | ||
uniform lowp float shadowTintIntensity; | ||
uniform lowp float highlightTintIntensity; | ||
uniform highp vec4 shadowTintColor; | ||
uniform highp vec4 highlightTintColor; | ||
|
||
const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721); | ||
|
||
void main() | ||
{ | ||
lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); | ||
highp float luminance = dot(textureColor.rgb, luminanceWeighting); | ||
|
||
highp vec4 shadowResult = mix(textureColor, max(textureColor, vec4( mix(shadowTintColor.rgb, textureColor.rgb, luminance), textureColor.a)), shadowTintIntensity); | ||
highp vec4 highlightResult = mix(textureColor, min(shadowResult, vec4( mix(shadowResult.rgb, highlightTintColor.rgb, luminance), textureColor.a)), highlightTintIntensity); | ||
|
||
gl_FragColor = vec4( mix(shadowResult.rgb, highlightResult.rgb, luminance), textureColor.a); | ||
} | ||
); | ||
#else | ||
NSString *const kGPUHighlightShadowTintFragmentShaderString = SHADER_STRING | ||
( | ||
varying vec2 textureCoordinate; | ||
|
||
uniform sampler2D inputImageTexture; | ||
uniform float shadowTintIntensity; | ||
uniform float highlightTintIntensity; | ||
uniform vec3 shadowTintColor; | ||
uniform vec3 highlightTintColor; | ||
|
||
const vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721); | ||
|
||
void main() | ||
{ | ||
vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); | ||
float luminance = dot(textureColor.rgb, luminanceWeighting); | ||
|
||
vec4 shadowResult = mix(textureColor, max(textureColor, vec4( mix(shadowTintColor.rgb, textureColor.rgb, luminance), textureColor.a)), shadowTintIntensity); | ||
vec4 highlightResult = mix(textureColor, min(shadowResult, vec4( mix(shadowResult.rgb, highlightTintColor.rgb, luminance), textureColor.a)), highlightTintIntensity); | ||
|
||
gl_FragColor = vec4( mix(shadowResult.rgb, highlightResult.rgb, luminance), textureColor.a); | ||
} | ||
); | ||
#endif | ||
|
||
|
||
@implementation GPUImageHighlightShadowTintFilter | ||
|
||
@synthesize shadowTintIntensity = _shadowTintIntensity; | ||
@synthesize highlightTintIntensity = _highlightTintIntensity; | ||
@synthesize shadowTintColor = _shadowTintColor; | ||
@synthesize highlightTintColor = _highlightTintColor; | ||
|
||
- (id)init; | ||
{ | ||
if (!(self = [super initWithFragmentShaderFromString:kGPUHighlightShadowTintFragmentShaderString])) | ||
{ | ||
return nil; | ||
} | ||
|
||
shadowTintIntensityUniform = [filterProgram uniformIndex:@"shadowTintIntensity"]; | ||
highlightTintIntensityUniform = [filterProgram uniformIndex:@"highlightTintIntensity"]; | ||
shadowTintColorUniform = [filterProgram uniformIndex:@"shadowTintColor"]; | ||
highlightTintColorUniform = [filterProgram uniformIndex:@"highlightTintColor"]; | ||
|
||
self.shadowTintIntensity = 0.0f; | ||
self.highlightTintIntensity = 0.0f; | ||
self.shadowTintColor = (GPUVector4){1.0f, 0.0f, 0.0f, 1.0f}; | ||
self.highlightTintColor = (GPUVector4){0.0f, 0.0f, 1.0f, 1.0f}; | ||
|
||
return self; | ||
} | ||
|
||
|
||
#pragma mark - | ||
#pragma mark Accessors | ||
|
||
- (void)setShadowTintIntensity:(GLfloat)newValue | ||
{ | ||
_shadowTintIntensity = newValue; | ||
|
||
[self setFloat:_shadowTintIntensity forUniform:shadowTintIntensityUniform program:filterProgram]; | ||
} | ||
|
||
- (void)setHighlightTintIntensity:(GLfloat)newValue | ||
{ | ||
_highlightTintIntensity = newValue; | ||
|
||
[self setFloat:_highlightTintIntensity forUniform:highlightTintIntensityUniform program:filterProgram]; | ||
} | ||
|
||
- (void)setShadowTintColor:(GPUVector4)newValue; | ||
{ | ||
_shadowTintColor = newValue; | ||
|
||
[self setShadowTintColorRed:_shadowTintColor.one green:_shadowTintColor.two blue:_shadowTintColor.three alpha:_shadowTintColor.four]; | ||
} | ||
|
||
- (void)setHighlightTintColor:(GPUVector4)newValue; | ||
{ | ||
_highlightTintColor = newValue; | ||
|
||
[self setHighlightTintColorRed:_highlightTintColor.one green:_highlightTintColor.two blue:_highlightTintColor.three alpha:_highlightTintColor.four]; | ||
} | ||
|
||
- (void)setShadowTintColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent; | ||
{ | ||
GPUVector4 shadowTintColor = {redComponent, greenComponent, blueComponent, alphaComponent}; | ||
|
||
[self setVec4:shadowTintColor forUniform:shadowTintColorUniform program:filterProgram]; | ||
} | ||
|
||
- (void)setHighlightTintColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent; | ||
{ | ||
GPUVector4 highlightTintColor = {redComponent, greenComponent, blueComponent, alphaComponent}; | ||
|
||
[self setVec4:highlightTintColor forUniform:highlightTintColorUniform program:filterProgram]; | ||
} | ||
|
||
@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,47 @@ | ||
// | ||
// GPUImageSkinToneFilter.h | ||
// | ||
// | ||
// Created by github.com/r3mus on 8/14/15. | ||
// | ||
// | ||
|
||
#import "GPUImageTwoInputFilter.h" | ||
|
||
typedef NS_ENUM(NSUInteger, GPUImageSkinToneUpperColor) { | ||
GPUImageSkinToneUpperColorGreen, | ||
|
||
}; | ||
|
||
extern NSString *const kGPUImageSkinToneFragmentShaderString; | ||
|
||
@interface GPUImageSkinToneFilter : GPUImageFilter | ||
{ | ||
GLint skinToneAdjustUniform; | ||
GLint skinHueUniform; | ||
GLint skinHueThresholdUniform; | ||
GLint maxHueShiftUniform; | ||
GLint maxSaturationShiftUniform; | ||
GLint upperSkinToneColorUniform; | ||
} | ||
|
||
// The amount of effect to apply, between -1.0 (pink) and +1.0 (orange OR green). Default is 0.0. | ||
@property (nonatomic, readwrite) CGFloat skinToneAdjust; | ||
|
||
// The initial hue of skin to adjust. Default is 0.05 (a common skin red). | ||
@property (nonatomic, readwrite) CGFloat skinHue; | ||
|
||
// The bell curve "breadth" of the skin hue adjustment (i.e. how different from the original skinHue will the modifications effect). | ||
// Default is 40.0 | ||
@property (nonatomic, readwrite) CGFloat skinHueThreshold; | ||
|
||
// The maximum amount of hue shift allowed in the adjustments that affect hue (pink, green). Default = 0.25. | ||
@property (nonatomic, readwrite) CGFloat maxHueShift; | ||
|
||
// The maximum amount of saturation shift allowed in the adjustments that affect saturation (orange). Default = 0.4. | ||
@property (nonatomic, readwrite) CGFloat maxSaturationShift; | ||
|
||
// Defines whether the upper range (> 0.0) will change the skin tone to green (hue) or orange (saturation) | ||
@property (nonatomic, readwrite) GPUImageSkinToneUpperColor upperSkinToneColor; | ||
|
||
@end |
Oops, something went wrong.