Name modification

This commit is contained in:
songchengjiang 2014-08-21 11:33:00 +08:00
parent 5bad6e216b
commit e42eb950a3
14 changed files with 268 additions and 268 deletions

View File

@ -278,13 +278,13 @@ GLProgram* Sprite3D::getDefaultGLProgram(bool textured)
if(textured) if(textured)
{ {
if (hasSkin) if (hasSkin)
return GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_3D_SKINPOSITION_TEXTURE); return GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_3D_SKINPOSITION_NORMAL_TEXTURE);
return GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_3D_POSITION_TEXTURE); return GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_3D_POSITION_NORMAL_TEXTURE);
} }
else else
{ {
return GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_3D_POSITION); return GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_3D_POSITION_NORMAL);
} }
} }
else else
@ -292,13 +292,13 @@ GLProgram* Sprite3D::getDefaultGLProgram(bool textured)
if(textured) if(textured)
{ {
if (hasSkin) if (hasSkin)
return GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_3D_SKINPOSITION_TEXTURE_NO_NORMAL); return GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_3D_SKINPOSITION_TEXTURE);
return GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_3D_POSITION_TEXTURE_NO_NORMAL); return GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_3D_POSITION_TEXTURE);
} }
else else
{ {
return GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_3D_POSITION_NO_NORMAL); return GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_3D_POSITION);
} }
} }
} }

View File

@ -79,9 +79,9 @@ const char* GLProgram::SHADER_NAME_LABEL_OUTLINE = "ShaderLabelOutline";
const char* GLProgram::SHADER_3D_POSITION = "Shader3DPosition"; const char* GLProgram::SHADER_3D_POSITION = "Shader3DPosition";
const char* GLProgram::SHADER_3D_POSITION_TEXTURE = "Shader3DPositionTexture"; const char* GLProgram::SHADER_3D_POSITION_TEXTURE = "Shader3DPositionTexture";
const char* GLProgram::SHADER_3D_SKINPOSITION_TEXTURE = "Shader3DSkinPositionTexture"; const char* GLProgram::SHADER_3D_SKINPOSITION_TEXTURE = "Shader3DSkinPositionTexture";
const char* GLProgram::SHADER_3D_POSITION_NO_NORMAL = "Shader3DPosition_noNormal"; const char* GLProgram::SHADER_3D_POSITION_NORMAL = "Shader3DPositionNormal";
const char* GLProgram::SHADER_3D_POSITION_TEXTURE_NO_NORMAL = "Shader3DPositionTexture_noNormal"; const char* GLProgram::SHADER_3D_POSITION_NORMAL_TEXTURE = "Shader3DPositionNormalTexture";
const char* GLProgram::SHADER_3D_SKINPOSITION_TEXTURE_NO_NORMAL = "Shader3DSkinPositionTexture_noNormal"; const char* GLProgram::SHADER_3D_SKINPOSITION_NORMAL_TEXTURE = "Shader3DSkinPositionNormalTexture";
// uniform names // uniform names

View File

@ -138,9 +138,9 @@ public:
static const char* SHADER_3D_POSITION; static const char* SHADER_3D_POSITION;
static const char* SHADER_3D_POSITION_TEXTURE; static const char* SHADER_3D_POSITION_TEXTURE;
static const char* SHADER_3D_SKINPOSITION_TEXTURE; static const char* SHADER_3D_SKINPOSITION_TEXTURE;
static const char* SHADER_3D_POSITION_NO_NORMAL; static const char* SHADER_3D_POSITION_NORMAL;
static const char* SHADER_3D_POSITION_TEXTURE_NO_NORMAL; static const char* SHADER_3D_POSITION_NORMAL_TEXTURE;
static const char* SHADER_3D_SKINPOSITION_TEXTURE_NO_NORMAL; static const char* SHADER_3D_SKINPOSITION_NORMAL_TEXTURE;
// uniform names // uniform names
static const char* UNIFORM_NAME_ENABLED_DIRECTIONAL_LIGHT_NUM; static const char* UNIFORM_NAME_ENABLED_DIRECTIONAL_LIGHT_NUM;

View File

