summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--src/Makefile_Evas.am30
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_3d.c7
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_3d_private.h27
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_3d_shader.c1097
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/color_pick_frag.shd7
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/color_pick_vert.shd28
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/diffuse_frag.shd47
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/diffuse_vert.shd52
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/flat_frag.shd195
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/flat_vert.shd154
-rwxr-xr-xsrc/modules/evas/engines/gl_common/shader_3d/gen_shaders_3d.sh45
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/normal_map_frag.shd283
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/normal_map_vert.shd189
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/phong_frag.shd235
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/phong_vert.shd116
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/shadow_map_frag.shd4
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/shadow_map_vert.shd28
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/vertex_color_frag.shd20
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/vertex_color_vert.shd50
20 files changed, 1553 insertions, 1062 deletions
diff --git a/.gitignore b/.gitignore
index 4f048401f4..96345bf5f9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -67,4 +67,5 @@ tags
67/config.rpath 67/config.rpath
68/coverage 68/coverage
69/src/lib/ecore_x/ecore_x_vsync 69/src/lib/ecore_x/ecore_x_vsync
70/src/modules/evas/engines/gl_common/shader_3d/evas_gl_3d_shaders.x
70Session.vim 71Session.vim
diff --git a/src/Makefile_Evas.am b/src/Makefile_Evas.am
index 0651d7fac0..3cfbcedac5 100644
--- a/src/Makefile_Evas.am
+++ b/src/Makefile_Evas.am
@@ -586,6 +586,7 @@ modules/evas/engines/gl_common/evas_gl_api.c \
586modules/evas/engines/gl_common/evas_gl_api_gles1.c \ 586modules/evas/engines/gl_common/evas_gl_api_gles1.c \
587modules/evas/engines/gl_common/evas_gl_api_ext.c \ 587modules/evas/engines/gl_common/evas_gl_api_ext.c \
588modules/evas/engines/gl_common/shader/evas_gl_shaders.x \ 588modules/evas/engines/gl_common/shader/evas_gl_shaders.x \
589modules/evas/engines/gl_common/shader_3d/evas_gl_3d_shaders.x \
589modules/evas/engines/gl_common/shader/evas_gl_enum.x 590modules/evas/engines/gl_common/shader/evas_gl_enum.x
590 591
591# 3D 592# 3D
@@ -729,6 +730,35 @@ modules/evas/engines/gl_common/shader/evas_gl_shaders.x: modules/evas/engines/gl
729 730
730modules/evas/engines/gl_common/shader/evas_gl_enum.x: modules/evas/engines/gl_common/shader/evas_gl_shaders.x 731modules/evas/engines/gl_common/shader/evas_gl_enum.x: modules/evas/engines/gl_common/shader/evas_gl_shaders.x
731 732
733# NOTE: order here should be equal with modes in file Evas_Eo.h
734GL_SHADERS_3D_GEN = \
735modules/evas/engines/gl_common/shader_3d/vertex_color_vert.shd \
736modules/evas/engines/gl_common/shader_3d/vertex_color_frag.shd \
737modules/evas/engines/gl_common/shader_3d/diffuse_vert.shd \
738modules/evas/engines/gl_common/shader_3d/diffuse_frag.shd \
739modules/evas/engines/gl_common/shader_3d/flat_vert.shd \
740modules/evas/engines/gl_common/shader_3d/flat_frag.shd \
741modules/evas/engines/gl_common/shader_3d/phong_vert.shd \
742modules/evas/engines/gl_common/shader_3d/phong_frag.shd \
743modules/evas/engines/gl_common/shader_3d/normal_map_vert.shd \
744modules/evas/engines/gl_common/shader_3d/normal_map_frag.shd \
745modules/evas/engines/gl_common/shader_3d/shadow_map_vert.shd \
746modules/evas/engines/gl_common/shader_3d/shadow_map_frag.shd \
747modules/evas/engines/gl_common/shader_3d/color_pick_vert.shd \
748modules/evas/engines/gl_common/shader_3d/color_pick_frag.shd \
749$(NULL)
750
751EXTRA_DIST += \
752modules/evas/engines/gl_common/shader_3d/gen_shaders_3d.sh
753
754BUILT_SOURCES += \
755modules/evas/engines/gl_common/shader_3d/evas_gl_3d_shaders.x
756
757modules/evas/engines/gl_common/shader_3d/evas_gl_3d_shaders.x: modules/evas/engines/gl_common/shader_3d/gen_shaders_3d.sh $(GL_SHADERS_3D_GEN)
758 @echo " SHADERS_3D $@"
759 @modules/evas/engines/gl_common/shader_3d/gen_shaders_3d.sh $(GL_SHADERS_3D_GEN)
760
761
732GL_GENERIC_SOURCES = \ 762GL_GENERIC_SOURCES = \
733modules/evas/engines/gl_generic/evas_engine.c \ 763modules/evas/engines/gl_generic/evas_engine.c \
734modules/evas/engines/gl_generic/Evas_Engine_GL_Generic.h 764modules/evas/engines/gl_generic/Evas_Engine_GL_Generic.h
diff --git a/src/modules/evas/engines/gl_common/evas_gl_3d.c b/src/modules/evas/engines/gl_common/evas_gl_3d.c
index b1b277dc99..403aea6187 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_3d.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_3d.c
@@ -1144,13 +1144,10 @@ _mesh_draw_data_build(E3D_Draw_Data *data,
1144 } 1144 }
1145 1145
1146 if (pdmesh->shadowed) 1146 if (pdmesh->shadowed)
1147 data->flags |= E3D_SHADER_FLAG_SHADOWED; 1147 data->flags |= E3D_SHADER_FLAG_SHADOWED;
1148 1148
1149 if (pdmesh->color_pick_enabled) 1149 if (pdmesh->color_pick_enabled)
1150 { 1150 data->color_pick_key = pdmesh->color_pick_key;
1151 data->flags |= E3D_SHADER_FLAG_COLOR_PICK_ENABLED;
1152 data->color_pick_key = pdmesh->color_pick_key;
1153 }
1154 1151
1155 data->blending = pdmesh->blending; 1152 data->blending = pdmesh->blending;
1156 data->blend_sfactor = pdmesh->blend_sfactor; 1153 data->blend_sfactor = pdmesh->blend_sfactor;
diff --git a/src/modules/evas/engines/gl_common/evas_gl_3d_private.h b/src/modules/evas/engines/gl_common/evas_gl_3d_private.h
index 6d956f554d..78ddc429f0 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_3d_private.h
+++ b/src/modules/evas/engines/gl_common/evas_gl_3d_private.h
@@ -7,6 +7,7 @@ typedef struct _E3D_Program E3D_Program;
7typedef struct _E3D_Draw_Data E3D_Draw_Data; 7typedef struct _E3D_Draw_Data E3D_Draw_Data;
8typedef unsigned long E3D_Shader_Flag; 8typedef unsigned long E3D_Shader_Flag;
9 9
10// NOTE: order here should be equal with flag names in file evas_gl_3d_shader.c
10#define E3D_SHADER_FLAG_NORMALIZE_NORMALS (1 << 0) 11#define E3D_SHADER_FLAG_NORMALIZE_NORMALS (1 << 0)
11#define E3D_SHADER_FLAG_VERTEX_POSITION (1 << 1) 12#define E3D_SHADER_FLAG_VERTEX_POSITION (1 << 1)
12#define E3D_SHADER_FLAG_VERTEX_POSITION_BLEND (1 << 2) 13#define E3D_SHADER_FLAG_VERTEX_POSITION_BLEND (1 << 2)
@@ -25,19 +26,19 @@ typedef unsigned long E3D_Shader_Flag;
25#define E3D_SHADER_FLAG_DIFFUSE (1 << 15) 26#define E3D_SHADER_FLAG_DIFFUSE (1 << 15)
26#define E3D_SHADER_FLAG_SPECULAR (1 << 16) 27#define E3D_SHADER_FLAG_SPECULAR (1 << 16)
27#define E3D_SHADER_FLAG_EMISSION (1 << 17) 28#define E3D_SHADER_FLAG_EMISSION (1 << 17)
28#define E3D_SHADER_FLAG_DIFFUSE_TEXTURE (1 << 19) 29#define E3D_SHADER_FLAG_DIFFUSE_TEXTURE (1 << 18)
29#define E3D_SHADER_FLAG_AMBIENT_TEXTURE (1 << 20) 30#define E3D_SHADER_FLAG_AMBIENT_TEXTURE (1 << 19)
30#define E3D_SHADER_FLAG_SPECULAR_TEXTURE (1 << 21) 31#define E3D_SHADER_FLAG_SPECULAR_TEXTURE (1 << 20)
31#define E3D_SHADER_FLAG_EMISSION_TEXTURE (1 << 22) 32#define E3D_SHADER_FLAG_EMISSION_TEXTURE (1 << 21)
32#define E3D_SHADER_FLAG_NORMAL_TEXTURE (1 << 23) 33#define E3D_SHADER_FLAG_NORMAL_TEXTURE (1 << 22)
33#define E3D_SHADER_FLAG_DIFFUSE_TEXTURE_BLEND (1 << 24) 34#define E3D_SHADER_FLAG_DIFFUSE_TEXTURE_BLEND (1 << 23)
34#define E3D_SHADER_FLAG_AMBIENT_TEXTURE_BLEND (1 << 25) 35#define E3D_SHADER_FLAG_AMBIENT_TEXTURE_BLEND (1 << 24)
35#define E3D_SHADER_FLAG_SPECULAR_TEXTURE_BLEND (1 << 26) 36#define E3D_SHADER_FLAG_SPECULAR_TEXTURE_BLEND (1 << 25)
36#define E3D_SHADER_FLAG_EMISSION_TEXTURE_BLEND (1 << 27) 37#define E3D_SHADER_FLAG_EMISSION_TEXTURE_BLEND (1 << 26)
37#define E3D_SHADER_FLAG_NORMAL_TEXTURE_BLEND (1 << 28) 38#define E3D_SHADER_FLAG_NORMAL_TEXTURE_BLEND (1 << 27)
38#define E3D_SHADER_FLAG_FOG_ENABLED (1 << 29) 39#define E3D_SHADER_FLAG_FOG_ENABLED (1 << 28)
39#define E3D_SHADER_FLAG_SHADOWED (1 << 30) 40#define E3D_SHADER_FLAG_SHADOWED (1 << 29)
40#define E3D_SHADER_FLAG_COLOR_PICK_ENABLED (1 << 31) 41#define E3D_SHADER_FLAG_COUNT 30
41 42
42static inline Eina_Bool 43static inline Eina_Bool
43_flags_need_tex_coord(E3D_Shader_Flag flags) 44_flags_need_tex_coord(E3D_Shader_Flag flags)
diff --git a/src/modules/evas/engines/gl_common/evas_gl_3d_shader.c b/src/modules/evas/engines/gl_common/evas_gl_3d_shader.c
index 757b26553c..4f8fcedbc7 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_3d_shader.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_3d_shader.c
@@ -1,4 +1,5 @@
1#include "evas_gl_3d_private.h" 1#include "evas_gl_3d_private.h"
2#include "shader_3d/evas_gl_3d_shaders.x"
2 3
3typedef enum _E3D_Uniform 4typedef enum _E3D_Uniform
4{ 5{
@@ -54,6 +55,40 @@ typedef enum _E3D_Uniform
54 E3D_UNIFORM_COUNT, 55 E3D_UNIFORM_COUNT,
55} E3D_Uniform; 56} E3D_Uniform;
56 57
58static const char *shader_flag_names[] =
59{
60 "NORMALIZE_NORMALS",
61 "VERTEX_POSITION",
62 "VERTEX_POSITION_BLEND",
63 "VERTEX_NORMAL",
64 "VERTEX_NORMAL_BLEND",
65 "VERTEX_TANGENT",
66 "VERTEX_TANGENT_BLEND",
67 "VERTEX_COLOR",
68 "VERTEX_COLOR_BLEND",
69 "VERTEX_TEXCOORD",
70 "VERTEX_TEXCOORD_BLEND",
71 "LIGHT_DIRECTIONAL",
72 "LIGHT_SPOT",
73 "LIGHT_ATTENUATION",
74 "AMBIENT",
75 "DIFFUSE",
76 "SPECULAR",
77 "EMISSION",
78 "DIFFUSE_TEXTURE",
79 "AMBIENT_TEXTURE",
80 "SPECULAR_TEXTURE",
81 "EMISSION_TEXTURE",
82 "NORMAL_TEXTURE",
83 "DIFFUSE_TEXTURE_BLEND",
84 "AMBIENT_TEXTURE_BLEND",
85 "SPECULAR_TEXTURE_BLEND",
86 "EMISSION_TEXTURE_BLEND",
87 "NORMAL_TEXTURE_BLEND",
88 "FOG_ENABLED",
89 "SHADOWED"
90};
91
57typedef struct _E3D_Shader_String 92typedef struct _E3D_Shader_String
58{ 93{
59 char *str; 94 char *str;
@@ -117,1050 +152,21 @@ void _shader_string_add(E3D_Shader_String *shader, const char *str)
117 shader->count += len; 152 shader->count += len;
118} 153}
119 154
120#define ADD_LINE(str) _shader_string_add(shader, str"\n") 155void _shader_flags_add(E3D_Shader_String *shader, E3D_Shader_Flag flags)
121
122static void
123_vertex_shader_string_variable_add(E3D_Shader_String *shader,
124 Evas_3D_Shade_Mode mode, E3D_Shader_Flag flags)
125{
126 ADD_LINE("uniform mat4 uMatrixMvp;");
127
128 if (flags & E3D_SHADER_FLAG_SHADOWED)
129 {
130 ADD_LINE("uniform mat4 uMatrixLight;");
131 ADD_LINE("varying vec4 lpos;");
132 }
133
134 /* Vertex attributes. */
135 if (flags & E3D_SHADER_FLAG_VERTEX_POSITION)
136 ADD_LINE("attribute vec4 aPosition0;");
137
138 if (flags & E3D_SHADER_FLAG_VERTEX_POSITION_BLEND)
139 {
140 ADD_LINE("attribute vec4 aPosition1;");
141 ADD_LINE("uniform float uPositionWeight;");
142 }
143
144 else if (mode == EVAS_3D_SHADE_MODE_SHADOW_MAP_RENDER) return;
145
146 if (flags & E3D_SHADER_FLAG_VERTEX_NORMAL)
147 ADD_LINE("attribute vec4 aNormal0;");
148
149 if (flags & E3D_SHADER_FLAG_VERTEX_NORMAL_BLEND)
150 {
151 ADD_LINE("attribute vec4 aNormal1;");
152 ADD_LINE("uniform float uNormalWeight;");
153 }
154
155 if (flags & E3D_SHADER_FLAG_VERTEX_TANGENT)
156 ADD_LINE("attribute vec4 aTangent0;");
157
158 if (flags & E3D_SHADER_FLAG_VERTEX_TANGENT_BLEND)
159 {
160 ADD_LINE("attribute vec4 aTangent1;");
161 ADD_LINE("uniform float uTangentWeight;");
162 }
163
164 if (flags & E3D_SHADER_FLAG_VERTEX_COLOR)
165 ADD_LINE("attribute vec4 aColor0;");
166
167 if (flags & E3D_SHADER_FLAG_VERTEX_COLOR_BLEND)
168 {
169 ADD_LINE("attribute vec4 aColor1;");
170 ADD_LINE("uniform float uColorWeight;");
171 }
172
173 if (flags & E3D_SHADER_FLAG_VERTEX_TEXCOORD)
174 ADD_LINE("attribute vec4 aTexCoord0;");
175
176 if (flags & E3D_SHADER_FLAG_VERTEX_TEXCOORD_BLEND)
177 {
178 ADD_LINE("attribute vec4 aTexCoord1;");
179 ADD_LINE("uniform float uTexCoordWeight;");
180 }
181
182 /* Texture coordinate. */
183 if (_flags_need_tex_coord(flags))
184 ADD_LINE("varying vec2 vTexCoord;");
185
186 /* Variables for each shade modes. */
187 if (mode == EVAS_3D_SHADE_MODE_VERTEX_COLOR)
188 {
189 ADD_LINE("varying vec4 vColor;");
190 }
191 else if (mode == EVAS_3D_SHADE_MODE_DIFFUSE)
192 {
193 /* Nothing to declare. */
194 }
195 else if (mode == EVAS_3D_SHADE_MODE_FLAT)
196 {
197 ADD_LINE("uniform mat3 uMatrixNormal;");
198 ADD_LINE("uniform mat4 uMatrixModelview;");
199 ADD_LINE("uniform vec4 uLightPosition;");
200
201 ADD_LINE("varying vec2 vFactor;");
202
203 if (flags & E3D_SHADER_FLAG_LIGHT_SPOT)
204 {
205 ADD_LINE("uniform vec3 uLightSpotDir;");
206 ADD_LINE("uniform float uLightSpotExp;");
207 ADD_LINE("uniform float uLightSpotCutoffCos;");
208 }
209
210 if (flags & E3D_SHADER_FLAG_SPECULAR)
211 ADD_LINE("uniform float uMaterialShininess;");
212
213 if (flags & E3D_SHADER_FLAG_LIGHT_ATTENUATION)
214 ADD_LINE("uniform vec3 uLightAtten;");
215 }
216 else if (mode == EVAS_3D_SHADE_MODE_PHONG || mode == EVAS_3D_SHADE_MODE_NORMAL_MAP)
217 {
218 ADD_LINE("uniform mat3 uMatrixNormal;");
219 ADD_LINE("uniform mat4 uMatrixModelview;");
220 ADD_LINE("uniform vec4 uLightPosition;");
221 ADD_LINE("varying vec3 vLightVector;");
222 ADD_LINE("varying vec3 vLightHalfVector;");
223
224 if (mode == EVAS_3D_SHADE_MODE_NORMAL_MAP)
225 ADD_LINE("varying vec3 vEyeVector;");
226
227 if (flags & E3D_SHADER_FLAG_LIGHT_ATTENUATION)
228 ADD_LINE("varying float vLightDist;");
229
230 if (mode == EVAS_3D_SHADE_MODE_PHONG || (flags & E3D_SHADER_FLAG_VERTEX_TANGENT) == 0)
231 ADD_LINE("varying vec3 vNormal;");
232 }
233}
234
235static void
236_vertex_shader_string_func_flat_add(E3D_Shader_String *shader,
237 Evas_3D_Shade_Mode mode EINA_UNUSED, E3D_Shader_Flag flags)
238{
239 ADD_LINE("void vertexFlat(vec4 position, vec3 normal) {");
240
241 ADD_LINE("vec3 lv;");
242 ADD_LINE("float factor;");
243
244 ADD_LINE("normal = uMatrixNormal * normal;");
245 ADD_LINE("position = uMatrixModelview * position;");
246
247 if (flags & E3D_SHADER_FLAG_NORMALIZE_NORMALS)
248 ADD_LINE("normal = normalize(normal);");
249
250 if (flags & E3D_SHADER_FLAG_LIGHT_DIRECTIONAL)
251 {
252 ADD_LINE("lv = uLightPosition.xyz;");
253 }
254 else
255 {
256 ADD_LINE("lv = uLightPosition.xyz - position.xyz;");
257 ADD_LINE("lv = normalize(lv);");
258 }
259
260 ADD_LINE("factor = max(dot(lv, normal), 0.0);");
261
262 if (flags & E3D_SHADER_FLAG_LIGHT_SPOT)
263 {
264 ADD_LINE("float f = dot(-lv, uLightSpotDir);");
265 ADD_LINE("if (f > uLightSpotCutoffCos)");
266 ADD_LINE("factor *= pow(f, uLightSpotExp);");
267 ADD_LINE("else");
268 ADD_LINE("factor = 0.0;");
269 }
270
271 ADD_LINE("if (factor > 0.0) {");
272
273 /* Diffuse term. */
274 if (flags & E3D_SHADER_FLAG_DIFFUSE)
275 ADD_LINE("vFactor.x = factor;");
276 else
277 ADD_LINE("vFactor.x = 0.0;");
278
279 /* Specular term. */
280 if (flags & E3D_SHADER_FLAG_SPECULAR)
281 {
282 ADD_LINE("vec3 hv = normalize(normalize(-position.xyz) + lv);");
283 ADD_LINE("factor = pow(max(dot(hv, normal), 0.0), uMaterialShininess);");
284 ADD_LINE("vFactor.y = factor;");
285 }
286
287 ADD_LINE("} else {");
288 ADD_LINE("vFactor = vec2(0.0, 0.0);");
289 ADD_LINE("}");
290
291 /* Light attenuation. */
292 if (flags & E3D_SHADER_FLAG_LIGHT_ATTENUATION)
293 {
294 ADD_LINE("float dist = length(lv);");
295 ADD_LINE("vFactor /= dot(uLightAtten, vec3(1.0, dist, dist * dist));");
296 }
297
298 ADD_LINE("}");
299}
300
301static void
302_vertex_shader_string_func_phong_add(E3D_Shader_String *shader,
303 Evas_3D_Shade_Mode mode EINA_UNUSED, E3D_Shader_Flag flags)
304{
305 ADD_LINE("void vertexPhong(vec4 position, vec3 normal) {");
306
307 ADD_LINE("normal = uMatrixNormal * normal;");
308 ADD_LINE("position = uMatrixModelview * position;");
309
310 if (flags & E3D_SHADER_FLAG_NORMALIZE_NORMALS)
311 ADD_LINE("normal = normalize(normal);");
312
313 if (flags & E3D_SHADER_FLAG_LIGHT_DIRECTIONAL)
314 {
315 ADD_LINE("vLightVector = uLightPosition.xyz;");
316 }
317 else
318 {
319 ADD_LINE("vLightVector = uLightPosition.xyz - position.xyz;");
320
321 if (flags & E3D_SHADER_FLAG_LIGHT_ATTENUATION)
322 ADD_LINE("vLightDist = length(vLightVector);");
323
324 ADD_LINE("vLightVector = normalize(vLightVector);");
325 }
326
327 ADD_LINE("vLightHalfVector = normalize(normalize(-position.xyz) + vLightVector);");
328 ADD_LINE("vNormal = normal;");
329 ADD_LINE("}");
330}
331
332static void
333_vertex_shader_string_func_normal_map_add(E3D_Shader_String *shader,
334 Evas_3D_Shade_Mode mode EINA_UNUSED,
335 E3D_Shader_Flag flags)
336{
337 if ((flags & E3D_SHADER_FLAG_VERTEX_TANGENT) == 0)
338 {
339 ADD_LINE("void vertexNormalMap(vec4 position, vec3 normal) {");
340
341 ADD_LINE("normal = uMatrixNormal * normal;");
342 ADD_LINE("position = uMatrixModelview * position;");
343 ADD_LINE("vEyeVector = normalize(-position.xyz);");
344
345 if (flags & E3D_SHADER_FLAG_NORMALIZE_NORMALS)
346 ADD_LINE("normal = normalize(normal);");
347
348 if (flags & E3D_SHADER_FLAG_LIGHT_DIRECTIONAL)
349 {
350 ADD_LINE("vLightVector = uLightPosition.xyz;");
351 }
352 else
353 {
354 ADD_LINE("vLightVector = uLightPosition.xyz - position.xyz;");
355
356 if (flags & E3D_SHADER_FLAG_LIGHT_ATTENUATION)
357 ADD_LINE("vLightDist = length(vLightVector);");
358
359 ADD_LINE("vLightVector = normalize(vLightVector);");
360 }
361
362 ADD_LINE("vLightHalfVector = normalize(vEyeVector + vLightVector);");
363 ADD_LINE("vNormal = normal;");
364 ADD_LINE("}");
365 }
366 else
367 {
368 ADD_LINE("void vertexNormalMap(vec4 position, vec3 normal, vec3 tangent) {");
369
370 ADD_LINE("vec3 n = normalize(uMatrixNormal * normal);");
371 ADD_LINE("vec3 t = normalize(uMatrixNormal * tangent);");
372 ADD_LINE("vec3 b = cross(n, t);");
373 ADD_LINE("vec3 tmp;");
374
375 ADD_LINE("position = uMatrixModelview * position;");
376
377 if (flags & E3D_SHADER_FLAG_LIGHT_DIRECTIONAL)
378 {
379 ADD_LINE("vec3 lightDir = uLightPosition.xyz;");
380 }
381 else
382 {
383 ADD_LINE("vec3 lightDir = uLightPosition.xyz - position.xyz;");
384
385 if (flags & E3D_SHADER_FLAG_LIGHT_ATTENUATION)
386 ADD_LINE("vLightDist = length(lightDir);");
387
388 ADD_LINE("lightDir = normalize(lightDir);");
389 }
390
391 ADD_LINE("tmp.x = dot(lightDir, t);");
392 ADD_LINE("tmp.y = dot(lightDir, b);");
393 ADD_LINE("tmp.z = dot(lightDir, n);");
394 ADD_LINE("vLightVector = tmp;");
395
396 ADD_LINE("tmp.x = dot(position.xyz, t);");
397 ADD_LINE("tmp.y = dot(position.xyz, b);");
398 ADD_LINE("tmp.z = dot(position.xyz, n);");
399 ADD_LINE("vEyeVector = normalize(tmp);");
400
401 ADD_LINE("vec3 hv = normalize(normalize(-position.xyz) + lightDir);");
402 ADD_LINE("tmp.x = dot(hv, t);");
403 ADD_LINE("tmp.y = dot(hv, b);");
404 ADD_LINE("tmp.z = dot(hv, n);");
405 ADD_LINE("vLightHalfVector = tmp;");
406
407 ADD_LINE("}");
408 }
409}
410
411static void
412_vertex_shader_string_get(E3D_Shader_String *shader,
413 Evas_3D_Shade_Mode mode, E3D_Shader_Flag flags)
414{
415 /* Add variables - vertex attributes. */
416 _vertex_shader_string_variable_add(shader, mode, flags);
417
418 /* Add functions. */
419 if (mode == EVAS_3D_SHADE_MODE_FLAT)
420 _vertex_shader_string_func_flat_add(shader, mode, flags);
421 else if (mode == EVAS_3D_SHADE_MODE_PHONG)
422 _vertex_shader_string_func_phong_add(shader, mode, flags);
423 else if (mode == EVAS_3D_SHADE_MODE_NORMAL_MAP)
424 _vertex_shader_string_func_normal_map_add(shader, mode, flags);
425
426 ADD_LINE("void main() {");
427
428 /* Process vertex attributes. */
429 if (flags & E3D_SHADER_FLAG_VERTEX_POSITION_BLEND)
430 {
431 ADD_LINE("vec4 position = aPosition0 * uPositionWeight + ");
432 ADD_LINE("aPosition1 * (1.0 - uPositionWeight);");
433 ADD_LINE("position = vec4(position.xyz, 1.0);");
434 }
435 else if (flags & E3D_SHADER_FLAG_VERTEX_POSITION)
436 {
437 ADD_LINE("vec4 position = vec4(aPosition0.xyz, 1.0);");
438 }
439
440 if (flags & E3D_SHADER_FLAG_VERTEX_NORMAL_BLEND)
441 {
442 ADD_LINE("vec3 normal = aNormal0.xyz * uNormalWeight + ");
443 ADD_LINE("aNormal1.xyz * (1.0 - uNormalWeight);");
444 }
445 else if (flags & E3D_SHADER_FLAG_VERTEX_NORMAL)
446 {
447 ADD_LINE("vec3 normal = aNormal0.xyz;");
448 }
449
450 if (flags & E3D_SHADER_FLAG_VERTEX_TANGENT_BLEND)
451 {
452 ADD_LINE("vec3 tangent = aTangent0.xyz * uTangentWeight + ");
453 ADD_LINE("aTangent1.xyz * (1.0 - uTangentWeight);");
454 }
455 else if (flags & E3D_SHADER_FLAG_VERTEX_TANGENT)
456 {
457 ADD_LINE("vec3 tangent = aTangent0.xyz;");
458 }
459
460 if (flags & E3D_SHADER_FLAG_VERTEX_COLOR_BLEND)
461 {
462 ADD_LINE("vec4 color = aColor0 * uColorWeight + aColor1 * (1.0 - uColorWeight);");
463 }
464 else if (flags & E3D_SHADER_FLAG_VERTEX_COLOR)
465 {
466 ADD_LINE("vec4 color = aColor0;");
467 }
468
469 if (flags & E3D_SHADER_FLAG_VERTEX_TEXCOORD_BLEND)
470 {
471 ADD_LINE("vTexCoord = aTexCoord0.st * uTexCoordWeight + ");
472 ADD_LINE("aTexCoord1.st * (1.0 - uTexCoordWeight);");
473 }
474 else if (flags & E3D_SHADER_FLAG_VERTEX_TEXCOORD)
475 {
476 ADD_LINE("vTexCoord = aTexCoord0.st;");
477 }
478
479 /* Transform vertex position. */
480 ADD_LINE("gl_Position = uMatrixMvp * position;");
481
482 /* Process according to the shade mode. */
483 if (mode == EVAS_3D_SHADE_MODE_VERTEX_COLOR)
484 {
485 ADD_LINE("vColor = color;");
486 }
487 else if (mode == EVAS_3D_SHADE_MODE_FLAT)
488 {
489 ADD_LINE("vertexFlat(position, normal);");
490 }
491 else if (mode == EVAS_3D_SHADE_MODE_PHONG)
492 {
493 ADD_LINE("vertexPhong(position, normal);");
494 }
495 else if (mode == EVAS_3D_SHADE_MODE_NORMAL_MAP)
496 {
497 if (flags & E3D_SHADER_FLAG_VERTEX_TANGENT)
498 ADD_LINE("vertexNormalMap(position, normal, tangent);");
499 else
500 ADD_LINE("vertexNormalMap(position, normal);");
501 }
502
503 if (flags & E3D_SHADER_FLAG_SHADOWED)
504 {
505 ADD_LINE("lpos = uMatrixLight * position;");
506 }
507
508 ADD_LINE("}");
509}
510
511static void
512_fragment_shader_string_variable_add(E3D_Shader_String *shader,
513 Evas_3D_Shade_Mode mode, E3D_Shader_Flag flags)
514{
515 /* Texture coordinate. */
516 if (_flags_need_tex_coord(flags))
517 ADD_LINE("varying vec2 vTexCoord;");
518
519 if (flags & E3D_SHADER_FLAG_FOG_ENABLED)
520 {
521 ADD_LINE("uniform float uFogFactor;");
522 ADD_LINE("uniform vec4 uFogColor;");
523 }
524 if (flags & E3D_SHADER_FLAG_SHADOWED)
525 {
526 ADD_LINE("varying vec4 lpos;");
527 ADD_LINE("uniform sampler2D uShadowMap;");
528 }
529
530 if (flags & E3D_SHADER_FLAG_COLOR_PICK_ENABLED)
531 ADD_LINE("uniform float uColorPick;");
532
533 /* Materials. */
534 if (flags & E3D_SHADER_FLAG_DIFFUSE)
535 {
536 ADD_LINE("uniform vec4 uMaterialDiffuse;");
537
538 if (flags & E3D_SHADER_FLAG_DIFFUSE_TEXTURE)
539 {
540 ADD_LINE("uniform sampler2D uTextureDiffuse0;");
541 }
542
543 if (flags & E3D_SHADER_FLAG_DIFFUSE_TEXTURE_BLEND)
544 {
545 ADD_LINE("uniform sampler2D uTextureDiffuse1;");
546 ADD_LINE("uniform float uTextureDiffuseWeight;");
547 }
548 }
549
550 if (flags & E3D_SHADER_FLAG_SPECULAR)
551 {
552 ADD_LINE("uniform vec4 uMaterialSpecular;");
553 ADD_LINE("uniform float uMaterialShininess;");
554
555 if (flags & E3D_SHADER_FLAG_SPECULAR_TEXTURE)
556 {
557 ADD_LINE("uniform sampler2D uTextureSpecular0;");
558 }
559
560 if (flags & E3D_SHADER_FLAG_SPECULAR_TEXTURE_BLEND)
561 {
562 ADD_LINE("uniform sampler2D uTextureSpecular1;");
563 ADD_LINE("uniform float uTextureSpecularWeight;");
564 }
565 }
566
567 if (flags & E3D_SHADER_FLAG_AMBIENT)
568 {
569 ADD_LINE("uniform vec4 uMaterialAmbient;");
570
571 if (flags & E3D_SHADER_FLAG_AMBIENT_TEXTURE)
572 {
573 ADD_LINE("uniform sampler2D uTextureAmbient0;");
574 }
575
576 if (flags & E3D_SHADER_FLAG_AMBIENT_TEXTURE_BLEND)
577 {
578 ADD_LINE("uniform sampler2D uTextureAmbient1;");
579 ADD_LINE("uniform float uTextureAmbientWeight;");
580 }
581 }
582
583 if (flags & E3D_SHADER_FLAG_EMISSION)
584 {
585 ADD_LINE("uniform vec4 uMaterialEmission;");
586
587 if (flags & E3D_SHADER_FLAG_EMISSION_TEXTURE)
588 {
589 ADD_LINE("uniform sampler2D uTextureEmission0;");
590 }
591
592 if (flags & E3D_SHADER_FLAG_EMISSION_TEXTURE_BLEND)
593 {
594 ADD_LINE("uniform sampler2D uTextureEmission1;");
595 ADD_LINE("uniform float uTextureEmissionWeight;");
596 }
597 }
598
599 if (mode == EVAS_3D_SHADE_MODE_VERTEX_COLOR)
600 {
601 ADD_LINE("varying vec4 vColor;");
602 }
603 else if (mode == EVAS_3D_SHADE_MODE_DIFFUSE)
604 {
605 /* Nothing to declare. */
606 }
607 else if (mode == EVAS_3D_SHADE_MODE_FLAT)
608 {
609 ADD_LINE("varying vec2 vFactor;");
610
611 if (flags & E3D_SHADER_FLAG_DIFFUSE)
612 ADD_LINE("uniform vec4 uLightDiffuse;");
613
614 if (flags & E3D_SHADER_FLAG_SPECULAR)
615 ADD_LINE("uniform vec4 uLightSpecular;");
616
617 if (flags & E3D_SHADER_FLAG_AMBIENT)
618 ADD_LINE("uniform vec4 uLightAmbient;");
619 }
620 else if (mode == EVAS_3D_SHADE_MODE_PHONG || mode == EVAS_3D_SHADE_MODE_NORMAL_MAP)
621 {
622 ADD_LINE("varying vec3 vLightVector;");
623 ADD_LINE("varying vec3 vLightHalfVector;");
624
625 if (flags & E3D_SHADER_FLAG_LIGHT_SPOT)
626 {
627 ADD_LINE("uniform vec3 uLightSpotDir;");
628 ADD_LINE("uniform float uLightSpotExp;");
629 ADD_LINE("uniform float uLightSpotCutoffCos;");
630 }
631
632 if (flags & E3D_SHADER_FLAG_DIFFUSE)
633 ADD_LINE("uniform vec4 uLightDiffuse;");
634
635 if (flags & E3D_SHADER_FLAG_SPECULAR)
636 ADD_LINE("uniform vec4 uLightSpecular;");
637
638 if (flags & E3D_SHADER_FLAG_AMBIENT)
639 ADD_LINE("uniform vec4 uLightAmbient;");
640
641 if (flags & E3D_SHADER_FLAG_LIGHT_ATTENUATION)
642 ADD_LINE("varying float vLightDist;");
643
644 if (mode == EVAS_3D_SHADE_MODE_PHONG)
645 {
646 ADD_LINE("varying vec3 vNormal;");
647 }
648 else /* Normal map. */
649 {
650 ADD_LINE("uniform sampler2D uTextureNormal0;");
651
652 if (flags & E3D_SHADER_FLAG_NORMAL_TEXTURE_BLEND)
653 {
654 ADD_LINE("uniform sampler2D uTextureNormal1;");
655 ADD_LINE("uniform float uTextureNormalWeight;");
656 }
657
658 ADD_LINE("varying vec3 vEyeVector;");
659
660 if ((flags & E3D_SHADER_FLAG_VERTEX_TANGENT) == 0)
661 ADD_LINE("varying vec3 vNormal;");
662 }
663 }
664}
665
666static void
667_fragment_shader_string_func_flat_add(E3D_Shader_String *shader,
668 Evas_3D_Shade_Mode mode EINA_UNUSED, E3D_Shader_Flag flags)
669{
670 ADD_LINE("void fragmentFlat() {");
671 ADD_LINE("vec4 color;");
672
673 if (flags & E3D_SHADER_FLAG_DIFFUSE)
674 {
675 if (flags & E3D_SHADER_FLAG_DIFFUSE_TEXTURE_BLEND)
676 {
677 ADD_LINE("color = texture2D(uTextureDiffuse0, vTexCoord) * uTextureDiffuseWeight +");
678 ADD_LINE("texture2D(uTextureDiffuse1, vTexCoord) * (1.0 - uTextureDiffuseWeight);");
679 ADD_LINE("color *= uMaterialDiffuse;");
680 }
681 else if (flags & E3D_SHADER_FLAG_DIFFUSE_TEXTURE)
682 {
683 ADD_LINE("color = texture2D(uTextureDiffuse0, vTexCoord) * uMaterialDiffuse;");
684 }
685 else
686 {
687 ADD_LINE("color = uMaterialDiffuse;");
688 }
689
690 ADD_LINE("gl_FragColor = uLightDiffuse * color * vFactor.x;");
691 }
692 else
693 {
694 ADD_LINE("gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);");
695 }
696
697 if (flags & E3D_SHADER_FLAG_SPECULAR)
698 {
699 if (flags & E3D_SHADER_FLAG_SPECULAR_TEXTURE_BLEND)
700 {
701 ADD_LINE("color = texture2D(uTextureSpecular0, vTexCoord) * uTextureSpecularWeight +");
702 ADD_LINE("texture2D(uTextureSpecular1, vTexCoord) * (1.0 - uTextureSpecularWeight);");
703 ADD_LINE("color *= uMaterialSpecular;");
704 }
705 else if (flags & E3D_SHADER_FLAG_SPECULAR_TEXTURE)
706 {
707 ADD_LINE("color = texture2D(uTextureSpecular0, vTexCoord) * uMaterialSpecular;");
708 }
709 else
710 {
711 ADD_LINE("color = uMaterialSpecular;");
712 }
713
714 ADD_LINE("gl_FragColor += uLightSpecular * color * vFactor.y;");
715 }
716
717 if (flags & E3D_SHADER_FLAG_SHADOWED)
718 {
719 ADD_LINE("gl_FragColor *= shadow;");
720 }
721
722 if (flags & E3D_SHADER_FLAG_AMBIENT)
723 {
724 if (flags & E3D_SHADER_FLAG_AMBIENT_TEXTURE_BLEND)
725 {
726 ADD_LINE("color = texture2D(uTextureAmbient0, vTexCoord) * uTextureAmbientWeight +");
727 ADD_LINE("texture2D(uTextureAmbient1, vTexCoord) * (1.0 - uTextureAmbientWeight);");
728 ADD_LINE("color *= uMaterialAmbient;");
729 }
730 else if (flags & E3D_SHADER_FLAG_AMBIENT_TEXTURE)
731 {
732 ADD_LINE("color = texture2D(uTextureAmbient0, vTexCoord) * uMaterialAmbient;");
733 }
734 else
735 {
736 ADD_LINE("color = uMaterialAmbient;");
737 }
738
739 ADD_LINE("gl_FragColor += uLightAmbient * color;");
740 }
741
742 if (flags & E3D_SHADER_FLAG_EMISSION)
743 {
744 if (flags & E3D_SHADER_FLAG_EMISSION_TEXTURE_BLEND)
745 {
746 ADD_LINE("color = texture2D(uTextureEmission0, vTexCoord) * uTextureEmissionWeight +");
747 ADD_LINE("texture2D(uTextureEmission1, vTexCoord) * (1.0 - uTextureEmissionWeight);");
748 ADD_LINE("color *= uMaterialEmission;");
749 }
750 else if (flags & E3D_SHADER_FLAG_EMISSION_TEXTURE)
751 {
752 ADD_LINE("color = texture2D(uTextureEmission0, vTexCoord) * uMaterialEmission;");
753 }
754 else
755 {
756 ADD_LINE("color = uMaterialEmission;");
757 }
758
759 ADD_LINE("gl_FragColor += color;");
760 }
761
762 ADD_LINE("}");
763}
764
765static void
766_fragment_shader_string_func_phong_add(E3D_Shader_String *shader,
767 Evas_3D_Shade_Mode mode EINA_UNUSED, E3D_Shader_Flag flags)
768{
769 ADD_LINE("void fragmentPhong() {");
770 ADD_LINE("vec3 normal = normalize(vNormal);");
771 ADD_LINE("vec3 lv = normalize(vLightVector);");
772 ADD_LINE("float factor = dot(lv, normal);");
773 ADD_LINE("vec4 color;");
774
775 if (flags & E3D_SHADER_FLAG_LIGHT_SPOT)
776 {
777 ADD_LINE("float f = dot(-lv, normalize(uLightSpotDir));");
778
779 ADD_LINE("if (f > uLightSpotCutoffCos)");
780 ADD_LINE("factor *= pow(f, uLightSpotExp);");
781 ADD_LINE("else");
782 ADD_LINE("factor = 0.0;");
783 }
784
785 ADD_LINE("if (factor > 0.0) {");
786
787 /* Diffuse term. */
788 if (flags & E3D_SHADER_FLAG_DIFFUSE)
789 {
790 if (flags & E3D_SHADER_FLAG_DIFFUSE_TEXTURE_BLEND)
791 {
792 ADD_LINE("color = texture2D(uTextureDiffuse0, vTexCoord) * uTextureDiffuseWeight +");
793 ADD_LINE("texture2D(uTextureDiffuse1, vTexCoord) * (1.0 - uTextureDiffuseWeight);");
794 }
795 else if (flags & E3D_SHADER_FLAG_DIFFUSE_TEXTURE)
796 {
797 ADD_LINE("color = texture2D(uTextureDiffuse0, vTexCoord);");
798 }
799 else
800 {
801 ADD_LINE("color = uMaterialDiffuse;");
802 }
803
804 ADD_LINE("gl_FragColor = uLightDiffuse * color * factor;");
805 }
806 else
807 {
808 ADD_LINE("gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);");
809 }
810
811 /* Specular term. */
812 if (flags & E3D_SHADER_FLAG_SPECULAR)
813 {
814 ADD_LINE("factor = dot(normalize(vLightHalfVector), normal);");
815 ADD_LINE("if (factor > 0.0) {");
816 ADD_LINE("factor = pow(factor, uMaterialShininess);");
817
818 if (flags & E3D_SHADER_FLAG_SPECULAR_TEXTURE_BLEND)
819 {
820 ADD_LINE("color = texture2D(uTextureSpecular0, vTexCoord) * uTextureSpecularWeight +");
821 ADD_LINE("texture2D(uTextureSpecular1, vTexCoord) * (1.0 - uTextureSpecularWeight);");
822 }
823 else if (flags & E3D_SHADER_FLAG_SPECULAR_TEXTURE)
824 {
825 ADD_LINE("color = texture2D(uTextureSpecular0, vTexCoord);");
826 }
827 else
828 {
829 ADD_LINE("color = uMaterialSpecular;");
830 }
831
832 ADD_LINE("gl_FragColor += uLightSpecular * color * factor;");
833 ADD_LINE("}");
834 }
835
836 ADD_LINE("} else {");
837 ADD_LINE("gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);");
838 ADD_LINE("}");
839
840 if (flags & E3D_SHADER_FLAG_SHADOWED)
841 {
842 ADD_LINE("gl_FragColor *= shadow;");
843 }
844
845 /* Ambient term. */
846 if (flags & E3D_SHADER_FLAG_AMBIENT)
847 {
848 if (flags & E3D_SHADER_FLAG_AMBIENT_TEXTURE_BLEND)
849 {
850 ADD_LINE("color = texture2D(uTextureAmbient0, vTexCoord) * uTextureAmbientWeight +");
851 ADD_LINE("texture2D(uTextureAmbient1 * vTexCoord) * (1.0 - uTextureAmbientWeight);");
852 }
853 else if (flags & E3D_SHADER_FLAG_AMBIENT_TEXTURE)
854 {
855 ADD_LINE("color = texture2D(uTextureAmbient0, vTexCoord);");
856 }
857 else
858 {
859 ADD_LINE("color = uMaterialAmbient;");
860 }
861
862 ADD_LINE("gl_FragColor += uLightAmbient * color;");
863 }
864
865 /* Light attenuation. */
866 if (flags & E3D_SHADER_FLAG_LIGHT_ATTENUATION)
867 ADD_LINE("gl_FragColor /= dot(uLightAtten, vec3(1.0, vLightDist, vLightDist * vLightDist));");
868
869 /* Emission term. */
870 if (flags & E3D_SHADER_FLAG_EMISSION)
871 {
872 if (flags & E3D_SHADER_FLAG_EMISSION_TEXTURE_BLEND)
873 {
874 ADD_LINE("color = texture2D(uTextureEmission0, vTexCoord) * uTextureEmissionWeight +");
875 ADD_LINE("texture2D(uTextureEmission1, vTexCoord) * (1.0 - uTextureEmissionWeight);");
876 }
877 else if (flags & E3D_SHADER_FLAG_EMISSION_TEXTURE)
878 {
879 ADD_LINE("color = texture2D(uTextureEmission0, vTexCoord);");
880 }
881 else
882 {
883 ADD_LINE("color = uMaterialEmission;");
884 }
885
886 ADD_LINE("gl_FragColor += color;");
887 }
888
889 ADD_LINE("}");
890}
891
892static void
893_fragment_shader_string_func_normal_map_add(E3D_Shader_String *shader,
894 Evas_3D_Shade_Mode mode EINA_UNUSED,
895 E3D_Shader_Flag flags)
896{ 156{
897 if ((flags & E3D_SHADER_FLAG_VERTEX_TANGENT) == 0) 157 int i;
898 {
899 ADD_LINE("mat3 cotangent_frame(vec3 n, vec3 p, vec2 uv) {");
900 ADD_LINE("vec3 dp1 = dFdx(p);");
901 ADD_LINE("vec3 dp2 = dFdy(p);");
902 ADD_LINE("vec2 duv1 = dFdx(uv);");
903 ADD_LINE("vec2 duv2 = dFdy(uv);");
904 ADD_LINE("vec3 dp2perp = cross(dp2, n);");
905 ADD_LINE("vec3 dp1perp = cross(n, dp1);");
906 ADD_LINE("vec3 t = dp2perp * duv1.x + dp1perp * duv2.x;");
907 ADD_LINE("vec3 b = dp2perp * duv1.y + dp1perp * duv2.y;");
908 ADD_LINE("float invmax = inversesqrt(max(dot(t, t), dot(b, b)));");
909 ADD_LINE("return mat3(t * invmax, b * invmax, n);");
910 ADD_LINE("}");
911
912 ADD_LINE("vec3 perturb_normal(vec3 normal) {");
913 ADD_LINE("mat3 tbn = cotangent_frame(vNormal, -vEyeVector, vTexCoord);");
914 ADD_LINE("return normalize(tbn * normal);");
915 ADD_LINE("}");
916 }
917
918 ADD_LINE("void fragmentNormalMap() {");
919 ADD_LINE("float factor;");
920 ADD_LINE("vec3 normal;");
921 ADD_LINE("vec4 color;");
922
923 if (flags & E3D_SHADER_FLAG_NORMAL_TEXTURE_BLEND)
924 {
925 ADD_LINE("normal = texture2D(uTextureNormal0, vTexCoord).rgb * uTextureNormalWeight;");
926 ADD_LINE("normal += texture2D(uTextureNormal1, vTexCoord).rgb * ");
927 ADD_LINE("(1.0 - uTextureNormalWeight);");
928 }
929 else
930 {
931 ADD_LINE("normal = texture2D(uTextureNormal0, vTexCoord).rgb;");
932 }
933
934 ADD_LINE("normal = 2.0 * normal - 1.0;");
935
936 if ((flags & E3D_SHADER_FLAG_VERTEX_TANGENT) == 0)
937 {
938 ADD_LINE("normal = perturb_normal(normal);");
939 }
940
941 /* Can we skip this normalization?? */
942 ADD_LINE("vec3 lv = normalize(vLightVector);");
943 ADD_LINE("normal = normalize(normal);");
944
945 ADD_LINE("factor = dot(lv, normal);");
946
947 if (flags & E3D_SHADER_FLAG_LIGHT_SPOT)
948 {
949 ADD_LINE("float f = dot(-lv, normalize(uLightSpotDir));");
950
951 ADD_LINE("if (f > uLightSpotCutoffCos)");
952 ADD_LINE("factor *= pow(f, uLightSpotExp);");
953 ADD_LINE("else");
954 ADD_LINE("factor = 0.0;");
955 }
956
957 ADD_LINE("if (factor > 0.0) {");
958
959 /* Diffuse term. */
960 if (flags & E3D_SHADER_FLAG_DIFFUSE)
961 {
962 if (flags & E3D_SHADER_FLAG_DIFFUSE_TEXTURE_BLEND)
963 {
964 ADD_LINE("color = texture2D(uTextureDiffuse0, vTexCoord) * uTextureDiffuseWeight +");
965 ADD_LINE("texture2D(uTextureDiffuse1, vTexCoord) * (1.0 - uTextureDiffuseWeight);");
966 }
967 else if (flags & E3D_SHADER_FLAG_DIFFUSE_TEXTURE)
968 {
969 ADD_LINE("color = texture2D(uTextureDiffuse0, vTexCoord);");
970 }
971 else
972 {
973 ADD_LINE("color = uMaterialDiffuse;");
974 }
975
976 ADD_LINE("gl_FragColor = uLightDiffuse * color * factor;");
977 }
978 else
979 {
980 ADD_LINE("gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);");
981 }
982
983 /* Specular term. */
984 if (flags & E3D_SHADER_FLAG_SPECULAR)
985 {
986 ADD_LINE("factor = dot(normalize(vLightHalfVector), normal);");
987 ADD_LINE("if (factor > 0.0) {");
988 ADD_LINE("factor = pow(factor, uMaterialShininess);");
989
990 if (flags & E3D_SHADER_FLAG_SPECULAR_TEXTURE_BLEND)
991 {
992 ADD_LINE("color = texture2D(uTextureSpecular0, vTexCoord) * uTextureSpecularWeight +");
993 ADD_LINE("texture2D(uTextureSpecular1, vTexCoord) * (1.0 - uTextureSpecularWeight);");
994 }
995 else if (flags & E3D_SHADER_FLAG_SPECULAR_TEXTURE)
996 {
997 ADD_LINE("color = texture2D(uTextureSpecular0, vTexCoord);");
998 }
999 else
1000 {
1001 ADD_LINE("color = uMaterialSpecular;");
1002 }
1003
1004 ADD_LINE("gl_FragColor += uLightSpecular * color * factor;");
1005 ADD_LINE("}");
1006 }
1007
1008 if (flags & E3D_SHADER_FLAG_SHADOWED)
1009 {
1010 ADD_LINE("gl_FragColor *= shadow;");
1011 }
1012
1013 ADD_LINE("} else {");
1014 ADD_LINE("gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);");
1015 ADD_LINE("}");
1016
1017 /* Ambient term. */
1018 if (flags & E3D_SHADER_FLAG_AMBIENT)
1019 {
1020 if (flags & E3D_SHADER_FLAG_AMBIENT_TEXTURE_BLEND)
1021 {
1022 ADD_LINE("color = texture2D(uTextureAmbient0, vTexCoord) * uTextureAmbientWeight +");
1023 ADD_LINE("texture2D(uTextureAmbient1, vTexCoord) * (1.0 - uTextureAmbientWeight);");
1024 }
1025 else if (flags & E3D_SHADER_FLAG_AMBIENT_TEXTURE)
1026 {
1027 ADD_LINE("color = texture2D(uTextureAmbient0, vTexCoord);");
1028 }
1029 else
1030 {
1031 ADD_LINE("color = uMaterialAmbient;");
1032 }
1033
1034 ADD_LINE("gl_FragColor += uLightAmbient * color;");
1035 }
1036
1037 /* Light attenuation. */
1038 if (flags & E3D_SHADER_FLAG_LIGHT_ATTENUATION)
1039 ADD_LINE("gl_FragColor /= dot(uLightAtten, vec3(1.0, vLightDist, vLightDist * vLightDist));");
1040
1041 /* Emission term. */
1042 if (flags & E3D_SHADER_FLAG_EMISSION)
1043 {
1044 if (flags & E3D_SHADER_FLAG_EMISSION_TEXTURE_BLEND)
1045 {
1046 ADD_LINE("color = texture2D(uTextureEmission0, vTexCoord) * uTextureEmissionWeight +");
1047 ADD_LINE("texture2D(uTextureEmission1, vTexCoord) * (1.0 - uTextureEmissionWeight);");
1048 }
1049 else if (flags & E3D_SHADER_FLAG_EMISSION_TEXTURE)
1050 {
1051 ADD_LINE("color = texture2D(uTextureEmission0, vTexCoord);");
1052 }
1053 else
1054 {
1055 ADD_LINE("color = uMaterialEmission;");
1056 }
1057
1058 ADD_LINE("gl_FragColor += color;");
1059 }
1060
1061 ADD_LINE("}");
1062}
1063
1064static void
1065_fragment_shader_string_pcf_even_func_add(E3D_Shader_String *shader,
1066 Evas_3D_Shade_Mode mode EINA_UNUSED,
1067 E3D_Shader_Flag flags EINA_UNUSED)
1068{
1069 ADD_LINE("float pcf(vec4 lpos, float size)");
1070 ADD_LINE("{");
1071 ADD_LINE("vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;");
1072 ADD_LINE("float i, j, randx, randy, shadow;");
1073 ADD_LINE("shadow = 0.0;");
1074 ADD_LINE("for (i = -4.0; i < 4.0; i++)");
1075 ADD_LINE("for (j = -4.0; j < 4.0; j++)");
1076 ADD_LINE("{");
1077 ADD_LINE("shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy +vec2(i / 8.0, j / 8.0)*size).x);");
1078 ADD_LINE("}");
1079 ADD_LINE("return shadow / 64.0;");
1080 ADD_LINE("}");
1081}
1082
1083static void
1084_fragment_shader_string_get(E3D_Shader_String *shader,
1085 Evas_3D_Shade_Mode mode, E3D_Shader_Flag flags)
1086{
1087 /* Add variables - vertex attributes. */
1088 _fragment_shader_string_variable_add(shader, mode, flags);
1089 if (flags & E3D_SHADER_FLAG_SHADOWED)
1090 {
1091 ADD_LINE("float shadow;");
1092 }
1093 /* Add functions. */
1094 if (mode == EVAS_3D_SHADE_MODE_FLAT)
1095 _fragment_shader_string_func_flat_add(shader, mode, flags);
1096 else if (mode == EVAS_3D_SHADE_MODE_PHONG)
1097 _fragment_shader_string_func_phong_add(shader, mode, flags);
1098 else if (mode == EVAS_3D_SHADE_MODE_NORMAL_MAP)
1099 _fragment_shader_string_func_normal_map_add(shader, mode, flags);
1100
1101 // TODO Add flexible bluring algorithm of shadows boundaries.
1102 if (flags & E3D_SHADER_FLAG_SHADOWED)
1103 _fragment_shader_string_pcf_even_func_add(shader, mode, flags);
1104
1105 /* Add main function. */
1106 ADD_LINE("void main() {");
1107 if (flags & E3D_SHADER_FLAG_SHADOWED)
1108 {
1109 ADD_LINE("shadow = pcf(lpos, 1.0 / 200.0);");
1110 }
1111
1112 if (mode == EVAS_3D_SHADE_MODE_VERTEX_COLOR)
1113 {
1114 ADD_LINE("gl_FragColor = vColor;");
1115 }
1116 else if (mode == EVAS_3D_SHADE_MODE_DIFFUSE)
1117 {
1118 if (flags & E3D_SHADER_FLAG_DIFFUSE_TEXTURE_BLEND)
1119 {
1120 ADD_LINE("gl_FragColor = (texture2D(uTextureDiffuse0, vTexCoord) *");
1121 ADD_LINE("uTextureDiffuseWeight + texture2D(uTextureDiffuse1, vTexCoord) *");
1122 ADD_LINE("(1.0 - uTextureDiffuseWeight)) * uMaterialDiffuse;");
1123 }
1124 else if (flags & E3D_SHADER_FLAG_DIFFUSE_TEXTURE)
1125 {
1126 ADD_LINE("gl_FragColor = texture2D(uTextureDiffuse0, vTexCoord) * uMaterialDiffuse;");
1127 }
1128 else
1129 {
1130 ADD_LINE("gl_FragColor = uMaterialDiffuse;");
1131 }
1132 }
1133 else if(mode == EVAS_3D_SHADE_MODE_SHADOW_MAP_RENDER)
1134 {
1135 ADD_LINE("gl_FragColor = vec4(gl_FragCoord.z);");
1136 }
1137 else if (mode == EVAS_3D_SHADE_MODE_FLAT)
1138 {
1139 ADD_LINE("fragmentFlat();");
1140 }
1141 else if (mode == EVAS_3D_SHADE_MODE_PHONG)
1142 {
1143 ADD_LINE("fragmentPhong();");
1144 }
1145 else if (mode == EVAS_3D_SHADE_MODE_NORMAL_MAP)
1146 {
1147 ADD_LINE("fragmentNormalMap();");
1148 }
1149
1150 if ((flags & E3D_SHADER_FLAG_FOG_ENABLED) && (mode != EVAS_3D_SHADE_MODE_SHADOW_MAP_RENDER))
1151 {
1152 ADD_LINE("float z = gl_FragCoord.z / gl_FragCoord.w;");
1153 ADD_LINE("float fogFactor = exp2( -uFogFactor * uFogFactor * z * z * 1.44 );");
1154 ADD_LINE("fogFactor = clamp(fogFactor, 0.0, 1.0);");
1155 ADD_LINE("gl_FragColor = mix(uFogColor, gl_FragColor, fogFactor );");
1156 }
1157
1158 if (mode == EVAS_3D_SHADE_MODE_COLOR_PICK)
1159 {
1160 ADD_LINE("gl_FragColor = vec4(uColorPick);");
1161 }
1162 158
1163 ADD_LINE("}"); 159 for (i = 0; i < E3D_SHADER_FLAG_COUNT; i++)
160 if (flags & (1 << i))
161 {
162 int len = strlen("#define ") + strlen(shader_flag_names[i]) + 2;
163 char str[len];
164 snprintf(str, len, "#define %s\n", shader_flag_names[i]);
165 _shader_string_add(shader, str);
166 }
167
168 if(_flags_need_tex_coord(flags))
169 _shader_string_add(shader, "#define NEED_TEX_COORD\n");
1164} 170}
1165 171
1166static inline Eina_Bool 172static inline Eina_Bool
@@ -1543,8 +549,11 @@ e3d_program_new(Evas_3D_Shade_Mode mode, E3D_Shader_Flag flags)
1543 program->mode = mode; 549 program->mode = mode;
1544 program->flags = flags; 550 program->flags = flags;
1545 551
1546 _vertex_shader_string_get(&vert, mode, flags); 552 _shader_flags_add(&vert, flags);
1547 _fragment_shader_string_get(&frag, mode, flags); 553 _shader_string_add(&frag, vert.str);
554
555 _shader_string_add(&vert, vertex_shaders[mode]);
556 _shader_string_add(&frag, fragment_shaders[mode]);
1548 557
1549 if (! _program_build(program, vert.str, frag.str)) 558 if (! _program_build(program, vert.str, frag.str))
1550 goto error; 559 goto error;
diff --git a/src/modules/evas/engines/gl_common/shader_3d/color_pick_frag.shd b/src/modules/evas/engines/gl_common/shader_3d/color_pick_frag.shd
new file mode 100644
index 0000000000..5e0fc6c494
--- /dev/null
+++ b/src/modules/evas/engines/gl_common/shader_3d/color_pick_frag.shd
@@ -0,0 +1,7 @@
1uniform float uColorPick;
2
3void main()
4{
5 gl_FragColor = vec4(uColorPick);
6}
7
diff --git a/src/modules/evas/engines/gl_common/shader_3d/color_pick_vert.shd b/src/modules/evas/engines/gl_common/shader_3d/color_pick_vert.shd
new file mode 100644
index 0000000000..472866f521
--- /dev/null
+++ b/src/modules/evas/engines/gl_common/shader_3d/color_pick_vert.shd
@@ -0,0 +1,28 @@
1uniform mat4 uMatrixMvp;
2
3#ifdef VERTEX_POSITION
4attribute vec4 aPosition0;
5#endif //VERTEX_POSITION
6
7#ifdef VERTEX_POSITION_BLEND
8attribute vec4 aPosition1;
9uniform float uPositionWeight;
10#endif //VERTEX_POSITION_BLEND
11
12void main()
13{
14#ifdef VERTEX_POSITION_BLEND
15 vec4 position = aPosition0 * uPositionWeight +
16 aPosition1 * (1.0 - uPositionWeight);
17 position = vec4(position.xyz, 1.0);
18#else
19
20#ifdef VERTEX_POSITION
21 vec4 position = vec4(aPosition0.xyz, 1.0);
22#endif // VERTEX_POSITION
23
24#endif //VERTEX_POSITION_BLEND
25
26 gl_Position = uMatrixMvp * position;
27}
28
diff --git a/src/modules/evas/engines/gl_common/shader_3d/diffuse_frag.shd b/src/modules/evas/engines/gl_common/shader_3d/diffuse_frag.shd
new file mode 100644
index 0000000000..7b6dc2bf69
--- /dev/null
+++ b/src/modules/evas/engines/gl_common/shader_3d/diffuse_frag.shd
@@ -0,0 +1,47 @@
1#ifdef NEED_TEX_COORD
2varying vec2 vTexCoord;
3#endif //TEX_COORD
4
5#ifdef FOG_ENABLED
6uniform float uFogFactor;
7uniform vec4 uFogColor;
8#endif //FOG_ENABLED
9
10#ifdef DIFFUSE
11uniform vec4 uMaterialDiffuse;
12
13#ifdef DIFFUSE_TEXTURE
14uniform sampler2D uTextureDiffuse0;
15#endif //DIFFUSE_TEXTURE
16
17#ifdef DIFFUSE_TEXTURE_BLEND
18uniform sampler2D uTextureDiffuse1;
19uniform float uTextureDiffuseWeight;
20#endif //DIFFUSE_TEXTURE_BLEND
21
22#endif //DIFFUSE
23
24void main() {
25
26#ifdef DIFFUSE_TEXTURE_BLEND
27 gl_FragColor = (texture2D(uTextureDiffuse0, vTexCoord) *
28 uTextureDiffuseWeight + texture2D(uTextureDiffuse1, vTexCoord) *
29 (1.0 - uTextureDiffuseWeight)) * uMaterialDiffuse;
30#else
31
32#ifdef DIFFUSE_TEXTURE
33 gl_FragColor = texture2D(uTextureDiffuse0, vTexCoord) * uMaterialDiffuse;
34#else
35 gl_FragColor = uMaterialDiffuse;
36#endif //DIFFUSE_TEXTURE
37
38#endif //DIFFUSE_TEXTURE_BLEND
39
40#ifdef FOG_ENABLED
41 float z = gl_FragCoord.z / gl_FragCoord.w;
42 float fogFactor = exp2( -uFogFactor * uFogFactor * z * z * 1.44);
43 fogFactor = clamp(fogFactor, 0.0, 1.0);
44 gl_FragColor = mix(uFogColor, gl_FragColor, fogFactor);
45#endif //FOG_ENABLED
46
47}
diff --git a/src/modules/evas/engines/gl_common/shader_3d/diffuse_vert.shd b/src/modules/evas/engines/gl_common/shader_3d/diffuse_vert.shd
new file mode 100644
index 0000000000..2b62b829cc
--- /dev/null
+++ b/src/modules/evas/engines/gl_common/shader_3d/diffuse_vert.shd
@@ -0,0 +1,52 @@
1uniform mat4 uMatrixMvp;
2
3#ifdef VERTEX_POSITION
4attribute vec4 aPosition0;
5#endif //VERTEX_POSITION
6
7#ifdef VERTEX_POSITION_BLEND
8attribute vec4 aPosition1;
9uniform float uPositionWeight;
10#endif //VERTEX_POSITION_BLEND
11
12#ifdef VERTEX_TEXCOORD
13attribute vec4 aTexCoord0;
14#endif //VERTEX_TEXCOORD
15
16#ifdef VERTEX_TEXCOORD_BLEND
17attribute vec4 aTexCoord1;
18uniform float uTexCoordWeight;
19#endif //VERTEX_TEXCOORD_BLEND
20
21#ifdef NEED_TEX_COORD
22varying vec2 vTexCoord;
23#endif //NEED_TEX_COORD
24
25void main()
26{
27
28#ifdef VERTEX_POSITION_BLEND
29 vec4 position = aPosition0 * uPositionWeight +
30 aPosition1 * (1.0 - uPositionWeight);
31 position = vec4(position.xyz, 1.0);
32#else
33
34#ifdef VERTEX_POSITION
35 vec4 position = vec4(aPosition0.xyz, 1.0);
36#endif // VERTEX_POSITION
37
38#endif //VERTEX_POSITION_BLEND
39
40#ifdef VERTEX_TEXCOORD_BLEND
41 vTexCoord = aTexCoord0.st * uTexCoordWeight +
42 aTexCoord1.st * (1.0 - uTexCoordWeight);
43#else
44
45#ifdef VERTEX_TEXCOORD
46 vTexCoord = aTexCoord0.st;
47#endif //VERTEX_TEXCOORD
48
49#endif //VERTEX_TEXCOORD_BLEND
50
51 gl_Position = uMatrixMvp * position;
52}
diff --git a/src/modules/evas/engines/gl_common/shader_3d/flat_frag.shd b/src/modules/evas/engines/gl_common/shader_3d/flat_frag.shd
new file mode 100644
index 0000000000..824fb6607c
--- /dev/null
+++ b/src/modules/evas/engines/gl_common/shader_3d/flat_frag.shd
@@ -0,0 +1,195 @@
1varying vec2 vFactor;
2
3#ifdef NEED_TEX_COORD
4varying vec2 vTexCoord;
5#endif //TEX_COORD
6
7#ifdef FOG_ENABLED
8uniform float uFogFactor;
9uniform vec4 uFogColor;
10#endif //FOG_ENABLED
11
12#ifdef SHADOWED
13varying vec4 vLightPosition;
14uniform sampler2D uShadowMap;
15float shadow;
16#endif //SHADOWED
17
18#ifdef DIFFUSE
19uniform vec4 uMaterialDiffuse;
20uniform vec4 uLightDiffuse;
21
22#ifdef DIFFUSE_TEXTURE
23uniform sampler2D uTextureDiffuse0;
24#endif //DIFFUSE_TEXTURE
25
26#ifdef DIFFUSE_TEXTURE_BLEND
27uniform sampler2D uTextureDiffuse1;
28uniform float uTextureDiffuseWeight;
29#endif //DIFFUSE_TEXTURE_BLEND
30
31#endif //DIFFUSE
32
33#ifdef SPECULAR
34uniform vec4 uLightSpecular;
35uniform float uMaterialShininess;
36uniform vec4 uMaterialSpecular;
37
38#ifdef SPECULAR_TEXTURE
39uniform sampler2D uTextureSpecular0;
40#endif //SPECULAR_TEXTURE
41
42#ifdef SPECULAR_TEXTURE_BLEND
43uniform sampler2D uTextureSpecular1;
44uniform float uTextureSpecularWeight;
45#endif //SPECULAR_TEXTURE_BLEND
46
47#endif //SPECULAR
48
49#ifdef AMBIENT
50uniform vec4 uMaterialAmbient;
51uniform vec4 uLightAmbient;
52
53#ifdef AMBIENT_TEXTURE
54uniform sampler2D uTextureAmbient0;
55#endif //AMBIENT_TEXTURE
56
57#ifdef AMBIENT_TEXTURE_BLEND
58uniform sampler2D uTextureAmbient1;
59uniform float uTextureAmbientWeight;
60#endif //AMBIENT_TEXTURE_BLEND
61
62#endif //AMBIENT
63
64#ifdef EMISSION
65uniform vec4 uMaterialEmission;
66
67#ifdef EMISSION_TEXTURE
68uniform sampler2D uTextureEmission0;
69#endif //EMISSION_TEXTURE
70
71#ifdef EMISSION_TEXTURE_BLEND
72uniform sampler2D uTextureEmission1;
73uniform float uTextureEmissionWeight;
74#endif //EMISSION_TEXTURE_BLEND
75
76#endif //EMISSION
77
78#ifdef SHADOWED
79float pcf(vec4 lpos, float size)
80{
81 vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;
82 float i, j, randx, randy, shadow;
83 shadow = 0.0;
84 for (i = -4.0; i < 4.0; i++)
85 for (j = -4.0; j < 4.0; j++)
86 shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy +vec2(i / 8.0, j / 8.0)*size).x);
87 return shadow / 64.0;
88}
89#endif //SHADOWED
90
91void fragmentFlat()
92{
93 vec4 color;
94
95#ifdef DIFFUSE
96
97#ifdef DIFFUSE_TEXTURE_BLEND
98 color = texture2D(uTextureDiffuse0, vTexCoord) * uTextureDiffuseWeight +
99 texture2D(uTextureDiffuse1, vTexCoord) * (1.0 - uTextureDiffuseWeight);
100 color *= uMaterialDiffuse;
101#else
102
103#ifdef DIFFUSE_TEXTURE
104 color = texture2D(uTextureDiffuse0, vTexCoord) * uMaterialDiffuse;
105#else
106 color = uMaterialDiffuse;
107#endif //DIFFUSE_TEXTURE
108
109#endif //DIFFUSE_TEXTURE_BLEND
110 gl_FragColor = uLightDiffuse * color * vFactor.x;
111#else
112 gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
113#endif //DIFFUSE
114
115#ifdef SPECULAR
116
117#ifdef SPECULAR_TEXTURE_BLEND
118 color = texture2D(uTextureSpecular0, vTexCoord) * uTextureSpecularWeight +
119 texture2D(uTextureSpecular1, vTexCoord) * (1.0 - uTextureSpecularWeight);
120 color *= uMaterialSpecular;
121#else
122
123#ifdef SPECULAR_TEXTURE
124 color = texture2D(uTextureSpecular0, vTexCoord) * uMaterialSpecular;
125#else
126 color = uMaterialSpecular;
127#endif //SPECULAR_TEXTURE
128
129#endif //SPECULAR_TEXTURE_BLEND
130
131 gl_FragColor += uLightSpecular * color * vFactor.y;
132
133#endif //SPECULAR
134
135#ifdef SHADOWED
136 gl_FragColor *= shadow;
137#endif //SHADOWED
138
139#ifdef E3D_SHADER_FLAG_AMBIENT
140
141#ifdef AMBIENT_TEXTURE_BLEND
142
143 color = texture2D(uTextureAmbient0, vTexCoord) * uTextureAmbientWeight +
144 texture2D(uTextureAmbient1, vTexCoord) * (1.0 - uTextureAmbientWeight);
145 color *= uMaterialAmbient;
146
147#else
148
149#ifdef AMBIENT_TEXTURE
150 color = texture2D(uTextureAmbient0, vTexCoord) * uMaterialAmbient;
151#else
152 color = uMaterialAmbient;
153#endif //AMBIENT_TEXTURE
154
155#endif //AMBIENT_TEXTURE_BLEND
156 gl_FragColor += uLightAmbient * color;
157#endif //AMBIENT
158
159#ifdef EMISSION
160
161#ifdef EMISSION_TEXTURE_BLEND
162 color = texture2D(uTextureEmission0, vTexCoord) * uTextureEmissionWeight +
163 texture2D(uTextureEmission1, vTexCoord) * (1.0 - uTextureEmissionWeight);
164 color *= uMaterialEmission;
165#else
166
167#ifdef EMISSION_TEXTURE
168 color = texture2D(uTextureEmission0, vTexCoord) * uMaterialEmission;
169#else
170 color = uMaterialEmission;
171#endif //EMISSION_TEXTURE
172
173#endif //EMISSION_TEXTURE_BLEND
174
175 gl_FragColor += color;
176#endif //EMISSION
177
178}
179
180void main() {
181
182#ifdef SHADOWED
183 shadow = pcf(vLightPosition, 1.0 / 200.0);
184#endif //SHADOWED
185
186 fragmentFlat();
187
188#ifdef FOG_ENABLED
189 float z = gl_FragCoord.z / gl_FragCoord.w;
190 float fogFactor = exp2( -uFogFactor * uFogFactor * z * z * 1.44);
191 fogFactor = clamp(fogFactor, 0.0, 1.0);
192 gl_FragColor = mix(uFogColor, gl_FragColor, fogFactor);
193#endif //FOG_ENABLED
194
195}
diff --git a/src/modules/evas/engines/gl_common/shader_3d/flat_vert.shd b/src/modules/evas/engines/gl_common/shader_3d/flat_vert.shd
new file mode 100644
index 0000000000..37aba1c18a
--- /dev/null
+++ b/src/modules/evas/engines/gl_common/shader_3d/flat_vert.shd
@@ -0,0 +1,154 @@
1uniform mat4 uMatrixMvp;
2uniform mat3 uMatrixNormal;
3uniform mat4 uMatrixModelview;
4uniform vec4 uLightPosition;
5varying vec2 vFactor;
6
7#ifdef SHADOWED
8uniform mat4 uMatrixLight;
9varying vec4 vLightPosition;
10#endif //SHADOWED
11
12#ifdef VERTEX_POSITION
13attribute vec4 aPosition0;
14#endif //VERTEX_POSITION
15
16#ifdef VERTEX_POSITION_BLEND
17attribute vec4 aPosition1;
18uniform float uPositionWeight;
19#endif //VERTEX_POSITION_BLEND
20
21#ifdef VERTEX_NORMAL
22attribute vec4 aNormal0;
23#endif //VERTEX_NORMAL
24
25#ifdef VERTEX_NORMAL_BLEND
26attribute vec4 aNormal1;
27uniform float uNormalWeight;
28#endif //VERTEX_NORMAL_BLEND
29
30#ifdef VERTEX_TEXCOORD
31attribute vec4 aTexCoord0;
32#endif //VERTEX_TEXCOORD
33
34#ifdef VERTEX_TEXCOORD_BLEND
35attribute vec4 aTexCoord1;
36uniform float uTexCoordWeight;
37#endif //VERTEX_TEXCOORD_BLEND
38
39#ifdef NEED_TEX_COORD
40varying vec2 vTexCoord;
41#endif //NEED_TEX_COORD
42
43#ifdef LIGHT_SPOT
44uniform vec3 uLightSpotDir;
45uniform float uLightSpotExp;
46uniform float uLightSpotCutoffCos;
47#endif //LIGHT_SPOT
48
49#ifdef SPECULAR
50uniform float uMaterialShininess;
51#endif //SPECULAR
52
53#ifdef LIGHT_ATTENUATION
54uniform vec3 uLightAtten;
55#endif //LIGHT_ATTENUATION
56
57void vertexFlat(vec4 position, vec3 normal)
58{
59 vec3 lv;
60 float factor;
61 normal = uMatrixNormal * normal;
62 position = uMatrixModelview * position;
63
64#ifdef NORMALIZE_NORMALS
65 normal = normalize(normal);
66#endif //NORMALIZE_NORMALS
67
68#ifdef LIGHT_DIRECTIONAL
69 lv = uLightPosition.xyz;
70#else
71 lv = uLightPosition.xyz - position.xyz;
72 lv = normalize(lv);
73#endif //LIGHT_DIRECTIONAL
74
75 factor = max(dot(lv, normal), 0.0);
76
77#ifdef LIGHT_SPOT
78 float f = dot(-lv, uLightSpotDir);
79 if (f > uLightSpotCutoffCos)
80 factor *= pow(f, uLightSpotExp);
81 else
82 factor = 0.0;
83#endif //LIGHT_SPOT
84
85 if (factor > 0.0)
86 {
87
88#ifdef DIFFUSE
89 vFactor.x = factor;
90#else
91 vFactor.x = 0.0;
92#endif //DIFFUSE
93
94#ifdef SPECULAR
95 vec3 hv = normalize(normalize(-position.xyz) + lv);
96 factor = pow(max(dot(hv, normal), 0.0), uMaterialShininess);
97 vFactor.y = factor;
98#endif //SPECULAR
99
100 }
101 else
102 vFactor = vec2(0.0, 0.0);
103
104 /* Light attenuation. */
105#ifdef LIGHT_ATTENUATION
106 float dist = length(lv);
107 vFactor /= dot(uLightAtten, vec3(1.0, dist, dist * dist));
108#endif //LIGHT_ATTENUATION
109}
110
111void main()
112{
113
114#ifdef VERTEX_POSITION_BLEND
115 vec4 position = aPosition0 * uPositionWeight +
116 aPosition1 * (1.0 - uPositionWeight);
117 position = vec4(position.xyz, 1.0);
118#else
119
120#ifdef VERTEX_POSITION
121 vec4 position = vec4(aPosition0.xyz, 1.0);
122#endif // VERTEX_POSITION
123
124#endif //VERTEX_POSITION_BLEND
125
126#ifdef VERTEX_NORMAL_BLEND
127 vec3 normal = aNormal0.xyz * uNormalWeight +
128 aNormal1.xyz * (1.0 - uNormalWeight);
129#else
130
131#ifdef VERTEX_NORMAL
132 vec3 normal = aNormal0.xyz;
133#endif //VERTEX_NORMAL
134
135#endif //VERTEX_NORMAL_BLEND
136
137#ifdef VERTEX_TEXCOORD_BLEND
138 vTexCoord = aTexCoord0.st * uTexCoordWeight +
139 aTexCoord1.st * (1.0 - uTexCoordWeight);
140#else
141
142#ifdef VERTEX_TEXCOORD
143 vTexCoord = aTexCoord0.st;
144#endif //VERTEX_TEXCOORD
145
146#endif //VERTEX_TEXCOORD_BLEND
147
148 gl_Position = uMatrixMvp * position;
149 vertexFlat(position, normal);
150
151#ifdef SHADOWED
152 vLightPosition = uMatrixLight * position;
153#endif
154}
diff --git a/src/modules/evas/engines/gl_common/shader_3d/gen_shaders_3d.sh b/src/modules/evas/engines/gl_common/shader_3d/gen_shaders_3d.sh
new file mode 100755
index 0000000000..8bb6a2af01
--- /dev/null
+++ b/src/modules/evas/engines/gl_common/shader_3d/gen_shaders_3d.sh
@@ -0,0 +1,45 @@
1#!/bin/bash
2
3# This script will generate a C file containing all the shaders used by Evas_3D
4
5DIR=`dirname $0`
6
7OUTPUT=${DIR}/evas_gl_3d_shaders.x
8
9exec 1<&-
10exec 1>${OUTPUT}
11
12SHADERS="$@"
13vert_shaders_source=""
14frag_shaders_source=""
15
16# Write header
17printf "/* DO NOT MODIFY THIS FILE AS IT IS AUTO-GENERATED\n * See: $0 */\n\n"
18for shd in ${SHADERS} ; do
19 lname=`basename ${shd} .shd`
20
21 if echo ${lname} |grep _vert 2>&1 >> /dev/null ; then
22 vert_shaders_source="${vert_shaders_source} ${lname}_glsl,\n"
23 fi
24 if echo ${lname} |grep _frag 2>&1 >> /dev/null ; then
25 frag_shaders_source="${frag_shaders_source} ${lname}_glsl,\n"
26 fi
27 OIFS=$IFS
28 IFS=$'\n'
29 printf "static const char const ${lname}_glsl[] ="
30 for line in `cat ${shd}` ; do
31 printf "\n \"${line}\\\n\""
32 done
33 printf ";\n\n"
34 IFS=${OIFS}
35done
36
37printf "static const char *vertex_shaders[] =
38{\n"
39 printf "${vert_shaders_source}"
40printf "};\n\n"
41
42printf "static const char *fragment_shaders[] =
43{\n"
44 printf "${frag_shaders_source}"
45printf "};\n"
diff --git a/src/modules/evas/engines/gl_common/shader_3d/normal_map_frag.shd b/src/modules/evas/engines/gl_common/shader_3d/normal_map_frag.shd
new file mode 100644
index 0000000000..766e07fb40
--- /dev/null
+++ b/src/modules/evas/engines/gl_common/shader_3d/normal_map_frag.shd
@@ -0,0 +1,283 @@
1varying vec3 vLightVector;
2varying vec3 vLightHalfVector;
3uniform sampler2D uTextureNormal0;
4varying vec3 vEyeVector;
5
6#ifdef NEED_TEX_COORD
7varying vec2 vTexCoord;
8#endif //TEX_COORD
9
10#ifdef FOG_ENABLED
11uniform float uFogFactor;
12uniform vec4 uFogColor;
13#endif //FOG_ENABLED
14
15#ifdef SHADOWED
16varying vec4 vLightPosition;
17uniform sampler2D uShadowMap;
18float shadow;
19#endif //SHADOWED
20
21#ifdef NORMAL_TEXTURE_BLEND
22uniform sampler2D uTextureNormal1;
23uniform float uTextureNormalWeight;
24#endif //NORMAL_TEXTURE_BLEND
25
26#ifndef VERTEX_TANGENT
27varying vec3 vNormal;
28#endif //VERTEX_TANGENT
29
30#ifdef DIFFUSE
31uniform vec4 uMaterialDiffuse;
32uniform vec4 uLightDiffuse;
33
34#ifdef DIFFUSE_TEXTURE
35uniform sampler2D uTextureDiffuse0;
36#endif //DIFFUSE_TEXTURE
37
38#ifdef DIFFUSE_TEXTURE_BLEND
39uniform sampler2D uTextureDiffuse1;
40uniform float uTextureDiffuseWeight;
41#endif //DIFFUSE_TEXTURE_BLEND
42
43#endif //DIFFUSE
44
45#ifdef SPECULAR
46uniform vec4 uLightSpecular;
47uniform float uMaterialShininess;
48uniform vec4 uMaterialSpecular;
49
50#ifdef SPECULAR_TEXTURE
51uniform sampler2D uTextureSpecular0;
52#endif //SPECULAR_TEXTURE
53
54#ifdef SPECULAR_TEXTURE_BLEND
55uniform sampler2D uTextureSpecular1;
56uniform float uTextureSpecularWeight;
57#endif //SPECULAR_TEXTURE_BLEND
58
59#endif //SPECULAR
60
61#ifdef AMBIENT
62uniform vec4 uMaterialAmbient;
63uniform vec4 uLightAmbient;
64
65#ifdef AMBIENT_TEXTURE
66uniform sampler2D uTextureAmbient0;
67#endif //AMBIENT_TEXTURE
68
69#ifdef AMBIENT_TEXTURE_BLEND
70uniform sampler2D uTextureAmbient1;
71uniform float uTextureAmbientWeight;
72#endif //AMBIENT_TEXTURE_BLEND
73
74#endif //AMBIENT
75
76#ifdef EMISSION
77uniform vec4 uMaterialEmission;
78
79#ifdef EMISSION_TEXTURE
80uniform sampler2D uTextureEmission0;
81#endif //EMISSION_TEXTURE
82
83#ifdef EMISSION_TEXTURE_BLEND
84uniform sampler2D uTextureEmission1;
85uniform float uTextureEmissionWeight;
86#endif //EMISSION_TEXTURE_BLEND
87
88#endif //EMISSION
89
90#ifdef LIGHT_SPOT
91uniform vec3 uLightSpotDir;
92uniform float uLightSpotExp;
93uniform float uLightSpotCutoffCos;
94#endif //LIGHT_SPOT
95
96#ifdef LIGHT_ATTENUATION
97varying float vLightDist;
98#endif //LIGHT_ATTENUATION
99
100#ifndef VERTEX_TANGENT
101
102mat3 cotangent_frame(vec3 n, vec3 p, vec2 uv)
103{
104 vec3 dp1 = dFdx(p);
105 vec3 dp2 = dFdy(p);
106 vec2 duv1 = dFdx(uv);
107 vec2 duv2 = dFdy(uv);
108 vec3 dp2perp = cross(dp2, n);
109 vec3 dp1perp = cross(n, dp1);
110 vec3 t = dp2perp * duv1.x + dp1perp * duv2.x;
111 vec3 b = dp2perp * duv1.y + dp1perp * duv2.y;
112 float invmax = inversesqrt(max(dot(t, t), dot(b, b)));
113 return mat3(t * invmax, b * invmax, n);
114}
115
116vec3 perturb_normal(vec3 normal)
117{
118 mat3 tbn = cotangent_frame(vNormal, -vEyeVector, vTexCoord);
119 return normalize(tbn * normal);
120}
121#endif //VERTEX_TANGENT
122
123void fragmentNormalMap()
124{
125 float factor;
126 vec3 normal;
127 vec4 color;
128
129#ifdef NORMAL_TEXTURE_BLEND
130 normal = texture2D(uTextureNormal0, vTexCoord).rgb * uTextureNormalWeight;
131 normal += texture2D(uTextureNormal1, vTexCoord).rgb *
132 (1.0 - uTextureNormalWeight);
133#else
134 normal = texture2D(uTextureNormal0, vTexCoord).rgb;
135#endif //NORMAL_TEXTURE_BLEND
136
137 normal = 2.0 * normal - 1.0;
138
139#ifndef VERTEX_TANGENT
140 normal = perturb_normal(normal);
141#endif //VERTEX_TANGENT
142
143 vec3 lv = normalize(vLightVector);
144 normal = normalize(normal);
145
146 factor = dot(lv, normal);
147
148#ifdef LIGHT_SPOT
149 float f = dot(-lv, normalize(uLightSpotDir));
150
151 if (f > uLightSpotCutoffCos)
152 factor *= pow(f, uLightSpotExp);
153 else
154 factor = 0.0;
155#endif //LIGHT_SPOT
156
157 if (factor > 0.0)
158 {
159
160#ifdef DIFFUSE
161
162#ifdef DIFFUSE_TEXTURE_BLEND
163 color = texture2D(uTextureDiffuse0, vTexCoord) * uTextureDiffuseWeight +
164 texture2D(uTextureDiffuse1, vTexCoord) * (1.0 - uTextureDiffuseWeight);
165#else
166
167#ifdef DIFFUSE_TEXTURE
168 color = texture2D(uTextureDiffuse0, vTexCoord);
169#else
170 color = uMaterialDiffuse;
171#endif //DIFFUSE_TEXTURE
172
173#endif //DIFFUSE_TEXTURE_BLEND
174
175 gl_FragColor = uLightDiffuse * color * factor;
176
177#else
178 gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
179#endif //DIFFUSE
180
181#ifdef SPECULAR
182
183 factor = dot(normalize(vLightHalfVector), normal);
184 if (factor > 0.0)
185 {
186 factor = pow(factor, uMaterialShininess);
187
188#ifdef SPECULAR_TEXTURE_BLEND
189 color = texture2D(uTextureSpecular0, vTexCoord) * uTextureSpecularWeight +
190 texture2D(uTextureSpecular1, vTexCoord) * (1.0 - uTextureSpecularWeight);
191#else
192#ifdef SPECULAR_TEXTURE
193 color = texture2D(uTextureSpecular0, vTexCoord);
194#else
195 color = uMaterialSpecular;
196#endif //SPECULAR_TEXTURE
197
198#endif //SPECULAR_TEXTURE_BLEND
199
200 gl_FragColor += uLightSpecular * color * factor;
201 }
202
203#endif //SPECULAR
204
205#ifdef SHADOWED
206 gl_FragColor *= shadow;
207#endif //SHADOWED
208
209 }
210 else
211 gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
212
213#ifdef AMBIENT
214#ifdef AMBIENT_TEXTURE_BLEND
215 color = texture2D(uTextureAmbient0, vTexCoord) * uTextureAmbientWeight +
216 texture2D(uTextureAmbient1, vTexCoord) * (1.0 - uTextureAmbientWeight);
217#else
218
219#ifdef AMBIENT_TEXTURE
220 color = texture2D(uTextureAmbient0, vTexCoord);
221#else
222 color = uMaterialAmbient;
223#endif //AMBIENT_TEXTURE
224
225#endif //AMBIENT_TEXTURE_BLEND
226
227 gl_FragColor += uLightAmbient * color;
228#endif //AMBIENT
229
230#ifdef LIGHT_ATTENUATION
231 gl_FragColor /= dot(uLightAtten, vec3(1.0, vLightDist, vLightDist * vLightDist));
232#endif //LIGHT_ATTENUATION
233
234#ifdef EMISSION
235
236#ifdef EMISSION_TEXTURE_BLEND
237 color = texture2D(uTextureEmission0, vTexCoord) * uTextureEmissionWeight +
238 texture2D(uTextureEmission1, vTexCoord) * (1.0 - uTextureEmissionWeight);
239#else
240
241#ifdef EMISSION_TEXTURE
242 color = texture2D(uTextureEmission0, vTexCoord);
243#else
244 color = uMaterialEmission;
245#endif //EMISSION_TEXTURE
246
247#endif //EMISSION_TEXTURE_BLEND
248
249 gl_FragColor += color;
250#endif //EMISSION
251
252}
253
254#ifdef SHADOWED
255float pcf(vec4 lpos, float size)
256{
257 vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;
258 float i, j, randx, randy, shadow;
259 shadow = 0.0;
260 for (i = -4.0; i < 4.0; i++)
261 for (j = -4.0; j < 4.0; j++)
262 shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy +vec2(i / 8.0, j / 8.0)*size).x);
263 return shadow / 64.0;
264}
265#endif //SHADOWED
266
267void main() {
268
269#ifdef SHADOWED
270 shadow = pcf(vLightPosition, 1.0 / 200.0);
271#endif //SHADOWED
272
273 fragmentNormalMap();
274
275#ifdef FOG_ENABLED
276 float z = gl_FragCoord.z / gl_FragCoord.w;
277 float fogFactor = exp2( -uFogFactor * uFogFactor * z * z * 1.44);
278 fogFactor = clamp(fogFactor, 0.0, 1.0);
279 gl_FragColor = mix(uFogColor, gl_FragColor, fogFactor);
280#endif //FOG_ENABLED
281
282}
283
diff --git a/src/modules/evas/engines/gl_common/shader_3d/normal_map_vert.shd b/src/modules/evas/engines/gl_common/shader_3d/normal_map_vert.shd
new file mode 100644
index 0000000000..3dc42d288f
--- /dev/null
+++ b/src/modules/evas/engines/gl_common/shader_3d/normal_map_vert.shd
@@ -0,0 +1,189 @@
1uniform mat4 uMatrixMvp;
2uniform mat3 uMatrixNormal;
3uniform mat4 uMatrixModelview;
4uniform vec4 uLightPosition;
5varying vec3 vLightVector;
6varying vec3 vLightHalfVector;
7varying vec3 vEyeVector;
8
9#ifndef VERTEX_TANGENT
10varying vec3 vNormal;
11#endif //VERTEX_TANGENT
12
13#ifdef SHADOWED
14uniform mat4 uMatrixLight;
15varying vec4 vLightPosition;
16#endif //SHADOWED
17
18#ifdef VERTEX_POSITION
19attribute vec4 aPosition0;
20#endif //VERTEX_POSITION
21
22#ifdef VERTEX_POSITION_BLEND
23attribute vec4 aPosition1;
24uniform float uPositionWeight;
25#endif //VERTEX_POSITION_BLEND
26
27#ifdef VERTEX_NORMAL
28attribute vec4 aNormal0;
29#endif //VERTEX_NORMAL
30
31#ifdef VERTEX_NORMAL_BLEND
32attribute vec4 aNormal1;
33uniform float uNormalWeight;
34#endif //VERTEX_NORMAL_BLEND
35
36#ifdef VERTEX_TANGENT
37attribute vec4 aTangent0;
38#endif //VERTEX_TANGENT
39
40#ifdef VERTEX_TANGENT_BLEND
41attribute vec4 aTangent1;
42uniform float uTangentWeight;
43#endif //VERTEX_TANGENT_BLEND
44
45#ifdef VERTEX_TEXCOORD
46attribute vec4 aTexCoord0;
47#endif //VERTEX_TEXCOORD
48
49#ifdef VERTEX_TEXCOORD_BLEND
50attribute vec4 aTexCoord1;
51uniform float uTexCoordWeight;
52#endif //VERTEX_TEXCOORD_BLEND
53
54#ifdef NEED_TEX_COORD
55varying vec2 vTexCoord;
56#endif //NEED_TEX_COORD
57
58#ifdef LIGHT_ATTENUATION
59varying float vLightDist;
60#endif //LIGHT_ATTENUATION
61
62#ifndef VERTEX_TANGENT
63void vertexNormalMap(vec4 position, vec3 normal)
64{
65 normal = uMatrixNormal * normal;
66 position = uMatrixModelview * position;
67 vEyeVector = normalize(-position.xyz);
68
69#ifdef NORMALIZE_NORMALS
70 normal = normalize(normal);
71#endif //NORMALIZE_NORMALS
72
73#ifdef LIGHT_DIRECTIONAL
74 vLightVector = uLightPosition.xyz;
75#else
76 vLightVector = uLightPosition.xyz - position.xyz;
77
78#ifdef LIGHT_ATTENUATION
79 vLightDist = length(vLightVector);
80#endif //LIGHT_ATTENUATION
81
82 vLightVector = normalize(vLightVector);
83#endif //LIGHT_DIRECTIONAL
84
85 vLightHalfVector = normalize(vEyeVector + vLightVector);
86 vNormal = normal;
87}
88
89#else
90
91void vertexNormalMap(vec4 position, vec3 normal, vec3 tangent)
92{
93 vec3 n = normalize(uMatrixNormal * normal);
94 vec3 t = normalize(uMatrixNormal * tangent);
95 vec3 b = cross(n, t);
96 vec3 tmp;
97
98 position = uMatrixModelview * position;
99
100#ifdef LIGHT_DIRECTIONAL
101 vec3 lightDir = uLightPosition.xyz;
102#else
103 vec3 lightDir = uLightPosition.xyz - position.xyz;
104
105#ifdef LIGHT_ATTENUATION
106 vLightDist = length(lightDir);
107#endif //LIGHT_ATTENUATION
108
109 lightDir = normalize(lightDir);
110#endif //LIGHT_DIRECTIONAL
111
112 tmp.x = dot(lightDir, t);
113 tmp.y = dot(lightDir, b);
114 tmp.z = dot(lightDir, n);
115 vLightVector = tmp;
116
117 tmp.x = dot(position.xyz, t);
118 tmp.y = dot(position.xyz, b);
119 tmp.z = dot(position.xyz, n);
120 vEyeVector = normalize(tmp);
121
122 vec3 hv = normalize(normalize(-position.xyz) + lightDir);
123 tmp.x = dot(hv, t);
124 tmp.y = dot(hv, b);
125 tmp.z = dot(hv, n);
126 vLightHalfVector = tmp;
127}
128#endif //VERTEX_TANGENT
129
130void main()
131{
132
133#ifdef VERTEX_POSITION_BLEND
134 vec4 position = aPosition0 * uPositionWeight +
135 aPosition1 * (1.0 - uPositionWeight);
136 position = vec4(position.xyz, 1.0);
137#else
138
139#ifdef VERTEX_POSITION
140 vec4 position = vec4(aPosition0.xyz, 1.0);
141#endif // VERTEX_POSITION
142
143#endif //VERTEX_POSITION_BLEND
144
145#ifdef VERTEX_NORMAL_BLEND
146 vec3 normal = aNormal0.xyz * uNormalWeight +
147 aNormal1.xyz * (1.0 - uNormalWeight);
148#else
149
150#ifdef VERTEX_NORMAL
151 vec3 normal = aNormal0.xyz;
152#endif //VERTEX_NORMAL
153
154#endif //VERTEX_NORMAL_BLEND
155
156#ifdef VERTEX_TANGENT_BLEND
157 vec3 tangent = aTangent0.xyz * uTangentWeight +
158 aTangent1.xyz * (1.0 - uTangentWeight);
159#else
160
161#ifdef VERTEX_TANGENT
162 vec3 tangent = aTangent0.xyz;
163#endif //VERTEX_TANGENT
164
165#endif //VERTEX_TANGENT_BLEND
166
167#ifdef VERTEX_TEXCOORD_BLEND
168 vTexCoord = aTexCoord0.st * uTexCoordWeight +
169 aTexCoord1.st * (1.0 - uTexCoordWeight);
170#else
171
172#ifdef VERTEX_TEXCOORD
173 vTexCoord = aTexCoord0.st;
174#endif //VERTEX_TEXCOORD
175
176#endif //VERTEX_TEXCOORD_BLEND
177
178 gl_Position = uMatrixMvp * position;
179
180#ifdef VERTEX_TANGENT
181 vertexNormalMap(position, normal, tangent);
182#else
183 vertexNormalMap(position, normal);
184#endif //VERTEX_TANGENT
185
186#ifdef SHADOWED
187 vLightPosition = uMatrixLight * position;
188#endif
189}
diff --git a/src/modules/evas/engines/gl_common/shader_3d/phong_frag.shd b/src/modules/evas/engines/gl_common/shader_3d/phong_frag.shd
new file mode 100644
index 0000000000..f6689848e6
--- /dev/null
+++ b/src/modules/evas/engines/gl_common/shader_3d/phong_frag.shd
@@ -0,0 +1,235 @@
1varying vec3 vLightVector;
2varying vec3 vLightHalfVector;
3varying vec3 vNormal;
4
5#ifdef NEED_TEX_COORD
6varying vec2 vTexCoord;
7#endif //TEX_COORD
8
9#ifdef FOG_ENABLED
10uniform float uFogFactor;
11uniform vec4 uFogColor;
12#endif //FOG_ENABLED
13
14#ifdef SHADOWED
15varying vec4 vLightPosition;
16uniform sampler2D uShadowMap;
17float shadow;
18#endif //SHADOWED
19
20#ifdef DIFFUSE
21uniform vec4 uMaterialDiffuse;
22uniform vec4 uLightDiffuse;
23
24#ifdef DIFFUSE_TEXTURE
25uniform sampler2D uTextureDiffuse0;
26#endif //DIFFUSE_TEXTURE
27
28#ifdef DIFFUSE_TEXTURE_BLEND
29uniform sampler2D uTextureDiffuse1;
30uniform float uTextureDiffuseWeight;
31#endif //DIFFUSE_TEXTURE_BLEND
32
33#endif //DIFFUSE
34
35#ifdef SPECULAR
36uniform vec4 uLightSpecular;
37uniform float uMaterialShininess;
38uniform vec4 uMaterialSpecular;
39
40#ifdef SPECULAR_TEXTURE
41uniform sampler2D uTextureSpecular0;
42#endif //SPECULAR_TEXTURE
43
44#ifdef SPECULAR_TEXTURE_BLEND
45uniform sampler2D uTextureSpecular1;
46uniform float uTextureSpecularWeight;
47#endif //SPECULAR_TEXTURE_BLEND
48
49#endif //SPECULAR
50
51#ifdef AMBIENT
52uniform vec4 uMaterialAmbient;
53uniform vec4 uLightAmbient;
54
55#ifdef AMBIENT_TEXTURE
56uniform sampler2D uTextureAmbient0;
57#endif //AMBIENT_TEXTURE
58
59#ifdef AMBIENT_TEXTURE_BLEND
60uniform sampler2D uTextureAmbient1;
61uniform float uTextureAmbientWeight;
62#endif //AMBIENT_TEXTURE_BLEND
63
64#endif //AMBIENT
65
66#ifdef EMISSION
67uniform vec4 uMaterialEmission;
68
69#ifdef EMISSION_TEXTURE
70uniform sampler2D uTextureEmission0;
71#endif //EMISSION_TEXTURE
72
73#ifdef EMISSION_TEXTURE_BLEND
74uniform sampler2D uTextureEmission1;
75uniform float uTextureEmissionWeight;
76#endif //EMISSION_TEXTURE_BLEND
77
78#endif //EMISSION
79
80#ifdef LIGHT_SPOT
81uniform vec3 uLightSpotDir;
82uniform float uLightSpotExp;
83uniform float uLightSpotCutoffCos;
84#endif //LIGHT_SPOT
85
86#ifdef LIGHT_ATTENUATION
87varying float vLightDist;
88#endif //LIGHT_ATTENUATION
89
90void fragmentPhong()
91{
92 vec3 normal = normalize(vNormal);
93 vec3 lv = normalize(vLightVector);
94 float factor = dot(lv, normal);
95 vec4 color;
96
97#ifdef LIGHT_SPOT
98 float f = dot(-lv, normalize(uLightSpotDir));
99
100 if (f > uLightSpotCutoffCos)
101 factor *= pow(f, uLightSpotExp);
102 else
103 factor = 0.0;
104#endif //LIGHT_SPOT
105
106 if (factor > 0.0)
107 {
108
109 /* Diffuse term. */
110#ifdef DIFFUSE
111
112#ifdef DIFFUSE_TEXTURE_BLEND
113 color = texture2D(uTextureDiffuse0, vTexCoord) * uTextureDiffuseWeight +
114 texture2D(uTextureDiffuse1, vTexCoord) * (1.0 - uTextureDiffuseWeight);
115#else
116
117#ifdef DIFFUSE_TEXTURE
118 color = texture2D(uTextureDiffuse0, vTexCoord);
119#else
120 color = uMaterialDiffuse;
121#endif //DIFFUSE_TEXTURE
122
123#endif //DIFFUSE_TEXTURE_BLEND
124
125 gl_FragColor = uLightDiffuse * color * factor;
126#else
127 gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
128#endif //DIFFUSE
129
130 /* Specular term. */
131#ifdef SPECULAR
132 factor = dot(normalize(vLightHalfVector), normal);
133 if (factor > 0.0)
134 {
135 factor = pow(factor, uMaterialShininess);
136
137#ifdef SPECULAR_TEXTURE_BLEND
138 color = texture2D(uTextureSpecular0, vTexCoord) * uTextureSpecularWeight +
139 texture2D(uTextureSpecular1, vTexCoord) * (1.0 - uTextureSpecularWeight);
140#else
141
142#ifdef SPECULAR_TEXTURE
143 color = texture2D(uTextureSpecular0, vTexCoord);
144#else
145 color = uMaterialSpecular;
146#endif
147
148#endif
149
150 gl_FragColor += uLightSpecular * color * factor;
151 }
152#endif
153
154 }
155 else
156 gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
157
158#ifdef SHADOWED
159 gl_FragColor *= shadow;
160#endif //SHADOWED
161
162#ifdef AMBIENT
163#ifdef AMBIENT_TEXTURE_BLEND
164 color = texture2D(uTextureAmbient0, vTexCoord) * uTextureAmbientWeight +
165 texture2D(uTextureAmbient1, vTexCoord) * (1.0 - uTextureAmbientWeight);
166#else
167
168#ifdef AMBIENT_TEXTURE
169 color = texture2D(uTextureAmbient0, vTexCoord);
170#else
171 color = uMaterialAmbient;
172#endif
173
174#endif
175
176 gl_FragColor += uLightAmbient * color;
177#endif
178
179 /* Light attenuation. */
180#ifdef LIGHT_ATTENUATION
181 gl_FragColor /= dot(uLightAtten, vec3(1.0, vLightDist, vLightDist * vLightDist));
182#endif
183
184 /* Emission term. */
185#ifdef EMISSION
186
187#ifdef EMISSION_TEXTURE_BLEND
188 color = texture2D(uTextureEmission0, vTexCoord) * uTextureEmissionWeight +
189 texture2D(uTextureEmission1, vTexCoord) * (1.0 - uTextureEmissionWeight);
190#else
191
192#ifdef EMISSION_TEXTURE
193 color = texture2D(uTextureEmission0, vTexCoord);
194#else
195 color = uMaterialEmission;
196#endif
197
198#endif
199
200 gl_FragColor += color;
201#endif
202
203}
204
205#ifdef SHADOWED
206float pcf(vec4 lpos, float size)
207{
208 vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;
209 float i, j, randx, randy, shadow;
210 shadow = 0.0;
211 for (i = -4.0; i < 4.0; i++)
212 for (j = -4.0; j < 4.0; j++)
213 shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy +vec2(i / 8.0, j / 8.0)*size).x);
214 return shadow / 64.0;
215}
216#endif //SHADOWED
217
218void main()
219{
220
221#ifdef SHADOWED
222 shadow = pcf(vLightPosition, 1.0 / 300.0);
223#endif //SHADOWED
224
225 fragmentPhong();
226
227#ifdef FOG_ENABLED
228 float z = gl_FragCoord.z / gl_FragCoord.w;
229 float fogFactor = exp2( -uFogFactor * uFogFactor * z * z * 1.44);
230 fogFactor = clamp(fogFactor, 0.0, 1.0);
231 gl_FragColor = mix(uFogColor, gl_FragColor, fogFactor);
232#endif //FOG_ENABLED
233
234}
235
diff --git a/src/modules/evas/engines/gl_common/shader_3d/phong_vert.shd b/src/modules/evas/engines/gl_common/shader_3d/phong_vert.shd
new file mode 100644
index 0000000000..fb2c5d4c51
--- /dev/null
+++ b/src/modules/evas/engines/gl_common/shader_3d/phong_vert.shd
@@ -0,0 +1,116 @@
1uniform mat4 uMatrixMvp;
2uniform mat3 uMatrixNormal;
3uniform mat4 uMatrixModelview;
4uniform vec4 uLightPosition;
5varying vec3 vLightVector;
6varying vec3 vLightHalfVector;
7varying vec3 vNormal;
8
9#ifdef SHADOWED
10uniform mat4 uMatrixLight;
11varying vec4 vLightPosition;
12#endif //SHADOWED
13
14#ifdef VERTEX_POSITION
15attribute vec4 aPosition0;
16#endif //VERTEX_POSITION
17
18#ifdef VERTEX_POSITION_BLEND
19attribute vec4 aPosition1;
20uniform float uPositionWeight;
21#endif //VERTEX_POSITION_BLEND
22
23#ifdef VERTEX_NORMAL
24attribute vec4 aNormal0;
25#endif //VERTEX_NORMAL
26
27#ifdef VERTEX_NORMAL_BLEND
28attribute vec4 aNormal1;
29uniform float uNormalWeight;
30#endif //VERTEX_NORMAL_BLEND
31
32#ifdef VERTEX_TEXCOORD
33attribute vec4 aTexCoord0;
34#endif //VERTEX_TEXCOORD
35
36#ifdef VERTEX_TEXCOORD_BLEND
37attribute vec4 aTexCoord1;
38uniform float uTexCoordWeight;
39#endif //VERTEX_TEXCOORD_BLEND
40
41#ifdef NEED_TEX_COORD
42varying vec2 vTexCoord;
43#endif //NEED_TEX_COORD
44
45#ifdef LIGHT_ATTENUATION
46varying float vLightDist;
47#endif //LIGHT_ATTENUATION
48
49void vertexPhong(vec4 position, vec3 normal)
50{
51 normal = uMatrixNormal * normal;
52 position = uMatrixModelview * position;
53
54#ifdef NORMALIZE_NORMALS
55 normal = normalize(normal);
56#endif //NORMALIZE_NORMALS
57
58#ifdef LIGHT_DIRECTIONAL
59 vLightVector = uLightPosition.xyz;
60#else
61 vLightVector = uLightPosition.xyz - position.xyz;
62
63#ifdef LIGHT_ATTENUATION
64 vLightDist = length(vLightVector);
65#endif //LIGHT_ATTENUATION
66
67 vLightVector = normalize(vLightVector);
68#endif //LIGHT_DIRECTIONAL
69
70 vLightHalfVector = normalize(normalize(-position.xyz) + vLightVector);
71 vNormal = normal;
72}
73
74void main() {
75
76#ifdef VERTEX_POSITION_BLEND
77 vec4 position = aPosition0 * uPositionWeight +
78 aPosition1 * (1.0 - uPositionWeight);
79 position = vec4(position.xyz, 1.0);
80#else
81
82#ifdef VERTEX_POSITION
83 vec4 position = vec4(aPosition0.xyz, 1.0);
84#endif // VERTEX_POSITION
85
86#endif //VERTEX_POSITION_BLEND
87
88#ifdef VERTEX_NORMAL_BLEND
89 vec3 normal = aNormal0.xyz * uNormalWeight +
90 aNormal1.xyz * (1.0 - uNormalWeight);
91#else
92
93#ifdef VERTEX_NORMAL
94 vec3 normal = aNormal0.xyz;
95#endif //VERTEX_NORMAL
96
97#endif //VERTEX_NORMAL_BLEND
98
99#ifdef VERTEX_TEXCOORD_BLEND
100 vTexCoord = aTexCoord0.st * uTexCoordWeight +
101 aTexCoord1.st * (1.0 - uTexCoordWeight);
102#else
103
104#ifdef VERTEX_TEXCOORD
105 vTexCoord = aTexCoord0.st;
106#endif //VERTEX_TEXCOORD
107
108#endif //VERTEX_TEXCOORD_BLEND
109
110 gl_Position = uMatrixMvp * position;
111 vertexPhong(position, normal);
112
113#ifdef SHADOWED
114 vLightPosition = uMatrixLight * position;
115#endif //SHADOWED
116}
diff --git a/src/modules/evas/engines/gl_common/shader_3d/shadow_map_frag.shd b/src/modules/evas/engines/gl_common/shader_3d/shadow_map_frag.shd
new file mode 100644
index 0000000000..84a586ac7b
--- /dev/null
+++ b/src/modules/evas/engines/gl_common/shader_3d/shadow_map_frag.shd
@@ -0,0 +1,4 @@
1void main()
2{
3 gl_FragColor.r = gl_FragCoord.z;
4}
diff --git a/src/modules/evas/engines/gl_common/shader_3d/shadow_map_vert.shd b/src/modules/evas/engines/gl_common/shader_3d/shadow_map_vert.shd
new file mode 100644
index 0000000000..3f12a69b2b
--- /dev/null
+++ b/src/modules/evas/engines/gl_common/shader_3d/shadow_map_vert.shd
@@ -0,0 +1,28 @@
1uniform mat4 uMatrixMvp;
2
3#ifdef VERTEX_POSITION
4attribute vec4 aPosition0;
5#endif //VERTEX_POSITION
6
7#ifdef VERTEX_POSITION_BLEND
8attribute vec4 aPosition1;
9uniform float uPositionWeight;
10#endif //VERTEX_POSITION_BLEND
11
12void main()
13{
14
15#ifdef VERTEX_POSITION_BLEND
16 vec4 position = aPosition0 * uPositionWeight +
17 aPosition1 * (1.0 - uPositionWeight);
18 position = vec4(position.xyz, 1.0);
19#else
20
21#ifdef VERTEX_POSITION
22 vec4 position = vec4(aPosition0.xyz, 1.0);
23#endif // VERTEX_POSITION
24
25#endif //VERTEX_POSITION_BLEND
26
27 gl_Position = uMatrixMvp * position;
28}
diff --git a/src/modules/evas/engines/gl_common/shader_3d/vertex_color_frag.shd b/src/modules/evas/engines/gl_common/shader_3d/vertex_color_frag.shd
new file mode 100644
index 0000000000..9b0c023e1b
--- /dev/null
+++ b/src/modules/evas/engines/gl_common/shader_3d/vertex_color_frag.shd
@@ -0,0 +1,20 @@
1varying vec4 vColor;
2
3#ifdef FOG_ENABLED
4uniform float uFogFactor;
5uniform vec4 uFogColor;
6#endif //FOG_ENABLED
7
8void main()
9{
10 gl_FragColor = vColor;
11
12#ifdef FOG_ENABLED
13 float z = gl_FragCoord.z / gl_FragCoord.w;
14 float fogFactor = exp2( -uFogFactor * uFogFactor * z * z * 1.44);
15 fogFactor = clamp(fogFactor, 0.0, 1.0);
16 gl_FragColor = mix(uFogColor, gl_FragColor, fogFactor);
17#endif //FOG_ENABLED
18
19}
20
diff --git a/src/modules/evas/engines/gl_common/shader_3d/vertex_color_vert.shd b/src/modules/evas/engines/gl_common/shader_3d/vertex_color_vert.shd
new file mode 100644
index 0000000000..560baad63d
--- /dev/null
+++ b/src/modules/evas/engines/gl_common/shader_3d/vertex_color_vert.shd
@@ -0,0 +1,50 @@
1uniform mat4 uMatrixMvp;
2varying vec4 vColor;
3
4#ifdef VERTEX_POSITION
5attribute vec4 aPosition0;
6#endif //VERTEX_POSITION
7
8#ifdef VERTEX_POSITION_BLEND
9attribute vec4 aPosition1;
10uniform float uPositionWeight;
11#endif //VERTEX_POSITION_BLEND
12
13#ifdef VERTEX_COLOR
14attribute vec4 aColor0;
15#endif //VERTEX_COLOR
16
17#ifdef VERTEX_COLOR_BLEND
18attribute vec4 aColor1;
19uniform float uColorWeight;
20#endif //VERTEX_COLOR_BLEND
21
22void main()
23{
24
25#ifdef VERTEX_POSITION_BLEND
26 vec4 position = aPosition0 * uPositionWeight +
27 aPosition1 * (1.0 - uPositionWeight);
28 position = vec4(position.xyz, 1.0);
29#else
30
31#ifdef VERTEX_POSITION
32 vec4 position = vec4(aPosition0.xyz, 1.0);
33#endif // VERTEX_POSITION
34
35#endif //VERTEX_POSITION_BLEND
36
37#ifdef VERTEX_COLOR_BLEND
38 vec4 color = aColor0 * uColorWeight + aColor1 * (1.0 - uColorWeight);
39#else
40
41#ifdef VERTEX_COLOR
42 vec4 color = aColor0;
43#endif //VERTEX_COLOR
44
45#endif //VERTEX_COLOR_BLEND
46
47 vColor = color;
48 gl_Position = uMatrixMvp * position;
49}
50