4
4
#import " CCEffectNode.h"
5
5
#import " CCEffectGaussianBlur.h"
6
6
7
- #if CC_ENABLE_EXPERIMENTAL_EFFECTS
8
7
9
8
@interface CCEffectsTest : TestBase @end
10
9
@implementation CCEffectsTest
@@ -492,23 +491,111 @@ -(void)setupHueEffectTest
492
491
}
493
492
}
494
493
494
+ -(void )setupStackTest
495
+ {
496
+ self.subTitle = @" Effect Stacking Test" ;
497
+
498
+ CCSprite *reflectEnvironment = [CCSprite spriteWithImageNamed: @" Images/MountainPanorama.jpg" ];
499
+ reflectEnvironment.positionType = CCPositionTypeNormalized;
500
+ reflectEnvironment.position = ccp (0 .5f , 0 .5f );
501
+ reflectEnvironment.visible = NO ;
502
+ [self .contentNode addChild: reflectEnvironment];
503
+
504
+ CCSprite *refractEnvironment = [CCSprite spriteWithImageNamed: @" Images/StoneWall.jpg" ];
505
+ refractEnvironment.positionType = CCPositionTypeNormalized;
506
+ refractEnvironment.position = ccp (0 .5f , 0 .5f );
507
+ refractEnvironment.scale = 0.5 ;
508
+ [self .contentNode addChild: refractEnvironment];
509
+
510
+ NSArray *effects = @[
511
+ [CCEffectGaussianBlur effectWithPixelBlurRadius: 7.0 ],
512
+ [CCEffectBloom effectWithPixelBlurRadius: 8 intensity: 1 .0f luminanceThreshold: 0 .0f ],
513
+ [CCEffectBrightness effectWithBrightness: 0 .25f ],
514
+ [CCEffectContrast effectWithContrast: 1 .0f ],
515
+ [CCEffectPixellate effectWithBlockSize: 8 .0f ],
516
+ [CCEffectSaturation effectWithSaturation: -1 .0f ],
517
+ [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 ],
521
+ ];
522
+
523
+
524
+ CCSprite *sprite = [CCSprite spriteWithImageNamed: @" Images/ShinyBallColor.png" ];
525
+ sprite.positionType = CCPositionTypeNormalized;
526
+ sprite.position = ccp (0 .1f , 0 .9f );
527
+ sprite.scale = 0 .5f ;
528
+
529
+ sprite.effect = [[CCEffectStack alloc ] initWithEffects: @[effects[4 ]]];
530
+ sprite.normalMapSpriteFrame = [CCSpriteFrame frameWithImageNamed: @" Images/ShinyBallNormals.png" ];
531
+ sprite.colorRGBA = [CCColor colorWithRed: 0 .75f green: 0 .75f blue: 0 .75f alpha: 0 .75f ];
532
+
533
+ [self .contentNode addChild: sprite];
534
+
535
+ [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 )],
540
+ nil
541
+ ]]];
542
+ }
543
+
495
544
-(void )setupPerformanceTest
496
545
{
497
546
self.subTitle = @" Effect Performance Test" ;
547
+
548
+ CCSprite *reflectEnvironment = [CCSprite spriteWithImageNamed: @" Images/MountainPanorama.jpg" ];
549
+ reflectEnvironment.positionType = CCPositionTypeNormalized;
550
+ reflectEnvironment.position = ccp (0 .5f , 0 .5f );
551
+ reflectEnvironment.visible = NO ;
552
+
553
+ CCSprite *refractEnvironment = [CCSprite spriteWithImageNamed: @" Images/StoneWall.jpg" ];
554
+ refractEnvironment.positionType = CCPositionTypeNormalized;
555
+ refractEnvironment.position = ccp (0 .5f , 0 .5f );
556
+ refractEnvironment.scale = 0.5 ;
557
+
558
+ NSArray *allEffects = @[
559
+ [CCEffectGaussianBlur effectWithPixelBlurRadius: 7.0 ],
560
+ [CCEffectBloom effectWithPixelBlurRadius: 8 intensity: 1 .0f luminanceThreshold: 0 .0f ],
561
+ [CCEffectBrightness effectWithBrightness: 0 .25f ],
562
+ [CCEffectContrast effectWithContrast: 1 .0f ],
563
+ [CCEffectPixellate effectWithBlockSize: 4 .0f ],
564
+ [CCEffectSaturation effectWithSaturation: -1 .0f ],
565
+ [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 ],
569
+ ];
570
+ CCEffect *selectedEffect = allEffects[8 ];
571
+
572
+
573
+ CCSpriteFrame *normalMap = nil ;
574
+ if ([selectedEffect.debugName isEqualToString: @" CCEffectGlass" ])
575
+ {
576
+ [self .contentNode addChild: reflectEnvironment];
577
+ [self .contentNode addChild: refractEnvironment];
578
+ normalMap = [CCSpriteFrame frameWithImageNamed: @" Images/ShinyBallNormals.png" ];
579
+ }
580
+ else if ([selectedEffect.debugName isEqualToString: @" CCEffectRefraction" ])
581
+ {
582
+ [self .contentNode addChild: refractEnvironment];
583
+ normalMap = [CCSpriteFrame frameWithImageNamed: @" Images/ShinyBallNormals.png" ];
584
+ }
585
+ else if ([selectedEffect.debugName isEqualToString: @" CCEffectReflection" ])
586
+ {
587
+ [self .contentNode addChild: reflectEnvironment];
588
+ normalMap = [CCSpriteFrame frameWithImageNamed: @" Images/ShinyBallNormals.png" ];
589
+ }
498
590
499
- // CCEffect *glow = [CCEffectGlow effectWithBlurStrength:0.02f];
500
- // CCEffect *brightness = [[CCEffectBrightness alloc] initWithBrightness:0.25f];
501
- // CCEffect *contrast = [[CCEffectContrast alloc] initWithContrast:1.0f];
502
- // CCEffect *pixellate = [[CCEffectPixellate alloc] initWithBlockSize:4.0f];
503
- // CCEffect *blur = [CCEffectGaussianBlur effectWithBlurStrength:0.02f direction:GLKVector2Make(1.0, 1.0)];
504
- CCEffect *saturation = [[CCEffectSaturation alloc ] initWithSaturation: 0 .0f ];
505
- NSArray *effects = @[saturation];
506
591
507
592
CGSize containerSize = self.contentNode .contentSizeInPoints ;
508
593
509
- NSString *spriteImage = @" Images/snow.png" ;
510
594
const float footprintScale = 1 .1f ;
511
- CCSprite *sprite = [self spriteWithEffects: effects image: spriteImage atPosition: ccp (0 , 0 )];
595
+
596
+ NSString *spriteImage = @" Images/r1.png" ;
597
+ CCSprite *sprite = [CCSprite spriteWithImageNamed: spriteImage];
598
+
512
599
CGSize spriteSize = sprite.contentSizeInPoints ;
513
600
CGSize spriteFootprint = CGSizeMake (spriteSize.width * footprintScale, spriteSize.height * footprintScale);
514
601
CGSize allSpritesBounds = CGSizeMake (((int )(containerSize.width / spriteFootprint.width ) * spriteFootprint.width ),
@@ -521,10 +608,25 @@ -(void)setupPerformanceTest
521
608
{
522
609
for (float xPos = origin.x ; (xPos + spriteFootprint.width ) < containerSize.width ; xPos += spriteFootprint.width )
523
610
{
524
- sprite = [self spriteWithEffects: effects image: spriteImage atPosition: ccp (xPos, yPos)];
525
- sprite.anchorPoint = ccp (0 .0f , 0 .0f );
611
+ if (normalMap)
612
+ {
613
+ sprite = [[CCSprite alloc ] init ];
614
+ sprite.normalMapSpriteFrame = normalMap;
615
+ sprite.scale = 0 .1f ;
616
+ sprite.colorRGBA = [CCColor colorWithRed: 0 .0f green: 0 .0f blue: 0 .0f alpha: 0 .0f ];
617
+ }
618
+ else
619
+ {
620
+ sprite = [CCSprite spriteWithImageNamed: spriteImage];
621
+ }
622
+
526
623
sprite.positionType = CCPositionTypePoints;
624
+ sprite.position = ccp (xPos, yPos);
625
+ sprite.anchorPoint = ccp (0 .0f , 0 .0f );
626
+ sprite.effect = selectedEffect;
627
+
527
628
[self .contentNode addChild: sprite];
629
+
528
630
count++;
529
631
}
530
632
}
@@ -608,5 +710,4 @@ -(void)renderTextureHelper:(CCNode *)stage size:(CGSize)size
608
710
[node addChild: sprite];
609
711
}
610
712
@end
611
- #endif
612
713
0 commit comments