@ -52,9 +52,9 @@ enum {
kShaderType_3DPosition, kShaderType_3DPosition,
kShaderType_3DPositionTex, kShaderType_3DPositionTex,
kShaderType_3DSkinPositionTex, kShaderType_3DSkinPositionTex,
kShaderType_3DPosition_noNormal, kShaderType_3DPositionNormal,
kShaderType_3DPositionTex_noNormal, kShaderType_3DPositionNormalTex,
kShaderType_3DSkinPositionTex_noNormal, kShaderType_3DSkinPositionNormalTex,
kShaderType_MAX, kShaderType_MAX,
}; };
@ -209,16 +209,16 @@ void GLProgramCache::loadDefaultGLPrograms()
_programs.insert(std::make_pair(GLProgram::SHADER_3D_SKINPOSITION_TEXTURE, p)); _programs.insert(std::make_pair(GLProgram::SHADER_3D_SKINPOSITION_TEXTURE, p));
p = new GLProgram(); p = new GLProgram();
loadDefaultGLProgram(p, kShaderType_3DPosition_noNormal); loadDefaultGLProgram(p, kShaderType_3DPositionNormal);
_programs.insert( std::make_pair(GLProgram::SHADER_3D_POSITION_NO_NORMAL, p) ); _programs.insert( std::make_pair(GLProgram::SHADER_3D_POSITION_NORMAL, p) );
p = new GLProgram(); p = new GLProgram();
loadDefaultGLProgram(p, kShaderType_3DPositionTex_noNormal); loadDefaultGLProgram(p, kShaderType_3DPositionNormalTex);
_programs.insert( std::make_pair(GLProgram::SHADER_3D_POSITION_TEXTURE_NO_NORMAL, p) ); _programs.insert( std::make_pair(GLProgram::SHADER_3D_POSITION_NORMAL_TEXTURE, p) );
p = new GLProgram(); p = new GLProgram();
loadDefaultGLProgram(p, kShaderType_3DSkinPositionTex_noNormal); loadDefaultGLProgram(p, kShaderType_3DSkinPositionNormalTex);
_programs.insert(std::make_pair(GLProgram::SHADER_3D_SKINPOSITION_TEXTURE_NO_NORMAL, p)); _programs.insert(std::make_pair(GLProgram::SHADER_3D_SKINPOSITION_NORMAL_TEXTURE, p));
} }
void GLProgramCache::reloadDefaultGLPrograms() void GLProgramCache::reloadDefaultGLPrograms()
@ -320,17 +320,17 @@ void GLProgramCache::reloadDefaultGLPrograms()
p->reset(); p->reset();
loadDefaultGLProgram(p, kShaderType_3DSkinPositionTex); loadDefaultGLProgram(p, kShaderType_3DSkinPositionTex);
p = getGLProgram(GLProgram::SHADER_3D_POSITION_NO_NORMAL); p = getGLProgram(GLProgram::SHADER_3D_POSITION_NORMAL);
p->reset(); p->reset();
loadDefaultGLProgram(p, kShaderType_3DPosition_noNormal); loadDefaultGLProgram(p, kShaderType_3DPositionNormal);
p = getGLProgram(GLProgram::SHADER_3D_POSITION_TEXTURE_NO_NORMAL); p = getGLProgram(GLProgram::SHADER_3D_POSITION_NORMAL_TEXTURE);
p->reset(); p->reset();
loadDefaultGLProgram(p, kShaderType_3DPositionTex_noNormal); loadDefaultGLProgram(p, kShaderType_3DPositionNormalTex);
p = getGLProgram(GLProgram::SHADER_3D_SKINPOSITION_TEXTURE_NO_NORMAL); p = getGLProgram(GLProgram::SHADER_3D_SKINPOSITION_NORMAL_TEXTURE);
p->reset(); p->reset();
loadDefaultGLProgram(p, kShaderType_3DSkinPositionTex_noNormal); loadDefaultGLProgram(p, kShaderType_3DSkinPositionNormalTex);
} }
void GLProgramCache::loadDefaultGLProgram(GLProgram *p, int type) void GLProgramCache::loadDefaultGLProgram(GLProgram *p, int type)
@ -393,14 +393,14 @@ void GLProgramCache::loadDefaultGLProgram(GLProgram *p, int type)
case kShaderType_3DSkinPositionTex: case kShaderType_3DSkinPositionTex:
p->initWithByteArrays(cc3D_SkinPositionTex_vert, cc3D_ColorTex_frag); p->initWithByteArrays(cc3D_SkinPositionTex_vert, cc3D_ColorTex_frag);
break; break;
case kShaderType_3DPosition_noNormal: case kShaderType_3DPositionNormal:
p->initWithByteArrays(cc3D_PositionTexNoNormal_vert, cc3D_ColorNoNormal_frag); p->initWithByteArrays(cc3D_PositionNormalTex_vert, cc3D_ColorNormal_frag);
break; break;
case kShaderType_3DPositionTex_noNormal: case kShaderType_3DPositionNormalTex:
p->initWithByteArrays(cc3D_PositionTexNoNormal_vert, cc3D_ColorTexNoNormal_frag); p->initWithByteArrays(cc3D_PositionNormalTex_vert, cc3D_ColorNormalTex_frag);
break; break;
case kShaderType_3DSkinPositionTex_noNormal: case kShaderType_3DSkinPositionNormalTex:
p->initWithByteArrays(cc3D_SkinPositionTexNoNormal_vert, cc3D_ColorTexNoNormal_frag); p->initWithByteArrays(cc3D_SkinPositionNormalTex_vert, cc3D_ColorNormalTex_frag);
break; break;
default: default:
CCLOG("cocos2d: %s:%d, error shader type", __FUNCTION__, __LINE__); CCLOG("cocos2d: %s:%d, error shader type", __FUNCTION__, __LINE__);

