Skip to content

Commit 6722f14

Browse files
committed
Merge pull request #904 from thayerandrews/develop
CCEffects - API documentation
2 parents 1738292 + bb26c65 commit 6722f14

13 files changed

+634
-11
lines changed

cocos2d/CCEffect.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,21 @@
1212
#import "ccConfig.h"
1313
#import "ccTypes.h"
1414

15+
16+
/**
17+
* CCEffect is the foundation of the Cocos2D effects system. Subclasses of CCEffect can be
18+
* used to easily add exciting visual effects such has blur, bloom, reflection, refraction, and
19+
* other image processing filters to your applications.
20+
*
21+
*/
22+
1523
@interface CCEffect : NSObject
1624

25+
/// -----------------------------------------------------------------------
26+
/// @name Accessing Effect Attributes
27+
/// -----------------------------------------------------------------------
28+
29+
/** An identifier for debugging effects. */
1730
@property (nonatomic, copy) NSString *debugName;
1831

1932
@end

cocos2d/CCEffectBloom.h

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,83 @@
88

99
#import "CCEffect.h"
1010

11+
/**
12+
* CCEffectBloom simulates bloooming of bright light when viewed against a darker
13+
* background. A threshold value allows for the selection of pixels above a certain
14+
* brightness level while radius and intensity parameters how large the bloom is and
15+
* how much it contributes to the resulting image.
16+
*/
17+
1118
@interface CCEffectBloom : CCEffect
1219

13-
// ranges between 0.0-1.0 - defines which part of the image should be glown via a luminance factor (brightness).
20+
/// -----------------------------------------------------------------------
21+
/// @name Accessing Effect Attributes
22+
/// -----------------------------------------------------------------------
23+
24+
/** The luminance threshold at which pixels will contribute to the bloom.
25+
* This value is in the range [0..1]. Lower values mean that more pixels will
26+
* contribute to the blurry bloom image.
27+
*/
1428
@property (nonatomic) float luminanceThreshold;
1529

16-
// intensity ranges between 0.0-1.0 - defines the contrast of the glowing image. A higher value will make the glow more prevelant.
30+
/** The intensity of the blurred out bloom image when added to the original
31+
* unmodified image. This value is in the range [0..1]. 0 results in no bloom
32+
* while higher values result in more bloom.
33+
*/
1734
@property (nonatomic) float intensity;
1835

19-
// blurRadius number of pixels blur will extend to (6 is the maximum, because we are limited by the number
20-
// of varying variables that can be passed to a glsl program). TODO: create a slower bloom shader, that does not have this restriction.
36+
/** The size of the blur of the bloom image. This value is in the range [0..6].
37+
*/
2138
@property (nonatomic) NSUInteger blurRadius;
2239

40+
41+
/// -----------------------------------------------------------------------
42+
/// @name Initializing a CCEffectBloom object
43+
/// -----------------------------------------------------------------------
44+
2345
/**
46+
* Initializes a CCEffectBloom object with the following default values:
47+
* blurRadius = 2, intensity = 1, luminanceThreshold = 0
48+
*
49+
* @return The CCEffectBloom object.
50+
*/
51+
-(id)init;
52+
53+
/**
54+
* Initializes a CCEffectBloom object with the following default parameters:
55+
*
2456
* @param blurRadius number of pixels blur will extend to (6 is the maximum, because we are limited by the number
25-
* of varying variables that can be passed to a glsl program). TODO: create a slower bloom shader, that does not have this restriction.
57+
* of varying variables that can be passed to a glsl program).
58+
*
2659
* @param intensity ranges between 0.0-1.0 - defines the contrast of the glowing image. A higher value will make the glow more prevelant.
27-
* @param luminanceThreshold ranges between 0.0-1.0 - defines which part of the image should be glown via a luminance factor (brightness).
60+
*
61+
* @param luminanceThreshold ranges between 0.0-1.0 - defines which part of the image should be glown via a luminance factor (brightness).
2862
* A value of 0.0 will apply bloom to the whole image, a value of 1.0 will only apply bloom to the brightest part of the image.
63+
*
64+
* @return The CCEffectBloom object.
65+
*
2966
*/
30-
-(id)init;
3167
-(id)initWithPixelBlurRadius:(NSUInteger)blurRadius intensity:(float)intensity luminanceThreshold:(float)luminanceThreshold;
68+
69+
70+
/// -----------------------------------------------------------------------
71+
/// @name Creating a CCEffectBloom object
72+
/// -----------------------------------------------------------------------
73+
74+
/**
75+
* Creates a CCEffectBloom object with the specified parameters.
76+
*
77+
* @param blurRadius number of pixels blur will extend to (6 is the maximum, because we are limited by the number
78+
* of varying variables that can be passed to a glsl program).
79+
*
80+
* @param intensity ranges between 0.0-1.0 - defines the contrast of the glowing image. A higher value will make the glow more prevelant.
81+
*
82+
* @param luminanceThreshold ranges between 0.0-1.0 - defines which part of the image should be glown via a luminance factor (brightness).
83+
* A value of 0.0 will apply bloom to the whole image, a value of 1.0 will only apply bloom to the brightest part of the image.
84+
*
85+
* @return The CCEffectBloom object.
86+
*
87+
*/
3288
+(id)effectWithPixelBlurRadius:(NSUInteger)blurRadius intensity:(float)intensity luminanceThreshold:(float)luminanceThreshold;
3389

