Skip to content

Commit b3c3673

Browse files
author
Thayer J Andrews
committed
CCLightNode - Add separate specular color and intensity properties
1 parent 55803eb commit b3c3673

File tree

2 files changed

+77
-16
lines changed

2 files changed

+77
-16
lines changed

cocos2d/CCLightNode.h

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ typedef NS_ENUM(NSUInteger, CCLightType)
5353
*/
5454
@property (nonatomic, assign) float intensity;
5555

56+
/** The specular color of the light. As described below, the color is modulated by the
57+
* specular intensity value to determine the contribution of the light to the lighting
58+
* effect. This color is used when computing the light's specular (shiny) contribution
59+
* to the lighting effect.
60+
*/
61+
@property (nonatomic, strong) CCColor* specularColor;
62+
63+
/** The brightness of the light's specular color. This value is in the range [0..1]
64+
* with 0 resulting in no contribution from the specular color to the final image
65+
* (the specular color effectively becomes black) and 1 resulting in full contribution
66+
* from this light.
67+
*/
68+
@property (nonatomic, assign) float specularIntensity;
69+
5670
/** The ambient color of the light. As described below, the color is modulated by the
5771
* ambient intensity value to determine the contribution of the light to the lighting
5872
* effect. The ambient color contributes to the lighting effect independent of the light's
@@ -101,15 +115,28 @@ typedef NS_ENUM(NSUInteger, CCLightType)
101115
/**
102116
* Initializes a CCLightNode object with the specified parameters.
103117
*
104-
* @param type The type of the light.
105-
* @param color The primary color of the light.
106-
* @param intensity The brightness of the light's primary color.
107-
* @param ambientColor The ambient color of the light.
108-
* @param ambientIntensity The brightness of the light's ambient color.
118+
* @param type The type of the light.
119+
* @param color The primary color of the light.
120+
* @param intensity The brightness of the light's primary color.
109121
*
110122
* @return The CCLighttNode object.
111123
*/
112-
-(id)initWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity ambientColor:(CCColor *)ambientColor ambientIntensity:(float)ambientIntensity;
124+
-(id)initWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity;
125+
126+
/**
127+
* Initializes a CCLightNode object with the specified parameters.
128+
*
129+
* @param type The type of the light.
130+
* @param color The primary color of the light.
131+
* @param intensity The brightness of the light's primary color.
132+
* @param specularColor The specular color of the light.
133+
* @param specularIntensity The brightness of the light's specular color.
134+
* @param ambientColor The ambient color of the light.
135+
* @param ambientIntensity The brightness of the light's ambient color.
136+
*
137+
* @return The CCLighttNode object.
138+
*/
139+
-(id)initWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity specularColor:(CCColor *)specularColor specularIntensity:(float)specularIntensity ambientColor:(CCColor *)ambientColor ambientIntensity:(float)ambientIntensity;
113140

114141

115142
/// -----------------------------------------------------------------------
@@ -119,15 +146,28 @@ typedef NS_ENUM(NSUInteger, CCLightType)
119146
/**
120147
* Creates a CCLightNode object with the specified parameters.
121148
*
122-
* @param type The type of the light.
123-
* @param color The primary color of the light.
124-
* @param intensity The brightness of the light's primary color.
125-
* @param ambientColor The ambient color of the light.
126-
* @param ambientIntensity The brightness of the light's ambient color.
149+
* @param type The type of the light.
150+
* @param color The primary color of the light.
151+
* @param intensity The brightness of the light's primary color.
152+
*
153+
* @return An initialized CCLightNode object.
154+
*/
155+
+(id)lightWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity;
156+
157+
/**
158+
* Creates a CCLightNode object with the specified parameters.
159+
*
160+
* @param type The type of the light.
161+
* @param color The primary color of the light.
162+
* @param intensity The brightness of the light's primary color.
163+
* @param specularColor The specular color of the light.
164+
* @param specularIntensity The brightness of the light's specular color.
165+
* @param ambientColor The ambient color of the light.
166+
* @param ambientIntensity The brightness of the light's ambient color.
127167
*
128168
* @return An initialized CCLightNode object.
129169
*/
130-
+(id)lightWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity ambientColor:(CCColor *)ambientColor ambientIntensity:(float)ambientIntensity;
170+
+(id)lightWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity specularColor:(CCColor *)specularColor specularIntensity:(float)specularIntensity ambientColor:(CCColor *)ambientColor ambientIntensity:(float)ambientIntensity;
131171

132172

133173
@end

cocos2d/CCLightNode.m

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,29 @@ @implementation CCLightNode
1414

1515
-(id)init
1616
{
17-
return [self initWithType:CCLightPoint color:[CCColor whiteColor] intensity:1.0f ambientColor:[CCColor whiteColor] ambientIntensity:0.5f];
17+
return [self initWithType:CCLightPoint color:[CCColor whiteColor] intensity:1.0f];
1818
}
1919

20+
-(id)initWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity
21+
{
22+
return [self initWithType:type color:color intensity:intensity specularColor:color specularIntensity:intensity ambientColor:[CCColor whiteColor] ambientIntensity:0.5f];
23+
}
2024

21-
-(id)initWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity ambientColor:(CCColor *)ambientColor ambientIntensity:(float)ambientIntensity
25+
-(id)initWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity specularColor:(CCColor *)specularColor specularIntensity:(float)specularIntensity ambientColor:(CCColor *)ambientColor ambientIntensity:(float)ambientIntensity
2226
{
2327
if ((self = [super init]))
2428
{
2529
_type = type;
30+
2631
_color = color.ccColor4f;
2732
_intensity = intensity;
33+
34+
_specularColor = specularColor;
35+
_specularIntensity = specularIntensity;
36+
2837
_ambientColor = ambientColor;
2938
_ambientIntensity = ambientIntensity;
39+
3040
_cutoffRadius = 0.0f;
3141
if (type == CCLightDirectional)
3242
{
@@ -41,9 +51,14 @@ -(id)initWithType:(CCLightType)type color:(CCColor *)color intensity:(float)inte
4151
return self;
4252
}
4353

44-
+(id)lightWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity ambientColor:(CCColor *)ambientColor ambientIntensity:(float)ambientIntensity
54+
+(id)lightWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity
55+
{
56+
return [[self alloc] initWithType:type color:color intensity:intensity];
57+
}
58+
59+
+(id)lightWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity specularColor:(CCColor *)specularColor specularIntensity:(float)specularIntensity ambientColor:(CCColor *)ambientColor ambientIntensity:(float)ambientIntensity
4560
{
46-
return [[self alloc] initWithType:type color:color intensity:intensity ambientColor:ambientColor ambientIntensity:ambientIntensity];
61+
return [[self alloc] initWithType:type color:color intensity:intensity specularColor:specularColor specularIntensity:specularIntensity ambientColor:ambientColor ambientIntensity:ambientIntensity];
4762
}
4863

4964
-(void)setIntensity:(float)intensity
@@ -52,6 +67,12 @@ -(void)setIntensity:(float)intensity
5267
_intensity = intensity;
5368
}
5469

70+
-(void)setSpecularIntensity:(float)intensity
71+
{
72+
NSCAssert((intensity >= 0.0) && (intensity <= 1.0), @"Supplied intensity out of range [0..1].");
73+
_specularIntensity = intensity;
74+
}
75+
5576
-(void)setAmbientIntensity:(float)intensity
5677
{
5778
NSCAssert((intensity >= 0.0) && (intensity <= 1.0), @"Supplied intensity out of range [0..1].");

0 commit comments

Comments
 (0)