View File

@ -3,88 +3,13 @@ const char* cc3D_Color_frag = STRINGIFY(
\n#ifdef GL_ES\n \n#ifdef GL_ES\n
varying lowp vec4 DestinationColor; varying lowp vec4 DestinationColor;
varying mediump vec4 ePosition;
varying mediump vec3 eNormal;
\n#else\n \n#else\n
varying vec4 DestinationColor; varying vec4 DestinationColor;
varying vec4 ePosition;
varying vec3 eNormal;
\n#endif\n \n#endif\n
uniform vec4 u_color; uniform vec4 u_color;
\n#if CC_MAX_POINT_LIGHT_NUM\n
void PointLight(int n, vec4 ePosition, vec3 eNormal, inout vec4 intensity)
{
if (distance(CC_PointLightSource[n].position.xyz, ePosition.xyz) < CC_PointLightSource[n].position.w)
{
vec3 lightDir = CC_PointLightSource[n].position.xyz - ePosition.xyz;
lightDir = normalize(lightDir);
intensity.xyz += CC_PointLightSource[n].color * max(0.0, dot(lightDir, eNormal));
}
intensity.w = 1.0;
}
\n#endif\n
\n#if CC_MAX_DIRECTIONAL_LIGHT_NUM\n
void DirectionalLight(int n, vec3 eNormal, inout vec4 intensity)
{
intensity.xyz += CC_DirLightSource[n].color * max(0.0, dot(normalize(-CC_DirLightSource[n].direction), eNormal));
intensity.w = 1.0;
}
\n#endif\n
\n#if CC_MAX_SPOT_LIGHT_NUM\n
void SpotLight(int n, vec4 ePosition, vec3 eNormal, inout vec4 intensity)
{
if (distance(CC_SpotLightSource[n].position, ePosition.xyz) < CC_SpotLightSource[n].params.z)
{
vec3 lightDir = CC_SpotLightSource[n].position - ePosition.xyz;
lightDir = normalize(lightDir);
float spotDot = dot(lightDir, normalize(-CC_SpotLightSource[n].direction));
float innerCos = cos(CC_SpotLightSource[n].params.x);
float outerCos = cos(CC_SpotLightSource[n].params.y);
float factor = smoothstep(outerCos, innerCos, spotDot);
intensity.xyz += CC_SpotLightSource[n].color * max(0.0, dot(lightDir, eNormal)) * factor;
}
intensity.w = 1.0;
}
\n#endif\n
void main(void) void main(void)
{ {
vec3 normal = normalize(eNormal);
vec4 intensity = vec4(0.0);
\n#if CC_MAX_DIRECTIONAL_LIGHT_NUM\n
for (int i = 0; i < CC_EnabledDirLightNum; ++i)
{
DirectionalLight(i, normal, intensity);
}
\n#endif\n
\n#if CC_MAX_POINT_LIGHT_NUM\n
for (int i = 0; i < CC_EnabledPointLightNum; ++i)
{
PointLight(i, ePosition, normal, intensity);
}
\n#endif\n
\n#if CC_MAX_SPOT_LIGHT_NUM\n
for (int i = 0; i < CC_EnabledSpotLightNum; ++i)
{
SpotLight(i, ePosition, normal, intensity);
}
\n#endif\n
if (intensity.w == 0.0)
gl_FragColor = u_color; gl_FragColor = u_color;
else
gl_FragColor = u_color * (CC_AmbientColor + intensity);
} }
); );

