6 precision mediump float;
15 uniform sampler2D sBlendShapeGeometry;
23 uniform highp mat4 uMvpMatrix;
24 uniform highp mat4 uViewMatrix;
25 uniform mat3 uNormalMatrix;
26 uniform mat4 uModelMatrix;
27 uniform mat4 uModelView;
28 uniform mat4 uProjection;
34 uniform mat4 uBone[MAX_BONES];
38 #define MAX_BLEND_SHAPE_NUMBER 128
39 uniform int uNumberOfBlendShapes; ///< Total number of blend shapes loaded.
40 uniform float uBlendShapeWeight[MAX_BLEND_SHAPE_NUMBER]; ///< The weight of each blend shape.
41 #ifdef MORPH_VERSION_2_0
42 uniform float uBlendShapeUnnormalizeFactor; ///< Factor used to unnormalize the geometry of the blend shape.
44 uniform float uBlendShapeUnnormalizeFactor[MAX_BLEND_SHAPE_NUMBER]; ///< Factor used to unnormalize the geometry of the blend shape.
46 uniform int uBlendShapeComponentSize; ///< The size in the texture of either the vertices, normals or tangents. Used to calculate the offset to address them.
51 vec4 position = vec4(aPosition, 1.0);
52 vec3 normal = aNormal;
53 vec3 tangent = aTangent;
56 int width = textureSize( sBlendShapeGeometry, 0 ).x;
58 int blendShapeBufferOffset = 0;
59 for( int index = 0; index < uNumberOfBlendShapes; ++index )
62 // Calculate the index to retrieve the geometry from the texture.
63 int vertexId = gl_VertexID + blendShapeBufferOffset;
64 int x = vertexId % width;
65 int y = vertexId / width;
67 vec3 diff = vec3(0.0);
68 // Retrieves the blend shape geometry from the texture, unnormalizes it and multiply by the weight.
69 if( 0.0 != uBlendShapeWeight[index] )
71 #ifdef MORPH_VERSION_2_0
72 float unnormalizeFactor = uBlendShapeUnnormalizeFactor;
74 float unnormalizeFactor = uBlendShapeUnnormalizeFactor[index];
77 diff = uBlendShapeWeight[index] * unnormalizeFactor * ( texelFetch( sBlendShapeGeometry, ivec2(x, y), 0 ).xyz - 0.5 );
82 blendShapeBufferOffset += uBlendShapeComponentSize;
86 // Calculate the index to retrieve the normal from the texture.
87 vertexId = gl_VertexID + blendShapeBufferOffset;
91 // Retrieves the blend shape normal from the texture, unnormalizes it and multiply by the weight.
92 if( 0.0 != uBlendShapeWeight[index] )
94 diff = uBlendShapeWeight[index] * 2.0 * ( texelFetch( sBlendShapeGeometry, ivec2(x, y), 0 ).xyz - 0.5 );
99 blendShapeBufferOffset += uBlendShapeComponentSize;
103 // Calculate the index to retrieve the tangent from the texture.
104 vertexId = gl_VertexID + blendShapeBufferOffset;
105 x = vertexId % width;
106 y = vertexId / width;
108 // Retrieves the blend shape tangent from the texture, unnormalizes it and multiply by the weight.
109 if( 0.0 != uBlendShapeWeight[index] )
111 diff = uBlendShapeWeight[index] * 2.0 * ( texelFetch( sBlendShapeGeometry, ivec2(x, y), 0 ).xyz - 0.5 );
116 blendShapeBufferOffset += uBlendShapeComponentSize;
123 mat4 bone = uBone[int(aJoints.x)] * aWeights.x +
124 uBone[int(aJoints.y)] * aWeights.y +
125 uBone[int(aJoints.z)] * aWeights.z +
126 uBone[int(aJoints.w)] * aWeights.w;
127 position = bone * position;
128 normal = (bone * vec4(normal, 0.0)).xyz;
129 tangent = (bone * vec4(tangent, 0.0)).xyz;
132 vec4 vPosition = uModelMatrix * position;
134 vNormal = normalize(uNormalMatrix * normal);
136 vTangent = normalize(uNormalMatrix * tangent);
139 vec4 viewPosition = uViewMatrix * vPosition;
140 gl_Position = uProjection * viewPosition;
143 vUV = vec2(aTexCoord.x, 1.0 - aTexCoord.y);
148 vViewVec = viewPosition.xyz;