Merge pull request #117 from songchengjiang/light_new

Replaced Light Shader By optimized Shader
This commit is contained in:
XiaoYang 2014-08-28 09:23:51 +08:00
commit c9aa93214d
5 changed files with 108 additions and 140 deletions

View File

@ -445,33 +445,21 @@ bool GLProgram::compileShader(GLuint * shader, GLenum type, const GLchar* source
GLchar lightStruct[] = { GLchar lightStruct[] = {
"#if CC_MAX_DIRECTIONAL_LIGHT_NUM \n" "#if CC_MAX_DIRECTIONAL_LIGHT_NUM \n"
"struct DirectionalLightSource \n" "uniform vec3 CC_DirLightSourceColor[CC_MAX_DIRECTIONAL_LIGHT_NUM]; \n"
"{ \n" "uniform vec3 CC_DirLightSourceDirection[CC_MAX_DIRECTIONAL_LIGHT_NUM]; \n"
" vec3 color; \n"
" vec3 direction; \n"
"}; \n"
"uniform DirectionalLightSource CC_DirLightSource[CC_MAX_DIRECTIONAL_LIGHT_NUM]; \n"
"uniform int CC_EnabledDirLightNum; \n"
"#endif \n" "#endif \n"
"#if CC_MAX_POINT_LIGHT_NUM \n" "#if CC_MAX_POINT_LIGHT_NUM \n"
"struct PointLightSource \n" "uniform vec3 CC_PointLightSourceColor[CC_MAX_POINT_LIGHT_NUM]; \n"
"{ \n" "uniform vec3 CC_PointLightSourcePosition[CC_MAX_POINT_LIGHT_NUM]; \n"
" vec3 color; \n" "uniform float CC_PointLightSourceRangeInverse[CC_MAX_POINT_LIGHT_NUM]; \n"
" vec4 position; \n"
"}; \n"
"uniform PointLightSource CC_PointLightSource[CC_MAX_POINT_LIGHT_NUM]; \n"
"uniform int CC_EnabledPointLightNum; \n"
"#endif \n" "#endif \n"
"#if CC_MAX_SPOT_LIGHT_NUM \n" "#if CC_MAX_SPOT_LIGHT_NUM \n"
"struct SpotLightSource \n" "uniform vec3 CC_SpotLightSourceColor[CC_MAX_SPOT_LIGHT_NUM]; \n"
"{ \n" "uniform vec3 CC_SpotLightSourcePosition[CC_MAX_SPOT_LIGHT_NUM]; \n"
" vec3 color; \n" "uniform vec3 CC_SpotLightSourceDirection[CC_MAX_SPOT_LIGHT_NUM]; \n"
" vec3 position; \n" "uniform float CC_SpotLightSourceInnerAngleCos[CC_MAX_SPOT_LIGHT_NUM]; \n"
" vec3 direction; \n" "uniform float CC_SpotLightSourceOuterAngleCos[CC_MAX_SPOT_LIGHT_NUM]; \n"
" vec3 params; \n" "uniform float CC_SpotLightSourceRangeInverse[CC_MAX_SPOT_LIGHT_NUM]; \n"
"}; \n"
"uniform SpotLightSource CC_SpotLightSource[CC_MAX_SPOT_LIGHT_NUM]; \n"
"uniform int CC_EnabledSpotLightNum; \n"
"#endif \n" "#endif \n"
"uniform vec4 CC_AmbientColor; \n" "uniform vec4 CC_AmbientColor; \n"
}; };
@ -571,9 +559,9 @@ void GLProgram::updateUniforms()
// _builtInUniforms[UNIFORM_ENABLED_SPOT_LIGHT_NUM] != -1 // _builtInUniforms[UNIFORM_ENABLED_SPOT_LIGHT_NUM] != -1
// ); // );
_flags.usesLights = CC_MAX_DIRECTIONAL_LIGHT_NUM || _flags.usesLights = (0 < CC_MAX_DIRECTIONAL_LIGHT_NUM) ||
CC_MAX_POINT_LIGHT_NUM || (0 < CC_MAX_POINT_LIGHT_NUM) ||
CC_MAX_SPOT_LIGHT_NUM; (0 < CC_MAX_SPOT_LIGHT_NUM);
_flags.usesP = _builtInUniforms[UNIFORM_P_MATRIX] != -1; _flags.usesP = _builtInUniforms[UNIFORM_P_MATRIX] != -1;
_flags.usesMV = _builtInUniforms[UNIFORM_MV_MATRIX] != -1; _flags.usesMV = _builtInUniforms[UNIFORM_MV_MATRIX] != -1;
_flags.usesMVP = _builtInUniforms[UNIFORM_MVP_MATRIX] != -1; _flags.usesMVP = _builtInUniforms[UNIFORM_MVP_MATRIX] != -1;
@ -1008,9 +996,9 @@ void GLProgram::setUniformsForBuiltins(const Mat4 &matrixMV)
CCASSERT(enabledDirLightNum < CC_MAX_DIRECTIONAL_LIGHT_NUM, ""); CCASSERT(enabledDirLightNum < CC_MAX_DIRECTIONAL_LIGHT_NUM, "");
Vec3 dir = light->getWorldDirection(); Vec3 dir = light->getWorldDirection();
dir.normalize(); dir.normalize();
sprintf(str, "CC_DirLightSource[%d].%s", enabledDirLightNum, "color"); sprintf(str, "CC_DirLightSourceColor[%d]", enabledDirLightNum);
setUniformLocationWith3f(glGetUniformLocation(_program, str), col.r / 255.0f, col.g / 255.0f, col.b / 255.0f); setUniformLocationWith3f(glGetUniformLocation(_program, str), col.r / 255.0f, col.g / 255.0f, col.b / 255.0f);
sprintf(str, "CC_DirLightSource[%d].%s", enabledDirLightNum, "direction"); sprintf(str, "CC_DirLightSourceDirection[%d]", enabledDirLightNum);
setUniformLocationWith3f(glGetUniformLocation(_program, str), dir.x, dir.y, dir.z); setUniformLocationWith3f(glGetUniformLocation(_program, str), dir.x, dir.y, dir.z);
++enabledDirLightNum; ++enabledDirLightNum;
} }
@ -1019,10 +1007,12 @@ void GLProgram::setUniformsForBuiltins(const Mat4 &matrixMV)
{ {
CCASSERT(enabledPointLightNum < CC_MAX_POINT_LIGHT_NUM, ""); CCASSERT(enabledPointLightNum < CC_MAX_POINT_LIGHT_NUM, "");
Mat4 mat= light->getNodeToWorldTransform(); Mat4 mat= light->getNodeToWorldTransform();
sprintf(str, "CC_PointLightSource[%d].%s", enabledPointLightNum, "color"); sprintf(str, "CC_PointLightSourceColor[%d]", enabledPointLightNum);
setUniformLocationWith3f(glGetUniformLocation(_program, str), col.r / 255.0f, col.g / 255.0f, col.b / 255.0f); setUniformLocationWith3f(glGetUniformLocation(_program, str), col.r / 255.0f, col.g / 255.0f, col.b / 255.0f);
sprintf(str, "CC_PointLightSource[%d].%s", enabledPointLightNum, "position"); sprintf(str, "CC_PointLightSourcePosition[%d]", enabledPointLightNum);
setUniformLocationWith4f(glGetUniformLocation(_program, str), mat.m[12], mat.m[13], mat.m[14], 1.0f / light->getRange()); setUniformLocationWith3f(glGetUniformLocation(_program, str), mat.m[12], mat.m[13], mat.m[14]);
sprintf(str, "CC_PointLightSourceRangeInverse[%d]", enabledPointLightNum);
setUniformLocationWith1f(glGetUniformLocation(_program, str), 1.0f / light->getRange());
++enabledPointLightNum; ++enabledPointLightNum;
} }
else else
@ -1031,14 +1021,18 @@ void GLProgram::setUniformsForBuiltins(const Mat4 &matrixMV)
Vec3 dir = light->getWorldDirection(); Vec3 dir = light->getWorldDirection();
dir.normalize(); dir.normalize();
Mat4 mat= light->getNodeToWorldTransform(); Mat4 mat= light->getNodeToWorldTransform();
sprintf(str, "CC_SpotLightSource[%d].%s", enabledSpotLightNum, "color"); sprintf(str, "CC_SpotLightSourceColor[%d]", enabledSpotLightNum);
setUniformLocationWith3f(glGetUniformLocation(_program, str), col.r / 255.0f, col.g / 255.0f, col.b / 255.0f); setUniformLocationWith3f(glGetUniformLocation(_program, str), col.r / 255.0f, col.g / 255.0f, col.b / 255.0f);
sprintf(str, "CC_SpotLightSource[%d].%s", enabledSpotLightNum, "position"); sprintf(str, "CC_SpotLightSourcePosition[%d]", enabledSpotLightNum);
setUniformLocationWith3f(glGetUniformLocation(_program, str), mat.m[12], mat.m[13], mat.m[14]); setUniformLocationWith3f(glGetUniformLocation(_program, str), mat.m[12], mat.m[13], mat.m[14]);
sprintf(str, "CC_SpotLightSource[%d].%s", enabledSpotLightNum, "direction"); sprintf(str, "CC_SpotLightSourceDirection[%d]", enabledSpotLightNum);
setUniformLocationWith3f(glGetUniformLocation(_program, str), dir.x, dir.y, dir.z); setUniformLocationWith3f(glGetUniformLocation(_program, str), dir.x, dir.y, dir.z);
sprintf(str, "CC_SpotLightSource[%d].%s", enabledSpotLightNum, "params"); sprintf(str, "CC_SpotLightSourceInnerAngleCos[%d]", enabledSpotLightNum);
setUniformLocationWith3f(glGetUniformLocation(_program, str), cosf(light->getInnerAngle()), cosf(light->getOuterAngle()), 1.0f / light->getRange()); setUniformLocationWith1f(glGetUniformLocation(_program, str), cosf(light->getInnerAngle()));
sprintf(str, "CC_SpotLightSourceOuterAngleCos[%d]", enabledSpotLightNum);
setUniformLocationWith1f(glGetUniformLocation(_program, str), cosf(light->getOuterAngle()));
sprintf(str, "CC_SpotLightSourceRangeInverse[%d]", enabledSpotLightNum);
setUniformLocationWith1f(glGetUniformLocation(_program, str), 1.0f / light->getRange());
++enabledSpotLightNum; ++enabledSpotLightNum;
} }
} }