View File

@ -1,15 +0,0 @@
const char* cc3D_ColorNoNormal_frag = STRINGIFY(
\n#ifdef GL_ES\n
varying lowp vec4 DestinationColor;
\n#else\n
varying vec4 DestinationColor;
\n#endif\n
uniform vec4 u_color;
void main(void)
{
gl_FragColor = u_color;
}
);

View File

@ -0,0 +1,90 @@
const char* cc3D_ColorNormal_frag = STRINGIFY(
\n#ifdef GL_ES\n
varying lowp vec4 DestinationColor;
varying mediump vec4 ePosition;
varying mediump vec3 eNormal;
\n#else\n
varying vec4 DestinationColor;
varying vec4 ePosition;
varying vec3 eNormal;
\n#endif\n
uniform vec4 u_color;
\n#if CC_MAX_POINT_LIGHT_NUM\n
void PointLight(int n, vec4 ePosition, vec3 eNormal, inout vec4 intensity)
{
if (distance(CC_PointLightSource[n].position.xyz, ePosition.xyz) < CC_PointLightSource[n].position.w)
{
vec3 lightDir = CC_PointLightSource[n].position.xyz - ePosition.xyz;
lightDir = normalize(lightDir);
intensity.xyz += CC_PointLightSource[n].color * max(0.0, dot(lightDir, eNormal));
}
intensity.w = 1.0;
}
\n#endif\n
\n#if CC_MAX_DIRECTIONAL_LIGHT_NUM\n
void DirectionalLight(int n, vec3 eNormal, inout vec4 intensity)
{
intensity.xyz += CC_DirLightSource[n].color * max(0.0, dot(normalize(-CC_DirLightSource[n].direction), eNormal));
intensity.w = 1.0;
}
\n#endif\n
\n#if CC_MAX_SPOT_LIGHT_NUM\n
void SpotLight(int n, vec4 ePosition, vec3 eNormal, inout vec4 intensity)
{
if (distance(CC_SpotLightSource[n].position, ePosition.xyz) < CC_SpotLightSource[n].params.z)
{
vec3 lightDir = CC_SpotLightSource[n].position - ePosition.xyz;
lightDir = normalize(lightDir);
float spotDot = dot(lightDir, normalize(-CC_SpotLightSource[n].direction));
float innerCos = cos(CC_SpotLightSource[n].params.x);
float outerCos = cos(CC_SpotLightSource[n].params.y);
float factor = smoothstep(outerCos, innerCos, spotDot);
intensity.xyz += CC_SpotLightSource[n].color * max(0.0, dot(lightDir, eNormal)) * factor;
}
intensity.w = 1.0;
}
\n#endif\n
void main(void)
{
vec3 normal = normalize(eNormal);
vec4 intensity = vec4(0.0);
\n#if CC_MAX_DIRECTIONAL_LIGHT_NUM\n
for (int i = 0; i < CC_EnabledDirLightNum; ++i)
{
DirectionalLight(i, normal, intensity);
}
\n#endif\n
\n#if CC_MAX_POINT_LIGHT_NUM\n
for (int i = 0; i < CC_EnabledPointLightNum; ++i)
{
PointLight(i, ePosition, normal, intensity);
}
\n#endif\n
\n#if CC_MAX_SPOT_LIGHT_NUM\n
for (int i = 0; i < CC_EnabledSpotLightNum; ++i)
{
SpotLight(i, ePosition, normal, intensity);
}
\n#endif\n
if (intensity.w == 0.0)
gl_FragColor = u_color;
else
gl_FragColor = u_color * (CC_AmbientColor + intensity);
}
);

