Skip to content

Commit 5880a3f

Browse files
committed
Merge pull request #905 from thayerandrews/develop
CCEffectGlass/Reflection/Refraction - New initializer / constructor variants
2 parents b3f9762 + fed1125 commit 5880a3f

File tree

7 files changed

+134
-10
lines changed

7 files changed

+134
-10
lines changed

cocos2d-ui-tests/tests/CCEffectsTest.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ -(void)setupGlassEffectTest
4141

4242

4343
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] initWithRefraction:1.0f refractionEnvironment:refractEnvironment reflectionEnvironment:reflectEnvironment];
4545
glass.fresnelBias = 0.1f;
4646
glass.fresnelPower = 2.0f;
4747
glass.refraction = 0.75f;
@@ -81,7 +81,7 @@ -(void)setupReflectEffectTest
8181
[self.contentNode addChild:environment];
8282

8383
CCSpriteFrame *normalMap = [CCSpriteFrame frameWithImageNamed:@"Images/ShinyBallNormals.png"];
84-
CCEffectReflection *reflection = [[CCEffectReflection alloc] initWithEnvironment:environment normalMap:nil];
84+
CCEffectReflection *reflection = [[CCEffectReflection alloc] initWithEnvironment:environment];
8585
reflection.fresnelBias = 0.0f;
8686
reflection.fresnelPower = 0.0f;
8787

@@ -148,7 +148,7 @@ -(void)setupRefractionEffectTest
148148
NSString *sphereTextureFile = @"Images/ShinyBallColor.png";
149149
CCTexture *sphereTexture = [CCTexture textureWithFile:sphereTextureFile];
150150
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];
152152
sphereRefraction.refraction = 0.75f;
153153

154154
p1 = CGPointMake(0.1f, 0.8f);
@@ -515,9 +515,9 @@ -(void)setupStackTest
515515
[CCEffectPixellate effectWithBlockSize:8.0f],
516516
[CCEffectSaturation effectWithSaturation:-1.0f],
517517
[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],
518+
[CCEffectGlass effectWithRefraction:0.5f refractionEnvironment:refractEnvironment reflectionEnvironment:reflectEnvironment],
519+
[CCEffectRefraction effectWithRefraction:0.5f environment:refractEnvironment],
520+
[CCEffectReflection effectWithFresnelBias:0.2f fresnelPower:2.0f environment:reflectEnvironment],
521521
];
522522

523523

@@ -563,9 +563,9 @@ -(void)setupPerformanceTest
563563
[CCEffectPixellate effectWithBlockSize:4.0f],
564564
[CCEffectSaturation effectWithSaturation:-1.0f],
565565
[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],
566+
[CCEffectGlass effectWithRefraction:0.5f refractionEnvironment:refractEnvironment reflectionEnvironment:reflectEnvironment],
567+
[CCEffectRefraction effectWithRefraction:0.5f environment:refractEnvironment],
568+
[CCEffectReflection effectWithFresnelBias:0.1f fresnelPower:4.0f environment:reflectEnvironment],
569569
];
570570
CCEffect *selectedEffect = allEffects[8];
571571

cocos2d/CCEffectGlass.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@
7272
*/
7373
-(id)init;
7474

