Skip to content

Commit 361338d

Browse files
author
Thayer J Andrews
committed
CCEffectLighting - Rename a few GLSL variables
In preparation for dynamic code generation based on light types.
1 parent 85212fc commit 361338d

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

cocos2d/CCEffectLighting.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ -(id)initWithLight:(CCLightNode *)light
3333
{
3434
NSArray *fragUniforms = @[
3535
[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)]],
3737
];
3838

3939
NSArray *vertUniforms = @[
@@ -70,10 +70,10 @@ -(void)buildFragmentFunctions
7070
vec4 normalMap = texture2D(cc_NormalMapTexture, cc_FragTexCoord2);
7171
vec4 tangentSpaceNormal = normalMap * 2.0 - 1.0;
7272

73-
float NdotL = dot(tangentSpaceNormal, v_tangentSpaceLightDir);
73+
vec4 lightContribution = u_lightColor * dot(tangentSpaceNormal, v_tangentSpaceLightDir);
7474
if (normalMap.a > 0.0)
7575
{
76-
return inputValue * (u_lightColor * NdotL + u_ambientColor);
76+
return inputValue * (lightContribution + u_globalAmbientColor);
7777
}
7878
else
7979
{
@@ -94,8 +94,7 @@ -(void)buildVertexFunctions
9494
// vertex. cc_Position was transformed on the CPU so we need to
9595
// back it out from NDC (normalized device coords) to tangent
9696
// 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);
9998
return cc_Position;
10099
);
101100

@@ -128,7 +127,7 @@ -(void)buildRenderPasses
128127

129128
pass.shaderUniforms[weakSelf.uniformTranslationTable[@"u_lightColor"]] = [NSValue valueWithGLKVector4:lightColor];
130129
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];
132131
pass.shaderUniforms[weakSelf.uniformTranslationTable[@"u_ndcToTangentSpace"]] = [NSValue valueWithGLKMatrix4:pass.ndcToNodeLocal];
133132

134133
} copy]];

0 commit comments

Comments
 (0)