@@ -29,19 +29,20 @@ @implementation CCEffectGlass
29
29
30
30
-(id )init
31
31
{
32
- return [self initWithRefraction :1 .0f refractionEnvironment: nil reflectionEnvironment: nil normalMap: nil ];
32
+ return [self initWithShininess: 1 . 0f refraction :1 .0f refractionEnvironment: nil reflectionEnvironment: nil normalMap: nil ];
33
33
}
34
34
35
- -(id )initWithRefraction : (float )refraction refractionEnvironment : (CCSprite *)refractionEnvironment reflectionEnvironment : (CCSprite *)reflectionEnvironment
35
+ -(id )initWithShininess : ( float ) shininess refraction : (float )refraction refractionEnvironment : (CCSprite *)refractionEnvironment reflectionEnvironment : (CCSprite *)reflectionEnvironment
36
36
{
37
- return [self initWithRefraction : refraction refractionEnvironment: refractionEnvironment reflectionEnvironment: reflectionEnvironment normalMap: nil ];
37
+ return [self initWithShininess: shininess refraction : refraction refractionEnvironment: refractionEnvironment reflectionEnvironment: reflectionEnvironment normalMap: nil ];
38
38
}
39
39
40
- -(id )initWithRefraction : (float )refraction refractionEnvironment : (CCSprite *)refractionEnvironment reflectionEnvironment : (CCSprite *)reflectionEnvironment normalMap : (CCSpriteFrame *)normalMap
40
+ -(id )initWithShininess : ( float ) shininess refraction : (float )refraction refractionEnvironment : (CCSprite *)refractionEnvironment reflectionEnvironment : (CCSprite *)reflectionEnvironment normalMap : (CCSpriteFrame *)normalMap
41
41
{
42
42
NSArray *uniforms = @[
43
43
[CCEffectUniform uniform: @" float" name: @" u_refraction" value: [NSNumber numberWithFloat: 1 .0f ]],
44
44
45
+ [CCEffectUniform uniform: @" float" name: @" u_shininess" value: [NSNumber numberWithFloat: 1 .0f ]],
45
46
[CCEffectUniform uniform: @" float" name: @" u_fresnelBias" value: [NSNumber numberWithFloat: 0 .0f ]],
46
47
[CCEffectUniform uniform: @" float" name: @" u_fresnelPower" value: [NSNumber numberWithFloat: 0 .0f ]],
47
48
@@ -60,6 +61,7 @@ -(id)initWithRefraction:(float)refraction refractionEnvironment:(CCSprite *)refr
60
61
if ((self = [super initWithFragmentUniforms: uniforms vertexUniforms: nil varying: nil ]))
61
62
{
62
63
_refraction = refraction;
64
+ _shininess = shininess;
63
65
_fresnelBias = 0 .1f ;
64
66
_fresnelPower = 2 .0f ;
65
67
_conditionedRefraction = CCEffectUtilsConditionRefraction (refraction);
@@ -71,14 +73,15 @@ -(id)initWithRefraction:(float)refraction refractionEnvironment:(CCSprite *)refr
71
73
}
72
74
return self;
73
75
}
74
- +(id )effectWithRefraction : (float )refraction refractionEnvironment : (CCSprite *)refractionEnvironment reflectionEnvironment : (CCSprite *)reflectionEnvironment
76
+
77
+ +(id )effectWithShininess : (float )shininess refraction : (float )refraction refractionEnvironment : (CCSprite *)refractionEnvironment reflectionEnvironment : (CCSprite *)reflectionEnvironment
75
78
{
76
- return [[self alloc ] initWithRefraction : refraction refractionEnvironment: refractionEnvironment reflectionEnvironment: reflectionEnvironment];
79
+ return [[self alloc ] initWithShininess: shininess refraction : refraction refractionEnvironment: refractionEnvironment reflectionEnvironment: reflectionEnvironment];
77
80
}
78
81
79
- +(id )effectWithRefraction : (float )refraction refractionEnvironment : (CCSprite *)refractionEnvironment reflectionEnvironment : (CCSprite *)reflectionEnvironment normalMap : (CCSpriteFrame *)normalMap
82
+ +(id )effectWithShininess : ( float ) shininess refraction : (float )refraction refractionEnvironment : (CCSprite *)refractionEnvironment reflectionEnvironment : (CCSprite *)reflectionEnvironment normalMap : (CCSpriteFrame *)normalMap
80
83
{
81
- return [[self alloc ] initWithRefraction : refraction refractionEnvironment: refractionEnvironment reflectionEnvironment: reflectionEnvironment normalMap: normalMap];
84
+ return [[self alloc ] initWithShininess: shininess refraction : refraction refractionEnvironment: refractionEnvironment reflectionEnvironment: reflectionEnvironment normalMap: normalMap];
82
85
}
83
86
84
87
-(void )buildFragmentFunctions
@@ -147,7 +150,7 @@ -(void)buildFragmentFunctions
147
150
// Add the reflected color modulated by the fresnel term. Multiplying by the normal
148
151
// map alpha also allows the effect to be disabled for specific pixels.
149
152
float fresnel = max (u_fresnelBias + (1.0 - u_fresnelBias) * pow ((1.0 - nDotV), u_fresnelPower), 0.0 );
150
- vec4 reflection = normalMap.a * fresnel * texture2D (u_reflectEnvMap, reflectTexCoords);
153
+ vec4 reflection = normalMap.a * fresnel * u_shininess * texture2D (u_reflectEnvMap, reflectTexCoords);
151
154
152
155
return primaryColor + refraction + reflection;
153
156
);
@@ -182,6 +185,7 @@ -(void)buildRenderPasses
182
185
183
186
pass.shaderUniforms [weakSelf.uniformTranslationTable[@" u_refraction" ]] = [NSNumber numberWithFloat: weakSelf.conditionedRefraction];
184
187
188
+ pass.shaderUniforms [weakSelf.uniformTranslationTable[@" u_shininess" ]] = [NSNumber numberWithFloat: weakSelf.shininess];
185
189
pass.shaderUniforms [weakSelf.uniformTranslationTable[@" u_fresnelBias" ]] = [NSNumber numberWithFloat: weakSelf.fresnelBias];
186
190
pass.shaderUniforms [weakSelf.uniformTranslationTable[@" u_fresnelPower" ]] = [NSNumber numberWithFloat: weakSelf.fresnelPower];
187
191
0 commit comments