axmol/cocos/renderer/ccShader_3D_PositionNormalT...

170 lines
4.8 KiB
GLSL
Raw Normal View History

2014-08-21 10:33:16 +08:00
2014-08-21 11:33:00 +08:00
const char* cc3D_PositionNormalTex_vert = STRINGIFY(
2014-09-22 18:08:58 +08:00
\n#if (MAX_POINT_LIGHT_NUM > 0)\n
uniform vec3 u_PointLightSourcePosition[MAX_POINT_LIGHT_NUM];
\n#endif\n
\n#if (MAX_SPOT_LIGHT_NUM > 0)\n
uniform vec3 u_SpotLightSourcePosition[MAX_SPOT_LIGHT_NUM];
\n#endif\n
2014-08-21 10:33:16 +08:00
attribute vec4 a_position;
attribute vec2 a_texCoord;
2014-08-21 11:33:00 +08:00
attribute vec3 a_normal;
2014-08-21 10:33:16 +08:00
varying vec2 TextureCoordOut;
2014-08-27 16:26:01 +08:00
2014-09-22 18:08:58 +08:00
\n#if MAX_POINT_LIGHT_NUM\n
varying vec3 v_vertexToPointLightDirection[MAX_POINT_LIGHT_NUM];
2014-08-27 16:26:01 +08:00
\n#endif\n
2014-09-22 18:08:58 +08:00
\n#if MAX_SPOT_LIGHT_NUM\n
varying vec3 v_vertexToSpotLightDirection[MAX_SPOT_LIGHT_NUM];
2014-08-27 16:26:01 +08:00
\n#endif\n
2014-09-22 18:08:58 +08:00
\n#if ((MAX_DIRECTIONAL_LIGHT_NUM > 0) || (MAX_POINT_LIGHT_NUM > 0) || (MAX_SPOT_LIGHT_NUM > 0))\n
2014-08-27 16:26:01 +08:00
varying vec3 v_normal;
2014-08-28 13:04:49 +08:00
\n#endif\n
2014-08-21 10:33:16 +08:00
void main(void)
{
2014-08-27 16:26:01 +08:00
vec4 ePosition = CC_MVMatrix * a_position;
2014-09-22 18:08:58 +08:00
\n#if (MAX_POINT_LIGHT_NUM > 0)\n
for (int i = 0; i < MAX_POINT_LIGHT_NUM; ++i)
2014-08-27 16:26:01 +08:00
{
2014-09-22 18:08:58 +08:00
v_vertexToPointLightDirection[i] = u_PointLightSourcePosition[i].xyz - ePosition.xyz;
2014-08-27 16:26:01 +08:00
}
\n#endif\n
2014-09-22 18:08:58 +08:00
\n#if (MAX_SPOT_LIGHT_NUM > 0)\n
for (int i = 0; i < MAX_SPOT_LIGHT_NUM; ++i)
2014-08-27 16:26:01 +08:00
{
2014-09-22 18:08:58 +08:00
v_vertexToSpotLightDirection[i] = u_SpotLightSourcePosition[i] - ePosition.xyz;
2014-08-27 16:26:01 +08:00
}
\n#endif\n
2014-09-22 18:08:58 +08:00
\n#if ((MAX_DIRECTIONAL_LIGHT_NUM > 0) || (MAX_POINT_LIGHT_NUM > 0) || (MAX_SPOT_LIGHT_NUM > 0))\n
2014-08-27 16:26:01 +08:00
v_normal = CC_NormalMatrix * a_normal;
2014-08-26 14:18:22 +08:00
\n#endif\n
2014-08-27 16:26:01 +08:00
2014-08-21 10:33:16 +08:00
TextureCoordOut = a_texCoord;
TextureCoordOut.y = 1.0 - TextureCoordOut.y;
2014-08-21 11:33:00 +08:00
gl_Position = CC_PMatrix * ePosition;
2014-08-21 10:33:16 +08:00
}
);
2014-08-21 11:33:00 +08:00
const char* cc3D_SkinPositionNormalTex_vert = STRINGIFY(
2014-09-22 18:08:58 +08:00
\n#if (MAX_POINT_LIGHT_NUM > 0)\n
uniform vec3 u_PointLightSourcePosition[MAX_POINT_LIGHT_NUM];
\n#endif\n
\n#if (MAX_SPOT_LIGHT_NUM > 0)\n
uniform vec3 u_SpotLightSourcePosition[MAX_SPOT_LIGHT_NUM];
\n#endif\n
2014-08-21 10:33:16 +08:00
attribute vec3 a_position;
attribute vec4 a_blendWeight;
attribute vec4 a_blendIndex;
attribute vec2 a_texCoord;
2014-08-21 11:33:00 +08:00
attribute vec3 a_normal;
2014-08-21 10:33:16 +08:00
const int SKINNING_JOINT_COUNT = 60;
// Uniforms
uniform vec4 u_matrixPalette[SKINNING_JOINT_COUNT * 3];
// Varyings
varying vec2 TextureCoordOut;
2014-08-27 16:26:01 +08:00
2014-09-22 18:08:58 +08:00
\n#if MAX_POINT_LIGHT_NUM\n
varying vec3 v_vertexToPointLightDirection[MAX_POINT_LIGHT_NUM];
2014-08-27 16:26:01 +08:00
\n#endif\n
2014-09-22 18:08:58 +08:00
\n#if MAX_SPOT_LIGHT_NUM\n
varying vec3 v_vertexToSpotLightDirection[MAX_SPOT_LIGHT_NUM];
2014-08-27 16:26:01 +08:00
\n#endif\n
varying vec3 v_normal;
2014-08-21 10:33:16 +08:00
2014-08-21 11:33:00 +08:00
void getPositionAndNormal(out vec4 position, out vec3 normal)
2014-08-21 10:33:16 +08:00
{
float blendWeight = a_blendWeight[0];
int matrixIndex = int (a_blendIndex[0]) * 3;
vec4 matrixPalette1 = u_matrixPalette[matrixIndex] * blendWeight;
vec4 matrixPalette2 = u_matrixPalette[matrixIndex + 1] * blendWeight;
vec4 matrixPalette3 = u_matrixPalette[matrixIndex + 2] * blendWeight;
blendWeight = a_blendWeight[1];
if (blendWeight > 0.0)
{
matrixIndex = int(a_blendIndex[1]) * 3;
matrixPalette1 += u_matrixPalette[matrixIndex] * blendWeight;
matrixPalette2 += u_matrixPalette[matrixIndex + 1] * blendWeight;
matrixPalette3 += u_matrixPalette[matrixIndex + 2] * blendWeight;
}
blendWeight = a_blendWeight[2];
if (blendWeight > 0.0)
{
matrixIndex = int(a_blendIndex[2]) * 3;
matrixPalette1 += u_matrixPalette[matrixIndex] * blendWeight;
matrixPalette2 += u_matrixPalette[matrixIndex + 1] * blendWeight;
matrixPalette3 += u_matrixPalette[matrixIndex + 2] * blendWeight;
}
blendWeight = a_blendWeight[3];
if (blendWeight > 0.0)
{
matrixIndex = int(a_blendIndex[3]) * 3;
matrixPalette1 += u_matrixPalette[matrixIndex] * blendWeight;
matrixPalette2 += u_matrixPalette[matrixIndex + 1] * blendWeight;
matrixPalette3 += u_matrixPalette[matrixIndex + 2] * blendWeight;
}
2014-08-21 11:33:00 +08:00
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;
2014-09-22 18:08:58 +08:00
\n#if ((MAX_DIRECTIONAL_LIGHT_NUM > 0) || (MAX_POINT_LIGHT_NUM > 0) || (MAX_SPOT_LIGHT_NUM > 0))\n
2014-08-27 19:12:49 +08:00
vec4 n = vec4(a_normal, 0.0);
2014-08-21 11:33:00 +08:00
normal.x = dot(n, matrixPalette1);
normal.y = dot(n, matrixPalette2);
normal.z = dot(n, matrixPalette3);
2014-08-26 14:18:22 +08:00
\n#endif\n
2014-08-21 10:33:16 +08:00
}
void main()
{
2014-08-21 11:33:00 +08:00
vec4 position;
vec3 normal;
getPositionAndNormal(position, normal);
2014-08-27 16:26:01 +08:00
vec4 ePosition = CC_MVMatrix * position;
2014-09-22 18:08:58 +08:00
\n#if (MAX_POINT_LIGHT_NUM > 0)\n
for (int i = 0; i < MAX_POINT_LIGHT_NUM; ++i)
2014-08-27 16:26:01 +08:00
{
2014-09-22 18:08:58 +08:00
v_vertexToPointLightDirection[i] = u_PointLightSourcePosition[i].xyz- ePosition.xyz;
2014-08-27 16:26:01 +08:00
}
\n#endif\n
2014-09-22 18:08:58 +08:00
\n#if (MAX_SPOT_LIGHT_NUM > 0)\n
for (int i = 0; i < MAX_SPOT_LIGHT_NUM; ++i)
2014-08-27 16:26:01 +08:00
{
2014-09-22 18:08:58 +08:00
v_vertexToSpotLightDirection[i] = u_SpotLightSourcePosition[i] - ePosition.xyz;
2014-08-27 16:26:01 +08:00
}
\n#endif\n
2014-09-22 18:08:58 +08:00
\n#if ((MAX_DIRECTIONAL_LIGHT_NUM > 0) || (MAX_POINT_LIGHT_NUM > 0) || (MAX_SPOT_LIGHT_NUM > 0))\n
2014-08-27 16:26:01 +08:00
v_normal = CC_NormalMatrix * normal;
2014-08-26 14:18:22 +08:00
\n#endif\n
2014-08-27 16:26:01 +08:00
2014-08-21 10:33:16 +08:00
TextureCoordOut = a_texCoord;
TextureCoordOut.y = 1.0 - TextureCoordOut.y;
2014-08-21 11:33:00 +08:00
gl_Position = CC_PMatrix * ePosition;
2014-08-21 10:33:16 +08:00
}
);