3490
@end

cocos2d/CCEffectBrightness.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,59 @@
88

99
#import "CCEffect.h"
1010

11+
12+
/**
13+
* CCEffectBrightness adjusts the brightness of the sprite or effect node
14+
* it is attached to.
15+
*
16+
*/
17+
1118
@interface CCEffectBrightness : CCEffect
1219

20+
/// -----------------------------------------------------------------------
21+
/// @name Accessing Effect Attributes
22+
/// -----------------------------------------------------------------------
23+
24+
/** The brightness adjustment value that is added to the pixel colors of the
25+
* affected node. This is a normalized value in the range of [-1..1]. A value
26+
* of -1 reduces the affected color to 0 (black), 0 results in no change, 1
27+
* increases the affected color to 1 (white).
28+
*/
1329
@property (nonatomic) float brightness;
1430

31+
32+
/// -----------------------------------------------------------------------
33+
/// @name Initializing a CCEffectBrightness object
34+
/// -----------------------------------------------------------------------
35+
36+
/**
37+
* Initializes a CCEffectBrightness object with a brightness adjustment of 0.
38+
*
39+
* @return The CCEffectBrightness object.
40+
*/
1541
-(id)init;
42+
43+
/**
44+
* Initializes a CCEffectBrightness object with the supplied parameters.
45+
*
46+
* @param brightness The desired brightness adjustment.
47+
*
48+
* @return The CCEffectBrightness object.
49+
*/
1650
-(id)initWithBrightness:(float)brightness;
51+
52+
53+
/// -----------------------------------------------------------------------
54+
/// @name Creating a CCEffectBrightness object
55+
/// -----------------------------------------------------------------------
56+
57+
/**
58+
* Creates a CCEffectBrightness object with the supplied parameters.
59+
*
60+
* @param brightness The desired brightness adjustment.
61+
*
62+
* @return The CCEffectBrightness object.
63+
*/
1764
+(id)effectWithBrightness:(float)brightness;
1865

1966
@end

cocos2d/CCEffectContrast.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,59 @@
88

99
#import "CCEffect.h"
1010

11+
/**
12+
* CCEffectContrast adjusts the contrast of the sprite or effect node
13+
* it is attached to.
14+
*
15+
*/
16+
1117
@interface CCEffectContrast : CCEffect
1218

19+
/// -----------------------------------------------------------------------
20+
/// @name Accessing Effect Attributes
21+
/// -----------------------------------------------------------------------
22+
23+
/** The contrast adjustment value that is used to scale the pixel colors of the
24+
* affected node. This value is in the range [-1..1], and the napping of this value
25+
* to the color scale factor is: pow(4.0, contrast). This means that
26+
* an adjustment value of -1 scales the affected color by 0.25, 0 results in no
27+
* change, and 1 scales the affected color by 4.
28+
*/
1329
@property (nonatomic) float contrast;
1430

