@@ -313,7 +313,7 @@ -(void)setupSimpleLightingTest
313
313
314
314
-(void )setupLightingParameterTest
315
315
{
316
- self.subTitle = @" Lighting Parameter Test" ;
316
+ self.subTitle = @" Varying Light Parameter Test" ;
317
317
318
318
NSString *normalMapImage = @" Images/ShinyTorusNormals.png" ;
319
319
NSString *diffuseImage = @" Images/ShinyTorusColor.png" ;
@@ -365,14 +365,17 @@ -(void)setupLightingParameterTest
365
365
CCSprite *sprite = nil ;
366
366
CCEffectLighting *lighting = nil ;
367
367
368
- light = setupBlock (ccp (0 .2f , 0 .65f ), @" Varying Intensity" , [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
369
- [CCActionTween actionWithDuration: 2 key: @" intensity" from: 0 .0f to: 1 .0f ],
370
- [CCActionDelay actionWithDuration: 2 ],
371
- [CCActionTween actionWithDuration: 2 key: @" intensity" from: 1 .0f to: 0 .0f ],
372
- nil
373
- ]]);
368
+
369
+ // Primary color
370
+ //
371
+ light = setupBlock (ccp (0 .1f , 0 .65f ), @" Primary Intensity" , [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
372
+ [CCActionTween actionWithDuration: 2 key: @" intensity" from: 0 .0f to: 1 .0f ],
373
+ [CCActionDelay actionWithDuration: 2 ],
374
+ [CCActionTween actionWithDuration: 2 key: @" intensity" from: 1 .0f to: 0 .0f ],
375
+ nil
376
+ ]]);
374
377
light.ambientIntensity = 0 .0f ;
375
- light = setupBlock (ccp (0 .2f , 0 .25f ), @" Varying Color" , [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
378
+ light = setupBlock (ccp (0 .1f , 0 .25f ), @" Primary Color" , [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
376
379
[CCActionTintTo actionWithDuration: 2 color: [CCColor redColor ]],
377
380
[CCActionDelay actionWithDuration: 1 ],
378
381
[CCActionTintTo actionWithDuration: 2 color: [CCColor greenColor ]],
@@ -385,13 +388,15 @@ -(void)setupLightingParameterTest
385
388
]]);
386
389
387
390
388
- light = setupBlock (ccp (0 .4f , 0 .65f ), @" Varying Ambient Intensity" , [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
389
- [CCActionTween actionWithDuration: 2 key: @" ambientIntensity" from: 0 .0f to: 1 .0f ],
390
- [CCActionDelay actionWithDuration: 2 ],
391
- [CCActionTween actionWithDuration: 2 key: @" ambientIntensity" from: 1 .0f to: 0 .0f ],
392
- nil
393
- ]]);
394
- light = setupBlock (ccp (0 .4f , 0 .25f ), @" Varying Ambient Color" , nil );
391
+ // Ambient color
392
+ //
393
+ light = setupBlock (ccp (0 .3f , 0 .65f ), @" Ambient Intensity" , [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
394
+ [CCActionTween actionWithDuration: 2 key: @" ambientIntensity" from: 0 .0f to: 1 .0f ],
395
+ [CCActionDelay actionWithDuration: 2 ],
396
+ [CCActionTween actionWithDuration: 2 key: @" ambientIntensity" from: 1 .0f to: 0 .0f ],
397
+ nil
398
+ ]]);
399
+ light = setupBlock (ccp (0 .3f , 0 .25f ), @" Ambient Color" , nil );
395
400
light.intensity = 0 .5f ;
396
401
light.ambientIntensity = 0 .5f ;
397
402
@@ -415,17 +420,26 @@ -(void)setupLightingParameterTest
415
420
return lerpBlock;
416
421
};
417
422
418
- AmbientLerpBlock whiteRedLerp = ambientLerpBuilder (ccc4f (0 .0f , -delta, -delta, 0 .0f ));
419
- CCActionInterval *whiteRedLerpAction = [CCActionRepeat actionWithAction: [CCActionSequence actionOne: [CCActionDelay actionWithDuration: timeStep] two: [CCActionCallBlock actionWithBlock: whiteRedLerp]] times: 120 ];
423
+ AmbientLerpBlock whiteRedLerp;
424
+ AmbientLerpBlock redGreenLerp;
425
+ AmbientLerpBlock greenBlueLerp;
426
+ AmbientLerpBlock blueWhiteLerp;
427
+ CCActionInterval *whiteRedLerpAction;
428
+ CCActionInterval *redGreenLerpAction;
429
+ CCActionInterval *greenBlueLerpAction;
430
+ CCActionInterval *blueWhiteLerpAction;
431
+
432
+ whiteRedLerp = ambientLerpBuilder (ccc4f (0 .0f , -delta, -delta, 0 .0f ));
433
+ whiteRedLerpAction = [CCActionRepeat actionWithAction: [CCActionSequence actionOne: [CCActionDelay actionWithDuration: timeStep] two: [CCActionCallBlock actionWithBlock: whiteRedLerp]] times: 120 ];
420
434
421
- AmbientLerpBlock redGreenLerp = ambientLerpBuilder (ccc4f (-delta, delta, 0 .0f , 0 .0f ));
422
- CCActionInterval * redGreenLerpAction = [CCActionRepeat actionWithAction: [CCActionSequence actionOne: [CCActionDelay actionWithDuration: timeStep] two: [CCActionCallBlock actionWithBlock: redGreenLerp]] times: 120 ];
435
+ redGreenLerp = ambientLerpBuilder (ccc4f (-delta, delta, 0 .0f , 0 .0f ));
436
+ redGreenLerpAction = [CCActionRepeat actionWithAction: [CCActionSequence actionOne: [CCActionDelay actionWithDuration: timeStep] two: [CCActionCallBlock actionWithBlock: redGreenLerp]] times: 120 ];
423
437
424
- AmbientLerpBlock greenBlueLerp = ambientLerpBuilder (ccc4f (0 .0f , -delta, delta, 0 .0f ));
425
- CCActionInterval * greenBlueLerpAction = [CCActionRepeat actionWithAction: [CCActionSequence actionOne: [CCActionDelay actionWithDuration: timeStep] two: [CCActionCallBlock actionWithBlock: greenBlueLerp]] times: 120 ];
438
+ greenBlueLerp = ambientLerpBuilder (ccc4f (0 .0f , -delta, delta, 0 .0f ));
439
+ greenBlueLerpAction = [CCActionRepeat actionWithAction: [CCActionSequence actionOne: [CCActionDelay actionWithDuration: timeStep] two: [CCActionCallBlock actionWithBlock: greenBlueLerp]] times: 120 ];
426
440
427
- AmbientLerpBlock blueWhiteLerp = ambientLerpBuilder (ccc4f (delta, delta, 0 .0f , 0 .0f ));
428
- CCActionInterval * blueWhiteLerpAction = [CCActionRepeat actionWithAction: [CCActionSequence actionOne: [CCActionDelay actionWithDuration: timeStep] two: [CCActionCallBlock actionWithBlock: blueWhiteLerp]] times: 120 ];
441
+ blueWhiteLerp = ambientLerpBuilder (ccc4f (delta, delta, 0 .0f , 0 .0f ));
442
+ blueWhiteLerpAction = [CCActionRepeat actionWithAction: [CCActionSequence actionOne: [CCActionDelay actionWithDuration: timeStep] two: [CCActionCallBlock actionWithBlock: blueWhiteLerp]] times: 120 ];
429
443
430
444
CCAction *ambientLerpAction = [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
431
445
whiteRedLerpAction,
@@ -440,24 +454,66 @@ -(void)setupLightingParameterTest
440
454
]];
441
455
[light runAction: ambientLerpAction];
442
456
443
- light = setupBlock (ccp (0 .6f , 0 .65f ), @" Varying Cutoff" , [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
444
- [CCActionTween actionWithDuration: 2 key: @" cutoffRadius" from: 1 .0f to: 500 .0f ],
445
- [CCActionTween actionWithDuration: 2 key: @" cutoffRadius" from: 500 .0f to: 1 .0f ],
446
- nil
447
- ]]);
448
- light.cutoffRadius = 1 .0f ;
449
- light = setupBlock (ccp (0 .6f , 0 .25f ), @" Varying Depth" , [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
450
- [CCActionTween actionWithDuration: 2 key: @" depth" from: 1 .0f to: 500 .0f ],
451
- [CCActionTween actionWithDuration: 2 key: @" depth" from: 500 .0f to: 1 .0f ],
452
- nil
453
- ]]);
454
- light.depth = 1 .0f ;
455
- sprite = (CCSprite *)light.parent ;
456
- lighting = (CCEffectLighting *)sprite.effect ;
457
- lighting.shininess = 20 .0f ;
458
457
458
+ // Specular color
459
+ //
460
+ light = setupBlock (ccp (0 .5f , 0 .65f ), @" Specular Intensity" , [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
461
+ [CCActionTween actionWithDuration: 2 key: @" specularIntensity" from: 0 .0f to: 1 .0f ],
462
+ [CCActionDelay actionWithDuration: 2 ],
463
+ [CCActionTween actionWithDuration: 2 key: @" specularIntensity" from: 1 .0f to: 0 .0f ],
464
+ nil
465
+ ]]);
466
+ light = setupBlock (ccp (0 .5f , 0 .25f ), @" Specular Color" , nil );
467
+ light.intensity = 0 .5f ;
468
+ light.ambientIntensity = 0 .5f ;
469
+ light.specularIntensity = 1 .0f ;
459
470
460
- light = setupBlock (ccp (0 .8f , 0 .65f ), @" Varying Shininess" , nil );
471
+ typedef void (^SpecularLerpBlock)();
472
+ typedef void (^SpecularLerpBuilderBlock)(ccColor4F deltaC);
473
+
474
+ weakLight = light;
475
+ SpecularLerpBlock (^specularLerpBuilder)(ccColor4F deltaC) = ^SpecularLerpBlock (ccColor4F deltaC)
476
+ {
477
+ SpecularLerpBlock lerpBlock = ^{
478
+ ccColor4F c = weakLight.specularColor .ccColor4f ;
479
+ c.r += deltaC.r ;
480
+ c.g += deltaC.g ;
481
+ c.b += deltaC.b ;
482
+ weakLight.specularColor = [CCColor colorWithCcColor4f: c];
483
+ };
484
+ return lerpBlock;
485
+ };
486
+
487
+ whiteRedLerp = specularLerpBuilder (ccc4f (0 .0f , -delta, -delta, 0 .0f ));
488
+ whiteRedLerpAction = [CCActionRepeat actionWithAction: [CCActionSequence actionOne: [CCActionDelay actionWithDuration: timeStep] two: [CCActionCallBlock actionWithBlock: whiteRedLerp]] times: 120 ];
489
+
490
+ redGreenLerp = specularLerpBuilder (ccc4f (-delta, delta, 0 .0f , 0 .0f ));
491
+ redGreenLerpAction = [CCActionRepeat actionWithAction: [CCActionSequence actionOne: [CCActionDelay actionWithDuration: timeStep] two: [CCActionCallBlock actionWithBlock: redGreenLerp]] times: 120 ];
492
+
493
+ greenBlueLerp = specularLerpBuilder (ccc4f (0 .0f , -delta, delta, 0 .0f ));
494
+ greenBlueLerpAction = [CCActionRepeat actionWithAction: [CCActionSequence actionOne: [CCActionDelay actionWithDuration: timeStep] two: [CCActionCallBlock actionWithBlock: greenBlueLerp]] times: 120 ];
495
+
496
+ blueWhiteLerp = specularLerpBuilder (ccc4f (delta, delta, 0 .0f , 0 .0f ));
497
+ blueWhiteLerpAction = [CCActionRepeat actionWithAction: [CCActionSequence actionOne: [CCActionDelay actionWithDuration: timeStep] two: [CCActionCallBlock actionWithBlock: blueWhiteLerp]] times: 120 ];
498
+
499
+ CCAction *specularLerpAction = [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
500
+ whiteRedLerpAction,
501
+ [CCActionDelay actionWithDuration: 1 ],
502
+ redGreenLerpAction,
503
+ [CCActionDelay actionWithDuration: 1 ],
504
+ greenBlueLerpAction,
505
+ [CCActionDelay actionWithDuration: 1 ],
506
+ blueWhiteLerpAction,
507
+ [CCActionDelay actionWithDuration: 1 ],
508
+ nil
509
+ ]];
510
+ [light runAction: specularLerpAction];
511
+
512
+
513
+ // Cutoff, depth, and shininess
514
+ //
515
+
516
+ light = setupBlock (ccp (0 .7f , 0 .65f ), @" Shininess" , nil );
461
517
sprite = (CCSprite *)light.parent ;
462
518
lighting = (CCEffectLighting *)sprite.effect ;
463
519
lighting.shininess = 4 .0f ;
@@ -474,16 +530,36 @@ -(void)setupLightingParameterTest
474
530
475
531
ShininessLerpBlock shininessRampUp = shininessLerpBuilder (delta * 50 .0f );
476
532
CCActionInterval *shininessRampUpAction = [CCActionRepeat actionWithAction: [CCActionSequence actionOne: [CCActionDelay actionWithDuration: timeStep] two: [CCActionCallBlock actionWithBlock: shininessRampUp]] times: 120 ];
477
-
533
+
478
534
ShininessLerpBlock shininessRampDown = shininessLerpBuilder (-delta * 50 .0f );
479
535
CCActionInterval *shininessRampDownAction = [CCActionRepeat actionWithAction: [CCActionSequence actionOne: [CCActionDelay actionWithDuration: timeStep] two: [CCActionCallBlock actionWithBlock: shininessRampDown]] times: 120 ];
480
536
481
537
[light runAction: [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
482
538
shininessRampUpAction,
483
- [CCActionDelay actionWithDuration: 1 ],
539
+ [CCActionDelay actionWithDuration: 2 ],
484
540
shininessRampDownAction,
485
541
nil
486
542
]]];
543
+
544
+ light = setupBlock (ccp (0 .7f , 0 .25f ), @" Cutoff" , [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
545
+ [CCActionTween actionWithDuration: 2 key: @" cutoffRadius" from: 1 .0f to: 1000 .0f ],
546
+ [CCActionDelay actionWithDuration: 2 ],
547
+ [CCActionTween actionWithDuration: 2 key: @" cutoffRadius" from: 1000 .0f to: 1 .0f ],
548
+ nil
549
+ ]]);
550
+ light.cutoffRadius = 1 .0f ;
551
+ light.ambientIntensity = 0 .0f ;
552
+ light.intensity = 1 .0f ;
553
+ light = setupBlock (ccp (0 .9f , 0 .65f ), @" Depth" , [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
554
+ [CCActionTween actionWithDuration: 2 key: @" depth" from: 1 .0f to: 500 .0f ],
555
+ [CCActionTween actionWithDuration: 2 key: @" depth" from: 500 .0f to: 1 .0f ],
556
+ nil
557
+ ]]);
558
+ light.depth = 1 .0f ;
559
+ sprite = (CCSprite *)light.parent ;
560
+ lighting = (CCEffectLighting *)sprite.effect ;
561
+ lighting.shininess = 20 .0f ;
562
+
487
563
}
488
564
489
565
#endif
0 commit comments