View File

@ -0,0 +1,91 @@
const char* cc3D_ColorNormalTex_frag = STRINGIFY(
\n#ifdef GL_ES\n
varying mediump vec2 TextureCoordOut;
varying mediump vec4 ePosition;
varying mediump vec3 eNormal;
\n#else\n
varying vec2 TextureCoordOut;
varying vec4 ePosition;
varying vec3 eNormal;
\n#endif\n
uniform vec4 u_color;
\n#if CC_MAX_POINT_LIGHT_NUM\n
void PointLight(int n, vec4 ePosition, vec3 eNormal, inout vec4 intensity)
{
if (distance(CC_PointLightSource[n].position.xyz, ePosition.xyz) < CC_PointLightSource[n].position.w)
{
vec3 lightDir = CC_PointLightSource[n].position.xyz - ePosition.xyz;
lightDir = normalize(lightDir);
intensity.xyz += CC_PointLightSource[n].color * max(0.0, dot(lightDir, eNormal));
}
intensity.w = 1.0;
}
\n#endif\n
\n#if CC_MAX_DIRECTIONAL_LIGHT_NUM\n
void DirectionalLight(int n, vec3 eNormal, inout vec4 intensity)
{
intensity.xyz += CC_DirLightSource[n].color * max(0.0, dot(normalize(-CC_DirLightSource[n].direction), eNormal));
intensity.w = 1.0;
}
\n#endif\n
\n#if CC_MAX_SPOT_LIGHT_NUM\n
void SpotLight(int n, vec4 ePosition, vec3 eNormal, inout vec4 intensity)
{
if (distance(CC_SpotLightSource[n].position, ePosition.xyz) < CC_SpotLightSource[n].params.z)
{
vec3 lightDir = CC_SpotLightSource[n].position - ePosition.xyz;
lightDir = normalize(lightDir);
float spotDot = dot(normalize(lightDir), normalize(-CC_SpotLightSource[n].direction));
float innerCos = cos(CC_SpotLightSource[n].params.x);
float outerCos = cos(CC_SpotLightSource[n].params.y);
float factor = smoothstep(outerCos, innerCos, spotDot);
intensity.xyz += CC_SpotLightSource[n].color * max(0.0, dot(lightDir, eNormal)) * factor;
}
intensity.w = 1.0;
}
\n#endif\n
void main(void)
{
vec3 normal = normalize(eNormal);
vec4 intensity = vec4(0.0);
\n#if CC_MAX_DIRECTIONAL_LIGHT_NUM\n
for (int i = 0; i < CC_EnabledDirLightNum; ++i)
{
DirectionalLight(i, normal, intensity);
}
\n#endif\n
\n#if CC_MAX_POINT_LIGHT_NUM\n
for (int i = 0; i < CC_EnabledPointLightNum; ++i)
{
PointLight(i, ePosition, normal, intensity);
}
\n#endif\n
\n#if CC_MAX_SPOT_LIGHT_NUM\n
for (int i = 0; i < CC_EnabledSpotLightNum; ++i)
{
SpotLight(i, ePosition, normal, intensity);
}
\n#endif\n
if (intensity.w == 0.0)
gl_FragColor = texture2D(CC_Texture0, TextureCoordOut) * u_color;
else
gl_FragColor = texture2D(CC_Texture0, TextureCoordOut) * u_color * (CC_AmbientColor + intensity);
}
);

View File

