[dali_2.0.7] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / resources / dli_pbr.vsh
1 #version 300 es\r
2 \r
3 #ifdef HIGHP\r
4   precision highp float;\r
5 #else\r
6   precision mediump float;\r
7 #endif\r
8 \r
9 in vec3 aPosition;\r
10 in vec2 aTexCoord;\r
11 in vec3 aNormal;\r
12 in vec3 aTangent;\r
13 \r
14 #ifdef MORPH\r
15   uniform sampler2D sBlendShapeGeometry;\r
16 #endif\r
17 \r
18 out vec2 vUV;\r
19 out vec3 vNormal;\r
20 out vec3 vTangent;\r
21 out vec3 vViewVec;\r
22 \r
23 \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
30 \r
31 #ifdef SKINNING\r
32   in vec4 aJoints;\r
33   in vec4 aWeights;\r
34   #define MAX_BONES 64\r
35   uniform mat4 uBone[MAX_BONES];\r
36 #endif\r
37 \r
38 #ifdef MORPH\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
44 #else\r
45 uniform float uBlendShapeUnnormalizeFactor[MAX_BLEND_SHAPE_NUMBER]; ///< Factor used to unnormalize the geometry of the blend shape.\r
46 #endif\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
48 #endif\r
49 \r
50 void main()\r
51 {\r
52   vec4 position = vec4(aPosition, 1.0);\r
53   vec3 normal = aNormal;\r
54   vec3 tangent = aTangent;\r
55 \r
56 #ifdef MORPH\r
57   int width = textureSize( sBlendShapeGeometry, 0 ).x;\r
58 \r
59   int blendShapeBufferOffset = 0;\r
60   for( int index = 0; index < uNumberOfBlendShapes; ++index )\r
61   {\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
67 \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
71     {\r
72 #ifdef MORPH_VERSION_2_0\r
73        float unnormalizeFactor = uBlendShapeUnnormalizeFactor;\r
74 #else\r
75        float unnormalizeFactor = uBlendShapeUnnormalizeFactor[index];\r
76 #endif\r
77 \r
78       diff = uBlendShapeWeight[index] * unnormalizeFactor * ( texelFetch( sBlendShapeGeometry, ivec2(x, y), 0 ).xyz - 0.5 );\r
79     }\r
80 \r
81     position.xyz += diff;\r
82 \r
83     blendShapeBufferOffset += uBlendShapeComponentSize;\r
84 #endif\r
85 \r
86 #ifdef MORPH_NORMAL\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
91 \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
94     {\r
95       diff = uBlendShapeWeight[index] * 2.0 * ( texelFetch( sBlendShapeGeometry, ivec2(x, y), 0 ).xyz - 0.5 );\r
96     }\r
97 \r
98     normal += diff.xyz;\r
99 \r
100     blendShapeBufferOffset += uBlendShapeComponentSize;\r
101 #endif\r
102 \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
108 \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
111     {\r
112       diff = uBlendShapeWeight[index] * 2.0 * ( texelFetch( sBlendShapeGeometry, ivec2(x, y), 0 ).xyz - 0.5 );\r
113     }\r
114 \r
115     tangent += diff.xyz;\r
116 \r
117     blendShapeBufferOffset += uBlendShapeComponentSize;\r
118 #endif\r
119   }\r
120 \r
121 #endif\r
122 \r
123 #ifdef SKINNING\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
131 #endif\r
132 \r
133   vec4 vPosition = uModelMatrix * position;\r
134 \r
135   vNormal = normalize(uNormalMatrix * normal);\r
136 \r
137   vTangent = normalize(uNormalMatrix * tangent);\r
138 \r
139 \r
140   vec4 viewPosition = uViewMatrix * vPosition;\r
141   gl_Position = uProjection * viewPosition;\r
142 \r
143 #ifdef FLIP_V\r
144   vUV = vec2(aTexCoord.x, 1.0 - aTexCoord.y);\r
145 #else\r
146   vUV = aTexCoord;\r
147 #endif\r
148 \r
149   vViewVec = viewPosition.xyz;\r
150 }\r