1 #define MORPH defined(MORPH_POSITION) || defined(MORPH_NORMAL) || defined(MORPH_TANGENT)
3 #define ADD_EXTRA_SKINNING_ATTRIBUTES
4 #define ADD_EXTRA_WEIGHTS
10 INPUT vec4 aVertexColor;
13 INPUT float aVertexID;
19 ADD_EXTRA_SKINNING_ATTRIBUTES;
23 uniform highp sampler2D sBlendShapeGeometry;
25 uniform int uBlendShapeGeometryWidth;
26 uniform int uBlendShapeGeometryHeight;
30 OUTPUT mediump vec2 vUV;
31 OUTPUT lowp vec4 vColor;
33 uniform highp mat4 uViewMatrix;
34 uniform highp mat4 uModelMatrix;
35 uniform highp mat4 uProjection;
41 uniform mat4 uBone[MAX_BONES];
44 layout(std140) uniform Bones
46 mat4 uBone[MAX_BONES];
50 uniform mediump vec3 uYDirection;
54 #define MAX_BLEND_SHAPE_NUMBER 256
55 uniform int uNumberOfBlendShapes; ///< Total number of blend shapes loaded.
56 uniform highp float uBlendShapeWeight[MAX_BLEND_SHAPE_NUMBER]; ///< The weight of each blend shape.
57 #ifdef MORPH_VERSION_2_0
58 uniform highp float uBlendShapeUnnormalizeFactor; ///< Factor used to unnormalize the geometry of the blend shape.
60 uniform highp float uBlendShapeUnnormalizeFactor[MAX_BLEND_SHAPE_NUMBER]; ///< Factor used to unnormalize the geometry of the blend shape.
62 uniform highp int uBlendShapeComponentSize; ///< The size in the texture of either the vertices, normals or tangents. Used to calculate the offset to address them.
65 uniform highp mat4 uShadowLightViewProjectionMatrix;
69 highp vec4 position = vec4(aPosition, 1.0);
74 int width = uBlendShapeGeometryWidth;
76 int width = textureSize( sBlendShapeGeometry, 0 ).x;
79 highp int blendShapeBufferOffset = 0;
82 highp float blendShapeWidth = float(uBlendShapeGeometryWidth);
83 highp float blendShapeHeight = float(uBlendShapeGeometryHeight);
84 highp float invertBlendShapeWidth = 1.0 / blendShapeWidth;
85 highp float invertBlendShapeHeight = 1.0 / blendShapeHeight;
88 for( int index = 0; index < uNumberOfBlendShapes; ++index )
90 highp vec3 diff = vec3(0.0);
91 highp int vertexId = 0;
94 highp float weight = clamp(uBlendShapeWeight[index], 0.0, 1.0);
97 // Calculate the index to retrieve the geometry from the texture.
99 vertexId = int(floor(aVertexID + 0.5)) + blendShapeBufferOffset;
100 y = vertexId / width;
101 x = vertexId - y * width;
103 vertexId = gl_VertexID + blendShapeBufferOffset;
104 x = vertexId % width;
105 y = vertexId / width;
108 // Retrieves the blend shape geometry from the texture, unnormalizes it and multiply by the weight.
109 if( 0.0 != uBlendShapeWeight[index] )
111 #ifdef MORPH_VERSION_2_0
112 highp float unnormalizeFactor = uBlendShapeUnnormalizeFactor;
114 highp float unnormalizeFactor = uBlendShapeUnnormalizeFactor[index];
117 #ifdef SL_VERSION_LOW
118 highp float floatX = float(x) + 0.5;
119 highp float floatY = float(y) + 0.5;
120 diff = weight * unnormalizeFactor * ( texture2D( sBlendShapeGeometry, vec2(floatX * invertBlendShapeWidth, floatY * invertBlendShapeHeight) ).xyz - 0.5 );
122 diff = weight * unnormalizeFactor * ( texelFetch( sBlendShapeGeometry, ivec2(x, y), 0 ).xyz - 0.5 );
126 position.xyz += diff;
128 blendShapeBufferOffset += uBlendShapeComponentSize;
132 blendShapeBufferOffset += uBlendShapeComponentSize;
136 blendShapeBufferOffset += uBlendShapeComponentSize;
143 highp mat4 bone = uBone[int(aJoints0.x)] * aWeights0.x +
144 uBone[int(aJoints0.y)] * aWeights0.y +
145 uBone[int(aJoints0.z)] * aWeights0.z +
146 uBone[int(aJoints0.w)] * aWeights0.w;
150 position = bone * position;
151 highp vec4 positionW = position;
153 highp vec4 positionW = uModelMatrix * position;
156 // To synchronize View-Projection matrix with pbr shader
157 gl_Position = uShadowLightViewProjectionMatrix * positionW;
160 vUV = vec2(aTexCoord.x, 1.0 - aTexCoord.y);
165 vColor = aVertexColor;