Shader compilation tool for dali-toolkit
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / graphics / shaders / model3d-view-nrmmap-shader.vert
1 attribute highp vec3 aPosition;
2 attribute highp vec2 aTexCoord;
3 attribute highp vec3 aNormal;
4 attribute highp vec3 aTangent;
5 attribute highp vec3 aBiNormal;
6 varying mediump vec2 vTexCoord;
7 varying mediump vec3 vLightDirection;
8 varying mediump vec3 vHalfVector;
9 uniform mediump vec3 uSize;
10 uniform mediump mat4 uMvpMatrix;
11 uniform mediump mat4 uModelView;
12 uniform mediump mat3 uNormalMatrix;
13 uniform mediump mat4 uObjectMatrix;
14 uniform mediump vec3 uLightPosition;
15
16 void main()
17 {
18   vec4 vertexPosition = vec4(aPosition*min(uSize.x, uSize.y), 1.0);
19   vertexPosition = uObjectMatrix * vertexPosition;
20   vertexPosition = uMvpMatrix * vertexPosition;
21
22   vec4 vertPos = uModelView * vec4(aPosition.xyz, 1.0);
23   vec4 lightPos = uModelView * vec4(uLightPosition, 1.0);
24
25   vec3 tangent = normalize(uNormalMatrix * aTangent);
26   vec3 binormal = normalize(uNormalMatrix * aBiNormal);
27   vec3 normal = normalize(uNormalMatrix * aNormal);
28
29   vec3 vecToLight = normalize( lightPos.xyz - vertPos.xyz );
30   vLightDirection.x = dot(vecToLight, tangent);
31   vLightDirection.y = dot(vecToLight, binormal);
32   vLightDirection.z = dot(vecToLight, normal);
33
34   vec3 viewDir = normalize(-vertPos.xyz);
35   vec3 halfVector = normalize(viewDir + vecToLight);
36   vHalfVector.x = dot(halfVector, tangent);
37   vHalfVector.y = dot(halfVector, binormal);
38   vHalfVector.z = dot(halfVector, normal);
39
40   vTexCoord = aTexCoord;
41   gl_Position = vertexPosition;
42 }