@ -3,89 +3,13 @@ const char* cc3D_ColorTex_frag = STRINGIFY(
\n#ifdef GL_ES\n \n#ifdef GL_ES\n
varying mediump vec2 TextureCoordOut; varying mediump vec2 TextureCoordOut;
varying mediump vec4 ePosition;
varying mediump vec3 eNormal;
\n#else\n \n#else\n
varying vec2 TextureCoordOut; varying vec2 TextureCoordOut;
varying vec4 ePosition;
varying vec3 eNormal;
\n#endif\n \n#endif\n
uniform vec4 u_color; uniform vec4 u_color;
\n#if CC_MAX_POINT_LIGHT_NUM\n
void PointLight(int n, vec4 ePosition, vec3 eNormal, inout vec4 intensity)
{
if (distance(CC_PointLightSource[n].position.xyz, ePosition.xyz) < CC_PointLightSource[n].position.w)
{
vec3 lightDir = CC_PointLightSource[n].position.xyz - ePosition.xyz;
lightDir = normalize(lightDir);
intensity.xyz += CC_PointLightSource[n].color * max(0.0, dot(lightDir, eNormal));
}
intensity.w = 1.0;
}
\n#endif\n
\n#if CC_MAX_DIRECTIONAL_LIGHT_NUM\n
void DirectionalLight(int n, vec3 eNormal, inout vec4 intensity)
{
intensity.xyz += CC_DirLightSource[n].color * max(0.0, dot(normalize(-CC_DirLightSource[n].direction), eNormal));
intensity.w = 1.0;
}
\n#endif\n
\n#if CC_MAX_SPOT_LIGHT_NUM\n
void SpotLight(int n, vec4 ePosition, vec3 eNormal, inout vec4 intensity)
{
if (distance(CC_SpotLightSource[n].position, ePosition.xyz) < CC_SpotLightSource[n].params.z)
{
vec3 lightDir = CC_SpotLightSource[n].position - ePosition.xyz;
lightDir = normalize(lightDir);
float spotDot = dot(normalize(lightDir), normalize(-CC_SpotLightSource[n].direction));
float innerCos = cos(CC_SpotLightSource[n].params.x);
float outerCos = cos(CC_SpotLightSource[n].params.y);
float factor = smoothstep(outerCos, innerCos, spotDot);
intensity.xyz += CC_SpotLightSource[n].color * max(0.0, dot(lightDir, eNormal)) * factor;
}
intensity.w = 1.0;
}
\n#endif\n
void main(void) void main(void)
{ {
vec3 normal = normalize(eNormal);
vec4 intensity = vec4(0.0);
\n#if CC_MAX_DIRECTIONAL_LIGHT_NUM\n
for (int i = 0; i < CC_EnabledDirLightNum; ++i)
{
DirectionalLight(i, normal, intensity);
}
\n#endif\n
\n#if CC_MAX_POINT_LIGHT_NUM\n
for (int i = 0; i < CC_EnabledPointLightNum; ++i)
{
PointLight(i, ePosition, normal, intensity);
}
\n#endif\n
\n#if CC_MAX_SPOT_LIGHT_NUM\n
for (int i = 0; i < CC_EnabledSpotLightNum; ++i)
{
SpotLight(i, ePosition, normal, intensity);
}
\n#endif\n
if (intensity.w == 0.0)
gl_FragColor = texture2D(CC_Texture0, TextureCoordOut) * u_color; gl_FragColor = texture2D(CC_Texture0, TextureCoordOut) * u_color;
else
gl_FragColor = texture2D(CC_Texture0, TextureCoordOut) * u_color * (CC_AmbientColor + intensity);
} }
); );

View File

@ -1,15 +0,0 @@
const char* cc3D_ColorTexNoNormal_frag = STRINGIFY(
\n#ifdef GL_ES\n
varying mediump vec2 TextureCoordOut;
\n#else\n
varying vec2 TextureCoordOut;
\n#endif\n
uniform vec4 u_color;
void main(void)
{
gl_FragColor = texture2D(CC_Texture0, TextureCoordOut) * u_color;
}
);

View File

