Skip to content

Commit a1ff8af

Browse files
author
Thayer J Andrews
committed
CCEffectLighting - Switch from CCNode to CCLightNode
1 parent 207b1b2 commit a1ff8af

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

cocos2d/CCEffectLighting.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import "CCEffect.h"
10+
#import "CCLightNode.h"
1011

1112
/**
1213
* CCEffectLighting uses a normal map and a collection of light nodes to compute the Phong
@@ -18,9 +19,10 @@
1819
/// @name Accessing Effect Attributes
1920
/// -----------------------------------------------------------------------
2021

21-
/** The node that will light the affected node.
22+
/** The lights that will contribute to the lighting of the affected
23+
* node.
2224
*/
23-
@property (nonatomic, strong) CCNode *light;
25+
@property (nonatomic, strong) CCLightNode *light;
2426

2527

2628
/// -----------------------------------------------------------------------
@@ -41,7 +43,7 @@
4143
*
4244
* @return The CCEffectLighting object.
4345
*/
44-
-(id)initWithLight:(CCNode *)light;
46+
-(id)initWithLight:(CCLightNode *)light;
4547

4648

4749
/// -----------------------------------------------------------------------
@@ -55,6 +57,6 @@
5557
*
5658
* @return The CCEffectLighting object.
5759
*/
58-
+(id)effectWithLight:(CCNode *)light;
60+
+(id)effectWithLight:(CCLightNode *)light;
5961

6062
@end

cocos2d/CCEffectLighting.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ -(void)buildRenderPasses
122122
// Compute the light's position in the effect node's coordinate system.
123123
GLKVector4 lightPosition = GLKMatrix4MultiplyVector4(lightNodeToEffectNode, GLKVector4Make(weakSelf.light.anchorPointInPoints.x, weakSelf.light.anchorPointInPoints.y, 500.0f, 1.0f));
124124

125-
pass.shaderUniforms[weakSelf.uniformTranslationTable[@"u_lightColor"]] = [NSValue valueWithGLKVector4:GLKVector4Make(1.0f, 1.0f, 1.0f, 1.0f)];
125+
GLKVector4 lightColor = GLKVector4MultiplyScalar(weakSelf.light.color.glkVector4, weakSelf.light.intensity);
126+
127+
pass.shaderUniforms[weakSelf.uniformTranslationTable[@"u_lightColor"]] = [NSValue valueWithGLKVector4:lightColor];
126128
pass.shaderUniforms[weakSelf.uniformTranslationTable[@"u_lightPosition"]] = [NSValue valueWithGLKVector4:lightPosition];
127129
pass.shaderUniforms[weakSelf.uniformTranslationTable[@"u_ndcToTangentSpace"]] = [NSValue valueWithGLKMatrix4:pass.ndcToNodeLocal];
128130

cocos2d/CCLightNode.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@
3737
/// @name Initializing a CCLightNode object
3838
/// -----------------------------------------------------------------------
3939

40+
41+
/**
42+
* Initializes a CCLightNode object with a white color and full intensity.
43+
*
44+
* @return The CCLightNode object.
45+
*/
46+
-(id)init;
47+
4048
/**
4149
* Initializes a CCLightNode object with the specified parameters.
4250
*

0 commit comments

Comments
 (0)