mirror of https://github.com/axmolengine/axmol.git
Name modification
This commit is contained in:
parent
5bad6e216b
commit
e42eb950a3
|
@ -278,13 +278,13 @@ GLProgram* Sprite3D::getDefaultGLProgram(bool textured)
|
|||
if(textured)
|
||||
{
|
||||
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
|
||||
{
|
||||
return GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_3D_POSITION);
|
||||
return GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_3D_POSITION_NORMAL);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -292,13 +292,13 @@ GLProgram* Sprite3D::getDefaultGLProgram(bool textured)
|
|||
if(textured)
|
||||
{
|
||||
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
|
||||
{
|
||||
return GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_3D_POSITION_NO_NORMAL);
|
||||
return GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_3D_POSITION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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_TEXTURE = "Shader3DPositionTexture";
|
||||
const char* GLProgram::SHADER_3D_SKINPOSITION_TEXTURE = "Shader3DSkinPositionTexture";
|
||||
const char* GLProgram::SHADER_3D_POSITION_NO_NORMAL = "Shader3DPosition_noNormal";
|
||||
const char* GLProgram::SHADER_3D_POSITION_TEXTURE_NO_NORMAL = "Shader3DPositionTexture_noNormal";
|
||||
const char* GLProgram::SHADER_3D_SKINPOSITION_TEXTURE_NO_NORMAL = "Shader3DSkinPositionTexture_noNormal";
|
||||
const char* GLProgram::SHADER_3D_POSITION_NORMAL = "Shader3DPositionNormal";
|
||||
const char* GLProgram::SHADER_3D_POSITION_NORMAL_TEXTURE = "Shader3DPositionNormalTexture";
|
||||
const char* GLProgram::SHADER_3D_SKINPOSITION_NORMAL_TEXTURE = "Shader3DSkinPositionNormalTexture";
|
||||
|
||||
|
||||
// uniform names
|
||||
|
|
|
@ -138,9 +138,9 @@ public:
|
|||
static const char* SHADER_3D_POSITION;
|
||||
static const char* SHADER_3D_POSITION_TEXTURE;
|
||||
static const char* SHADER_3D_SKINPOSITION_TEXTURE;
|
||||
static const char* SHADER_3D_POSITION_NO_NORMAL;
|
||||
static const char* SHADER_3D_POSITION_TEXTURE_NO_NORMAL;
|
||||
static const char* SHADER_3D_SKINPOSITION_TEXTURE_NO_NORMAL;
|
||||
static const char* SHADER_3D_POSITION_NORMAL;
|
||||
static const char* SHADER_3D_POSITION_NORMAL_TEXTURE;
|
||||
static const char* SHADER_3D_SKINPOSITION_NORMAL_TEXTURE;
|
||||
|
||||
// uniform names
|
||||
static const char* UNIFORM_NAME_ENABLED_DIRECTIONAL_LIGHT_NUM;
|
||||
|
|
|
@ -52,9 +52,9 @@ enum {
|
|||
kShaderType_3DPosition,
|
||||
kShaderType_3DPositionTex,
|
||||
kShaderType_3DSkinPositionTex,
|
||||
kShaderType_3DPosition_noNormal,
|
||||
kShaderType_3DPositionTex_noNormal,
|
||||
kShaderType_3DSkinPositionTex_noNormal,
|
||||
kShaderType_3DPositionNormal,
|
||||
kShaderType_3DPositionNormalTex,
|
||||
kShaderType_3DSkinPositionNormalTex,
|
||||
kShaderType_MAX,
|
||||
};
|
||||
|
||||
|
@ -209,16 +209,16 @@ void GLProgramCache::loadDefaultGLPrograms()
|
|||
_programs.insert(std::make_pair(GLProgram::SHADER_3D_SKINPOSITION_TEXTURE, p));
|
||||
|
||||
p = new GLProgram();
|
||||
loadDefaultGLProgram(p, kShaderType_3DPosition_noNormal);
|
||||
_programs.insert( std::make_pair(GLProgram::SHADER_3D_POSITION_NO_NORMAL, p) );
|
||||
loadDefaultGLProgram(p, kShaderType_3DPositionNormal);
|
||||
_programs.insert( std::make_pair(GLProgram::SHADER_3D_POSITION_NORMAL, p) );
|
||||
|
||||
p = new GLProgram();
|
||||
loadDefaultGLProgram(p, kShaderType_3DPositionTex_noNormal);
|
||||
_programs.insert( std::make_pair(GLProgram::SHADER_3D_POSITION_TEXTURE_NO_NORMAL, p) );
|
||||
loadDefaultGLProgram(p, kShaderType_3DPositionNormalTex);
|
||||
_programs.insert( std::make_pair(GLProgram::SHADER_3D_POSITION_NORMAL_TEXTURE, p) );
|
||||
|
||||
p = new GLProgram();
|
||||
loadDefaultGLProgram(p, kShaderType_3DSkinPositionTex_noNormal);
|
||||
_programs.insert(std::make_pair(GLProgram::SHADER_3D_SKINPOSITION_TEXTURE_NO_NORMAL, p));
|
||||
loadDefaultGLProgram(p, kShaderType_3DSkinPositionNormalTex);
|
||||
_programs.insert(std::make_pair(GLProgram::SHADER_3D_SKINPOSITION_NORMAL_TEXTURE, p));
|
||||
}
|
||||
|
||||
void GLProgramCache::reloadDefaultGLPrograms()
|
||||
|
@ -320,17 +320,17 @@ void GLProgramCache::reloadDefaultGLPrograms()
|
|||
p->reset();
|
||||
loadDefaultGLProgram(p, kShaderType_3DSkinPositionTex);
|
||||
|
||||
p = getGLProgram(GLProgram::SHADER_3D_POSITION_NO_NORMAL);
|
||||
p = getGLProgram(GLProgram::SHADER_3D_POSITION_NORMAL);
|
||||
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();
|
||||
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();
|
||||
loadDefaultGLProgram(p, kShaderType_3DSkinPositionTex_noNormal);
|
||||
loadDefaultGLProgram(p, kShaderType_3DSkinPositionNormalTex);
|
||||
}
|
||||
|
||||
void GLProgramCache::loadDefaultGLProgram(GLProgram *p, int type)
|
||||
|
@ -393,14 +393,14 @@ void GLProgramCache::loadDefaultGLProgram(GLProgram *p, int type)
|
|||
case kShaderType_3DSkinPositionTex:
|
||||
p->initWithByteArrays(cc3D_SkinPositionTex_vert, cc3D_ColorTex_frag);
|
||||
break;
|
||||
case kShaderType_3DPosition_noNormal:
|
||||
p->initWithByteArrays(cc3D_PositionTexNoNormal_vert, cc3D_ColorNoNormal_frag);
|
||||
case kShaderType_3DPositionNormal:
|
||||
p->initWithByteArrays(cc3D_PositionNormalTex_vert, cc3D_ColorNormal_frag);
|
||||
break;
|
||||
case kShaderType_3DPositionTex_noNormal:
|
||||
p->initWithByteArrays(cc3D_PositionTexNoNormal_vert, cc3D_ColorTexNoNormal_frag);
|
||||
case kShaderType_3DPositionNormalTex:
|
||||
p->initWithByteArrays(cc3D_PositionNormalTex_vert, cc3D_ColorNormalTex_frag);
|
||||
break;
|
||||
case kShaderType_3DSkinPositionTex_noNormal:
|
||||
p->initWithByteArrays(cc3D_SkinPositionTexNoNormal_vert, cc3D_ColorTexNoNormal_frag);
|
||||
case kShaderType_3DSkinPositionNormalTex:
|
||||
p->initWithByteArrays(cc3D_SkinPositionNormalTex_vert, cc3D_ColorNormalTex_frag);
|
||||
break;
|
||||
default:
|
||||
CCLOG("cocos2d: %s:%d, error shader type", __FUNCTION__, __LINE__);
|
||||
|
|
|
@ -3,88 +3,13 @@ const char* cc3D_Color_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);
|
||||
gl_FragColor = u_color;
|
||||
}
|
||||
);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
);
|
|
@ -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);
|
||||
}
|
||||
);
|
|
@ -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);
|
||||
}
|
||||
);
|
|
@ -3,89 +3,13 @@ const char* cc3D_ColorTex_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);
|
||||
{
|
||||
gl_FragColor = texture2D(CC_Texture0, TextureCoordOut) * u_color;
|
||||
}
|
||||
);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
);
|
|
@ -1,20 +1,24 @@
|
|||
|
||||
const char* cc3D_PositionTexNoNormal_vert = STRINGIFY(
|
||||
const char* cc3D_PositionNormalTex_vert = STRINGIFY(
|
||||
|
||||
attribute vec4 a_position;
|
||||
attribute vec2 a_texCoord;
|
||||
|
||||
attribute vec3 a_normal;
|
||||
varying vec2 TextureCoordOut;
|
||||
varying vec4 ePosition;
|
||||
varying vec3 eNormal;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_Position = CC_MVPMatrix * a_position;
|
||||
ePosition = CC_MVMatrix * a_position;
|
||||
eNormal = CC_NormalMatrix * a_normal;
|
||||
TextureCoordOut = a_texCoord;
|
||||
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 vec4 a_blendWeight;
|
||||
|
@ -22,14 +26,18 @@ attribute vec4 a_blendIndex;
|
|||
|
||||
attribute vec2 a_texCoord;
|
||||
|
||||
attribute vec3 a_normal;
|
||||
|
||||
const int SKINNING_JOINT_COUNT = 60;
|
||||
// Uniforms
|
||||
uniform vec4 u_matrixPalette[SKINNING_JOINT_COUNT * 3];
|
||||
|
||||
// Varyings
|
||||
varying vec2 TextureCoordOut;
|
||||
varying vec4 ePosition;
|
||||
varying vec3 eNormal;
|
||||
|
||||
vec4 getPosition()
|
||||
void getPositionAndNormal(out vec4 position, out vec3 normal)
|
||||
{
|
||||
float blendWeight = a_blendWeight[0];
|
||||
|
||||
|
@ -69,23 +77,29 @@ vec4 getPosition()
|
|||
}
|
||||
|
||||
|
||||
vec4 _skinnedPosition;
|
||||
vec4 postion = vec4(a_position, 1.0);
|
||||
_skinnedPosition.x = dot(postion, matrixPalette1);
|
||||
_skinnedPosition.y = dot(postion, matrixPalette2);
|
||||
_skinnedPosition.z = dot(postion, matrixPalette3);
|
||||
_skinnedPosition.w = postion.w;
|
||||
|
||||
return _skinnedPosition;
|
||||
vec4 p = vec4(a_position, 1.0);
|
||||
position.x = dot(p, matrixPalette1);
|
||||
position.y = dot(p, matrixPalette2);
|
||||
position.z = dot(p, matrixPalette3);
|
||||
position.w = p.w;
|
||||
|
||||
vec4 n = vec4(a_normal, 0.0);
|
||||
normal.x = dot(n, matrixPalette1);
|
||||
normal.y = dot(n, matrixPalette2);
|
||||
normal.z = dot(n, matrixPalette3);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 position = getPosition();
|
||||
gl_Position = CC_MVPMatrix * position;
|
||||
|
||||
vec4 position;
|
||||
vec3 normal;
|
||||
getPositionAndNormal(position, normal);
|
||||
|
||||
ePosition = CC_MVMatrix * position;
|
||||
eNormal = CC_NormalMatrix * normal;
|
||||
TextureCoordOut = a_texCoord;
|
||||
TextureCoordOut.y = 1.0 - TextureCoordOut.y;
|
||||
gl_Position = CC_PMatrix * ePosition;
|
||||
}
|
||||
|
||||
);
|
|
@ -3,18 +3,14 @@ const char* cc3D_PositionTex_vert = STRINGIFY(
|
|||
|
||||
attribute vec4 a_position;
|
||||
attribute vec2 a_texCoord;
|
||||
attribute vec3 a_normal;
|
||||
|
||||
varying vec2 TextureCoordOut;
|
||||
varying vec4 ePosition;
|
||||
varying vec3 eNormal;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
ePosition = CC_MVMatrix * a_position;
|
||||
eNormal = CC_NormalMatrix * a_normal;
|
||||
gl_Position = CC_MVPMatrix * a_position;
|
||||
TextureCoordOut = a_texCoord;
|
||||
TextureCoordOut.y = 1.0 - TextureCoordOut.y;
|
||||
gl_Position = CC_PMatrix * ePosition;
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -26,18 +22,14 @@ attribute vec4 a_blendIndex;
|
|||
|
||||
attribute vec2 a_texCoord;
|
||||
|
||||
attribute vec3 a_normal;
|
||||
|
||||
const int SKINNING_JOINT_COUNT = 60;
|
||||
// Uniforms
|
||||
uniform vec4 u_matrixPalette[SKINNING_JOINT_COUNT * 3];
|
||||
|
||||
// Varyings
|
||||
varying vec2 TextureCoordOut;
|
||||
varying vec4 ePosition;
|
||||
varying vec3 eNormal;
|
||||
|
||||
void getPositionAndNormal(out vec4 position, out vec3 normal)
|
||||
vec4 getPosition()
|
||||
{
|
||||
float blendWeight = a_blendWeight[0];
|
||||
|
||||
|
@ -77,29 +69,23 @@ void getPositionAndNormal(out vec4 position, out vec3 normal)
|
|||
}
|
||||
|
||||
|
||||
vec4 p = vec4(a_position, 1.0);
|
||||
position.x = dot(p, matrixPalette1);
|
||||
position.y = dot(p, matrixPalette2);
|
||||
position.z = dot(p, matrixPalette3);
|
||||
position.w = p.w;
|
||||
|
||||
vec4 n = vec4(a_normal, 0.0);
|
||||
normal.x = dot(n, matrixPalette1);
|
||||
normal.y = dot(n, matrixPalette2);
|
||||
normal.z = dot(n, matrixPalette3);
|
||||
vec4 _skinnedPosition;
|
||||
vec4 postion = vec4(a_position, 1.0);
|
||||
_skinnedPosition.x = dot(postion, matrixPalette1);
|
||||
_skinnedPosition.y = dot(postion, matrixPalette2);
|
||||
_skinnedPosition.z = dot(postion, matrixPalette3);
|
||||
_skinnedPosition.w = postion.w;
|
||||
|
||||
return _skinnedPosition;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 position;
|
||||
vec3 normal;
|
||||
getPositionAndNormal(position, normal);
|
||||
|
||||
ePosition = CC_MVMatrix * position;
|
||||
eNormal = CC_NormalMatrix * normal;
|
||||
vec4 position = getPosition();
|
||||
gl_Position = CC_MVPMatrix * position;
|
||||
|
||||
TextureCoordOut = a_texCoord;
|
||||
TextureCoordOut.y = 1.0 - TextureCoordOut.y;
|
||||
gl_Position = CC_PMatrix * ePosition;
|
||||
}
|
||||
|
||||
);
|
|
@ -74,8 +74,8 @@ NS_CC_BEGIN
|
|||
#include "ccShader_3D_PositionTex.vert"
|
||||
#include "ccShader_3D_Color.frag"
|
||||
#include "ccShader_3D_ColorTex.frag"
|
||||
#include "ccShader_3D_PositionTexNoNormal.vert"
|
||||
#include "ccShader_3D_ColorNoNormal.frag"
|
||||
#include "ccShader_3D_ColorTexNoNormal.frag"
|
||||
#include "ccShader_3D_PositionNormalTex.vert"
|
||||
#include "ccShader_3D_ColorNormal.frag"
|
||||
#include "ccShader_3D_ColorNormalTex.frag"
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -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_ColorTex_frag;
|
||||
extern CC_DLL const GLchar * cc3D_Color_frag;
|
||||
extern CC_DLL const GLchar * cc3D_PositionTexNoNormal_vert;
|
||||
extern CC_DLL const GLchar * cc3D_SkinPositionTexNoNormal_vert;
|
||||
extern CC_DLL const GLchar * cc3D_ColorTexNoNormal_frag;
|
||||
extern CC_DLL const GLchar * cc3D_ColorNoNormal_frag;
|
||||
extern CC_DLL const GLchar * cc3D_PositionNormalTex_vert;
|
||||
extern CC_DLL const GLchar * cc3D_SkinPositionNormalTex_vert;
|
||||
extern CC_DLL const GLchar * cc3D_ColorNormalTex_frag;
|
||||
extern CC_DLL const GLchar * cc3D_ColorNormal_frag;
|
||||
// end of shaders group
|
||||
/// @}
|
||||
|
||||
|
|
Loading…
Reference in New Issue