Skip to content

Commit d8ba36e

Browse files
author
Thayer J Andrews
committed
CCEffectHue - Remove non-color matrix version of the hue transform
1 parent 0bda1e7 commit d8ba36e

File tree

1 file changed

+0
-101
lines changed

1 file changed

+0
-101
lines changed

cocos2d/CCEffectHue.m

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,20 @@
44
//
55
// Created by Thayer J Andrews on 7/9/14.
66
//
7-
//
8-
// This effect makes use of algorithms and GLSL shaders from GPUImage whose
9-
// license is included here.
10-
//
11-
// <Begin GPUImage license>
12-
//
13-
// Copyright (c) 2012, Brad Larson, Ben Cochran, Hugues Lismonde, Keitaroh
14-
// Kobayashi, Alaric Cole, Matthew Clark, Jacob Gundersen, Chris Williams.
15-
// All rights reserved.
16-
//
17-
// Redistribution and use in source and binary forms, with or without
18-
// modification, are permitted provided that the following conditions are met:
19-
//
20-
// Redistributions of source code must retain the above copyright notice, this
21-
// list of conditions and the following disclaimer.
22-
// Redistributions in binary form must reproduce the above copyright notice,
23-
// this list of conditions and the following disclaimer in the documentation
24-
// and/or other materials provided with the distribution.
25-
// Neither the name of the GPUImage framework nor the names of its contributors
26-
// may be used to endorse or promote products derived from this software
27-
// without specific prior written permission.
28-
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29-
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30-
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31-
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
32-
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33-
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34-
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35-
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36-
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37-
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38-
// POSSIBILITY OF SUCH DAMAGE.
39-
//
40-
// <End GPUImage license>
417

428

439
#import "CCEffectHue.h"
4410
#import "CCEffect_Private.h"
4511
#import "CCRenderer.h"
4612
#import "CCTexture.h"
4713

48-
#define CCEFFECTHUE_USES_COLOR_MATRIX 1
49-
50-
5114
static float conditionHue(float hue);
5215

53-
#if CCEFFECTHUE_USES_COLOR_MATRIX
5416
static GLKMatrix4 matrixWithHue(float hue);
55-
#endif
5617

5718

5819
@interface CCEffectHue ()
59-
#if CCEFFECTHUE_USES_COLOR_MATRIX
6020
@property (nonatomic, strong) NSValue *hueRotationMtx;
61-
#else
62-
@property (nonatomic, strong) NSNumber *conditionedHue;
63-
#endif
6421
@end
6522

6623

