Make visualOffset as Absolute scale.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / graphics / shaders / mesh-visual-normal-map-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 mat4 uViewMatrix;
13 uniform mediump mat3 uNormalMatrix;
14 uniform mediump mat4 uObjectMatrix;
15 uniform mediump vec3 lightPosition;
16 uniform mediump vec2 uStageOffset;
17
18 //Visual size and offset
19 uniform mediump vec2 offset;
20 uniform mediump vec2 size;
21 uniform mediump vec4 offsetSizeMode;
22 uniform mediump vec2 origin;
23 uniform mediump vec2 anchorPoint;
24
25 vec4 ComputeVertexPosition()
26 {
27   vec2 visualSize = mix(size * uSize.xy, size, offsetSizeMode.zw );
28   float scaleFactor = min( visualSize.x, visualSize.y );
29   vec3 originFlipY =vec3(origin.x, -origin.y, 0.0);
30   vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0);
31   vec3 visualOffset = vec3( offset * offsetSizeMode.xy + offset * uSize.xy * (1.0 - offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);
32   return vec4( (aPosition + anchorPointFlipY)*scaleFactor + visualOffset + originFlipY * uSize, 1.0 );
33 }
34
35 void main()
36 {
37   vec4 normalisedVertexPosition = ComputeVertexPosition();
38   vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;
39   vertexPosition = uMvpMatrix * vertexPosition;
40
41   vec4 mvVertexPosition = uModelView * normalisedVertexPosition;
42
43   vec3 tangent = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aTangent );
44   vec3 binormal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aBiNormal );
45   vec3 normal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aNormal );
46
47   vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );
48   mvLightPosition = uViewMatrix * mvLightPosition;
49   vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );
50   vLightDirection.x = dot( vectorToLight, tangent );
51   vLightDirection.y = dot( vectorToLight, binormal );
52   vLightDirection.z = dot( vectorToLight, normal );
53
54   vec3 viewDirection = normalize( -mvVertexPosition.xyz );
55   vec3 halfVector = normalize( viewDirection + vectorToLight );
56   vHalfVector.x = dot( halfVector, tangent );
57   vHalfVector.y = dot( halfVector, binormal );
58   vHalfVector.z = dot( halfVector, normal );
59
60   vTexCoord = aTexCoord;
61   gl_Position = vertexPosition;
62 }