75+
/**
76+
* Initializes a CCEffectGlass object with the supplied parameters and a nil normal map.
77+
*
78+
* @param refraction The refraction strength.
79+
* @param refractionEnvironment The environment image that will be refracted by the affected node.
80+
* @param reflectionEnvironment The environment image that will be reflected by the affected node.
81+
*
82+
* @return The CCEffectGlass object.
83+
*/
84+
-(id)initWithRefraction:(float)refraction refractionEnvironment:(CCSprite *)refractionEnvironment reflectionEnvironment:(CCSprite *)reflectionEnvironment;
85+
7586
/**
7687
* Initializes a CCEffectGlass object with the supplied parameters.
7788
*
@@ -89,6 +100,18 @@
89100
/// @name Creating a CCEffectGlass object
90101
/// -----------------------------------------------------------------------
91102

103+
104+
/**
105+
* Creates a CCEffectGlass object with the supplied parameters and a nil normal map.
106+
*
107+
* @param refraction The refraction strength.
108+
* @param refractionEnvironment The environment image that will be refracted by the affected node.
109+
* @param reflectionEnvironment The environment image that will be reflected by the affected node.
110+
*
111+
* @return The CCEffectGlass object.
112+
*/
113+
+(id)effectWithRefraction:(float)refraction refractionEnvironment:(CCSprite *)refractionEnvironment reflectionEnvironment:(CCSprite *)reflectionEnvironment;
114+
92115
/**
93116
* Creates a CCEffectGlass object with the supplied parameters.
94117
*

cocos2d/CCEffectGlass.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ -(id)init
3232
return [self initWithRefraction:1.0f refractionEnvironment:nil reflectionEnvironment:nil normalMap:nil];
3333
}
3434

35+
-(id)initWithRefraction:(float)refraction refractionEnvironment:(CCSprite *)refractionEnvironment reflectionEnvironment:(CCSprite *)reflectionEnvironment
36+
{
37+
return [self initWithRefraction:refraction refractionEnvironment:refractionEnvironment reflectionEnvironment:reflectionEnvironment normalMap:nil];
38+
}
39+
3540
-(id)initWithRefraction:(float)refraction refractionEnvironment:(CCSprite *)refractionEnvironment reflectionEnvironment:(CCSprite *)reflectionEnvironment normalMap:(CCSpriteFrame *)normalMap
3641
{
3742
NSArray *uniforms = @[
@@ -66,6 +71,10 @@ -(id)initWithRefraction:(float)refraction refractionEnvironment:(CCSprite *)refr
6671
}
6772
return self;
6873
}
74+
+(id)effectWithRefraction:(float)refraction refractionEnvironment:(CCSprite *)refractionEnvironment reflectionEnvironment:(CCSprite *)reflectionEnvironment
75+
{
76+
return [[self alloc] initWithRefraction:refraction refractionEnvironment:refractionEnvironment reflectionEnvironment:reflectionEnvironment];
77+
}
6978

7079
+(id)effectWithRefraction:(float)refraction refractionEnvironment:(CCSprite *)refractionEnvironment reflectionEnvironment:(CCSprite *)reflectionEnvironment normalMap:(CCSpriteFrame *)normalMap
7180
{

cocos2d/CCEffectReflection.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@
5959
*/
6060
-(id)init;
6161

62+
/**
63+
* Initializes a CCEffectReflection object with the specified environment and normal map and the following default parameters:
64+
* fresnelBias = 1.0, fresnelPower = 0.0, normalMap = nil
65+
*
66+
* @param environment The environment image that will be reflected by the affected node.
67+
*
68+
* @return The CCEffectReflection object.
69+
*/
70+
-(id)initWithEnvironment:(CCSprite *)environment;
71+
6272
/**
6373
* Initializes a CCEffectReflection object with the specified environment and normal map and the following default parameters:
6474
* fresnelBias = 1.0, fresnelPower = 0.0
@@ -70,6 +80,17 @@
7080
*/
7181
-(id)initWithEnvironment:(CCSprite *)environment normalMap:(CCSpriteFrame *)normalMap;
7282

83+
/**
84+
* Initializes a CCEffectReflection object with the specified parameters and a nil normal map.
85+
*
86+
* @param bias The bias term in the fresnel reflectance equation.
87+
* @param power The power term in the fresnel reflectance equation.
88+
* @param environment The environment image that will be reflected by the affected node.
89+
*
90+
* @return The CCEffectReflection object.
91+
*/
92+
-(id)initWithFresnelBias:(float)bias fresnelPower:(float)power environment:(CCSprite *)environment;
93+
7394
/**
7495
* Initializes a CCEffectReflection object with the specified parameters.
7596
*
@@ -87,6 +108,16 @@
87108
/// @name Creating a CCEffectReflection object
88109
/// -----------------------------------------------------------------------
89110

111+
/**
112+
* Creates a CCEffectReflection object with the specified environment and the following default parameters:
113+
* fresnelBias = 1.0, fresnelPower = 0.0, normalMap = nil
114+
*
115+
* @param environment The environment image that will be reflected by the affected node.
116+
*
117+
* @return The CCEffectReflection object.
118+
*/
119+
+(id)effectWithEnvironment:(CCSprite *)environment;
120+
90121
/**
91122
* Creates a CCEffectReflection object with the specified environment and normal map and the following default parameters:
92123
* fresnelBias = 1.0, fresnelPower = 0.0
@@ -98,6 +129,17 @@
98129
*/
99130
+(id)effectWithEnvironment:(CCSprite *)environment normalMap:(CCSpriteFrame *)normalMap;
100131