@ -1,20 +1,24 @@
const char* cc3D_PositionTexNoNormal_vert = STRINGIFY( const char* cc3D_PositionNormalTex_vert = STRINGIFY(
attribute vec4 a_position; attribute vec4 a_position;
attribute vec2 a_texCoord; attribute vec2 a_texCoord;
attribute vec3 a_normal;
varying vec2 TextureCoordOut; varying vec2 TextureCoordOut;
varying vec4 ePosition;
varying vec3 eNormal;
void main(void) void main(void)
{ {
gl_Position = CC_MVPMatrix * a_position; ePosition = CC_MVMatrix * a_position;
eNormal = CC_NormalMatrix * a_normal;
TextureCoordOut = a_texCoord; TextureCoordOut = a_texCoord;
TextureCoordOut.y = 1.0 - TextureCoordOut.y; TextureCoordOut.y = 1.0 - TextureCoordOut.y;
gl_Position = CC_PMatrix * ePosition;
} }
); );
const char* cc3D_SkinPositionTexNoNormal_vert = STRINGIFY( const char* cc3D_SkinPositionNormalTex_vert = STRINGIFY(
attribute vec3 a_position; attribute vec3 a_position;
attribute vec4 a_blendWeight; attribute vec4 a_blendWeight;
@ -22,14 +26,18 @@ attribute vec4 a_blendIndex;
attribute vec2 a_texCoord; attribute vec2 a_texCoord;
attribute vec3 a_normal;
const int SKINNING_JOINT_COUNT = 60; const int SKINNING_JOINT_COUNT = 60;
// Uniforms // Uniforms
uniform vec4 u_matrixPalette[SKINNING_JOINT_COUNT * 3]; uniform vec4 u_matrixPalette[SKINNING_JOINT_COUNT * 3];
// Varyings // Varyings
varying vec2 TextureCoordOut; varying vec2 TextureCoordOut;
varying vec4 ePosition;
varying vec3 eNormal;
vec4 getPosition() void getPositionAndNormal(out vec4 position, out vec3 normal)
{ {
float blendWeight = a_blendWeight[0]; float blendWeight = a_blendWeight[0];
@ -69,23 +77,29 @@ vec4 getPosition()
} }
vec4 _skinnedPosition; vec4 p = vec4(a_position, 1.0);
vec4 postion = vec4(a_position, 1.0); position.x = dot(p, matrixPalette1);
_skinnedPosition.x = dot(postion, matrixPalette1); position.y = dot(p, matrixPalette2);
_skinnedPosition.y = dot(postion, matrixPalette2); position.z = dot(p, matrixPalette3);
_skinnedPosition.z = dot(postion, matrixPalette3); position.w = p.w;
_skinnedPosition.w = postion.w;
return _skinnedPosition; vec4 n = vec4(a_normal, 0.0);
normal.x = dot(n, matrixPalette1);
normal.y = dot(n, matrixPalette2);
normal.z = dot(n, matrixPalette3);
} }
void main() void main()
{ {
vec4 position = getPosition(); vec4 position;
gl_Position = CC_MVPMatrix * position; vec3 normal;
getPositionAndNormal(position, normal);
ePosition = CC_MVMatrix * position;
eNormal = CC_NormalMatrix * normal;
TextureCoordOut = a_texCoord; TextureCoordOut = a_texCoord;
TextureCoordOut.y = 1.0 - TextureCoordOut.y; TextureCoordOut.y = 1.0 - TextureCoordOut.y;
gl_Position = CC_PMatrix * ePosition;
} }
); );

View File