@@ -74,21 +31,13 @@ -(id)init
7431
-(id)initWithHue:(float)hue
7532
{
7633
NSArray *uniforms = @[
77-
#if CCEFFECTHUE_USES_COLOR_MATRIX
7834
[CCEffectUniform uniform:@"mat4" name:@"u_hueRotationMtx" value:[NSValue valueWithGLKMatrix4:GLKMatrix4Identity]]
79-
#else
80-
[CCEffectUniform uniform:@"float" name:@"u_hue" value:[NSNumber numberWithFloat:hue]]
81-
#endif
8235
];
8336

8437
if((self = [super initWithFragmentUniforms:uniforms vertexUniforms:nil varyings:nil]))
8538
{
8639
_hue = hue;
87-
#if CCEFFECTHUE_USES_COLOR_MATRIX
8840
_hueRotationMtx = [NSValue valueWithGLKMatrix4:matrixWithHue(conditionHue(hue))];
89-
#else
90-
_conditionedHue = [NSNumber numberWithFloat:conditionHue(hue)];
91-
#endif
9241
self.debugName = @"CCEffectHue";
9342
}
9443
return self;
@@ -106,47 +55,9 @@ -(void)buildFragmentFunctions
10655
CCEffectFunctionInput *input = [[CCEffectFunctionInput alloc] initWithType:@"vec4" name:@"inputValue" initialSnippet:@"cc_FragColor * texture2D(cc_PreviousPassTexture, cc_FragTexCoord1)" snippet:@"texture2D(cc_PreviousPassTexture, cc_FragTexCoord1)"];
10756

10857
// The non-color matrix shader is based on the hue filter in GPUImage - https://github.com/BradLarson/GPUImage
109-
#if CCEFFECTHUE_USES_COLOR_MATRIX
11058
NSString* effectBody = CC_GLSL(
11159
return u_hueRotationMtx * inputValue;
11260
);
113-
#else
114-
NSString* effectBody = CC_GLSL(
115-
const highp vec4 kRGBToYPrime = vec4 (0.299, 0.587, 0.114, 0.0);
116-
const highp vec4 kRGBToI = vec4 (0.595716, -0.274453, -0.321263, 0.0);
117-
const highp vec4 kRGBToQ = vec4 (0.211456, -0.522591, 0.31135, 0.0);
118-
119-
const highp vec4 kYIQToR = vec4 (1.0, 0.9563, 0.6210, 0.0);
120-
const highp vec4 kYIQToG = vec4 (1.0, -0.2721, -0.6474, 0.0);
121-
const highp vec4 kYIQToB = vec4 (1.0, -1.1070, 1.7046, 0.0);
122-
123-
// Convert to YIQ
124-
highp float YPrime = dot (inputValue, kRGBToYPrime);
125-
highp float I = dot (inputValue, kRGBToI);
126-
highp float Q = dot (inputValue, kRGBToQ);
127-
128-
// Calculate the hue and chroma
129-
highp float hue = atan (Q, I);
130-
highp float chroma = sqrt (I * I + Q * Q);
131-
132-
// Make the user's adjustments.
133-
hue += -u_hue; // Why is this negative?
134-
135-
// Convert back to YIQ
136-
Q = chroma * sin (hue);
137-
I = chroma * cos (hue);
138-
139-
// Convert back to RGB
140-
vec4 outputColor;
141-
highp vec4 yIQ = vec4 (YPrime, I, Q, 0.0);
142-
outputColor.r = dot (yIQ, kYIQToR);
143-
outputColor.g = dot (yIQ, kYIQToG);
144-
outputColor.b = dot (yIQ, kYIQToB);
145-
outputColor.a = inputValue.a;
146-
147-
return outputColor;
148-
);
149-
#endif
15061

15162
CCEffectFunction* fragmentFunction = [[CCEffectFunction alloc] initWithName:@"hueEffect" body:effectBody inputs:@[input] returnType:@"vec4"];
15263
[self.fragmentFunctions addObject:fragmentFunction];
@@ -163,11 +74,7 @@ -(void)buildRenderPasses
16374

16475
pass.shaderUniforms[CCShaderUniformMainTexture] = previousPassTexture;
16576
pass.shaderUniforms[CCShaderUniformPreviousPassTexture] = previousPassTexture;
166-
#if CCEFFECTHUE_USES_COLOR_MATRIX
16777
pass.shaderUniforms[weakSelf.uniformTranslationTable[@"u_hueRotationMtx"]] = weakSelf.hueRotationMtx;
168-
#else
169-
pass.shaderUniforms[weakSelf.uniformTranslationTable[@"u_hue"]] = weakSelf.conditionedHue;
170-
#endif
17178
} copy]];
17279

17380
self.renderPasses = @[pass0];
@@ -176,11 +83,7 @@ -(void)buildRenderPasses
17683
-(void)setHue:(float)hue
17784
{
17885
_hue = hue;
179-
#if CCEFFECTHUE_USES_COLOR_MATRIX
18086
_hueRotationMtx = [NSValue valueWithGLKMatrix4:matrixWithHue(conditionHue(hue))];
181-
#else
182-
_conditionedHue = [NSNumber numberWithFloat:conditionHue(hue)];
183-
#endif
18487
}
18588

18689
@end
@@ -191,12 +94,9 @@ float conditionHue(float hue)
19194
return clampf(hue, -180.0f, 180.0f) * M_PI / 180.0f;
19295
}
19396

194-
#if CCEFFECTHUE_USES_COLOR_MATRIX
19597
GLKMatrix4 matrixWithHue(float hue)
19698
{
19799
// RGB to YIQ and YIQ to RGB matrix values source from here:
198-
// https://github.com/BradLarson/GPUImage/blob/master/framework/Source/GPUImageHueFilter.m
199-
// And here:
200100
// http://en.wikipedia.org/wiki/YIQ
201101
//
202102
// Note that GL matrices are column major so we have to transpose them when loading them in
@@ -224,5 +124,4 @@ GLKMatrix4 matrixWithHue(float hue)
224124
GLKMatrix4 composed = GLKMatrix4Multiply(yiqToRgb, GLKMatrix4Multiply(rotation, rgbToYiq));
225125
return composed;
226126
}
227-
#endif
228127

0 commit comments

Comments
 (0)