2
2
#import " CCTextureCache.h"
3
3
#import " CCNodeColor.h"
4
4
#import " CCEffectNode.h"
5
- #import " CCEffectGaussianBlur .h"
5
+ #import " CCEffectBlur .h"
6
6
7
7
8
8
@interface CCEffectsTest : TestBase @end
@@ -41,7 +41,7 @@ -(void)setupGlassEffectTest
41
41
42
42
43
43
CCSpriteFrame *normalMap = [CCSpriteFrame frameWithImageNamed: @" Images/ShinyBallNormals.png" ];
44
- CCEffectGlass *glass = [[CCEffectGlass alloc ] initWithRefraction :1 .0f refractionEnvironment: refractEnvironment reflectionEnvironment: reflectEnvironment normalMap: nil ];
44
+ CCEffectGlass *glass = [[CCEffectGlass alloc ] initWithShininess :1 .0f refraction: 1 . 0f refractionEnvironment: refractEnvironment reflectionEnvironment: reflectEnvironment];
45
45
glass.fresnelBias = 0 .1f ;
46
46
glass.fresnelPower = 2 .0f ;
47
47
glass.refraction = 0 .75f ;
@@ -81,7 +81,7 @@ -(void)setupReflectEffectTest
81
81
[self .contentNode addChild: environment];
82
82
83
83
CCSpriteFrame *normalMap = [CCSpriteFrame frameWithImageNamed: @" Images/ShinyBallNormals.png" ];
84
- CCEffectReflection *reflection = [[CCEffectReflection alloc ] initWithEnvironment: environment normalMap: nil ];
84
+ CCEffectReflection *reflection = [[CCEffectReflection alloc ] initWithShininess: 1 . 0f environment: environment ];
85
85
reflection.fresnelBias = 0 .0f ;
86
86
reflection.fresnelPower = 0 .0f ;
87
87
@@ -148,7 +148,7 @@ -(void)setupRefractionEffectTest
148
148
NSString *sphereTextureFile = @" Images/ShinyBallColor.png" ;
149
149
CCTexture *sphereTexture = [CCTexture textureWithFile: sphereTextureFile];
150
150
CCSpriteFrame *sphereNormalMap = [CCSpriteFrame frameWithImageNamed: @" Images/ShinyBallNormals.png" ];
151
- CCEffectRefraction *sphereRefraction = [[CCEffectRefraction alloc ] initWithRefraction: 0 .1f environment: renderTexture.sprite normalMap: nil ];
151
+ CCEffectRefraction *sphereRefraction = [[CCEffectRefraction alloc ] initWithRefraction: 0 .1f environment: renderTexture.sprite];
152
152
sphereRefraction.refraction = 0 .75f ;
153
153
154
154
p1 = CGPointMake (0 .1f , 0 .8f );
@@ -283,7 +283,7 @@ -(void)setupBlurEffectNodeTest
283
283
effectNode.positionType = CCPositionTypeNormalized;
284
284
effectNode.position = ccp (0.1 , 0.5 );
285
285
[effectNode addChild: sampleSprite];
286
- CCEffectGaussianBlur * effect = [CCEffectGaussianBlur effectWithPixelBlurRadius :1.0 ];
286
+ CCEffectBlur * effect = [CCEffectBlur effectWithBlurRadius :1.0 ];
287
287
effectNode.effect = effect;
288
288
289
289
[self .contentNode addChild: effectNode];
@@ -297,7 +297,7 @@ -(void)setupBlurEffectNodeTest
297
297
effectNode2.positionType = CCPositionTypeNormalized;
298
298
effectNode2.position = ccp (0.21 , 0.5 );
299
299
[effectNode2 addChild: sampleSprite2];
300
- CCEffectGaussianBlur * effect2 = [CCEffectGaussianBlur effectWithPixelBlurRadius :7.0 ];
300
+ CCEffectBlur * effect2 = [CCEffectBlur effectWithBlurRadius :7.0 ];
301
301
effectNode2.effect = effect2;
302
302
303
303
[self .contentNode addChild: effectNode2];
@@ -313,7 +313,7 @@ -(void)setupBlurEffectNodeTest
313
313
effectNode3.position = ccp (0.5 , 0.5 );
314
314
effectNode3.anchorPoint = ccp (0.5 , 0.5 );
315
315
[effectNode3 addChild: sampleSprite3];
316
- CCEffectGaussianBlur * effect3 = [CCEffectGaussianBlur effectWithPixelBlurRadius :1.0 ];
316
+ CCEffectBlur * effect3 = [CCEffectBlur effectWithBlurRadius :1.0 ];
317
317
effectNode3.effect = effect3;
318
318
319
319
[self .contentNode addChild: effectNode3];
@@ -327,15 +327,15 @@ -(void)setupBlurEffectNodeTest
327
327
effectNode4.positionType = CCPositionTypeNormalized;
328
328
effectNode4.position = ccp (0.6 , 0.5 );
329
329
[effectNode4 addChild: sampleSprite4];
330
- CCEffectGaussianBlur * effect4 = [CCEffectGaussianBlur effectWithPixelBlurRadius :7.0 ];
330
+ CCEffectBlur * effect4 = [CCEffectBlur effectWithBlurRadius :7.0 ];
331
331
effectNode4.effect = effect4;
332
332
333
333
[self .contentNode addChild: effectNode4];
334
334
}
335
335
336
- -(void )setupGlowEffectNodeTest
336
+ -(void )setupBloomEffectTest
337
337
{
338
- self.subTitle = @" Glow Effect Node Test" ;
338
+ self.subTitle = @" Bloom Effect Test" ;
339
339
340
340
CCSprite *sampleSprite_base = [CCSprite spriteWithImageNamed: @" Images/sample_hollow_circle.png" ];
341
341
sampleSprite_base.anchorPoint = ccp (0.0 , 0.0 );
@@ -358,7 +358,7 @@ -(void)setupGlowEffectNodeTest
358
358
glowEffectNode.positionType = CCPositionTypeNormalized;
359
359
glowEffectNode.position = ccp (0.1 , 0.5 );
360
360
[glowEffectNode addChild: sampleSprite];
361
- CCEffectBloom* glowEffect = [CCEffectBloom effectWithPixelBlurRadius :8 intensity: 1 .0f luminanceThreshold: 0 .0f ];
361
+ CCEffectBloom* glowEffect = [CCEffectBloom effectWithBlurRadius :8 intensity: 1 .0f luminanceThreshold: 0 .0f ];
362
362
glowEffectNode.effect = glowEffect;
363
363
364
364
[self .contentNode addChild: glowEffectNode];
@@ -385,10 +385,26 @@ -(void)setupGlowEffectNodeTest
385
385
glowEffectNode2.positionType = CCPositionTypeNormalized;
386
386
glowEffectNode2.position = ccp (0.4 , 0.5 );
387
387
[glowEffectNode2 addChild: sampleSprite2];
388
- CCEffectBloom* glowEffect2 = [CCEffectBloom effectWithPixelBlurRadius :2 intensity: 0 .0f luminanceThreshold: 0 .0f ];
388
+ CCEffectBloom* glowEffect2 = [CCEffectBloom effectWithBlurRadius :2 intensity: 0 .0f luminanceThreshold: 0 .0f ];
389
389
glowEffectNode2.effect = glowEffect2;
390
390
391
391
[self .contentNode addChild: glowEffectNode2];
392
+
393
+ // Create a sprite to blur
394
+ const int steps = 5 ;
395
+ for (int i = 0 ; i < steps; i++)
396
+ {
397
+ CCSprite *sampleSprite3 = [CCSprite spriteWithImageNamed: @" Images/grossini_dance_08.png" ];
398
+ sampleSprite3.anchorPoint = ccp (0.5 , 0.5 );
399
+ sampleSprite3.position = ccp (0 .1f + i * (0 .8f / (steps - 1 )), 0 .2f );
400
+ sampleSprite3.positionType = CCPositionTypeNormalized;
401
+
402
+ // Blend glow maps test
403
+ CCEffectBloom* glowEffect3 = [CCEffectBloom effectWithBlurRadius: 8 intensity: 1 .0f luminanceThreshold: 1 .0f - ((float )i/(float )(steps-1 ))];
404
+ sampleSprite3.effect = glowEffect3;
405
+
406
+ [self .contentNode addChild: sampleSprite3];
407
+ }
392
408
}
393
409
394
410
-(void )setupBrightnessAndContrastEffectNodeTest
@@ -454,15 +470,15 @@ -(void)setupSaturationEffectNodeTest
454
470
];
455
471
456
472
// Effect nodes that use the effects in different combinations.
457
- [self .contentNode addChild: [self effectNodeWithEffects : @[effects[0 ]] appliedToSpriteWithImage :@" Images/grossini.png" atPosition: ccp (0.1 , 0.5 )]];
458
- [self .contentNode addChild: [self effectNodeWithEffects : @[effects[1 ]] appliedToSpriteWithImage :@" Images/grossini.png" atPosition: ccp (0.2 , 0.5 )]];
459
- [self .contentNode addChild: [self effectNodeWithEffects : @[effects[2 ]] appliedToSpriteWithImage :@" Images/grossini.png" atPosition: ccp (0.3 , 0.5 )]];
460
- [self .contentNode addChild: [self effectNodeWithEffects : @[effects[3 ]] appliedToSpriteWithImage :@" Images/grossini.png" atPosition: ccp (0.4 , 0.5 )]];
461
- [self .contentNode addChild: [self effectNodeWithEffects : @[effects[4 ]] appliedToSpriteWithImage :@" Images/grossini.png" atPosition: ccp (0.5 , 0.5 )]];
462
- [self .contentNode addChild: [self effectNodeWithEffects : @[effects[5 ]] appliedToSpriteWithImage :@" Images/grossini.png" atPosition: ccp (0.6 , 0.5 )]];
463
- [self .contentNode addChild: [self effectNodeWithEffects : @[effects[6 ]] appliedToSpriteWithImage :@" Images/grossini.png" atPosition: ccp (0.7 , 0.5 )]];
464
- [self .contentNode addChild: [self effectNodeWithEffects : @[effects[7 ]] appliedToSpriteWithImage :@" Images/grossini.png" atPosition: ccp (0.8 , 0.5 )]];
465
- [self .contentNode addChild: [self effectNodeWithEffects : @[effects[8 ]] appliedToSpriteWithImage :@" Images/grossini.png" atPosition: ccp (0.9 , 0.5 )]];
473
+ [self .contentNode addChild: [self spriteWithEffects : @[effects[0 ]] image :@" Images/grossini.png" atPosition: ccp (0.1 , 0.5 )]];
474
+ [self .contentNode addChild: [self spriteWithEffects : @[effects[1 ]] image :@" Images/grossini.png" atPosition: ccp (0.2 , 0.5 )]];
475
+ [self .contentNode addChild: [self spriteWithEffects : @[effects[2 ]] image :@" Images/grossini.png" atPosition: ccp (0.3 , 0.5 )]];
476
+ [self .contentNode addChild: [self spriteWithEffects : @[effects[3 ]] image :@" Images/grossini.png" atPosition: ccp (0.4 , 0.5 )]];
477
+ [self .contentNode addChild: [self spriteWithEffects : @[effects[4 ]] image :@" Images/grossini.png" atPosition: ccp (0.5 , 0.5 )]];
478
+ [self .contentNode addChild: [self spriteWithEffects : @[effects[5 ]] image :@" Images/grossini.png" atPosition: ccp (0.6 , 0.5 )]];
479
+ [self .contentNode addChild: [self spriteWithEffects : @[effects[6 ]] image :@" Images/grossini.png" atPosition: ccp (0.7 , 0.5 )]];
480
+ [self .contentNode addChild: [self spriteWithEffects : @[effects[7 ]] image :@" Images/grossini.png" atPosition: ccp (0.8 , 0.5 )]];
481
+ [self .contentNode addChild: [self spriteWithEffects : @[effects[8 ]] image :@" Images/grossini.png" atPosition: ccp (0.9 , 0.5 )]];
466
482
}
467
483
468
484
-(void )setupHueEffectTest
@@ -508,35 +524,41 @@ -(void)setupStackTest
508
524
[self .contentNode addChild: refractEnvironment];
509
525
510
526
NSArray *effects = @[
511
- [CCEffectGaussianBlur effectWithPixelBlurRadius :7.0 ],
512
- [CCEffectBloom effectWithPixelBlurRadius :8 intensity: 1 .0f luminanceThreshold: 0 .0f ],
527
+ [CCEffectBlur effectWithBlurRadius :7.0 ],
528
+ [CCEffectBloom effectWithBlurRadius :8 intensity: 1 .0f luminanceThreshold: 0 .0f ],
513
529
[CCEffectBrightness effectWithBrightness: 0 .25f ],
514
530
[CCEffectContrast effectWithContrast: 1 .0f ],
515
531
[CCEffectPixellate effectWithBlockSize: 8 .0f ],
516
532
[CCEffectSaturation effectWithSaturation: -1 .0f ],
517
533
[CCEffectHue effectWithHue: 90 .0f ],
518
- [CCEffectGlass effectWithRefraction: 0 . 5f refractionEnvironment: refractEnvironment reflectionEnvironment: reflectEnvironment normalMap: nil ],
519
- [CCEffectRefraction effectWithRefraction: 0 .5f environment: refractEnvironment normalMap: nil ],
520
- [CCEffectReflection effectWithFresnelBias: 0 . 2f fresnelPower: 2 .0f environment: reflectEnvironment normalMap: nil ],
534
+ [CCEffectGlass effectWithShininess: 1 . 0f refraction: 0 . 75f refractionEnvironment: refractEnvironment reflectionEnvironment: reflectEnvironment],
535
+ [CCEffectRefraction effectWithRefraction: 0 .75f environment: refractEnvironment],
536
+ [CCEffectReflection effectWithShininess: 1 . 0f fresnelBias: 0 . 1f fresnelPower: 2 .0f environment: reflectEnvironment],
521
537
];
522
538
523
539
524
- CCSprite *sprite = [CCSprite spriteWithImageNamed: @" Images/ShinyBallColor.png" ];
540
+ // CCSprite *sprite = [CCSprite spriteWithImageNamed:@"Images/ShinyBallColor.png"];
541
+ CCSprite *sprite = [[CCSprite alloc ] init ];
525
542
sprite.positionType = CCPositionTypeNormalized;
526
- sprite.position = ccp (0 .1f , 0 .9f );
543
+ sprite.position = ccp (0 .5f , 0 .5f );
527
544
sprite.scale = 0 .5f ;
528
545
529
- sprite.effect = [[CCEffectStack alloc ] initWithEffects: @[effects[4 ]]];
546
+ sprite.effect = [CCEffectStack effects: effects[7 ], effects[4 ], nil ];
547
+
530
548
sprite.normalMapSpriteFrame = [CCSpriteFrame frameWithImageNamed: @" Images/ShinyBallNormals.png" ];
531
549
sprite.colorRGBA = [CCColor colorWithRed: 0 .75f green: 0 .75f blue: 0 .75f alpha: 0 .75f ];
550
+ sprite.colorRGBA = [CCColor colorWithRed: 0 .0f green: 0 .0f blue: 0 .0f alpha: 0 .0f ];
532
551
533
552
[self .contentNode addChild: sprite];
534
553
554
+ CGPoint p1 = CGPointMake (0 .1f , 0 .1f );
555
+ CGPoint p2 = CGPointMake (0 .9f , 0 .9f );
556
+
535
557
[sprite runAction: [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
536
- [CCActionMoveTo actionWithDuration: 8 .0 position: ccp (0 . 9f , 0 . 9f )],
537
- [CCActionMoveTo actionWithDuration: 8 .0 position: ccp (0 . 9f , 0 . 1f )],
538
- [CCActionMoveTo actionWithDuration: 8 .0 position: ccp (0 . 1f , 0 . 1f )],
539
- [CCActionMoveTo actionWithDuration: 8 .0 position: ccp (0 . 1f , 0 . 9f )],
558
+ [CCActionMoveTo actionWithDuration: 2 .0 position: ccp (p1.x, p2.y )],
559
+ [CCActionMoveTo actionWithDuration: 4 .0 position: ccp (p2.x, p2.y )],
560
+ [CCActionMoveTo actionWithDuration: 2 .0 position: ccp (p2.x, p1.y )],
561
+ [CCActionMoveTo actionWithDuration: 4 .0 position: ccp (p1.x, p1.y )],
540
562
nil
541
563
]]];
542
564
}
@@ -556,16 +578,16 @@ -(void)setupPerformanceTest
556
578
refractEnvironment.scale = 0.5 ;
557
579
558
580
NSArray *allEffects = @[
559
- [CCEffectGaussianBlur effectWithPixelBlurRadius :7.0 ],
560
- [CCEffectBloom effectWithPixelBlurRadius :8 intensity: 1 .0f luminanceThreshold: 0 .0f ],
581
+ [CCEffectBlur effectWithBlurRadius :7.0 ],
582
+ [CCEffectBloom effectWithBlurRadius :8 intensity: 1 .0f luminanceThreshold: 0 .0f ],
561
583
[CCEffectBrightness effectWithBrightness: 0 .25f ],
562
584
[CCEffectContrast effectWithContrast: 1 .0f ],
563
585
[CCEffectPixellate effectWithBlockSize: 4 .0f ],
564
586
[CCEffectSaturation effectWithSaturation: -1 .0f ],
565
587
[CCEffectHue effectWithHue: 90 .0f ],
566
- [CCEffectGlass effectWithRefraction: 0 .5f refractionEnvironment: refractEnvironment reflectionEnvironment: reflectEnvironment normalMap: nil ],
567
- [CCEffectRefraction effectWithRefraction: 0 .5f environment: refractEnvironment normalMap: nil ],
568
- [CCEffectReflection effectWithFresnelBias: 0 .1f fresnelPower: 4 .0f environment: reflectEnvironment normalMap: nil ],
588
+ [CCEffectGlass effectWithShininess: 1 . 0f refraction: 0 .5f refractionEnvironment: refractEnvironment reflectionEnvironment: reflectEnvironment],
589
+ [CCEffectRefraction effectWithRefraction: 0 .5f environment: refractEnvironment],
590
+ [CCEffectReflection effectWithShininess: 1 . 0f fresnelBias: 0 .1f fresnelPower: 4 .0f environment: reflectEnvironment],
569
591
];
570
592
CCEffect *selectedEffect = allEffects[8 ];
571
593
@@ -655,7 +677,7 @@ - (CCNode *)effectNodeWithEffects:(NSArray *)effects appliedToSpriteWithImage:(N
655
677
}
656
678
else if (effects.count > 1 )
657
679
{
658
- CCEffectStack *stack = [[ CCEffectStack alloc ] initWithEffects : effects];
680
+ CCEffectStack *stack = [CCEffectStack effectWithArray : effects];
659
681
effectNode.effect = stack;
660
682
}
661
683
@@ -676,7 +698,7 @@ - (CCSprite *)spriteWithEffects:(NSArray *)effects image:(NSString *)spriteImage
676
698
}
677
699
else if (effects.count > 1 )
678
700
{
679
- CCEffectStack *stack = [[ CCEffectStack alloc ] initWithEffects : effects];
701
+ CCEffectStack *stack = [CCEffectStack effectWithArray : effects];
680
702
sprite.effect = stack;
681
703
}
682
704
0 commit comments