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