@@ -33,7 +33,7 @@ -(id)initWithLight:(CCLightNode *)light
33
33
{
34
34
NSArray *fragUniforms = @[
35
35
[CCEffectUniform uniform: @" vec4" name: @" u_lightColor" value: [NSValue valueWithGLKVector4: GLKVector4Make (1 .0f , 1 .0f , 1 .0f , 1 .0f )]],
36
- [CCEffectUniform uniform: @" vec4" name: @" u_ambientColor " value: [NSValue valueWithGLKVector4: GLKVector4Make (1 .0f , 1 .0f , 1 .0f , 1 .0f )]],
36
+ [CCEffectUniform uniform: @" vec4" name: @" u_globalAmbientColor " value: [NSValue valueWithGLKVector4: GLKVector4Make (1 .0f , 1 .0f , 1 .0f , 1 .0f )]],
37
37
];
38
38
39
39
NSArray *vertUniforms = @[
@@ -70,10 +70,10 @@ -(void)buildFragmentFunctions
70
70
vec4 normalMap = texture2D (cc_NormalMapTexture, cc_FragTexCoord2);
71
71
vec4 tangentSpaceNormal = normalMap * 2.0 - 1.0 ;
72
72
73
- float NdotL = dot (tangentSpaceNormal, v_tangentSpaceLightDir);
73
+ vec4 lightContribution = u_lightColor * dot (tangentSpaceNormal, v_tangentSpaceLightDir);
74
74
if (normalMap.a > 0.0 )
75
75
{
76
- return inputValue * (u_lightColor * NdotL + u_ambientColor );
76
+ return inputValue * (lightContribution + u_globalAmbientColor );
77
77
}
78
78
else
79
79
{
@@ -94,8 +94,7 @@ -(void)buildVertexFunctions
94
94
// vertex. cc_Position was transformed on the CPU so we need to
95
95
// back it out from NDC (normalized device coords) to tangent
96
96
// space before using it to compute the light direction.
97
- vec4 tangentSpacePosition = u_ndcToTangentSpace * cc_Position;
98
- v_tangentSpaceLightDir = normalize (u_lightPosition - tangentSpacePosition);
97
+ v_tangentSpaceLightDir = normalize (u_lightPosition - u_ndcToTangentSpace * cc_Position);
99
98
return cc_Position;
100
99
);
101
100
@@ -128,7 +127,7 @@ -(void)buildRenderPasses
128
127
129
128
pass.shaderUniforms [weakSelf.uniformTranslationTable[@" u_lightColor" ]] = [NSValue valueWithGLKVector4: lightColor];
130
129
pass.shaderUniforms [weakSelf.uniformTranslationTable[@" u_lightPosition" ]] = [NSValue valueWithGLKVector4: lightPosition];
131
- pass.shaderUniforms [weakSelf.uniformTranslationTable[@" u_ambientColor " ]] = [NSValue valueWithGLKVector4: ambientColor];
130
+ pass.shaderUniforms [weakSelf.uniformTranslationTable[@" u_globalAmbientColor " ]] = [NSValue valueWithGLKVector4: ambientColor];
132
131
pass.shaderUniforms [weakSelf.uniformTranslationTable[@" u_ndcToTangentSpace" ]] = [NSValue valueWithGLKMatrix4: pass.ndcToNodeLocal];
133
132
134
133
} copy]];
0 commit comments