6 precision mediump float;
15 uniform sampler2D sBlendShapeGeometry;
24 uniform highp mat4 uMvpMatrix;
25 uniform highp mat4 uViewMatrix;
26 uniform mat3 uNormalMatrix;
27 uniform mat4 uModelMatrix;
28 uniform mat4 uModelView;
29 uniform mat4 uProjection;
35 uniform mat4 uBone[MAX_BONES];
39 #define MAX_BLEND_SHAPE_NUMBER 128
40 uniform int uNumberOfBlendShapes; ///< Total number of blend shapes loaded.
41 uniform float uBlendShapeWeight[MAX_BLEND_SHAPE_NUMBER]; ///< The weight of each blend shape.
42 #ifdef MORPH_VERSION_2_0
43 uniform float uBlendShapeUnnormalizeFactor; ///< Factor used to unnormalize the geometry of the blend shape.
45 uniform float uBlendShapeUnnormalizeFactor[MAX_BLEND_SHAPE_NUMBER]; ///< Factor used to unnormalize the geometry of the blend shape.
47 uniform int uBlendShapeComponentSize; ///< The size in the texture of either the vertices, normals or tangents. Used to calculate the offset to address them.
52 vec4 position = vec4(aPosition, 1.0);
53 vec3 normal = aNormal;
54 vec3 tangent = aTangent;
57 int width = textureSize( sBlendShapeGeometry, 0 ).x;
59 int blendShapeBufferOffset = 0;
60 for( int index = 0; index < uNumberOfBlendShapes; ++index )
63 // Calculate the index to retrieve the geometry from the texture.
64 int vertexId = gl_VertexID + blendShapeBufferOffset;
65 int x = vertexId % width;
66 int y = vertexId / width;
68 vec3 diff = vec3(0.0);
69 // Retrieves the blend shape geometry from the texture, unnormalizes it and multiply by the weight.
70 if( 0.0 != uBlendShapeWeight[index] )
72 #ifdef MORPH_VERSION_2_0
73 float unnormalizeFactor = uBlendShapeUnnormalizeFactor;
75 float unnormalizeFactor = uBlendShapeUnnormalizeFactor[index];
78 diff = uBlendShapeWeight[index] * unnormalizeFactor * ( texelFetch( sBlendShapeGeometry, ivec2(x, y), 0 ).xyz - 0.5 );
83 blendShapeBufferOffset += uBlendShapeComponentSize;
87 // Calculate the index to retrieve the normal from the texture.
88 vertexId = gl_VertexID + blendShapeBufferOffset;
92 // Retrieves the blend shape normal from the texture, unnormalizes it and multiply by the weight.
93 if( 0.0 != uBlendShapeWeight[index] )
95 diff = uBlendShapeWeight[index] * 2.0 * ( texelFetch( sBlendShapeGeometry, ivec2(x, y), 0 ).xyz - 0.5 );
100 blendShapeBufferOffset += uBlendShapeComponentSize;
104 // Calculate the index to retrieve the tangent from the texture.
105 vertexId = gl_VertexID + blendShapeBufferOffset;
106 x = vertexId % width;
107 y = vertexId / width;
109 // Retrieves the blend shape tangent from the texture, unnormalizes it and multiply by the weight.
110 if( 0.0 != uBlendShapeWeight[index] )
112 diff = uBlendShapeWeight[index] * 2.0 * ( texelFetch( sBlendShapeGeometry, ivec2(x, y), 0 ).xyz - 0.5 );
117 blendShapeBufferOffset += uBlendShapeComponentSize;
124 mat4 bone = uBone[int(aJoints.x)] * aWeights.x +
125 uBone[int(aJoints.y)] * aWeights.y +
126 uBone[int(aJoints.z)] * aWeights.z +
127 uBone[int(aJoints.w)] * aWeights.w;
128 position = bone * position;
129 normal = (bone * vec4(normal, 0.0)).xyz;
130 tangent = (bone * vec4(tangent, 0.0)).xyz;
132 normal = normalize(normal);
133 tangent = normalize(tangent);
134 vec4 vPosition = position;
136 vec4 vPosition = uModelMatrix * position;
139 vNormal = normalize(uNormalMatrix * normal);
141 vTangent = normalize(uNormalMatrix * tangent);
144 vec4 viewPosition = uViewMatrix * vPosition;
145 gl_Position = uProjection * viewPosition;
148 vUV = vec2(aTexCoord.x, 1.0 - aTexCoord.y);
153 vViewVec = viewPosition.xyz;