132+
/**
133+
* Creates a CCEffectReflection object with the specified parameters and nil normal map.
134+
*
135+
* @param bias The bias term in the fresnel reflectance equation.
136+
* @param power The power term in the fresnel reflectance equation.
137+
* @param environment The environment image that will be reflected by the affected node.
138+
*
139+
* @return The CCEffectReflection object.
140+
*/
141+
+(id)effectWithFresnelBias:(float)bias fresnelPower:(float)power environment:(CCSprite *)environment;
142+
101143
/**
102144
* Creates a CCEffectReflection object with the specified parameters.
103145
*

cocos2d/CCEffectReflection.m

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,24 @@ @implementation CCEffectReflection
3030

3131
-(id)init
3232
{
33-
return [self initWithEnvironment:nil normalMap:nil];
33+
return [self initWithEnvironment:nil];
34+
}
35+
36+
-(id)initWithEnvironment:(CCSprite *)environment
37+
{
38+
return [self initWithEnvironment:environment normalMap:nil];
3439
}
3540

3641
-(id)initWithEnvironment:(CCSprite *)environment normalMap:(CCSpriteFrame *)normalMap
3742
{
3843
return [self initWithFresnelBias:1.0f fresnelPower:0.0f environment:environment normalMap:normalMap];
3944
}
4045

46+
-(id)initWithFresnelBias:(float)bias fresnelPower:(float)power environment:(CCSprite *)environment
47+
{
48+
return [self initWithFresnelBias:bias fresnelPower:power environment:environment normalMap:nil];
49+
}
50+
4151
-(id)initWithFresnelBias:(float)bias fresnelPower:(float)power environment:(CCSprite *)environment normalMap:(CCSpriteFrame *)normalMap
4252
{
4353
NSArray *uniforms = @[
@@ -61,11 +71,21 @@ -(id)initWithFresnelBias:(float)bias fresnelPower:(float)power environment:(CCSp
6171
return self;
6272
}
6373

74+
+(id)effectWithEnvironment:(CCSprite *)environment
75+
{
76+
return [[self alloc] initWithEnvironment:environment];
77+
}
78+
6479
+(id)effectWithEnvironment:(CCSprite *)environment normalMap:(CCSpriteFrame *)normalMap
6580
{
6681
return [[self alloc] initWithEnvironment:environment normalMap:normalMap];
6782
}
6883

84+
+(id)effectWithFresnelBias:(float)bias fresnelPower:(float)power environment:(CCSprite *)environment
85+
{
86+
return [[self alloc] initWithFresnelBias:bias fresnelPower:power environment:environment];
87+
}
88+
6989
+(id)effectWithFresnelBias:(float)bias fresnelPower:(float)power environment:(CCSprite *)environment normalMap:(CCSpriteFrame *)normalMap
7090
{
7191
return [[self alloc] initWithFresnelBias:bias fresnelPower:power environment:environment normalMap:normalMap];

cocos2d/CCEffectRefraction.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@
4949
*/
5050
-(id)init;
5151

52+
/**
53+
* Initializes a CCEffectRefraction object with the supplied parameters and a nil normal map.
54+
*
55+
* @param refraction The refraction strength.
56+
* @param environment The environment image that will be refracted by the affected node.
57+
*
58+
* @return The CCEffectRefraction object.
59+
*/
60+
-(id)initWithRefraction:(float)refraction environment:(CCSprite *)environment;
61+
5262
/**
5363
* Initializes a CCEffectRefraction object with the supplied parameters.
5464
*
@@ -65,6 +75,16 @@
6575
/// @name Initializing a CCEffectRefraction object
6676
/// -----------------------------------------------------------------------
6777

78+
/**
79+
* Creates a CCEffectRefraction object with the supplied parameters and a nil normal map.
80+
*
81+
* @param refraction The refraction strength.
82+
* @param environment The environment image that will be refracted by the affected node.
83+
*
84+
* @return The CCEffectRefraction object.
85+
*/
86+
+(id)effectWithRefraction:(float)refraction environment:(CCSprite *)environment;
87+
6888
/**
6989
* Creates a CCEffectRefraction object with the supplied parameters.
7090
*

cocos2d/CCEffectRefraction.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ -(id)init
3131
return [self initWithRefraction:1.0f environment:nil normalMap:nil];
3232
}
3333

34+
-(id)initWithRefraction:(float)refraction environment:(CCSprite *)environment
35+
{
36+
return [self initWithRefraction:refraction environment:environment normalMap:nil];
37+
}
38+
3439
-(id)initWithRefraction:(float)refraction environment:(CCSprite *)environment normalMap:(CCSpriteFrame *)normalMap
3540
{
3641
NSArray *uniforms = @[
@@ -53,6 +58,11 @@ -(id)initWithRefraction:(float)refraction environment:(CCSprite *)environment no
5358
return self;
5459
}
5560

61+
+(id)effectWithRefraction:(float)refraction environment:(CCSprite *)environment
62+
{
63+
return [[self alloc] initWithRefraction:refraction environment:environment];
64+
}
65+
5666
+(id)effectWithRefraction:(float)refraction environment:(CCSprite *)environment normalMap:(CCSpriteFrame *)normalMap
5767
{
5868
return [[self alloc] initWithRefraction:refraction environment:environment normalMap:normalMap];

0 commit comments

Comments
 (0)