31+
32+
/// -----------------------------------------------------------------------
33+
/// @name Initializing a CCEffectContrast object
34+
/// -----------------------------------------------------------------------
35+
36+
/**
37+
* Initializes a CCEffectContrast object with a contrast adjustment of 0.
38+
*
39+
* @return The CCEffectContrast object.
40+
*/
1541
-(id)init;
42+
43+
/**
44+
* Initializes a CCEffectContrast object with the supplied parameters.
45+
*
46+
* @param contrast The desired contrast adjustment.
47+
*
48+
* @return The CCEffectContrast object.
49+
*/
1650
-(id)initWithContrast:(float)contrast;
51+
52+
53+
/// -----------------------------------------------------------------------
54+
/// @name Creating a CCEffectContrast object
55+
/// -----------------------------------------------------------------------
56+
57+
/**
58+
* Initializes a CCEffectContrast object with the supplied parameters.
59+
*
60+
* @param contrast The desired contrast adjustment.
61+
*
62+
* @return The CCEffectContrast object.
63+
*/
1764
+(id)effectWithContrast:(float)contrast;
1865

1966
@end

cocos2d/CCEffectGaussianBlur.h

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,58 @@
88

99
#import "CCEffect.h"
1010

11+
12+
/**
13+
* CCEffectGaussianBlur performs blur operation on the pixels of the attached node.
14+
*/
15+
1116
@interface CCEffectGaussianBlur : CCEffect
1217

13-
// blurRadius number of pixels blur will extend to (6 is the maximum, because we are limited by the number
14-
// of varying variables that can be passed to a glsl program). TODO: create a slower bloom shader, that does not have this restriction.
18+
19+
/// -----------------------------------------------------------------------
20+
/// @name Accessing Effect Attributes
21+
/// -----------------------------------------------------------------------
22+
23+
/** The size of the blur. This value is in the range [0..6].
24+
*/
1525
@property (nonatomic) NSUInteger blurRadius;
1626

27+
28+
/// -----------------------------------------------------------------------
29+
/// @name Initializing a CCEffectGaussianBlur object
30+
/// -----------------------------------------------------------------------
31+
1732
/**
18-
* @param blurRadius number of pixels blur will extend to (6 is the maximum, because we are limited by the number
19-
* of varying variables that can be passed to a glsl program). TODO: create a slower bloom shader, that does not have this restriction.
33+
* Initializes a CCEffectGaussianBlur object with the following default parameters:
34+
* blurRadius = 2
35+
*
36+
* @return The CCEffectGaussianBlur object.
2037
*/
2138
-(id)init;
39+
40+
/**
41+
* Initializes a CCEffectGaussianBlur object with the specified parameters.
42+
*
43+
* @param blurRadius number of pixels blur will extend to (6 is the maximum, because we are limited by the number
44+
* of varying variables that can be passed to a glsl program).
45+
*
46+
* @return The CCEffectGaussianBlur object.
47+
*/
2248
-(id)initWithPixelBlurRadius:(NSUInteger)blurRadius;
49+
50+
51+
/// -----------------------------------------------------------------------
52+
/// @name Creating a CCEffectGaussianBlur object
53+
/// -----------------------------------------------------------------------
54+
55+
/**
56+
* Creates a CCEffectGaussianBlur object with the specified parameters.
57+
*
58+
* @param blurRadius number of pixels blur will extend to (6 is the maximum, because we are limited by the number
59+
* of varying variables that can be passed to a glsl program).
60+
*
61+
* @return The CCEffectGaussianBlur object.
62+
*/
2363
+(id)effectWithPixelBlurRadius:(NSUInteger)blurRadius;
2464

2565
@end

cocos2d/CCEffectGlass.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,97 @@
88

99
#import "CCEffect.h"
1010

11+
/**
12+
* CCEffectGlass uses reflection and refraction to simulate the appearance of a transparent object
13+
* contained within an environment. Refraction is controlled with a single refraction strength value,
14+
* the normal map, and a refraction environment sprite. Reflection is controlled with two fresnel
15+
* reflectance values, the normal map, and a reflection environment sprite (which may be different
16+
* from the refraction environment).
17+
*
18+
*/
1119
@interface CCEffectGlass : CCEffect
1220

