Skip to content

Commit ad4d614

Browse files
committed
Merge pull request #920 from thayerandrews/develop
CCEffectNode - Fix a bunch of sizing issues and add tests for them
2 parents 88ec7e2 + 4b62c1a commit ad4d614

29 files changed

+851
-118
lines changed

cocos2d-ui-tests/tests/CCEffectsTest.m

Lines changed: 582 additions & 0 deletions
Large diffs are not rendered by default.

cocos2d/CCEffect.m

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,23 @@ -(NSString*)callStringWithInputs:(NSArray*)inputs
9999

100100
@implementation CCEffectFunctionInput
101101

102-
-(id)initWithType:(NSString*)type name:(NSString*)name snippet:(NSString*)snippet
102+
-(id)initWithType:(NSString*)type name:(NSString*)name initialSnippet:(NSString*)initialSnippet snippet:(NSString*)snippet
103103
{
104104
if((self = [super init]))
105105
{
106106
_type = [type copy];
107107
_name = [name copy];
108+
_initialSnippet = [initialSnippet copy];
108109
_snippet = [snippet copy];
109110
return self;
110111
}
111112

112113
return self;
113114
}
114115

115-
+(id)inputWithType:(NSString*)type name:(NSString*)name snippet:(NSString*)snippet
116+
+(id)inputWithType:(NSString*)type name:(NSString*)name initialSnippet:(NSString*)initialSnippet snippet:(NSString*)snippet
116117
{
117-
return [[self alloc] initWithType:type name:name snippet:snippet];
118+
return [[self alloc] initWithType:type name:name initialSnippet:initialSnippet snippet:snippet];
118119
}
119120

120121
@end
@@ -316,12 +317,22 @@ -(id)initWithFragmentFunction:(NSMutableArray*) fragmentFunctions vertexFunction
316317
{
317318
if((self = [super init]))
318319
{
319-
[self buildEffectWithFragmentFunction:fragmentFunctions vertexFunctions:vertexFunctions fragmentUniforms:fragmentUniforms vertexUniforms:vertexUniforms varyings:varyings];
320+
[self buildEffectWithFragmentFunction:fragmentFunctions vertexFunctions:vertexFunctions fragmentUniforms:fragmentUniforms vertexUniforms:vertexUniforms varyings:varyings firstInStack:YES];
320321
}
321322
return self;
322323
}
323324