@ -3,18 +3,14 @@ const char* cc3D_PositionTex_vert = STRINGIFY(
attribute vec4 a_position; attribute vec4 a_position;
attribute vec2 a_texCoord; attribute vec2 a_texCoord;
attribute vec3 a_normal;
varying vec2 TextureCoordOut; varying vec2 TextureCoordOut;
varying vec4 ePosition;
varying vec3 eNormal;
void main(void) void main(void)
{ {
ePosition = CC_MVMatrix * a_position; gl_Position = CC_MVPMatrix * a_position;
eNormal = CC_NormalMatrix * a_normal;
TextureCoordOut = a_texCoord; TextureCoordOut = a_texCoord;
TextureCoordOut.y = 1.0 - TextureCoordOut.y; TextureCoordOut.y = 1.0 - TextureCoordOut.y;
gl_Position = CC_PMatrix * ePosition;
} }
); );
@ -26,18 +22,14 @@ attribute vec4 a_blendIndex;
attribute vec2 a_texCoord; attribute vec2 a_texCoord;
attribute vec3 a_normal;
const int SKINNING_JOINT_COUNT = 60; const int SKINNING_JOINT_COUNT = 60;
// Uniforms // Uniforms
uniform vec4 u_matrixPalette[SKINNING_JOINT_COUNT * 3]; uniform vec4 u_matrixPalette[SKINNING_JOINT_COUNT * 3];
// Varyings // Varyings
varying vec2 TextureCoordOut; varying vec2 TextureCoordOut;
varying vec4 ePosition;
varying vec3 eNormal;
void getPositionAndNormal(out vec4 position, out vec3 normal) vec4 getPosition()
{ {
float blendWeight = a_blendWeight[0]; float blendWeight = a_blendWeight[0];
@ -77,29 +69,23 @@ void getPositionAndNormal(out vec4 position, out vec3 normal)
} }
vec4 p = vec4(a_position, 1.0); vec4 _skinnedPosition;
position.x = dot(p, matrixPalette1); vec4 postion = vec4(a_position, 1.0);
position.y = dot(p, matrixPalette2); _skinnedPosition.x = dot(postion, matrixPalette1);
position.z = dot(p, matrixPalette3); _skinnedPosition.y = dot(postion, matrixPalette2);
position.w = p.w; _skinnedPosition.z = dot(postion, matrixPalette3);
_skinnedPosition.w = postion.w;
vec4 n = vec4(a_normal, 0.0); return _skinnedPosition;
normal.x = dot(n, matrixPalette1);
normal.y = dot(n, matrixPalette2);
normal.z = dot(n, matrixPalette3);
} }
void main() void main()
{ {
vec4 position; vec4 position = getPosition();
vec3 normal; gl_Position = CC_MVPMatrix * position;
getPositionAndNormal(position, normal);
ePosition = CC_MVMatrix * position;
eNormal = CC_NormalMatrix * normal;
TextureCoordOut = a_texCoord; TextureCoordOut = a_texCoord;
TextureCoordOut.y = 1.0 - TextureCoordOut.y; TextureCoordOut.y = 1.0 - TextureCoordOut.y;
gl_Position = CC_PMatrix * ePosition;
} }
); );

View File

@ -74,8 +74,8 @@ NS_CC_BEGIN
#include "ccShader_3D_PositionTex.vert" #include "ccShader_3D_PositionTex.vert"
#include "ccShader_3D_Color.frag" #include "ccShader_3D_Color.frag"
#include "ccShader_3D_ColorTex.frag" #include "ccShader_3D_ColorTex.frag"
#include "ccShader_3D_PositionTexNoNormal.vert" #include "ccShader_3D_PositionNormalTex.vert"
#include "ccShader_3D_ColorNoNormal.frag" #include "ccShader_3D_ColorNormal.frag"
#include "ccShader_3D_ColorTexNoNormal.frag" #include "ccShader_3D_ColorNormalTex.frag"
NS_CC_END NS_CC_END

View File

@ -73,10 +73,10 @@ extern CC_DLL const GLchar * cc3D_PositionTex_vert;
extern CC_DLL const GLchar * cc3D_SkinPositionTex_vert; extern CC_DLL const GLchar * cc3D_SkinPositionTex_vert;
extern CC_DLL const GLchar * cc3D_ColorTex_frag; extern CC_DLL const GLchar * cc3D_ColorTex_frag;
extern CC_DLL const GLchar * cc3D_Color_frag; extern CC_DLL const GLchar * cc3D_Color_frag;
extern CC_DLL const GLchar * cc3D_PositionTexNoNormal_vert; extern CC_DLL const GLchar * cc3D_PositionNormalTex_vert;
extern CC_DLL const GLchar * cc3D_SkinPositionTexNoNormal_vert; extern CC_DLL const GLchar * cc3D_SkinPositionNormalTex_vert;
extern CC_DLL const GLchar * cc3D_ColorTexNoNormal_frag; extern CC_DLL const GLchar * cc3D_ColorNormalTex_frag;
extern CC_DLL const GLchar * cc3D_ColorNoNormal_frag; extern CC_DLL const GLchar * cc3D_ColorNormal_frag;
// end of shaders group // end of shaders group
/// @} /// @}