Skip to content

Commit 55d1785

Browse files
author
Thayer J Andrews
committed
CCEffectReflection - Add initializer / constructor methods that accept fresnel parameters
1 parent 9e78c32 commit 55d1785

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

cocos2d-ui-tests/tests/CCEffectsTest.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ -(void)setupStackTest
518518
[CCEffectHue effectWithHue:90.0f],
519519
[CCEffectGlass effectWithRefraction:0.5f refractionEnvironment:refractEnvironment reflectionEnvironment:reflectEnvironment normalMap:nil],
520520
[CCEffectRefraction effectWithRefraction:0.5f environment:refractEnvironment normalMap:nil],
521-
[CCEffectReflection effectWithEnvironment:reflectEnvironment normalMap:nil],
521+
[CCEffectReflection effectWithFresnelBias:0.2f fresnelPower:2.0f environment:reflectEnvironment normalMap:nil],
522522
];
523523

524524

@@ -566,7 +566,7 @@ -(void)setupPerformanceTest
566566
[CCEffectHue effectWithHue:90.0f],
567567
[CCEffectGlass effectWithRefraction:0.5f refractionEnvironment:refractEnvironment reflectionEnvironment:reflectEnvironment normalMap:nil],
568568
[CCEffectRefraction effectWithRefraction:0.5f environment:refractEnvironment normalMap:nil],
569-
[CCEffectReflection effectWithEnvironment:reflectEnvironment normalMap:nil],
569+
[CCEffectReflection effectWithFresnelBias:0.1f fresnelPower:4.0f environment:reflectEnvironment normalMap:nil],
570570
];
571571
CCEffect *selectedEffect = allEffects[8];
572572

cocos2d/CCEffectReflection.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818

1919
-(id)init;
2020
-(id)initWithEnvironment:(CCSprite *)environment normalMap:(CCSpriteFrame *)normalMap;
21+
-(id)initWithFresnelBias:(float)bias fresnelPower:(float)power environment:(CCSprite *)environment normalMap:(CCSpriteFrame *)normalMap;
22+
2123
+(id)effectWithEnvironment:(CCSprite *)environment normalMap:(CCSpriteFrame *)normalMap;
24+
+(id)effectWithFresnelBias:(float)bias fresnelPower:(float)power environment:(CCSprite *)environment normalMap:(CCSpriteFrame *)normalMap;
2225

2326
@end
2427
#endif

cocos2d/CCEffectReflection.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,14 @@ -(id)init
3535
}
3636

3737
-(id)initWithEnvironment:(CCSprite *)environment normalMap:(CCSpriteFrame *)normalMap
38+
{
39+
return [self initWithFresnelBias:1.0f fresnelPower:0.0f environment:environment normalMap:normalMap];
40+
}
41+
42+
-(id)initWithFresnelBias:(float)bias fresnelPower:(float)power environment:(CCSprite *)environment normalMap:(CCSpriteFrame *)normalMap
3843
{
3944
NSArray *uniforms = @[
40-
[CCEffectUniform uniform:@"float" name:@"u_fresnelBias" value:[NSNumber numberWithFloat:0.0f]],
45+
[CCEffectUniform uniform:@"float" name:@"u_fresnelBias" value:[NSNumber numberWithFloat:1.0f]],
4146
[CCEffectUniform uniform:@"float" name:@"u_fresnelPower" value:[NSNumber numberWithFloat:0.0f]],
4247
[CCEffectUniform uniform:@"sampler2D" name:@"u_envMap" value:(NSValue*)[CCTexture none]],
4348
[CCEffectUniform uniform:@"vec2" name:@"u_tangent" value:[NSValue valueWithGLKVector2:GLKVector2Make(1.0f, 0.0f)]],
@@ -49,6 +54,8 @@ -(id)initWithEnvironment:(CCSprite *)environment normalMap:(CCSpriteFrame *)norm
4954
{
5055
_environment = environment;
5156
_normalMap = normalMap;
57+
_fresnelBias = bias;
58+
_fresnelPower = power;
5259

5360
self.debugName = @"CCEffectReflection";
5461
}
@@ -60,6 +67,11 @@ +(id)effectWithEnvironment:(CCSprite *)environment normalMap:(CCSpriteFrame *)no
6067
return [[self alloc] initWithEnvironment:environment normalMap:normalMap];
6168
}
6269

70+
+(id)effectWithFresnelBias:(float)bias fresnelPower:(float)power environment:(CCSprite *)environment normalMap:(CCSpriteFrame *)normalMap
71+
{
72+
return [[self alloc] initWithFresnelBias:bias fresnelPower:power environment:environment normalMap:normalMap];
73+
}
74+
6375
-(void)buildFragmentFunctions
6476
{
6577
self.fragmentFunctions = [[NSMutableArray alloc] init];

0 commit comments

Comments
 (0)