View File

@ -27,76 +27,63 @@ varying vec3 v_normal;
uniform vec4 u_color; uniform vec4 u_color;
\n#if CC_MAX_POINT_LIGHT_NUM\n vec3 computeLighting(vec3 normalVector, vec3 lightDirection, vec3 lightColor, float attenuation)
void PointLight(int n, vec3 normal, inout vec4 intensity)
{ {
vec3 dir = v_vertexToPointLightDirection[n]; float diffuse = max(dot(normalVector, lightDirection), 0.0);
vec3 ldir = dir * CC_PointLightSource[n].position.w; vec3 diffuseColor = lightColor * diffuse * attenuation;
float attenuation = clamp(1.0 - dot(ldir, ldir), 0.0, 1.0);
intensity.xyz += CC_PointLightSource[n].color * max(0.0, dot(normalize(dir), normal)) * attenuation;
intensity.w = 1.0;
}
\n#endif\n
\n#if CC_MAX_DIRECTIONAL_LIGHT_NUM\n return diffuseColor;
void DirectionalLight(int n, vec3 normal, inout vec4 intensity)
{
intensity.xyz += CC_DirLightSource[n].color * max(0.0, dot(-CC_DirLightSource[n].direction, normal));
intensity.w = 1.0;
} }
\n#endif\n
\n#if CC_MAX_SPOT_LIGHT_NUM\n
void SpotLight(int n, vec3 normal, inout vec4 intensity)
{
vec3 dir = v_vertexToSpotLightDirection[n];
vec3 ldir = dir * CC_SpotLightSource[n].params.z;
float attenuation = clamp(1.0 - dot(ldir, ldir), 0.0, 1.0);
float spotDot = dot(normalize(dir), -CC_SpotLightSource[n].direction);
float innerCos = CC_SpotLightSource[n].params.x;
float outerCos = CC_SpotLightSource[n].params.y;
float factor = smoothstep(outerCos, innerCos, spotDot);
intensity.xyz += CC_SpotLightSource[n].color * max(0.0, dot(normalize(dir), normal)) * factor * attenuation;
intensity.w = 1.0;
}
\n#endif\n
void main(void) void main(void)
{ {
vec4 intensity = vec4(0.0); \n#if ((CC_MAX_DIRECTIONAL_LIGHT_NUM > 0) || (CC_MAX_POINT_LIGHT_NUM > 0) || (CC_MAX_SPOT_LIGHT_NUM > 0))\n
\n#if (CC_MAX_DIRECTIONAL_LIGHT_NUM || CC_MAX_POINT_LIGHT_NUM || CC_MAX_SPOT_LIGHT_NUM)\n
vec3 normal = normalize(v_normal); vec3 normal = normalize(v_normal);
\n#endif\n \n#endif\n
\n#if CC_MAX_DIRECTIONAL_LIGHT_NUM\n vec4 combinedColor = CC_AmbientColor;
// Directional light contribution
\n#if (CC_MAX_DIRECTIONAL_LIGHT_NUM > 0)\n
for (int i = 0; i < CC_MAX_DIRECTIONAL_LIGHT_NUM; ++i) for (int i = 0; i < CC_MAX_DIRECTIONAL_LIGHT_NUM; ++i)
{ {
DirectionalLight(i, normal, intensity); vec3 lightDirection = normalize(CC_DirLightSourceDirection[i] * 2.0);
combinedColor.xyz += computeLighting(normal, -lightDirection, CC_DirLightSourceColor[i], 1.0);
} }
\n#endif\n \n#endif\n
\n#if CC_MAX_POINT_LIGHT_NUM\n // Point light contribution
\n#if (CC_MAX_POINT_LIGHT_NUM > 0)\n
for (int i = 0; i < CC_MAX_POINT_LIGHT_NUM; ++i) for (int i = 0; i < CC_MAX_POINT_LIGHT_NUM; ++i)
{ {
PointLight(i, normal, intensity); vec3 ldir = v_vertexToPointLightDirection[i] * CC_PointLightSourceRangeInverse[i];
float attenuation = clamp(1.0 - dot(ldir, ldir), 0.0, 1.0);
combinedColor.xyz += computeLighting(normal, normalize(v_vertexToPointLightDirection[i]), CC_PointLightSourceColor[i], attenuation);
} }
\n#endif\n \n#endif\n
\n#if CC_MAX_SPOT_LIGHT_NUM\n // Spot light contribution
\n#if (CC_MAX_SPOT_LIGHT_NUM > 0)\n
for (int i = 0; i < CC_MAX_SPOT_LIGHT_NUM; ++i) for (int i = 0; i < CC_MAX_SPOT_LIGHT_NUM; ++i)
{ {
SpotLight(i, normal, intensity); // Compute range attenuation
} vec3 ldir = v_vertexToSpotLightDirection[i] * CC_SpotLightSourceRangeInverse[i];
float attenuation = clamp(1.0 - dot(ldir, ldir), 0.0, 1.0);
vec3 vertexToSpotLightDirection = normalize(v_vertexToSpotLightDirection[i]);
vec3 spotLightDirection = normalize(CC_SpotLightSourceDirection[i] * 2.0);
// "-lightDirection" is used because light direction points in opposite direction to spot direction.
float spotCurrentAngleCos = dot(spotLightDirection, -vertexToSpotLightDirection);
// Apply spot attenuation
attenuation *= smoothstep(CC_SpotLightSourceOuterAngleCos[i], CC_SpotLightSourceInnerAngleCos[i], spotCurrentAngleCos);
combinedColor.xyz += computeLighting(normal, vertexToSpotLightDirection, CC_SpotLightSourceColor[i], attenuation);
}
\n#endif\n \n#endif\n
\n#if (CC_MAX_DIRECTIONAL_LIGHT_NUM || CC_MAX_POINT_LIGHT_NUM || CC_MAX_SPOT_LIGHT_NUM)\n \n#if ((CC_MAX_DIRECTIONAL_LIGHT_NUM > 0) || (CC_MAX_POINT_LIGHT_NUM > 0) || (CC_MAX_SPOT_LIGHT_NUM > 0))\n
gl_FragColor = u_color * (CC_AmbientColor + intensity); gl_FragColor = u_color * combinedColor;
\n#else\n \n#else\n
gl_FragColor = u_color; gl_FragColor = u_color;
\n#endif\n \n#endif\n

View File

@ -27,78 +27,66 @@ varying vec3 v_normal;
uniform vec4 u_color; uniform vec4 u_color;
\n#if CC_MAX_POINT_LIGHT_NUM\n vec3 computeLighting(vec3 normalVector, vec3 lightDirection, vec3 lightColor, float attenuation)
void PointLight(int n, vec3 normal, inout vec4 intensity)
{ {
vec3 dir = v_vertexToPointLightDirection[n]; float diffuse = max(dot(normalVector, lightDirection), 0.0);
vec3 ldir = dir * CC_PointLightSource[n].position.w; vec3 diffuseColor = lightColor * diffuse * attenuation;
float attenuation = clamp(1.0 - dot(ldir, ldir), 0.0, 1.0);
intensity.xyz += CC_PointLightSource[n].color * max(0.0, dot(normalize(dir), normal)) * attenuation;
intensity.w = 1.0;
}
\n#endif\n
\n#if CC_MAX_DIRECTIONAL_LIGHT_NUM\n return diffuseColor;
void DirectionalLight(int n, vec3 normal, inout vec4 intensity)
{
intensity.xyz += CC_DirLightSource[n].color * max(0.0, dot(-CC_DirLightSource[n].direction, normal));
intensity.w = 1.0;
} }
\n#endif\n
\n#if CC_MAX_SPOT_LIGHT_NUM\n
void SpotLight(int n, vec3 normal, inout vec4 intensity)
{
vec3 dir = v_vertexToSpotLightDirection[n];
vec3 ldir = dir * CC_SpotLightSource[n].params.z;
float attenuation = clamp(1.0 - dot(ldir, ldir), 0.0, 1.0);
float spotDot = dot(normalize(dir), -CC_SpotLightSource[n].direction);
float innerCos = CC_SpotLightSource[n].params.x;
float outerCos = CC_SpotLightSource[n].params.y;
float factor = smoothstep(outerCos, innerCos, spotDot);
intensity.xyz += CC_SpotLightSource[n].color * max(0.0, dot(normalize(dir), normal)) * factor * attenuation;
intensity.w = 1.0;
}
\n#endif\n
void main(void) void main(void)
{ {
vec4 intensity = vec4(0.0); \n#if ((CC_MAX_DIRECTIONAL_LIGHT_NUM > 0) || (CC_MAX_POINT_LIGHT_NUM > 0) || (CC_MAX_SPOT_LIGHT_NUM > 0))\n
\n#if (CC_MAX_DIRECTIONAL_LIGHT_NUM || CC_MAX_POINT_LIGHT_NUM || CC_MAX_SPOT_LIGHT_NUM)\n
vec3 normal = normalize(v_normal); vec3 normal = normalize(v_normal);
\n#endif\n \n#endif\n
\n#if CC_MAX_DIRECTIONAL_LIGHT_NUM\n vec4 combinedColor = CC_AmbientColor;
// Directional light contribution
\n#if (CC_MAX_DIRECTIONAL_LIGHT_NUM > 0)\n
for (int i = 0; i < CC_MAX_DIRECTIONAL_LIGHT_NUM; ++i) for (int i = 0; i < CC_MAX_DIRECTIONAL_LIGHT_NUM; ++i)
{ {
DirectionalLight(i, normal, intensity); vec3 lightDirection = normalize(CC_DirLightSourceDirection[i] * 2.0);
combinedColor.xyz += computeLighting(normal, -lightDirection, CC_DirLightSourceColor[i], 1.0);
} }
\n#endif\n \n#endif\n
\n#if CC_MAX_POINT_LIGHT_NUM\n // Point light contribution
\n#if (CC_MAX_POINT_LIGHT_NUM > 0)\n
for (int i = 0; i < CC_MAX_POINT_LIGHT_NUM; ++i) for (int i = 0; i < CC_MAX_POINT_LIGHT_NUM; ++i)
{ {
PointLight(i, normal, intensity); vec3 ldir = v_vertexToPointLightDirection[i] * CC_PointLightSourceRangeInverse[i];
float attenuation = clamp(1.0 - dot(ldir, ldir), 0.0, 1.0);
combinedColor.xyz += computeLighting(normal, normalize(v_vertexToPointLightDirection[i]), CC_PointLightSourceColor[i], attenuation);
} }
\n#endif\n \n#endif\n
\n#if CC_MAX_SPOT_LIGHT_NUM\n // Spot light contribution
\n#if (CC_MAX_SPOT_LIGHT_NUM > 0)\n
for (int i = 0; i < CC_MAX_SPOT_LIGHT_NUM; ++i) for (int i = 0; i < CC_MAX_SPOT_LIGHT_NUM; ++i)
{ {
SpotLight(i, normal, intensity); // Compute range attenuation
} vec3 ldir = v_vertexToSpotLightDirection[i] * CC_SpotLightSourceRangeInverse[i];
float attenuation = clamp(1.0 - dot(ldir, ldir), 0.0, 1.0);
vec3 vertexToSpotLightDirection = normalize(v_vertexToSpotLightDirection[i]);
vec3 spotLightDirection = normalize(CC_SpotLightSourceDirection[i] * 2.0);
// "-lightDirection" is used because light direction points in opposite direction to spot direction.
float spotCurrentAngleCos = dot(spotLightDirection, -vertexToSpotLightDirection);
// Apply spot attenuation
attenuation *= smoothstep(CC_SpotLightSourceOuterAngleCos[i], CC_SpotLightSourceInnerAngleCos[i], spotCurrentAngleCos);
combinedColor.xyz += computeLighting(normal, vertexToSpotLightDirection, CC_SpotLightSourceColor[i], attenuation);
}
\n#endif\n \n#endif\n
\n#if (CC_MAX_DIRECTIONAL_LIGHT_NUM || CC_MAX_POINT_LIGHT_NUM || CC_MAX_SPOT_LIGHT_NUM)\n
gl_FragColor = texture2D(CC_Texture0, TextureCoordOut) * u_color * (CC_AmbientColor + intensity); \n#if ((CC_MAX_DIRECTIONAL_LIGHT_NUM > 0) || (CC_MAX_POINT_LIGHT_NUM > 0) || (CC_MAX_SPOT_LIGHT_NUM > 0))\n
gl_FragColor = texture2D(CC_Texture0, TextureCoordOut) * u_color * combinedColor;
\n#else\n \n#else\n
gl_FragColor = texture2D(CC_Texture0, TextureCoordOut) * u_color; gl_FragColor = texture2D(CC_Texture0, TextureCoordOut) * u_color;
\n#endif\n \n#endif\n
} }

View File

@ -20,18 +20,18 @@ void main(void)
\n#if (CC_MAX_POINT_LIGHT_NUM > 0)\n \n#if (CC_MAX_POINT_LIGHT_NUM > 0)\n
for (int i = 0; i < CC_MAX_POINT_LIGHT_NUM; ++i) for (int i = 0; i < CC_MAX_POINT_LIGHT_NUM; ++i)
{ {
v_vertexToPointLightDirection[i] = CC_PointLightSource[i].position.xyz - ePosition.xyz; v_vertexToPointLightDirection[i] = CC_PointLightSourcePosition[i].xyz - ePosition.xyz;
} }
\n#endif\n \n#endif\n
\n#if (CC_MAX_SPOT_LIGHT_NUM > 0)\n \n#if (CC_MAX_SPOT_LIGHT_NUM > 0)\n
for (int i = 0; i < CC_MAX_SPOT_LIGHT_NUM; ++i) for (int i = 0; i < CC_MAX_SPOT_LIGHT_NUM; ++i)
{ {
v_vertexToSpotLightDirection[i] = CC_SpotLightSource[i].position.xyz - ePosition.xyz; v_vertexToSpotLightDirection[i] = CC_SpotLightSourcePosition[i] - ePosition.xyz;
} }
\n#endif\n \n#endif\n
\n#if (CC_MAX_DIRECTIONAL_LIGHT_NUM || CC_MAX_POINT_LIGHT_NUM || CC_MAX_SPOT_LIGHT_NUM)\n \n#if ((CC_MAX_DIRECTIONAL_LIGHT_NUM > 0) || (CC_MAX_POINT_LIGHT_NUM > 0) || (CC_MAX_SPOT_LIGHT_NUM > 0))\n
v_normal = CC_NormalMatrix * a_normal; v_normal = CC_NormalMatrix * a_normal;
\n#endif\n \n#endif\n
@ -112,8 +112,8 @@ void getPositionAndNormal(out vec4 position, out vec3 normal)
position.z = dot(p, matrixPalette3); position.z = dot(p, matrixPalette3);
position.w = p.w; position.w = p.w;
\n#if (CC_MAX_DIRECTIONAL_LIGHT_NUM || CC_MAX_POINT_LIGHT_NUM || CC_MAX_SPOT_LIGHT_NUM)\n \n#if ((CC_MAX_DIRECTIONAL_LIGHT_NUM > 0) || (CC_MAX_POINT_LIGHT_NUM > 0) || (CC_MAX_SPOT_LIGHT_NUM > 0))\n
vec3 n = vec4(a_normal, 0.0); vec4 n = vec4(a_normal, 0.0);
normal.x = dot(n, matrixPalette1); normal.x = dot(n, matrixPalette1);
normal.y = dot(n, matrixPalette2); normal.y = dot(n, matrixPalette2);
normal.z = dot(n, matrixPalette3); normal.z = dot(n, matrixPalette3);
@ -130,18 +130,18 @@ void main()
\n#if (CC_MAX_POINT_LIGHT_NUM > 0)\n \n#if (CC_MAX_POINT_LIGHT_NUM > 0)\n
for (int i = 0; i < CC_MAX_POINT_LIGHT_NUM; ++i) for (int i = 0; i < CC_MAX_POINT_LIGHT_NUM; ++i)
{ {
v_vertexToPointLightDirection[i] = CC_PointLightSource[i].position.xyz- ePosition.xyz; v_vertexToPointLightDirection[i] = CC_PointLightSourcePosition[i].xyz- ePosition.xyz;
} }
\n#endif\n \n#endif\n
\n#if (CC_MAX_SPOT_LIGHT_NUM > 0)\n \n#if (CC_MAX_SPOT_LIGHT_NUM > 0)\n
for (int i = 0; i < CC_MAX_SPOT_LIGHT_NUM; ++i) for (int i = 0; i < CC_MAX_SPOT_LIGHT_NUM; ++i)
{ {
v_vertexToSpotLightDirection[i] = CC_SpotLightSource[i].position.xyz - ePosition.xyz; v_vertexToSpotLightDirection[i] = CC_SpotLightSourcePosition[i] - ePosition.xyz;
} }
\n#endif\n \n#endif\n
\n#if (CC_MAX_DIRECTIONAL_LIGHT_NUM || CC_MAX_POINT_LIGHT_NUM || CC_MAX_SPOT_LIGHT_NUM)\n \n#if ((CC_MAX_DIRECTIONAL_LIGHT_NUM > 0) || (CC_MAX_POINT_LIGHT_NUM > 0) || (CC_MAX_SPOT_LIGHT_NUM > 0))\n
v_normal = CC_NormalMatrix * normal; v_normal = CC_NormalMatrix * normal;
\n#endif\n \n#endif\n

View File

@ -78,7 +78,6 @@ Controller g_aTestNames[] = {
{ "Node: Spine", []() { return new SpineTestScene(); } }, { "Node: Spine", []() { return new SpineTestScene(); } },
{ "Node: Sprite", [](){return new SpriteTestScene(); } }, { "Node: Sprite", [](){return new SpriteTestScene(); } },
{ "Node: Sprite3D", [](){ return new Sprite3DTestScene(); }}, { "Node: Sprite3D", [](){ return new Sprite3DTestScene(); }},
{ "Node: LightTest", [](){ return new LightTestScene(); }},
{ "Node: TileMap", [](){return new TileMapTestScene(); } }, { "Node: TileMap", [](){return new TileMapTestScene(); } },
#if CC_TARGET_PLATFORM != CC_PLATFORM_WP8 #if CC_TARGET_PLATFORM != CC_PLATFORM_WP8
{ "Node: FastTileMap", [](){return new TileMapTestSceneNew(); } }, { "Node: FastTileMap", [](){return new TileMapTestSceneNew(); } },