21+
/// -----------------------------------------------------------------------
22+
/// @name Accessing Effect Attributes
23+
/// -----------------------------------------------------------------------
24+
25+
/** The refraction strength value. This value is in the range [-1..1] with -1
26+
* resulting in maximum minification of the refracted image, 0 resulting in no
27+
* refraction, and 1 resulting in maximum magnification of the refracted image.
28+
*/
1329
@property (nonatomic) float refraction;
30+
31+
/** The bias term in the fresnel reflectance equation:
32+
* reflectance = max(0.0, fresnelBias + (1 - fresnelBias) * pow((1 - nDotV), fresnelPower))
33+
* This value is in the range [0..1] and it controls the constant (view angle independent) contribution
34+
* to the reflectance equation.
35+
*/
1436
@property (nonatomic) float fresnelBias;
37+
38+
/** The power term in the fresnel reflectance equation:
39+
* reflectance = max(0.0, fresnelBias + (1 - fresnelBias) * pow((1 - nDotV), fresnelPower))
40+
* This value is in the range [0..inf] and it controls the view angle dependent contribution
41+
* to the reflectance equation.
42+
*/
1543
@property (nonatomic) float fresnelPower;
44+
45+
/** The environment that will be refracted by the affected node. Typically this is a
46+
* sprite that serves as the background for the affected node so it appears that the viewer
47+
* is seeing the refracted environment through the refracting node.
48+
*/
1649
@property (nonatomic) CCSprite *refractionEnvironment;
50+
51+
/** The environment that will be reflected by the affected node. Typically this is a sprite
52+
* that is not visible in the scene as it is conceptually "behind the viewer" and only visible
53+
* where reflected by the affected node.
54+
*/
1755
@property (nonatomic) CCSprite *reflectionEnvironment;
56+
57+
/** The normal map that encodes the normal vectors of the affected node. Each pixel in the normal
58+
* map is a 3 component vector that is perpendicular to the surface of the sprite at that point.
59+
*/
1860
@property (nonatomic) CCSpriteFrame *normalMap;
1961

62+
63+
/// -----------------------------------------------------------------------
64+
/// @name Initializing a CCEffectGlass object
65+
/// -----------------------------------------------------------------------
66+
67+
/**
68+
* Initializes a CCEffectGlass object with the following default parameters:
69+
* refraction = 1.0, fresnelBias = 0.1, fresnelPower = 2.0, refractionEnvironment = nil, reflectionEnvironment = nil, normalMap = nil
70+
*
71+
* @return The CCEffectGlass object.
72+
*/
2073
-(id)init;
74+
75+
/**
76+
* Initializes a CCEffectGlass object with the supplied parameters.
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+
* @param normalMap The normal map of the affected node. This can also be specified as a property of the affected sprite.
82+
*
83+
* @return The CCEffectGlass object.
84+
*/
2185
-(id)initWithRefraction:(float)refraction refractionEnvironment:(CCSprite *)refractionEnvironment reflectionEnvironment:(CCSprite *)reflectionEnvironment normalMap:(CCSpriteFrame *)normalMap;
86+
87+
88+
/// -----------------------------------------------------------------------
89+
/// @name Creating a CCEffectGlass object
90+
/// -----------------------------------------------------------------------
91+
92+
/**
93+
* Creates a CCEffectGlass object with the supplied parameters.
94+
*
95+
* @param refraction The refraction strength.
96+
* @param refractionEnvironment The environment image that will be refracted by the affected node.
97+
* @param reflectionEnvironment The environment image that will be reflected by the affected node.
98+
* @param normalMap The normal map of the affected node. This can also be specified as a property of the affected sprite.
99+
*
100+
* @return The CCEffectGlass object.
101+
*/
22102
+(id)effectWithRefraction:(float)refraction refractionEnvironment:(CCSprite *)refractionEnvironment reflectionEnvironment:(CCSprite *)reflectionEnvironment normalMap:(CCSpriteFrame *)normalMap;
23103

24104
@end

0 commit comments

Comments
 (0)