summaryrefslogtreecommitdiff
path: root/src/modules/evas/engines/gl_common/shader_3d/phong_vert.shd
blob: fb2c5d4c51c94555015b4903684ecc5203449c27 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
uniform  mat4  uMatrixMvp;
uniform  mat3  uMatrixNormal;
uniform  mat4  uMatrixModelview;
uniform  vec4  uLightPosition;
varying  vec3  vLightVector;
varying  vec3  vLightHalfVector;
varying  vec3  vNormal;

#ifdef SHADOWED
uniform mat4 uMatrixLight;
varying vec4 vLightPosition;
#endif //SHADOWED

#ifdef VERTEX_POSITION
attribute   vec4  aPosition0;
#endif //VERTEX_POSITION

#ifdef VERTEX_POSITION_BLEND
attribute   vec4  aPosition1;
uniform     float uPositionWeight;
#endif //VERTEX_POSITION_BLEND

#ifdef VERTEX_NORMAL
attribute   vec4  aNormal0;
#endif //VERTEX_NORMAL

#ifdef VERTEX_NORMAL_BLEND
attribute   vec4  aNormal1;
uniform     float uNormalWeight;
#endif //VERTEX_NORMAL_BLEND

#ifdef VERTEX_TEXCOORD
attribute   vec4  aTexCoord0;
#endif //VERTEX_TEXCOORD

#ifdef VERTEX_TEXCOORD_BLEND
attribute   vec4  aTexCoord1;
uniform     float uTexCoordWeight;
#endif //VERTEX_TEXCOORD_BLEND

#ifdef NEED_TEX_COORD
varying vec2 vTexCoord;
#endif //NEED_TEX_COORD

#ifdef LIGHT_ATTENUATION
varying  float vLightDist;
#endif //LIGHT_ATTENUATION

void vertexPhong(vec4 position, vec3 normal)
{
   normal = uMatrixNormal * normal;
   position = uMatrixModelview * position;

#ifdef NORMALIZE_NORMALS
   normal = normalize(normal);
#endif //NORMALIZE_NORMALS

#ifdef LIGHT_DIRECTIONAL
   vLightVector = uLightPosition.xyz;
#else
   vLightVector = uLightPosition.xyz - position.xyz;

#ifdef LIGHT_ATTENUATION
   vLightDist = length(vLightVector);
#endif //LIGHT_ATTENUATION

   vLightVector = normalize(vLightVector);
#endif //LIGHT_DIRECTIONAL

   vLightHalfVector = normalize(normalize(-position.xyz) + vLightVector);
   vNormal = normal;
}

void main() {

#ifdef VERTEX_POSITION_BLEND
   vec4 position = aPosition0 * uPositionWeight +
   aPosition1 * (1.0 - uPositionWeight);
   position = vec4(position.xyz, 1.0);
#else

#ifdef VERTEX_POSITION
   vec4 position = vec4(aPosition0.xyz, 1.0);
#endif // VERTEX_POSITION

#endif //VERTEX_POSITION_BLEND

#ifdef VERTEX_NORMAL_BLEND
   vec3 normal = aNormal0.xyz * uNormalWeight +
   aNormal1.xyz * (1.0 - uNormalWeight);
#else

#ifdef VERTEX_NORMAL
   vec3 normal = aNormal0.xyz;
#endif //VERTEX_NORMAL

#endif //VERTEX_NORMAL_BLEND

#ifdef VERTEX_TEXCOORD_BLEND
   vTexCoord = aTexCoord0.st * uTexCoordWeight +
   aTexCoord1.st * (1.0 - uTexCoordWeight);
#else

#ifdef VERTEX_TEXCOORD
   vTexCoord = aTexCoord0.st;
#endif //VERTEX_TEXCOORD

#endif //VERTEX_TEXCOORD_BLEND

   gl_Position = uMatrixMvp * position;
   vertexPhong(position, normal);

#ifdef SHADOWED
   vLightPosition = uMatrixLight * position;
#endif //SHADOWED
}