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