diff --git a/cocos2d-ui-tests/tests/CCEffectsTest.m b/cocos2d-ui-tests/tests/CCEffectsTest.m index 9720814eb02..1d0420b3b7d 100644 --- a/cocos2d-ui-tests/tests/CCEffectsTest.m +++ b/cocos2d-ui-tests/tests/CCEffectsTest.m @@ -313,7 +313,7 @@ -(void)setupSimpleLightingTest -(void)setupLightingParameterTest { - self.subTitle = @"Lighting Parameter Test"; + self.subTitle = @"Varying Light Parameter Test"; NSString *normalMapImage = @"Images/ShinyTorusNormals.png"; NSString *diffuseImage = @"Images/ShinyTorusColor.png"; @@ -365,14 +365,17 @@ -(void)setupLightingParameterTest CCSprite *sprite = nil; CCEffectLighting *lighting = nil; - light = setupBlock(ccp(0.2f, 0.65f), @"Varying Intensity", [CCActionRepeatForever actionWithAction:[CCActionSequence actions: - [CCActionTween actionWithDuration:2 key:@"intensity" from:0.0f to:1.0f], - [CCActionDelay actionWithDuration:2], - [CCActionTween actionWithDuration:2 key:@"intensity" from:1.0f to:0.0f], - nil - ]]); + + // Primary color + // + light = setupBlock(ccp(0.1f, 0.65f), @"Primary Intensity", [CCActionRepeatForever actionWithAction:[CCActionSequence actions: + [CCActionTween actionWithDuration:2 key:@"intensity" from:0.0f to:1.0f], + [CCActionDelay actionWithDuration:2], + [CCActionTween actionWithDuration:2 key:@"intensity" from:1.0f to:0.0f], + nil + ]]); light.ambientIntensity = 0.0f; - light = setupBlock(ccp(0.2f, 0.25f), @"Varying Color", [CCActionRepeatForever actionWithAction:[CCActionSequence actions: + light = setupBlock(ccp(0.1f, 0.25f), @"Primary Color", [CCActionRepeatForever actionWithAction:[CCActionSequence actions: [CCActionTintTo actionWithDuration:2 color:[CCColor redColor]], [CCActionDelay actionWithDuration:1], [CCActionTintTo actionWithDuration:2 color:[CCColor greenColor]], @@ -385,13 +388,15 @@ -(void)setupLightingParameterTest ]]); - light = setupBlock(ccp(0.4f, 0.65f), @"Varying Ambient Intensity", [CCActionRepeatForever actionWithAction:[CCActionSequence actions: - [CCActionTween actionWithDuration:2 key:@"ambientIntensity" from:0.0f to:1.0f], - [CCActionDelay actionWithDuration:2], - [CCActionTween actionWithDuration:2 key:@"ambientIntensity" from:1.0f to:0.0f], - nil - ]]); - light = setupBlock(ccp(0.4f, 0.25f), @"Varying Ambient Color", nil); + // Ambient color + // + light = setupBlock(ccp(0.3f, 0.65f), @"Ambient Intensity", [CCActionRepeatForever actionWithAction:[CCActionSequence actions: + [CCActionTween actionWithDuration:2 key:@"ambientIntensity" from:0.0f to:1.0f], + [CCActionDelay actionWithDuration:2], + [CCActionTween actionWithDuration:2 key:@"ambientIntensity" from:1.0f to:0.0f], + nil + ]]); + light = setupBlock(ccp(0.3f, 0.25f), @"Ambient Color", nil); light.intensity = 0.5f; light.ambientIntensity = 0.5f; @@ -415,17 +420,26 @@ -(void)setupLightingParameterTest return lerpBlock; }; - AmbientLerpBlock whiteRedLerp = ambientLerpBuilder(ccc4f(0.0f, -delta, -delta, 0.0f)); - CCActionInterval *whiteRedLerpAction = [CCActionRepeat actionWithAction:[CCActionSequence actionOne:[CCActionDelay actionWithDuration:timeStep] two:[CCActionCallBlock actionWithBlock:whiteRedLerp]] times:120]; + AmbientLerpBlock whiteRedLerp; + AmbientLerpBlock redGreenLerp; + AmbientLerpBlock greenBlueLerp; + AmbientLerpBlock blueWhiteLerp; + CCActionInterval *whiteRedLerpAction; + CCActionInterval *redGreenLerpAction; + CCActionInterval *greenBlueLerpAction; + CCActionInterval *blueWhiteLerpAction; + + whiteRedLerp = ambientLerpBuilder(ccc4f(0.0f, -delta, -delta, 0.0f)); + whiteRedLerpAction = [CCActionRepeat actionWithAction:[CCActionSequence actionOne:[CCActionDelay actionWithDuration:timeStep] two:[CCActionCallBlock actionWithBlock:whiteRedLerp]] times:120]; - AmbientLerpBlock redGreenLerp = ambientLerpBuilder(ccc4f(-delta, delta, 0.0f, 0.0f)); - CCActionInterval *redGreenLerpAction = [CCActionRepeat actionWithAction:[CCActionSequence actionOne:[CCActionDelay actionWithDuration:timeStep] two:[CCActionCallBlock actionWithBlock:redGreenLerp]] times:120]; + redGreenLerp = ambientLerpBuilder(ccc4f(-delta, delta, 0.0f, 0.0f)); + redGreenLerpAction = [CCActionRepeat actionWithAction:[CCActionSequence actionOne:[CCActionDelay actionWithDuration:timeStep] two:[CCActionCallBlock actionWithBlock:redGreenLerp]] times:120]; - AmbientLerpBlock greenBlueLerp = ambientLerpBuilder(ccc4f(0.0f, -delta, delta, 0.0f)); - CCActionInterval *greenBlueLerpAction = [CCActionRepeat actionWithAction:[CCActionSequence actionOne:[CCActionDelay actionWithDuration:timeStep] two:[CCActionCallBlock actionWithBlock:greenBlueLerp]] times:120]; + greenBlueLerp = ambientLerpBuilder(ccc4f(0.0f, -delta, delta, 0.0f)); + greenBlueLerpAction = [CCActionRepeat actionWithAction:[CCActionSequence actionOne:[CCActionDelay actionWithDuration:timeStep] two:[CCActionCallBlock actionWithBlock:greenBlueLerp]] times:120]; - AmbientLerpBlock blueWhiteLerp = ambientLerpBuilder(ccc4f(delta, delta, 0.0f, 0.0f)); - CCActionInterval *blueWhiteLerpAction = [CCActionRepeat actionWithAction:[CCActionSequence actionOne:[CCActionDelay actionWithDuration:timeStep] two:[CCActionCallBlock actionWithBlock:blueWhiteLerp]] times:120]; + blueWhiteLerp = ambientLerpBuilder(ccc4f(delta, delta, 0.0f, 0.0f)); + blueWhiteLerpAction = [CCActionRepeat actionWithAction:[CCActionSequence actionOne:[CCActionDelay actionWithDuration:timeStep] two:[CCActionCallBlock actionWithBlock:blueWhiteLerp]] times:120]; CCAction *ambientLerpAction = [CCActionRepeatForever actionWithAction:[CCActionSequence actions: whiteRedLerpAction, @@ -440,24 +454,66 @@ -(void)setupLightingParameterTest ]]; [light runAction:ambientLerpAction]; - light = setupBlock(ccp(0.6f, 0.65f), @"Varying Cutoff", [CCActionRepeatForever actionWithAction:[CCActionSequence actions: - [CCActionTween actionWithDuration:2 key:@"cutoffRadius" from:1.0f to:500.0f], - [CCActionTween actionWithDuration:2 key:@"cutoffRadius" from:500.0f to:1.0f], - nil - ]]); - light.cutoffRadius = 1.0f; - light = setupBlock(ccp(0.6f, 0.25f), @"Varying Depth", [CCActionRepeatForever actionWithAction:[CCActionSequence actions: - [CCActionTween actionWithDuration:2 key:@"depth" from:1.0f to:500.0f], - [CCActionTween actionWithDuration:2 key:@"depth" from:500.0f to:1.0f], - nil - ]]); - light.depth = 1.0f; - sprite = (CCSprite *)light.parent; - lighting = (CCEffectLighting *)sprite.effect; - lighting.shininess = 20.0f; + // Specular color + // + light = setupBlock(ccp(0.5f, 0.65f), @"Specular Intensity", [CCActionRepeatForever actionWithAction:[CCActionSequence actions: + [CCActionTween actionWithDuration:2 key:@"specularIntensity" from:0.0f to:1.0f], + [CCActionDelay actionWithDuration:2], + [CCActionTween actionWithDuration:2 key:@"specularIntensity" from:1.0f to:0.0f], + nil + ]]); + light = setupBlock(ccp(0.5f, 0.25f), @"Specular Color", nil); + light.intensity = 0.5f; + light.ambientIntensity = 0.5f; + light.specularIntensity = 1.0f; - light = setupBlock(ccp(0.8f, 0.65f), @"Varying Shininess", nil); + typedef void (^SpecularLerpBlock)(); + typedef void (^SpecularLerpBuilderBlock)(ccColor4F deltaC); + + weakLight = light; + SpecularLerpBlock (^specularLerpBuilder)(ccColor4F deltaC) = ^SpecularLerpBlock(ccColor4F deltaC) + { + SpecularLerpBlock lerpBlock = ^{ + ccColor4F c = weakLight.specularColor.ccColor4f; + c.r += deltaC.r; + c.g += deltaC.g; + c.b += deltaC.b; + weakLight.specularColor = [CCColor colorWithCcColor4f:c]; + }; + return lerpBlock; + }; + + whiteRedLerp = specularLerpBuilder(ccc4f(0.0f, -delta, -delta, 0.0f)); + whiteRedLerpAction = [CCActionRepeat actionWithAction:[CCActionSequence actionOne:[CCActionDelay actionWithDuration:timeStep] two:[CCActionCallBlock actionWithBlock:whiteRedLerp]] times:120]; + + redGreenLerp = specularLerpBuilder(ccc4f(-delta, delta, 0.0f, 0.0f)); + redGreenLerpAction = [CCActionRepeat actionWithAction:[CCActionSequence actionOne:[CCActionDelay actionWithDuration:timeStep] two:[CCActionCallBlock actionWithBlock:redGreenLerp]] times:120]; + + greenBlueLerp = specularLerpBuilder(ccc4f(0.0f, -delta, delta, 0.0f)); + greenBlueLerpAction = [CCActionRepeat actionWithAction:[CCActionSequence actionOne:[CCActionDelay actionWithDuration:timeStep] two:[CCActionCallBlock actionWithBlock:greenBlueLerp]] times:120]; + + blueWhiteLerp = specularLerpBuilder(ccc4f(delta, delta, 0.0f, 0.0f)); + blueWhiteLerpAction = [CCActionRepeat actionWithAction:[CCActionSequence actionOne:[CCActionDelay actionWithDuration:timeStep] two:[CCActionCallBlock actionWithBlock:blueWhiteLerp]] times:120]; + + CCAction *specularLerpAction = [CCActionRepeatForever actionWithAction:[CCActionSequence actions: + whiteRedLerpAction, + [CCActionDelay actionWithDuration:1], + redGreenLerpAction, + [CCActionDelay actionWithDuration:1], + greenBlueLerpAction, + [CCActionDelay actionWithDuration:1], + blueWhiteLerpAction, + [CCActionDelay actionWithDuration:1], + nil + ]]; + [light runAction:specularLerpAction]; + + + // Cutoff, depth, and shininess + // + + light = setupBlock(ccp(0.7f, 0.65f), @"Shininess", nil); sprite = (CCSprite *)light.parent; lighting = (CCEffectLighting *)sprite.effect; lighting.shininess = 4.0f; @@ -474,16 +530,36 @@ -(void)setupLightingParameterTest ShininessLerpBlock shininessRampUp = shininessLerpBuilder(delta * 50.0f); CCActionInterval *shininessRampUpAction = [CCActionRepeat actionWithAction:[CCActionSequence actionOne:[CCActionDelay actionWithDuration:timeStep] two:[CCActionCallBlock actionWithBlock:shininessRampUp]] times:120]; - + ShininessLerpBlock shininessRampDown = shininessLerpBuilder(-delta * 50.0f); CCActionInterval *shininessRampDownAction = [CCActionRepeat actionWithAction:[CCActionSequence actionOne:[CCActionDelay actionWithDuration:timeStep] two:[CCActionCallBlock actionWithBlock:shininessRampDown]] times:120]; [light runAction:[CCActionRepeatForever actionWithAction:[CCActionSequence actions: shininessRampUpAction, - [CCActionDelay actionWithDuration:1], + [CCActionDelay actionWithDuration:2], shininessRampDownAction, nil ]]]; + + light = setupBlock(ccp(0.7f, 0.25f), @"Cutoff", [CCActionRepeatForever actionWithAction:[CCActionSequence actions: + [CCActionTween actionWithDuration:2 key:@"cutoffRadius" from:1.0f to:1000.0f], + [CCActionDelay actionWithDuration:2], + [CCActionTween actionWithDuration:2 key:@"cutoffRadius" from:1000.0f to:1.0f], + nil + ]]); + light.cutoffRadius = 1.0f; + light.ambientIntensity = 0.0f; + light.intensity = 1.0f; + light = setupBlock(ccp(0.9f, 0.65f), @"Depth", [CCActionRepeatForever actionWithAction:[CCActionSequence actions: + [CCActionTween actionWithDuration:2 key:@"depth" from:1.0f to:500.0f], + [CCActionTween actionWithDuration:2 key:@"depth" from:500.0f to:1.0f], + nil + ]]); + light.depth = 1.0f; + sprite = (CCSprite *)light.parent; + lighting = (CCEffectLighting *)sprite.effect; + lighting.shininess = 20.0f; + } #endif diff --git a/cocos2d/CCEffectLighting.m b/cocos2d/CCEffectLighting.m index a5837c8dd3e..b45c8884c51 100644 --- a/cocos2d/CCEffectLighting.m +++ b/cocos2d/CCEffectLighting.m @@ -105,8 +105,9 @@ +(NSMutableArray *)buildFragmentFunctionsWithLights:(NSArray*)lights normalMap:( NSMutableString *effectBody = [[NSMutableString alloc] init]; [effectBody appendString:CC_GLSL( vec4 lightColor; - vec4 diffuseLightColor = u_globalAmbientColor; - vec4 specularLightColor = vec4(0,0,0,0); + vec4 lightSpecularColor; + vec4 diffuseSum = u_globalAmbientColor; + vec4 specularSum = vec4(0,0,0,0); vec3 tangentSpaceLightDir; vec3 halfAngleDir; @@ -146,6 +147,7 @@ +(NSMutableArray *)buildFragmentFunctionsWithLights:(NSArray*)lights normalMap:( { [effectBody appendFormat:@"tangentSpaceLightDir = v_tangentSpaceLightDir%lu.xyz;\n", (unsigned long)lightIndex]; [effectBody appendFormat:@"lightColor = u_lightColor%lu;\n", (unsigned long)lightIndex]; + [effectBody appendFormat:@"lightSpecularColor = u_lightSpecularColor%lu;\n", (unsigned long)lightIndex]; } else { @@ -153,21 +155,25 @@ +(NSMutableArray *)buildFragmentFunctionsWithLights:(NSArray*)lights normalMap:( [effectBody appendFormat:@"lightDist = length(v_tangentSpaceLightDir%lu.xyz);\n", (unsigned long)lightIndex]; [effectBody appendFormat:@"falloffTerm = max(0.0, (1.0 - lightDist * u_lightFalloff%lu));\n", (unsigned long)lightIndex]; [effectBody appendFormat:@"lightColor = u_lightColor%lu * falloffTerm;\n", (unsigned long)lightIndex]; + if (needsSpecular) + { + [effectBody appendFormat:@"lightSpecularColor = u_lightSpecularColor%lu * falloffTerm;\n", (unsigned long)lightIndex]; + } } [effectBody appendString:@"diffuseTerm = max(0.0, dot(tangentSpaceNormal, tangentSpaceLightDir));\n"]; - [effectBody appendString:@"diffuseLightColor += lightColor * diffuseTerm;\n"]; + [effectBody appendString:@"diffuseSum += lightColor * diffuseTerm;\n"]; if (needsSpecular) { [effectBody appendString:@"halfAngleDir = (2.0 * dot(tangentSpaceLightDir, tangentSpaceNormal) * tangentSpaceNormal - tangentSpaceLightDir);\n"]; [effectBody appendString:@"specularTerm = max(0.0, dot(halfAngleDir, vec3(0,0,1))) * step(0.0, diffuseTerm);\n"]; - [effectBody appendString:@"specularLightColor += lightColor * pow(specularTerm, u_specularExponent);\n"]; + [effectBody appendString:@"specularSum += lightSpecularColor * pow(specularTerm, u_specularExponent);\n"]; } } - [effectBody appendString:@"vec4 resultColor = diffuseLightColor * inputValue;\n"]; + [effectBody appendString:@"vec4 resultColor = diffuseSum * inputValue;\n"]; if (needsSpecular) { - [effectBody appendString:@"resultColor += specularLightColor * u_specularColor;\n"]; + [effectBody appendString:@"resultColor += specularSum * u_specularColor;\n"]; } [effectBody appendString:@"return vec4(resultColor.xyz, inputValue.a);\n"]; @@ -249,12 +255,24 @@ -(void)buildRenderPasses NSString *lightVectorLabel = [NSString stringWithFormat:@"u_lightVector%lu", (unsigned long)lightIndex]; pass.shaderUniforms[weakSelf.uniformTranslationTable[lightVectorLabel]] = [NSValue valueWithGLKVector4:lightVector]; + + if (self.needsSpecular) + { + GLKVector4 lightSpecularColor = GLKVector4MultiplyScalar(light.specularColor.glkVector4, light.specularIntensity); + + NSString *lightSpecularColorLabel = [NSString stringWithFormat:@"u_lightSpecularColor%lu", (unsigned long)lightIndex]; + pass.shaderUniforms[weakSelf.uniformTranslationTable[lightSpecularColorLabel]] = [NSValue valueWithGLKVector4:lightSpecularColor]; + } } pass.shaderUniforms[weakSelf.uniformTranslationTable[@"u_globalAmbientColor"]] = [NSValue valueWithGLKVector4:globalAmbientColor]; - pass.shaderUniforms[weakSelf.uniformTranslationTable[@"u_specularExponent"]] = [NSNumber numberWithFloat:weakSelf.shininess]; - pass.shaderUniforms[weakSelf.uniformTranslationTable[@"u_specularColor"]] = [NSValue valueWithGLKVector4:weakSelf.specularColor.glkVector4]; - + + if (self.needsSpecular) + { + pass.shaderUniforms[weakSelf.uniformTranslationTable[@"u_specularExponent"]] = [NSNumber numberWithFloat:weakSelf.shininess]; + pass.shaderUniforms[weakSelf.uniformTranslationTable[@"u_specularColor"]] = [NSValue valueWithGLKVector4:weakSelf.specularColor.glkVector4]; + } + } copy]]; self.renderPasses = @[pass0]; @@ -286,6 +304,10 @@ - (CCEffectPrepareStatus)prepareForRenderingWithSprite:(CCSprite *)sprite [vertUniforms addObject:[CCEffectUniform uniform:@"vec4" name:[NSString stringWithFormat:@"u_lightVector%lu", (unsigned long)lightIndex] value:[NSValue valueWithGLKVector4:GLKVector4Make(0.0f, 0.0f, 0.0f, 1.0f)]]]; [fragUniforms addObject:[CCEffectUniform uniform:@"vec4" name:[NSString stringWithFormat:@"u_lightColor%lu", (unsigned long)lightIndex] value:[NSValue valueWithGLKVector4:GLKVector4Make(1.0f, 1.0f, 1.0f, 1.0f)]]]; + if (self.needsSpecular) + { + [fragUniforms addObject:[CCEffectUniform uniform:@"vec4" name:[NSString stringWithFormat:@"u_lightSpecularColor%lu", (unsigned long)lightIndex] value:[NSValue valueWithGLKVector4:GLKVector4Make(1.0f, 1.0f, 1.0f, 1.0f)]]]; + } if (light.type != CCLightDirectional) { diff --git a/cocos2d/CCLightNode.h b/cocos2d/CCLightNode.h index 8547d524c12..2c23253163e 100644 --- a/cocos2d/CCLightNode.h +++ b/cocos2d/CCLightNode.h @@ -53,6 +53,20 @@ typedef NS_ENUM(NSUInteger, CCLightType) */ @property (nonatomic, assign) float intensity; +/** The specular color of the light. As described below, the color is modulated by the + * specular intensity value to determine the contribution of the light to the lighting + * effect. This color is used when computing the light's specular (shiny) contribution + * to the lighting effect. + */ +@property (nonatomic, strong) CCColor* specularColor; + +/** The brightness of the light's specular color. This value is in the range [0..1] + * with 0 resulting in no contribution from the specular color to the final image + * (the specular color effectively becomes black) and 1 resulting in full contribution + * from this light. + */ +@property (nonatomic, assign) float specularIntensity; + /** The ambient color of the light. As described below, the color is modulated by the * ambient intensity value to determine the contribution of the light to the lighting * effect. The ambient color contributes to the lighting effect independent of the light's @@ -101,15 +115,28 @@ typedef NS_ENUM(NSUInteger, CCLightType) /** * Initializes a CCLightNode object with the specified parameters. * - * @param type The type of the light. - * @param color The primary color of the light. - * @param intensity The brightness of the light's primary color. - * @param ambientColor The ambient color of the light. - * @param ambientIntensity The brightness of the light's ambient color. + * @param type The type of the light. + * @param color The primary color of the light. + * @param intensity The brightness of the light's primary color. * * @return The CCLighttNode object. */ --(id)initWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity ambientColor:(CCColor *)ambientColor ambientIntensity:(float)ambientIntensity; +-(id)initWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity; + +/** + * Initializes a CCLightNode object with the specified parameters. + * + * @param type The type of the light. + * @param color The primary color of the light. + * @param intensity The brightness of the light's primary color. + * @param specularColor The specular color of the light. + * @param specularIntensity The brightness of the light's specular color. + * @param ambientColor The ambient color of the light. + * @param ambientIntensity The brightness of the light's ambient color. + * + * @return The CCLighttNode object. + */ +-(id)initWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity specularColor:(CCColor *)specularColor specularIntensity:(float)specularIntensity ambientColor:(CCColor *)ambientColor ambientIntensity:(float)ambientIntensity; /// ----------------------------------------------------------------------- @@ -119,15 +146,28 @@ typedef NS_ENUM(NSUInteger, CCLightType) /** * Creates a CCLightNode object with the specified parameters. * - * @param type The type of the light. - * @param color The primary color of the light. - * @param intensity The brightness of the light's primary color. - * @param ambientColor The ambient color of the light. - * @param ambientIntensity The brightness of the light's ambient color. + * @param type The type of the light. + * @param color The primary color of the light. + * @param intensity The brightness of the light's primary color. + * + * @return An initialized CCLightNode object. + */ ++(id)lightWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity; + +/** + * Creates a CCLightNode object with the specified parameters. + * + * @param type The type of the light. + * @param color The primary color of the light. + * @param intensity The brightness of the light's primary color. + * @param specularColor The specular color of the light. + * @param specularIntensity The brightness of the light's specular color. + * @param ambientColor The ambient color of the light. + * @param ambientIntensity The brightness of the light's ambient color. * * @return An initialized CCLightNode object. */ -+(id)lightWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity ambientColor:(CCColor *)ambientColor ambientIntensity:(float)ambientIntensity; ++(id)lightWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity specularColor:(CCColor *)specularColor specularIntensity:(float)specularIntensity ambientColor:(CCColor *)ambientColor ambientIntensity:(float)ambientIntensity; @end diff --git a/cocos2d/CCLightNode.m b/cocos2d/CCLightNode.m index 71ea447cd52..0da14f6fb80 100644 --- a/cocos2d/CCLightNode.m +++ b/cocos2d/CCLightNode.m @@ -14,19 +14,29 @@ @implementation CCLightNode -(id)init { - return [self initWithType:CCLightPoint color:[CCColor whiteColor] intensity:1.0f ambientColor:[CCColor whiteColor] ambientIntensity:0.5f]; + return [self initWithType:CCLightPoint color:[CCColor whiteColor] intensity:1.0f]; } +-(id)initWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity +{ + return [self initWithType:type color:color intensity:intensity specularColor:color specularIntensity:intensity ambientColor:[CCColor whiteColor] ambientIntensity:0.5f]; +} --(id)initWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity ambientColor:(CCColor *)ambientColor ambientIntensity:(float)ambientIntensity +-(id)initWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity specularColor:(CCColor *)specularColor specularIntensity:(float)specularIntensity ambientColor:(CCColor *)ambientColor ambientIntensity:(float)ambientIntensity { if ((self = [super init])) { _type = type; + _color = color.ccColor4f; _intensity = intensity; + + _specularColor = specularColor; + _specularIntensity = specularIntensity; + _ambientColor = ambientColor; _ambientIntensity = ambientIntensity; + _cutoffRadius = 0.0f; if (type == CCLightDirectional) { @@ -41,9 +51,14 @@ -(id)initWithType:(CCLightType)type color:(CCColor *)color intensity:(float)inte return self; } -+(id)lightWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity ambientColor:(CCColor *)ambientColor ambientIntensity:(float)ambientIntensity ++(id)lightWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity +{ + return [[self alloc] initWithType:type color:color intensity:intensity]; +} + ++(id)lightWithType:(CCLightType)type color:(CCColor *)color intensity:(float)intensity specularColor:(CCColor *)specularColor specularIntensity:(float)specularIntensity ambientColor:(CCColor *)ambientColor ambientIntensity:(float)ambientIntensity { - return [[self alloc] initWithType:type color:color intensity:intensity ambientColor:ambientColor ambientIntensity:ambientIntensity]; + return [[self alloc] initWithType:type color:color intensity:intensity specularColor:specularColor specularIntensity:specularIntensity ambientColor:ambientColor ambientIntensity:ambientIntensity]; } -(void)setIntensity:(float)intensity @@ -52,6 +67,12 @@ -(void)setIntensity:(float)intensity _intensity = intensity; } +-(void)setSpecularIntensity:(float)intensity +{ + NSCAssert((intensity >= 0.0) && (intensity <= 1.0), @"Supplied intensity out of range [0..1]."); + _specularIntensity = intensity; +} + -(void)setAmbientIntensity:(float)intensity { NSCAssert((intensity >= 0.0) && (intensity <= 1.0), @"Supplied intensity out of range [0..1].");