summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleksandr Shcherbina <o.shcherbina@samsung.com>2015-05-26 18:40:03 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-05-27 00:31:07 +0200
commitabc1eabecb6da1bf77b530132814a2427bfb44fb (patch)
tree364ef0d71a21ceb0eac700c45e0426b0c985b69d
parent6986e3126d646b693300b78c96bb0eabae34782e (diff)
evas: fix compatibility with GLES2.0. Shadow effect
Summary: Use RGBA texture unit for generation shadow. Use separate framebuffer and renderbuffer for shadow map. Refactor shadow map shader to use position of shadow and pack depth value in RGBA texture. Refactor shader function for generation shadow factor to unpack depth value from RGBA shadow map. Reviewers: cedric, Hermet Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2578 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_3d.c50
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_3d_private.h4
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/evas_gl_3d_shaders.x128
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/include.shd26
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/shadow_map_frag.shd14
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/shadow_map_vert.shd3
6 files changed, 161 insertions, 64 deletions
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 1c393159e9..8caf9ae620 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_3d.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_3d.c
@@ -276,6 +276,9 @@ e3d_drawable_new(int w, int h, int alpha, GLenum depth_format, GLenum stencil_fo
276 GLuint depth_stencil_buf = 0; 276 GLuint depth_stencil_buf = 0;
277 GLuint depth_buf = 0; 277 GLuint depth_buf = 0;
278 GLuint stencil_buf = 0; 278 GLuint stencil_buf = 0;
279#ifdef GL_GLES
280 GLuint shadow_fbo, depth_render_buf;
281#endif
279 Eina_Bool depth_stencil = EINA_FALSE; 282 Eina_Bool depth_stencil = EINA_FALSE;
280 283
281 glGenTextures(1, &tex); 284 glGenTextures(1, &tex);
@@ -298,8 +301,13 @@ e3d_drawable_new(int w, int h, int alpha, GLenum depth_format, GLenum stencil_fo
298 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 301 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
299#ifndef GL_GLES 302#ifndef GL_GLES
300 glTexImage2D(GL_TEXTURE_2D, 0, GL_R16, w, h, 0, GL_RED, GL_UNSIGNED_SHORT, 0); 303 glTexImage2D(GL_TEXTURE_2D, 0, GL_R16, w, h, 0, GL_RED, GL_UNSIGNED_SHORT, 0);
304#else
305 glGenFramebuffers(1, &shadow_fbo);
306 glGenFramebuffers(1, &depth_render_buf);
307 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
301#endif 308#endif
302 309
310 glGenFramebuffers(1, &color_pick_fb_id);
303 glGenTextures(1, &texcolorpick); 311 glGenTextures(1, &texcolorpick);
304 glBindTexture(GL_TEXTURE_2D, texcolorpick); 312 glBindTexture(GL_TEXTURE_2D, texcolorpick);
305 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 313 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -310,8 +318,6 @@ e3d_drawable_new(int w, int h, int alpha, GLenum depth_format, GLenum stencil_fo
310 glTexImage2D(GL_TEXTURE_2D, 0, GL_R16, w, h, 0, GL_RED, GL_UNSIGNED_SHORT, 0); 318 glTexImage2D(GL_TEXTURE_2D, 0, GL_R16, w, h, 0, GL_RED, GL_UNSIGNED_SHORT, 0);
311#endif 319#endif
312 320
313 glGenFramebuffers(1, &color_pick_fb_id);
314
315 glGenFramebuffers(1, &fbo); 321 glGenFramebuffers(1, &fbo);
316 glBindFramebuffer(GL_FRAMEBUFFER, fbo); 322 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
317 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0); 323 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
@@ -393,7 +399,10 @@ e3d_drawable_new(int w, int h, int alpha, GLenum depth_format, GLenum stencil_fo
393 drawable->depth_buf = depth_buf; 399 drawable->depth_buf = depth_buf;
394 drawable->stencil_buf = stencil_buf; 400 drawable->stencil_buf = stencil_buf;
395 drawable->texDepth = texDepth; 401 drawable->texDepth = texDepth;
396 402#ifdef GL_GLES
403 drawable->shadow_fbo = shadow_fbo;
404 drawable->depth_render_buf = depth_render_buf;
405#endif
397 return drawable; 406 return drawable;
398 407
399error: 408error:
@@ -403,6 +412,8 @@ error:
403 glDeleteTextures(1, &tex); 412 glDeleteTextures(1, &tex);
404 if (texcolorpick) 413 if (texcolorpick)
405 glDeleteTextures(1, &texcolorpick); 414 glDeleteTextures(1, &texcolorpick);
415 if (texDepth)
416 glDeleteTextures(1, &texDepth);
406 417
407 if (fbo) 418 if (fbo)
408 glDeleteFramebuffers(1, &fbo); 419 glDeleteFramebuffers(1, &fbo);
@@ -424,6 +435,13 @@ error:
424 if (stencil_buf) 435 if (stencil_buf)
425 glDeleteRenderbuffers(1, &stencil_buf); 436 glDeleteRenderbuffers(1, &stencil_buf);
426 437
438#ifdef GL_GLES
439 if (shadow_fbo)
440 glDeleteFramebuffers(1, &shadow_fbo);
441 if (depth_render_buf)
442 glDeleteFramebuffers(1, &depth_render_buf);
443#endif
444
427 return NULL; 445 return NULL;
428} 446}
429 447
@@ -1146,7 +1164,9 @@ _mesh_draw(E3D_Renderer *renderer, Evas_3D_Mesh *mesh, int frame, Evas_3D_Node *
1146 e3d_renderer_draw(renderer, &data); 1164 e3d_renderer_draw(renderer, &data);
1147} 1165}
1148 1166
1149void _shadowmap_render(E3D_Drawable *drawable, E3D_Renderer *renderer, Evas_3D_Scene_Public_Data *data, Evas_Mat4 *matrix_light_eye, Evas_3D_Node *light) 1167void _shadowmap_render(E3D_Drawable *drawable, E3D_Renderer *renderer,
1168 Evas_3D_Scene_Public_Data *data, Evas_Mat4 *matrix_light_eye,
1169 Evas_3D_Node *light)
1150{ 1170{
1151 Eina_List *l; 1171 Eina_List *l;
1152 Evas_3D_Node *n; 1172 Evas_3D_Node *n;
@@ -1157,12 +1177,24 @@ void _shadowmap_render(E3D_Drawable *drawable, E3D_Renderer *renderer, Evas_3D_S
1157 1177
1158 glEnable(GL_POLYGON_OFFSET_FILL); 1178 glEnable(GL_POLYGON_OFFSET_FILL);
1159 glPolygonOffset(4.0, 100.0); 1179 glPolygonOffset(4.0, 100.0);
1160 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, drawable->texDepth, 0); 1180#ifdef GL_GLES
1181 glBindFramebuffer(GL_FRAMEBUFFER, drawable->shadow_fbo);
1182 glBindRenderbuffer(GL_RENDERBUFFER, drawable->depth_render_buf);
1183#endif
1184 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
1185 drawable->texDepth, 0);
1186#ifdef GL_GLES
1187 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, drawable->w,
1188 drawable->h);
1189 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
1190 drawable->depth_render_buf);
1191#endif
1161 e3d_renderer_target_set(renderer, drawable); 1192 e3d_renderer_target_set(renderer, drawable);
1162 e3d_renderer_clear(renderer, &c); 1193 e3d_renderer_clear(renderer, &c);
1163 1194
1164 Evas_3D_Node_Data *pd_light_node = eo_data_scope_get(light, EVAS_3D_NODE_CLASS); 1195 Evas_3D_Node_Data *pd_light_node = eo_data_scope_get(light, EVAS_3D_NODE_CLASS);
1165 Evas_3D_Light_Data *pd = eo_data_scope_get(pd_light_node->data.light.light, EVAS_3D_LIGHT_CLASS); 1196 Evas_3D_Light_Data *pd = eo_data_scope_get(pd_light_node->data.light.light,
1197 EVAS_3D_LIGHT_CLASS);
1166 1198
1167 Evas_Vec4 planes[6]; 1199 Evas_Vec4 planes[6];
1168 evas_mat4_multiply(&matrix_vp, &pd->projection, matrix_light_eye); 1200 evas_mat4_multiply(&matrix_vp, &pd->projection, matrix_light_eye);
@@ -1180,7 +1212,8 @@ void _shadowmap_render(E3D_Drawable *drawable, E3D_Renderer *renderer, Evas_3D_S
1180 blend_enabled = pdmesh->blending; 1212 blend_enabled = pdmesh->blending;
1181 pdmesh->blending = EINA_FALSE; 1213 pdmesh->blending = EINA_FALSE;
1182 pdmesh->shade_mode = EVAS_3D_SHADE_MODE_SHADOW_MAP_RENDER; 1214 pdmesh->shade_mode = EVAS_3D_SHADE_MODE_SHADOW_MAP_RENDER;
1183 _mesh_draw(renderer, nm->mesh, nm->frame, light, matrix_light_eye, &matrix_mv, &matrix_mvp, &matrix_mvp); 1215 _mesh_draw(renderer, nm->mesh, nm->frame, light, matrix_light_eye,
1216 &matrix_mv, &matrix_mvp, &matrix_mvp);
1184 pdmesh->shade_mode = shade_mode; 1217 pdmesh->shade_mode = shade_mode;
1185 pdmesh->blending = blend_enabled; 1218 pdmesh->blending = blend_enabled;
1186 } 1219 }
@@ -1189,6 +1222,9 @@ void _shadowmap_render(E3D_Drawable *drawable, E3D_Renderer *renderer, Evas_3D_S
1189 } 1222 }
1190 1223
1191 glDisable(GL_POLYGON_OFFSET_FILL); 1224 glDisable(GL_POLYGON_OFFSET_FILL);
1225#ifdef GL_GLES
1226 glBindFramebuffer(GL_FRAMEBUFFER, drawable->fbo);
1227#endif
1192 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, drawable->tex, 0); 1228 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, drawable->tex, 0);
1193} 1229}
1194 1230
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 87fbb8a31c..ad8d992c8a 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
@@ -147,6 +147,10 @@ struct _E3D_Drawable
147 GLuint texDepth; 147 GLuint texDepth;
148 GLuint texcolorpick; 148 GLuint texcolorpick;
149 GLuint color_pick_fb_id; 149 GLuint color_pick_fb_id;
150#ifdef GL_GLES
151 GLuint shadow_fbo;
152 GLuint depth_render_buf;
153#endif
150}; 154};
151 155
152/* Texture internal functions. */ 156/* Texture internal functions. */
diff --git a/src/modules/evas/engines/gl_common/shader_3d/evas_gl_3d_shaders.x b/src/modules/evas/engines/gl_common/shader_3d/evas_gl_3d_shaders.x
index d4bd7ebb4f..0505e412f9 100644
--- a/src/modules/evas/engines/gl_common/shader_3d/evas_gl_3d_shaders.x
+++ b/src/modules/evas/engines/gl_common/shader_3d/evas_gl_3d_shaders.x
@@ -403,19 +403,25 @@ static const char flat_frag_glsl[] =
403 "uniform sampler2D uShadowMap;\n" 403 "uniform sampler2D uShadowMap;\n"
404 "float shadow;\n" 404 "float shadow;\n"
405 "float pcf(vec4 lpos, float size)\n" 405 "float pcf(vec4 lpos, float size)\n"
406 " {\n" 406 "{\n"
407 " vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;\n"
408 " float i, j, shadow;\n"
409 " shadow = 0.0;\n"
407 "#ifndef GL_ES\n" 410 "#ifndef GL_ES\n"
408 " vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;\n" 411 " for (i = -4.0; i < 4.0; i++)\n"
409 " float i, j, randx, randy, shadow;\n" 412 " for (j = -4.0; j < 4.0; j++)\n"
410 " shadow = 0.0;\n" 413 " shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size).x);\n"
411 " for (i = -4.0; i < 4.0; i++)\n" 414 "#else\n"
412 " for (j = -4.0; j < 4.0; j++)\n" 415 " const vec4 unpack = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);\n"
413 " shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size).x);\n" 416 " const float bias = 0.00015 /*TODO Optimizate set of offset*/;\n"
414 " return shadow / 64.0;\n" 417 " for (i = -4.0; i < 4.0; i++)\n"
415 "#else\n" 418 " for (j = -4.0; j < 4.0; j++)\n"
416 " /*TODO Add algorithm generate shadow*/\n" 419 " {\n"
417 " return 1.0;\n" 420 " vec4 zvalue = texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size);\n"
421 " shadow += float(smcoord.z < dot(zvalue, unpack) + bias);\n"
422 " }\n"
418 "#endif //GL_ES\n" 423 "#endif //GL_ES\n"
424 " return shadow / 64.0;\n"
419 "}\n" 425 "}\n"
420 "#endif //SHADOWED\n" 426 "#endif //SHADOWED\n"
421 "#ifdef DIFFUSE\n" 427 "#ifdef DIFFUSE\n"
@@ -734,19 +740,25 @@ static const char phong_frag_glsl[] =
734 "uniform sampler2D uShadowMap;\n" 740 "uniform sampler2D uShadowMap;\n"
735 "float shadow;\n" 741 "float shadow;\n"
736 "float pcf(vec4 lpos, float size)\n" 742 "float pcf(vec4 lpos, float size)\n"
737 " {\n" 743 "{\n"
744 " vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;\n"
745 " float i, j, shadow;\n"
746 " shadow = 0.0;\n"
738 "#ifndef GL_ES\n" 747 "#ifndef GL_ES\n"
739 " vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;\n" 748 " for (i = -4.0; i < 4.0; i++)\n"
740 " float i, j, randx, randy, shadow;\n" 749 " for (j = -4.0; j < 4.0; j++)\n"
741 " shadow = 0.0;\n" 750 " shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size).x);\n"
742 " for (i = -4.0; i < 4.0; i++)\n" 751 "#else\n"
743 " for (j = -4.0; j < 4.0; j++)\n" 752 " const vec4 unpack = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);\n"
744 " shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size).x);\n" 753 " const float bias = 0.00015 /*TODO Optimizate set of offset*/;\n"
745 " return shadow / 64.0;\n" 754 " for (i = -4.0; i < 4.0; i++)\n"
746 "#else\n" 755 " for (j = -4.0; j < 4.0; j++)\n"
747 " /*TODO Add algorithm generate shadow*/\n" 756 " {\n"
748 " return 1.0;\n" 757 " vec4 zvalue = texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size);\n"
758 " shadow += float(smcoord.z < dot(zvalue, unpack) + bias);\n"
759 " }\n"
749 "#endif //GL_ES\n" 760 "#endif //GL_ES\n"
761 " return shadow / 64.0;\n"
750 "}\n" 762 "}\n"
751 "#endif //SHADOWED\n" 763 "#endif //SHADOWED\n"
752 "#ifdef DIFFUSE\n" 764 "#ifdef DIFFUSE\n"
@@ -1158,19 +1170,25 @@ static const char normal_map_frag_glsl[] =
1158 "uniform sampler2D uShadowMap;\n" 1170 "uniform sampler2D uShadowMap;\n"
1159 "float shadow;\n" 1171 "float shadow;\n"
1160 "float pcf(vec4 lpos, float size)\n" 1172 "float pcf(vec4 lpos, float size)\n"
1161 " {\n" 1173 "{\n"
1174 " vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;\n"
1175 " float i, j, shadow;\n"
1176 " shadow = 0.0;\n"
1162 "#ifndef GL_ES\n" 1177 "#ifndef GL_ES\n"
1163 " vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;\n" 1178 " for (i = -4.0; i < 4.0; i++)\n"
1164 " float i, j, randx, randy, shadow;\n" 1179 " for (j = -4.0; j < 4.0; j++)\n"
1165 " shadow = 0.0;\n" 1180 " shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size).x);\n"
1166 " for (i = -4.0; i < 4.0; i++)\n" 1181 "#else\n"
1167 " for (j = -4.0; j < 4.0; j++)\n" 1182 " const vec4 unpack = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);\n"
1168 " shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size).x);\n" 1183 " const float bias = 0.00015 /*TODO Optimizate set of offset*/;\n"
1169 " return shadow / 64.0;\n" 1184 " for (i = -4.0; i < 4.0; i++)\n"
1170 "#else\n" 1185 " for (j = -4.0; j < 4.0; j++)\n"
1171 " /*TODO Add algorithm generate shadow*/\n" 1186 " {\n"
1172 " return 1.0;\n" 1187 " vec4 zvalue = texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size);\n"
1188 " shadow += float(smcoord.z < dot(zvalue, unpack) + bias);\n"
1189 " }\n"
1173 "#endif //GL_ES\n" 1190 "#endif //GL_ES\n"
1191 " return shadow / 64.0;\n"
1174 "}\n" 1192 "}\n"
1175 "#endif //SHADOWED\n" 1193 "#endif //SHADOWED\n"
1176 "#ifdef NORMAL_TEXTURE\n" 1194 "#ifdef NORMAL_TEXTURE\n"
@@ -1461,6 +1479,7 @@ static const char shadow_map_vert_glsl[] =
1461 "precision lowp sampler2D;\n" 1479 "precision lowp sampler2D;\n"
1462 "#endif\n" 1480 "#endif\n"
1463 "uniform mat4 uMatrixMvp;\n" 1481 "uniform mat4 uMatrixMvp;\n"
1482 "varying vec4 shadowmapposition;\n"
1464 "#ifdef VERTEX_POSITION\n" 1483 "#ifdef VERTEX_POSITION\n"
1465 "attribute vec4 aPosition0;\n" 1484 "attribute vec4 aPosition0;\n"
1466 "#endif //VERTEX_POSITION\n" 1485 "#endif //VERTEX_POSITION\n"
@@ -1500,6 +1519,7 @@ static const char shadow_map_vert_glsl[] =
1500 "#endif //VERTEX_TEXCOORD_BLEND\n" 1519 "#endif //VERTEX_TEXCOORD_BLEND\n"
1501 "#endif //ALPHA_TEST_ENABLED\n" 1520 "#endif //ALPHA_TEST_ENABLED\n"
1502 " gl_Position = uMatrixMvp * position;\n" 1521 " gl_Position = uMatrixMvp * position;\n"
1522 " shadowmapposition = gl_Position;\n"
1503 "}\n"; 1523 "}\n";
1504 1524
1505static const char shadow_map_frag_glsl[] = 1525static const char shadow_map_frag_glsl[] =
@@ -1508,6 +1528,7 @@ static const char shadow_map_frag_glsl[] =
1508 "precision mediump int;\n" 1528 "precision mediump int;\n"
1509 "precision lowp sampler2D;\n" 1529 "precision lowp sampler2D;\n"
1510 "#endif\n" 1530 "#endif\n"
1531 "varying vec4 shadowmapposition;\n"
1511 "#ifdef ALPHA_TEST_ENABLED\n" 1532 "#ifdef ALPHA_TEST_ENABLED\n"
1512 "#ifdef NEED_TEX_COORD\n" 1533 "#ifdef NEED_TEX_COORD\n"
1513 "varying vec2 vTexCoord;\n" 1534 "varying vec2 vTexCoord;\n"
@@ -1544,7 +1565,7 @@ static const char shadow_map_frag_glsl[] =
1544 " (1.0 - uTextureDiffuseWeight));\n" 1565 " (1.0 - uTextureDiffuseWeight));\n"
1545 "#else\n" 1566 "#else\n"
1546 "#ifdef DIFFUSE_TEXTURE\n" 1567 "#ifdef DIFFUSE_TEXTURE\n"
1547 " color = texture2D(uTextureDiffuse0, vec2(Tex0CoordDiffuse)) ;\n" 1568 " color = texture2D(uTextureDiffuse0, vec2(Tex0CoordDiffuse));\n"
1548 "#else\n" 1569 "#else\n"
1549 " color = vec4(1);\n" 1570 " color = vec4(1);\n"
1550 "#endif //DIFFUSE_TEXTURE\n" 1571 "#endif //DIFFUSE_TEXTURE\n"
@@ -1590,7 +1611,18 @@ static const char shadow_map_frag_glsl[] =
1590 " gl_FragColor = color;\n" 1611 " gl_FragColor = color;\n"
1591 "#endif //GL_ES\n" 1612 "#endif //GL_ES\n"
1592 "#endif //ALPHA_TEST_ENABLED\n" 1613 "#endif //ALPHA_TEST_ENABLED\n"
1614 "#ifndef GL_ES\n"
1593 " gl_FragColor.r = gl_FragCoord.z;\n" 1615 " gl_FragColor.r = gl_FragCoord.z;\n"
1616 "#else\n"
1617 " const vec4 pack = vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0);\n"
1618 " const vec4 mask = vec4(0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);\n"
1619 " vec4 depthcolor;\n"
1620 " float normdist = shadowmapposition.z / shadowmapposition.w;\n"
1621 " normdist = ((normdist + 1.0) / 2.0);\n"
1622 " depthcolor = vec4(fract(pack * normdist));\n"
1623 " depthcolor -= depthcolor.xxyz * mask;\n"
1624 " gl_FragColor = depthcolor;\n"
1625 "#endif\n"
1594 "}\n"; 1626 "}\n";
1595 1627
1596static const char color_pick_vert_glsl[] = 1628static const char color_pick_vert_glsl[] =
@@ -1832,19 +1864,25 @@ static const char parallax_occlusion_frag_glsl[] =
1832 "uniform sampler2D uShadowMap;\n" 1864 "uniform sampler2D uShadowMap;\n"
1833 "float shadow;\n" 1865 "float shadow;\n"
1834 "float pcf(vec4 lpos, float size)\n" 1866 "float pcf(vec4 lpos, float size)\n"
1835 " {\n" 1867 "{\n"
1868 " vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;\n"
1869 " float i, j, shadow;\n"
1870 " shadow = 0.0;\n"
1836 "#ifndef GL_ES\n" 1871 "#ifndef GL_ES\n"
1837 " vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;\n" 1872 " for (i = -4.0; i < 4.0; i++)\n"
1838 " float i, j, randx, randy, shadow;\n" 1873 " for (j = -4.0; j < 4.0; j++)\n"
1839 " shadow = 0.0;\n" 1874 " shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size).x);\n"
1840 " for (i = -4.0; i < 4.0; i++)\n" 1875 "#else\n"
1841 " for (j = -4.0; j < 4.0; j++)\n" 1876 " const vec4 unpack = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);\n"
1842 " shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size).x);\n" 1877 " const float bias = 0.00015 /*TODO Optimizate set of offset*/;\n"
1843 " return shadow / 64.0;\n" 1878 " for (i = -4.0; i < 4.0; i++)\n"
1844 "#else\n" 1879 " for (j = -4.0; j < 4.0; j++)\n"
1845 " /*TODO Add algorithm generate shadow*/\n" 1880 " {\n"
1846 " return 1.0;\n" 1881 " vec4 zvalue = texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size);\n"
1882 " shadow += float(smcoord.z < dot(zvalue, unpack) + bias);\n"
1883 " }\n"
1847 "#endif //GL_ES\n" 1884 "#endif //GL_ES\n"
1885 " return shadow / 64.0;\n"
1848 "}\n" 1886 "}\n"
1849 "#endif //SHADOWED\n" 1887 "#endif //SHADOWED\n"
1850 "#ifdef DIFFUSE\n" 1888 "#ifdef DIFFUSE\n"
diff --git a/src/modules/evas/engines/gl_common/shader_3d/include.shd b/src/modules/evas/engines/gl_common/shader_3d/include.shd
index 706def92c4..3b92e827d0 100644
--- a/src/modules/evas/engines/gl_common/shader_3d/include.shd
+++ b/src/modules/evas/engines/gl_common/shader_3d/include.shd
@@ -42,19 +42,25 @@ varying vec4 vLightPosition;
42uniform sampler2D uShadowMap; 42uniform sampler2D uShadowMap;
43float shadow; 43float shadow;
44float pcf(vec4 lpos, float size) 44float pcf(vec4 lpos, float size)
45 { 45{
46 vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;
47 float i, j, shadow;
48 shadow = 0.0;
46`#ifndef GL_ES' 49`#ifndef GL_ES'
47 vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5; 50 for (i = -4.0; i < 4.0; i++)
48 float i, j, randx, randy, shadow; 51 for (j = -4.0; j < 4.0; j++)
49 shadow = 0.0; 52 shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size).x);
50 for (i = -4.0; i < 4.0; i++)
51 for (j = -4.0; j < 4.0; j++)
52 shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size).x);
53 return shadow / 64.0;
54`#else' 53`#else'
55 /*TODO Add algorithm generate shadow*/ 54 const vec4 unpack = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);
56 return 1.0; 55 const float bias = 0.00015 /*TODO Optimizate set of offset*/;
56 for (i = -4.0; i < 4.0; i++)
57 for (j = -4.0; j < 4.0; j++)
58 {
59 vec4 zvalue = texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0) * size);
60 shadow += float(smcoord.z < dot(zvalue, unpack) + bias);
61 }
57`#endif //GL_ES' 62`#endif //GL_ES'
63 return shadow / 64.0;
58} 64}
59#endif //SHADOWED') 65#endif //SHADOWED')
60 66
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
index cfdd298db4..bdb16e59bb 100644
--- 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
@@ -1,3 +1,4 @@
1varying vec4 shadowmapposition;
1#ifdef ALPHA_TEST_ENABLED 2#ifdef ALPHA_TEST_ENABLED
2FRAGMENT_SHADER_USE_TEX_COORD 3FRAGMENT_SHADER_USE_TEX_COORD
3FRAGMENT_SHADER_USE_ALPHA_TEST_GLES 4FRAGMENT_SHADER_USE_ALPHA_TEST_GLES
@@ -39,7 +40,7 @@ void main() {
39#else 40#else
40 41
41#ifdef DIFFUSE_TEXTURE 42#ifdef DIFFUSE_TEXTURE
42 color = texture2D(uTextureDiffuse0, vec2(Tex0CoordDiffuse)) ; 43 color = texture2D(uTextureDiffuse0, vec2(Tex0CoordDiffuse));
43#else 44#else
44 color = vec4(1); 45 color = vec4(1);
45#endif //DIFFUSE_TEXTURE 46#endif //DIFFUSE_TEXTURE
@@ -49,5 +50,16 @@ void main() {
49 FRAGMENT_SHADER_ALPHA_TEST_GLES_APPLY(color) 50 FRAGMENT_SHADER_ALPHA_TEST_GLES_APPLY(color)
50 51
51#endif //ALPHA_TEST_ENABLED 52#endif //ALPHA_TEST_ENABLED
53#ifndef GL_ES
52 gl_FragColor.r = gl_FragCoord.z; 54 gl_FragColor.r = gl_FragCoord.z;
55#else
56 const vec4 pack = vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0);
57 const vec4 mask = vec4(0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);
58 vec4 depthcolor;
59 float normdist = shadowmapposition.z / shadowmapposition.w;
60 normdist = ((normdist + 1.0) / 2.0);
61 depthcolor = vec4(fract(pack * normdist));
62 depthcolor -= depthcolor.xxyz * mask;
63 gl_FragColor = depthcolor;
64#endif
53} 65}
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
index 095fc9c9c9..66ce4f3d62 100644
--- 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
@@ -1,5 +1,5 @@
1uniform mat4 uMatrixMvp; 1uniform mat4 uMatrixMvp;
2 2varying vec4 shadowmapposition;
3VERTEX_SHADER_USE_POSITION 3VERTEX_SHADER_USE_POSITION
4 4
5#ifdef ALPHA_TEST_ENABLED 5#ifdef ALPHA_TEST_ENABLED
@@ -17,4 +17,5 @@ VERTEX_SHADER_POSITION
17#endif //ALPHA_TEST_ENABLED 17#endif //ALPHA_TEST_ENABLED
18 18
19 gl_Position = uMatrixMvp * position; 19 gl_Position = uMatrixMvp * position;
20 shadowmapposition = gl_Position;
20} 21}