Merge changes I776588c1,I7292a2fb into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / graphics / shaders / shadow-map-shader.vert
1 #version 300 es
2
3 precision highp float;
4
5 in vec3 aPosition;
6 in vec2 aTexCoord;
7 in vec4 aVertexColor;
8
9 out mediump vec2 vUV;
10 out lowp vec4 vColor;
11
12 uniform highp mat4 uViewMatrix;
13 uniform highp mat4 uModelMatrix;
14 uniform highp mat4 uProjection;
15
16 #ifdef SKINNING
17   in vec4 aJoints;
18   in vec4 aWeights;
19   #define MAX_BONES 64
20   uniform mat4 uBone[MAX_BONES];
21   uniform mediump vec3 uYDirection;
22 #endif
23
24 #ifdef MORPH
25 #define MAX_BLEND_SHAPE_NUMBER 128
26 uniform int uNumberOfBlendShapes;                                         ///< Total number of blend shapes loaded.
27 uniform highp float uBlendShapeWeight[MAX_BLEND_SHAPE_NUMBER];            ///< The weight of each blend shape.
28 #ifdef MORPH_VERSION_2_0
29 uniform highp float uBlendShapeUnnormalizeFactor;                         ///< Factor used to unnormalize the geometry of the blend shape.
30 #else
31 uniform highp float uBlendShapeUnnormalizeFactor[MAX_BLEND_SHAPE_NUMBER]; ///< Factor used to unnormalize the geometry of the blend shape.
32 #endif
33 uniform highp int uBlendShapeComponentSize;                               ///< The size in the texture of either the vertices, normals or tangents. Used to calculate the offset to address them.
34 #endif
35
36 uniform highp mat4 uShadowLightViewProjectionMatrix;
37
38 void main()
39 {
40   highp vec4 position = vec4(aPosition, 1.0);
41
42 #ifdef MORPH
43   int width = textureSize( sBlendShapeGeometry, 0 ).x;
44
45   highp int blendShapeBufferOffset = 0;
46
47   for( int index = 0; index < uNumberOfBlendShapes; ++index )
48   {
49     highp vec3 diff = vec3(0.0);
50     highp int vertexId = 0;
51     highp int x = 0;
52     highp int y = 0;
53
54 #ifdef MORPH_POSITION
55     // Calculate the index to retrieve the geometry from the texture.
56     vertexId = gl_VertexID + blendShapeBufferOffset;
57     x = vertexId % width;
58     y = vertexId / width;
59
60     // Retrieves the blend shape geometry from the texture, unnormalizes it and multiply by the weight.
61     if( 0.0 != uBlendShapeWeight[index] )
62     {
63 #ifdef MORPH_VERSION_2_0
64        highp float unnormalizeFactor = uBlendShapeUnnormalizeFactor;
65 #else
66        highp float unnormalizeFactor = uBlendShapeUnnormalizeFactor[index];
67 #endif
68
69       diff = uBlendShapeWeight[index] * unnormalizeFactor * ( texelFetch( sBlendShapeGeometry, ivec2(x, y), 0 ).xyz - 0.5 );
70     }
71
72     position.xyz += diff;
73
74     blendShapeBufferOffset += uBlendShapeComponentSize;
75 #endif
76
77 #ifdef MORPH_NORMAL
78     blendShapeBufferOffset += uBlendShapeComponentSize;
79 #endif
80
81 #ifdef MORPH_TANGENT
82     blendShapeBufferOffset += uBlendShapeComponentSize;
83 #endif
84   }
85
86 #endif
87
88 #ifdef SKINNING
89   highp mat4 bone = uBone[int(aJoints.x)] * aWeights.x +
90     uBone[int(aJoints.y)] * aWeights.y +
91     uBone[int(aJoints.z)] * aWeights.z +
92     uBone[int(aJoints.w)] * aWeights.w;
93   position = bone * position;
94
95   highp vec4 positionW = position;
96 #else
97   highp vec4 positionW = uModelMatrix * position;
98 #endif
99
100   // To synchronize View-Projection matrix with pbr shader
101   gl_Position = uShadowLightViewProjectionMatrix * positionW;
102
103 #ifdef FLIP_V
104   vUV = vec2(aTexCoord.x, 1.0 - aTexCoord.y);
105 #else
106   vUV = aTexCoord;
107 #endif
108
109   vColor = aVertexColor;
110 }