324-
- (void)buildEffectWithFragmentFunction:(NSMutableArray*) fragmentFunctions vertexFunctions:(NSMutableArray*)vertexFunctions fragmentUniforms:(NSArray*)fragmentUniforms vertexUniforms:(NSArray*)vertexUniforms varyings:(NSArray*)varyings
325+
-(id)initWithFragmentFunction:(NSMutableArray*) fragmentFunctions vertexFunctions:(NSMutableArray*)vertexFunctions fragmentUniforms:(NSArray*)fragmentUniforms vertexUniforms:(NSArray*)vertexUniforms varyings:(NSArray*)varyings firstInStack:(BOOL)firstInStack
326+
{
327+
if((self = [super init]))
328+
{
329+
[self buildEffectWithFragmentFunction:fragmentFunctions vertexFunctions:vertexFunctions fragmentUniforms:fragmentUniforms vertexUniforms:vertexUniforms varyings:varyings firstInStack:firstInStack];
330+
}
331+
return self;
332+
}
333+
334+
335+
- (void)buildEffectWithFragmentFunction:(NSMutableArray*) fragmentFunctions vertexFunctions:(NSMutableArray*)vertexFunctions fragmentUniforms:(NSArray*)fragmentUniforms vertexUniforms:(NSArray*)vertexUniforms varyings:(NSArray*)varyings firstInStack:(BOOL)firstInStack
325336
{
326337
if (fragmentFunctions)
327338
{
@@ -363,6 +374,7 @@ - (void)buildEffectWithFragmentFunction:(NSMutableArray*) fragmentFunctions vert
363374
[self setVaryings:varyings];
364375

365376
_stitchFlags = CCEffectFunctionStitchBoth;
377+
_firstInStack = firstInStack;
366378

367379
[self buildShaderUniforms:_fragmentUniforms vertexUniforms:_vertexUniforms];
368380
[self buildUniformTranslationTable];
@@ -414,17 +426,17 @@ -(void)setVaryings:(NSArray*)varyings
414426

415427
-(void)buildEffectShader
416428
{
417-
NSString *fragBody = [self buildShaderSourceFromBase:fragBase functions:_fragmentFunctions uniforms:_fragmentUniforms varyings:_varyingVars];
429+
NSString *fragBody = [self buildShaderSourceFromBase:fragBase functions:_fragmentFunctions uniforms:_fragmentUniforms varyings:_varyingVars firstInStack:_firstInStack];
418430
// NSLog(@"\n------------fragBody:\n%@", fragBody);
419431

420-
NSString *vertBody = [self buildShaderSourceFromBase:vertBase functions:_vertexFunctions uniforms:_vertexUniforms varyings:_varyingVars];
432+
NSString *vertBody = [self buildShaderSourceFromBase:vertBase functions:_vertexFunctions uniforms:_vertexUniforms varyings:_varyingVars firstInStack:_firstInStack];
421433
// NSLog(@"\n------------vertBody:\n%@", vertBody);
422434

423435
_shader = [[CCShader alloc] initWithVertexShaderSource:vertBody fragmentShaderSource:fragBody];
424436

425437
}
426438

427-
-(NSString *)buildShaderSourceFromBase:(NSString *)shaderBase functions:(NSArray *)functions uniforms:(NSArray *)uniforms varyings:(NSArray *)varyings
439+
-(NSString *)buildShaderSourceFromBase:(NSString *)shaderBase functions:(NSArray *)functions uniforms:(NSArray *)uniforms varyings:(NSArray *)varyings firstInStack:(BOOL)firstInStack
428440
{
429441
// Build the varying string
430442
NSMutableString* varyingString = [[NSMutableString alloc] init];
@@ -451,9 +463,19 @@ -(NSString *)buildShaderSourceFromBase:(NSString *)shaderBase functions:(NSArray
451463

452464
if([functions firstObject] == curFunction)
453465
{
454-
for (CCEffectFunctionInput *input in curFunction.inputs)
466+
if (firstInStack)
467+
{
468+
for (CCEffectFunctionInput *input in curFunction.inputs)
469+
{
470+
[effectFunctionBody appendFormat:@"tmp = %@;\n", input.initialSnippet];
471+
}
472+
}
473+
else
455474
{
456-
[effectFunctionBody appendFormat:@"tmp = %@;\n", input.snippet];
475+
for (CCEffectFunctionInput *input in curFunction.inputs)
476+
{
477+
[effectFunctionBody appendFormat:@"tmp = %@;\n", input.snippet];
478+
}
457479
}
458480
}
459481

cocos2d/CCEffectBloom.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@
2525
* This value is in the range [0..1]. Lower values mean that more pixels will
2626
* contribute to the blurry bloom image.
2727
*/
28-
@property (nonatomic) float luminanceThreshold;
28+
@property (nonatomic, assign) float luminanceThreshold;
2929

3030
/** The intensity of the blurred out bloom image when added to the original
3131
* unmodified image. This value is in the range [0..1]. 0 results in no bloom
3232
* while higher values result in more bloom.
3333
*/
34-
@property (nonatomic) float intensity;
34+
@property (nonatomic, assign) float intensity;
3535

3636
/** The size of the blur of the bloom image. This value is in the range [0..6].
3737
*/
38-
@property (nonatomic) NSUInteger blurRadius;
38+
@property (nonatomic, assign) NSUInteger blurRadius;
3939

4040

4141
/// -----------------------------------------------------------------------

cocos2d/CCEffectBlur.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
/** The size of the blur. This value is in the range [0..6].
2424
*/
25-
@property (nonatomic) NSUInteger blurRadius;
25+
@property (nonatomic, assign) NSUInteger blurRadius;
2626

2727

2828
/// -----------------------------------------------------------------------

cocos2d/CCEffectBrightness.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* of -1 reduces the affected color to 0 (black), 0 results in no change, 1
2727
* increases the affected color to 1 (white).
2828
*/
29-
@property (nonatomic) float brightness;
29+
@property (nonatomic, assign) float brightness;
3030

3131

3232
/// -----------------------------------------------------------------------

cocos2d/CCEffectBrightness.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
@interface CCEffectBrightness ()
1717

18-
@property (nonatomic) NSNumber *conditionedBrightness;
18+
@property (nonatomic, strong) NSNumber *conditionedBrightness;
1919

2020
@end
2121

@@ -50,7 +50,7 @@ -(void)buildFragmentFunctions
5050
{
5151
self.fragmentFunctions = [[NSMutableArray alloc] init];
5252

53-
CCEffectFunctionInput *input = [[CCEffectFunctionInput alloc] initWithType:@"vec4" name:@"inputValue" snippet:@"texture2D(cc_PreviousPassTexture, cc_FragTexCoord1)"];
53+
CCEffectFunctionInput *input = [[CCEffectFunctionInput alloc] initWithType:@"vec4" name:@"inputValue" initialSnippet:@"cc_FragColor * texture2D(cc_PreviousPassTexture, cc_FragTexCoord1)" snippet:@"texture2D(cc_PreviousPassTexture, cc_FragTexCoord1)"];
5454

5555
NSString* effectBody = CC_GLSL(
5656
return vec4((inputValue.rgb + vec3(u_brightness * inputValue.a)), inputValue.a);

cocos2d/CCEffectContrast.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* an adjustment value of -1 scales the affected color by 0.25, 0 results in no
2727
* change, and 1 scales the affected color by 4.
2828
*/
29-
@property (nonatomic) float contrast;
29+
@property (nonatomic, assign) float contrast;
3030

3131

3232
/// -----------------------------------------------------------------------

cocos2d/CCEffectContrast.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
@interface CCEffectContrast ()
1818

19-
@property (nonatomic) NSNumber *conditionedContrast;
19+
@property (nonatomic, strong) NSNumber *conditionedContrast;
2020

2121
@end
2222

@@ -51,7 +51,7 @@ -(void)buildFragmentFunctions
5151
{
5252
self.fragmentFunctions = [[NSMutableArray alloc] init];
5353

54-
CCEffectFunctionInput *input = [[CCEffectFunctionInput alloc] initWithType:@"vec4" name:@"inputValue" snippet:@"texture2D(cc_PreviousPassTexture, cc_FragTexCoord1)"];
54+
CCEffectFunctionInput *input = [[CCEffectFunctionInput alloc] initWithType:@"vec4" name:@"inputValue" initialSnippet:@"cc_FragColor * texture2D(cc_PreviousPassTexture, cc_FragTexCoord1)" snippet:@"texture2D(cc_PreviousPassTexture, cc_FragTexCoord1)"];
5555

5656
NSString* effectBody = CC_GLSL(
5757
return vec4(((inputValue.rgb - vec3(0.5)) * vec3(u_contrast) + vec3(0.5)), inputValue.a);

cocos2d/CCEffectGlass.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,26 @@
2626
* resulting in maximum minification of the refracted image, 0 resulting in no
2727
* refraction, and 1 resulting in maximum magnification of the refracted image.
2828
*/
29-
@property (nonatomic) float refraction;
29+
@property (nonatomic, assign) float refraction;
3030

3131
/** The overall shininess of the attached sprite. This value is in the range [0..1] and it controls
3232
* how much of the reflected environment contributes to the final color of the affected pixels.
3333
*/
34-
@property (nonatomic) float shininess;
34+
@property (nonatomic, assign) float shininess;
3535

3636
/** The bias term in the fresnel reflectance equation:
3737
* reflectance = max(0.0, fresnelBias + (1 - fresnelBias) * pow((1 - nDotV), fresnelPower))
3838
* This value is in the range [0..1] and it controls the constant (view angle independent) contribution
3939
* to the reflectance equation.
4040
*/
41-
@property (nonatomic) float fresnelBias;
41+
@property (nonatomic, assign) float fresnelBias;
4242

4343
/** The power term in the fresnel reflectance equation:
4444
* reflectance = max(0.0, fresnelBias + (1 - fresnelBias) * pow((1 - nDotV), fresnelPower))
4545
* This value is in the range [0..inf] and it controls the view angle dependent contribution
4646
* to the reflectance equation.
4747
*/
48-
@property (nonatomic) float fresnelPower;
48+
@property (nonatomic, assign) float fresnelPower;
4949

5050
/** The environment that will be refracted by the affected node. Typically this is a
5151
* sprite that serves as the background for the affected node so it appears that the viewer

cocos2d/CCEffectGlass.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424

2525
@interface CCEffectGlass ()
2626

27-
@property (nonatomic) float conditionedRefraction;
28-
@property (nonatomic) float conditionedShininess;
29-
@property (nonatomic) float conditionedFresnelBias;
30-
@property (nonatomic) float conditionedFresnelPower;
27+
@property (nonatomic, assign) float conditionedRefraction;
28+
@property (nonatomic, assign) float conditionedShininess;
29+
@property (nonatomic, assign) float conditionedFresnelBias;
30+
@property (nonatomic, assign) float conditionedFresnelPower;
3131

3232
@end
3333

@@ -110,7 +110,7 @@ -(void)buildFragmentFunctions
110110
{
111111
self.fragmentFunctions = [[NSMutableArray alloc] init];
112112

113-
CCEffectFunctionInput *input = [[CCEffectFunctionInput alloc] initWithType:@"vec4" name:@"inputValue" snippet:@"cc_FragColor * texture2D(cc_PreviousPassTexture, cc_FragTexCoord1)"];
113+
CCEffectFunctionInput *input = [[CCEffectFunctionInput alloc] initWithType:@"vec4" name:@"inputValue" initialSnippet:@"cc_FragColor * texture2D(cc_PreviousPassTexture, cc_FragTexCoord1)" snippet:@"texture2D(cc_PreviousPassTexture, cc_FragTexCoord1)"];
114114

115115
NSString* effectBody = CC_GLSL(
116116
// Index the normal map and expand the color value from [0..1] to [-1..1]

0 commit comments

Comments
 (0)