2 #define ADD_EXTRA_SKINNING_ATTRIBUTES
3 #define ADD_EXTRA_WEIGHTS
9 INPUT vec4 aVertexColor;
12 INPUT float aVertexID;
18 ADD_EXTRA_SKINNING_ATTRIBUTES;
22 uniform highp sampler2D sBlendShapeGeometry;
24 uniform int uBlendShapeGeometryWidth;
25 uniform int uBlendShapeGeometryHeight;
29 OUTPUT mediump vec2 vUV;
30 OUTPUT lowp vec4 vColor;
32 uniform highp mat4 uViewMatrix;
33 uniform highp mat4 uModelMatrix;
34 uniform highp mat4 uProjection;
40 uniform mat4 uBone[MAX_BONES];
43 layout(std140) uniform Bones
45 mat4 uBone[MAX_BONES];
49 uniform mediump vec3 uYDirection;
53 #define MAX_BLEND_SHAPE_NUMBER 256
54 uniform int uNumberOfBlendShapes; ///< Total number of blend shapes loaded.
55 uniform highp float uBlendShapeWeight[MAX_BLEND_SHAPE_NUMBER]; ///< The weight of each blend shape.
56 #ifdef MORPH_VERSION_2_0
57 uniform highp float uBlendShapeUnnormalizeFactor; ///< Factor used to unnormalize the geometry of the blend shape.
59 uniform highp float uBlendShapeUnnormalizeFactor[MAX_BLEND_SHAPE_NUMBER]; ///< Factor used to unnormalize the geometry of the blend shape.
61 uniform highp int uBlendShapeComponentSize; ///< The size in the texture of either the vertices, normals or tangents. Used to calculate the offset to address them.
64 uniform highp mat4 uShadowLightViewProjectionMatrix;
68 highp vec4 position = vec4(aPosition, 1.0);
73 int width = uBlendShapeGeometryWidth;
75 int width = textureSize( sBlendShapeGeometry, 0 ).x;
78 highp int blendShapeBufferOffset = 0;
81 highp float blendShapeWidth = float(uBlendShapeGeometryWidth);
82 highp float blendShapeHeight = float(uBlendShapeGeometryHeight);
83 highp float invertBlendShapeWidth = 1.0 / blendShapeWidth;
84 highp float invertBlendShapeHeight = 1.0 / blendShapeHeight;
87 for( int index = 0; index < uNumberOfBlendShapes; ++index )
89 highp vec3 diff = vec3(0.0);
90 highp int vertexId = 0;
93 highp float weight = clamp(uBlendShapeWeight[index], 0.0, 1.0);
96 // Calculate the index to retrieve the geometry from the texture.
98 vertexId = int(floor(aVertexID + 0.5)) + blendShapeBufferOffset;
100 x = vertexId - y * width;
102 vertexId = gl_VertexID + blendShapeBufferOffset;
103 x = vertexId % width;
104 y = vertexId / width;
107 // Retrieves the blend shape geometry from the texture, unnormalizes it and multiply by the weight.
108 if( 0.0 != uBlendShapeWeight[index] )
110 #ifdef MORPH_VERSION_2_0
111 highp float unnormalizeFactor = uBlendShapeUnnormalizeFactor;
113 highp float unnormalizeFactor = uBlendShapeUnnormalizeFactor[index];
116 #ifdef SL_VERSION_LOW
117 highp float floatX = float(x) + 0.5;
118 highp float floatY = float(y) + 0.5;
119 diff = weight * unnormalizeFactor * ( texture2D( sBlendShapeGeometry, vec2(floatX * invertBlendShapeWidth, floatY * invertBlendShapeHeight) ).xyz - 0.5 );
121 diff = weight * unnormalizeFactor * ( texelFetch( sBlendShapeGeometry, ivec2(x, y), 0 ).xyz - 0.5 );
125 position.xyz += diff;
127 blendShapeBufferOffset += uBlendShapeComponentSize;
131 blendShapeBufferOffset += uBlendShapeComponentSize;
135 blendShapeBufferOffset += uBlendShapeComponentSize;
142 highp mat4 bone = uBone[int(aJoints0.x)] * aWeights0.x +
143 uBone[int(aJoints0.y)] * aWeights0.y +
144 uBone[int(aJoints0.z)] * aWeights0.z +
145 uBone[int(aJoints0.w)] * aWeights0.w;
149 position = bone * position;
150 highp vec4 positionW = position;
152 highp vec4 positionW = uModelMatrix * position;
155 // To synchronize View-Projection matrix with pbr shader
156 gl_Position = uShadowLightViewProjectionMatrix * positionW;
159 vUV = vec2(aTexCoord.x, 1.0 - aTexCoord.y);
164 vColor = aVertexColor;