Merge "Added getter for the shader in Material" into devel/new_mesh
[platform/core/uifw/dali-core.git] / dali / internal / render / shader-source / textured-mesh.txt
1 <VertexShader>
2
3 uniform   mediump mat4    uProjection;
4 uniform   mediump mat4    uModelView;
5 uniform   mediump mat4    uMvpMatrix;
6
7 uniform           bool    uTextureMapped;
8 uniform   mediump vec4    uCustomTextureCoords;
9 attribute highp   vec2    aTexCoord;
10 varying   mediump vec2    vTexCoord;
11
12 uniform   mat3            uModelViewIT;
13 attribute mediump vec3    aNormal;
14 varying   mediump vec3    vNormal;
15
16 attribute mediump vec3    aPosition;
17 varying   mediump vec4    vVertex;
18
19 #define MAX_BONES_PER_MESH  12
20
21 #ifdef USE_BONES
22 uniform   int             uBoneCount;
23 uniform   mediump mat4    uBoneMatrices[MAX_BONES_PER_MESH];
24 uniform   mediump mat3    uBoneMatricesIT[MAX_BONES_PER_MESH];
25 attribute mediump vec4    aBoneWeights;
26 attribute mediump vec4    aBoneIndices;
27 #endif
28
29 void main()
30 {
31   mediump vec4 vertexPosition = vec4(aPosition, 1.0);
32
33 #ifdef USE_BONES
34   if(uBoneCount > 0)
35   {
36     mediump vec4 boneWeights = aBoneWeights;
37     mediump ivec4 boneIndices = ivec4(aBoneIndices);
38     mediump vec3 vertexNormal;
39
40     // re-calculate the final weight
41     boneWeights.w = 1.0 - dot(boneWeights.xyz, vec3(1.0, 1.0, 1.0));
42
43     mediump vec4 bonePos = (uBoneMatrices[boneIndices.x] * vertexPosition) * boneWeights.x;
44     bonePos     += (uBoneMatrices[boneIndices.y] * vertexPosition) * boneWeights.y;
45     bonePos     += (uBoneMatrices[boneIndices.z] * vertexPosition) * boneWeights.z;
46     bonePos     += (uBoneMatrices[boneIndices.w] * vertexPosition) * boneWeights.w;
47
48     vertexNormal  = (uBoneMatricesIT[boneIndices.x] * aNormal) * boneWeights.x;
49     vertexNormal += (uBoneMatricesIT[boneIndices.y] * aNormal) * boneWeights.y;
50     vertexNormal += (uBoneMatricesIT[boneIndices.z] * aNormal) * boneWeights.z;
51     vertexNormal += (uBoneMatricesIT[boneIndices.w] * aNormal) * boneWeights.w;
52     vertexNormal =  normalize(vertexNormal);
53
54     vertexPosition = uProjection * bonePos;
55     vVertex = bonePos;
56     vNormal = vertexNormal;
57   }
58   else
59   {
60 #endif
61     vertexPosition = uMvpMatrix * vec4(aPosition, 1.0);
62     vVertex = uModelView * vec4(aPosition, 1.0);
63     vNormal = uModelViewIT * aNormal;
64 #ifdef USE_BONES
65   }
66 #endif
67   gl_Position = vertexPosition;
68
69   mediump vec2 start = uCustomTextureCoords.xy;
70   mediump vec2 scale = uCustomTextureCoords.zw;
71   vTexCoord = vec2(start.x + aTexCoord.x * scale.x, start.y + aTexCoord.y * scale.y);
72 }
73
74 </VertexShader>
75
76 <FragmentShader>
77
78 struct Material
79 {
80   mediump float mOpacity;
81   mediump float mShininess;
82   lowp    vec4  mAmbient;
83   lowp    vec4  mDiffuse;
84   lowp    vec4  mSpecular;
85   lowp    vec4  mEmissive;
86 };
87
88 uniform sampler2D     sTexture;
89 uniform sampler2D     sOpacityTexture;
90 uniform sampler2D     sNormalMapTexture;
91 uniform sampler2D     sEffect;
92 varying mediump vec2 vTexCoord;
93
94 uniform Material      uMaterial;
95
96 uniform lowp  vec4    uColor;
97 varying highp vec4    vVertex;
98 varying highp vec3    vNormal;
99
100 void main()
101 {
102   // sample the texture for the initial color
103   mediump vec4 fragColor = texture2D(sTexture, vTexCoord);
104
105   // apply material properties
106   fragColor.rgb *= (uMaterial.mAmbient + uMaterial.mDiffuse).rgb;
107
108   // apply material alpha/opacity to alpha channel
109   fragColor.a *= uMaterial.mOpacity * uMaterial.mDiffuse.a;
110
111   // and finally, apply Actor color
112   fragColor *= uColor;
113
114   gl_FragColor = fragColor;
115 }
116
117 </FragmentShader>