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