summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleksandr Shcherbina <o.shcherbina@samsung.com>2016-04-12 00:50:46 +0900
committerHermet Park <hermet@hermet.pe.kr>2016-04-12 00:50:46 +0900
commit1f66a9e7315f7b5744e73fe5456b7633fc9104a2 (patch)
treeaafaf60c91c18bbaea15b547f84cce6521898435
parent5f9e73b96601d225d3d1d1bc842e4fc18b2a0822 (diff)
evas.canvas3d: Add FXAA post processing render.
Summary: Add post processing render function as rendering full screen quard after rendering to texture. Add possibility use size of current frame in shader. Add FXAA shader source files Reviewers: raster, cedric, Hermet Subscribers: jpeg Differential Revision: https://phab.enlightenment.org/D3847
-rw-r--r--src/Makefile_Evas.am2
-rw-r--r--src/lib/evas/canvas/efl_canvas_scene3d.c11
-rw-r--r--src/lib/evas/canvas/evas_canvas3d_scene.c4
-rw-r--r--src/lib/evas/canvas/evas_canvas3d_scene.eo2
-rw-r--r--src/lib/evas/canvas/evas_types.eot18
-rw-r--r--src/lib/evas/include/evas_private.h3
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_3d.c81
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_3d_private.h5
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_3d_renderer.c12
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_3d_shader.c11
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/evas_gl_3d_shaders.x90
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/post_processing_fxaa_frag.shd63
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/post_processing_fxaa_vert.shd12
13 files changed, 282 insertions, 32 deletions
diff --git a/src/Makefile_Evas.am b/src/Makefile_Evas.am
index d2e15decb1..bd376877cb 100644
--- a/src/Makefile_Evas.am
+++ b/src/Makefile_Evas.am
@@ -785,6 +785,8 @@ modules/evas/engines/gl_common/shader_3d/color_pick_vert.shd \
785modules/evas/engines/gl_common/shader_3d/color_pick_frag.shd \ 785modules/evas/engines/gl_common/shader_3d/color_pick_frag.shd \
786modules/evas/engines/gl_common/shader_3d/parallax_occlusion_vert.shd \ 786modules/evas/engines/gl_common/shader_3d/parallax_occlusion_vert.shd \
787modules/evas/engines/gl_common/shader_3d/parallax_occlusion_frag.shd \ 787modules/evas/engines/gl_common/shader_3d/parallax_occlusion_frag.shd \
788modules/evas/engines/gl_common/shader_3d/post_processing_fxaa_vert.shd \
789modules/evas/engines/gl_common/shader_3d/post_processing_fxaa_frag.shd \
788$(NULL) 790$(NULL)
789 791
790EXTRA_DIST += \ 792EXTRA_DIST += \
diff --git a/src/lib/evas/canvas/efl_canvas_scene3d.c b/src/lib/evas/canvas/efl_canvas_scene3d.c
index 0a86c4770f..81d6375878 100644
--- a/src/lib/evas/canvas/efl_canvas_scene3d.c
+++ b/src/lib/evas/canvas/efl_canvas_scene3d.c
@@ -29,7 +29,7 @@ _efl_canvas_scene3d_scene3d_get(Eo *eo_obj, void *pd EINA_UNUSED)
29} 29}
30 30
31void 31void
32_evas_image_3d_render(Evas *eo_e, Evas_Object *eo_obj EINA_UNUSED, 32_evas_image_3d_render(Evas *eo_e, Evas_Object *eo_obj,
33 Evas_Object_Protected_Data *obj, Evas_Image_Data *o EINA_UNUSED, 33 Evas_Object_Protected_Data *obj, Evas_Image_Data *o EINA_UNUSED,
34 Evas_Canvas3D_Scene *scene) 34 Evas_Canvas3D_Scene *scene)
35{ 35{
@@ -107,7 +107,14 @@ _evas_image_3d_render(Evas *eo_e, Evas_Object *eo_obj EINA_UNUSED,
107 scene_data.camera_node = pd_scene->camera_node; 107 scene_data.camera_node = pd_scene->camera_node;
108 scene_data.depth_offset = pd_scene->depth_offset; 108 scene_data.depth_offset = pd_scene->depth_offset;
109 scene_data.depth_constant = pd_scene->depth_constant; 109 scene_data.depth_constant = pd_scene->depth_constant;
110 110 if (evas_object_anti_alias_get(eo_obj))
111 {
112 /*Use post processing render*/
113 scene_data.post_processing = EINA_TRUE;
114 scene_data.color_pick_enabled = EINA_FALSE;
115 scene_data.render_to_texture = EINA_TRUE;
116 scene_data.post_processing_type = EVAS_CANVAS3D_SHADE_MODE_POST_PROCESSING_FXAA;
117 }
111 /* Phase 1 - Update scene graph tree. */ 118 /* Phase 1 - Update scene graph tree. */
112 evas_canvas3d_object_update(scene); 119 evas_canvas3d_object_update(scene);
113 120
diff --git a/src/lib/evas/canvas/evas_canvas3d_scene.c b/src/lib/evas/canvas/evas_canvas3d_scene.c
index a8cc117050..8a7d08ecfd 100644
--- a/src/lib/evas/canvas/evas_canvas3d_scene.c
+++ b/src/lib/evas/canvas/evas_canvas3d_scene.c
@@ -13,6 +13,8 @@ evas_canvas3d_scene_data_init(Evas_Canvas3D_Scene_Public_Data *data)
13 data->colors_node_mesh = NULL; 13 data->colors_node_mesh = NULL;
14 data->render_to_texture = EINA_FALSE; 14 data->render_to_texture = EINA_FALSE;
15 data->lod_distance = 0; 15 data->lod_distance = 0;
16 data->post_processing = EINA_FALSE;
17 data->post_processing_type = EVAS_CANVAS3D_SHADE_MODE_POST_PROCESSING_FXAA;
16} 18}
17 19
18void 20void
@@ -78,7 +80,6 @@ _evas_canvas3d_scene_eo_base_constructor(Eo *obj, Evas_Canvas3D_Scene_Data *pd)
78 pd->colors_node_mesh = NULL; 80 pd->colors_node_mesh = NULL;
79 pd->depth_offset = 4.0; 81 pd->depth_offset = 4.0;
80 pd->depth_constant = 100.0; 82 pd->depth_constant = 100.0;
81
82 return obj; 83 return obj;
83} 84}
84 85
@@ -635,6 +636,7 @@ _evas_canvas3d_scene_pick(const Eo *obj, Evas_Canvas3D_Scene_Data *pd, Evas_Real
635 scene_data.camera_node = pd->camera_node; 636 scene_data.camera_node = pd->camera_node;
636 scene_data.color_pick_enabled = pd->color_pick_enabled; 637 scene_data.color_pick_enabled = pd->color_pick_enabled;
637 update_scene = evas_canvas3d_object_dirty_get(obj, EVAS_CANVAS3D_STATE_SCENE_UPDATED); 638 update_scene = evas_canvas3d_object_dirty_get(obj, EVAS_CANVAS3D_STATE_SCENE_UPDATED);
639 scene_data.post_processing = EINA_FALSE;
638 if (update_scene) 640 if (update_scene)
639 { 641 {
640 if (pd->node_mesh_colors) 642 if (pd->node_mesh_colors)
diff --git a/src/lib/evas/canvas/evas_canvas3d_scene.eo b/src/lib/evas/canvas/evas_canvas3d_scene.eo
index 04648094f1..283c3d4636 100644
--- a/src/lib/evas/canvas/evas_canvas3d_scene.eo
+++ b/src/lib/evas/canvas/evas_canvas3d_scene.eo
@@ -160,7 +160,7 @@ class Evas.Canvas3D.Scene (Evas.Canvas3D.Object, Evas.Common_Interface)
160 depth offset]] 160 depth offset]]
161 } 161 }
162 } 162 }
163 } 163}
164 implements { 164 implements {
165 Eo.Base.constructor; 165 Eo.Base.constructor;
166 Evas.Canvas3D.Object.update_notify; 166 Evas.Canvas3D.Object.update_notify;
diff --git a/src/lib/evas/canvas/evas_types.eot b/src/lib/evas/canvas/evas_types.eot
index 27a2830769..7d1a24e6fd 100644
--- a/src/lib/evas/canvas/evas_types.eot
+++ b/src/lib/evas/canvas/evas_types.eot
@@ -297,6 +297,7 @@ enum Evas.Canvas3D.State
297 scene_shadows_enabled, 297 scene_shadows_enabled,
298 scene_updated, [[@since 1.14]] 298 scene_updated, [[@since 1.14]]
299 scene_shadows_depth, 299 scene_shadows_depth,
300 scene_render_to_texture,
300 301
301 texture_data = 1, 302 texture_data = 1,
302 texture_wrap, 303 texture_wrap,
@@ -487,14 +488,15 @@ enum Evas.Canvas3D.Shade_Mode
487 [[Shader shade modes 488 [[Shader shade modes
488 489
489 @since 1.10]] 490 @since 1.10]]
490 vertex_color = 0, [[Shaded using vertex color attribute]] 491 vertex_color = 0, [[Shaded using vertex color attribute]]
491 diffuse, [[Shaded using material diffuse term]] 492 diffuse, [[Shaded using material diffuse term]]
492 flat, [[Per-vertex flat lighting]] 493 flat, [[Per-vertex flat lighting]]
493 phong, [[Per-pixel phong shading]] 494 phong, [[Per-pixel phong shading]]
494 normal_map, [[Per-pixel normal map shading]] 495 normal_map, [[Per-pixel normal map shading]]
495 shadow_map_render, [[Fragment color is defined by its z-coord]] 496 shadow_map_render, [[Fragment color is defined by its z-coord]]
496 color_pick, [[Rendering to additional frame bufer]] 497 color_pick, [[Rendering to additional frame bufer]]
497 parallax_occlusion [[Per-pixel parallax occlusion map shading]] 498 parallax_occlusion, [[Per-pixel parallax occlusion map shading]]
499 post_processing_FXAA [[Render full screen quard]]
498} 500}
499 501
500enum Evas.Canvas3D.Vertex_Attrib 502enum Evas.Canvas3D.Vertex_Attrib
diff --git a/src/lib/evas/include/evas_private.h b/src/lib/evas/include/evas_private.h
index 4a8b37ae79..2b2c174b63 100644
--- a/src/lib/evas/include/evas_private.h
+++ b/src/lib/evas/include/evas_private.h
@@ -458,6 +458,9 @@ struct _Evas_Canvas3D_Scene_Public_Data
458 Eina_Bool render_to_texture; 458 Eina_Bool render_to_texture;
459 459
460 unsigned int lod_distance; 460 unsigned int lod_distance;
461
462 Eina_Bool post_processing :1;
463 Evas_Canvas3D_Shade_Mode post_processing_type;
461}; 464};
462 465
463struct _Evas_Canvas3D_Pick_Data 466struct _Evas_Canvas3D_Pick_Data
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 6f0e1ec19e..f4f7b00cee 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_3d.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_3d.c
@@ -1167,7 +1167,6 @@ void _shadowmap_render(E3D_Drawable *drawable, E3D_Renderer *renderer,
1167 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 1167 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
1168 drawable->texDepth, 0); 1168 drawable->texDepth, 0);
1169 1169
1170 e3d_renderer_target_set(renderer, drawable);
1171 e3d_renderer_clear(renderer, &c); 1170 e3d_renderer_clear(renderer, &c);
1172 1171
1173 Evas_Canvas3D_Node_Data *pd_light_node = eo_data_scope_get(light, EVAS_CANVAS3D_NODE_CLASS); 1172 Evas_Canvas3D_Node_Data *pd_light_node = eo_data_scope_get(light, EVAS_CANVAS3D_NODE_CLASS);
@@ -1199,19 +1198,20 @@ void _shadowmap_render(E3D_Drawable *drawable, E3D_Renderer *renderer,
1199 } 1198 }
1200 } 1199 }
1201 1200
1202 glDisable(GL_POLYGON_OFFSET_FILL); 1201 glDisable(GL_POLYGON_OFFSET_FILL);
1203 1202
1204 if (data->render_to_texture) 1203 if (data->render_to_texture)
1205 { 1204 {
1206 data->render_to_texture = EINA_FALSE; 1205 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
1207 e3d_renderer_color_pick_target_set(renderer, drawable); 1206 drawable->texcolorpick, 0);
1208 } 1207 e3d_renderer_clear(renderer, &data->bg_color);
1209 else 1208 }
1210 { 1209 else
1211 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 1210 {
1212 drawable->tex, 0); 1211 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
1213 e3d_renderer_clear(renderer, &data->bg_color); 1212 drawable->tex, 0);
1214 } 1213 e3d_renderer_clear(renderer, &data->bg_color);
1214 }
1215} 1215}
1216 1216
1217void 1217void
@@ -1301,8 +1301,49 @@ e3d_drawable_scene_render(E3D_Drawable *drawable, E3D_Renderer *renderer, Evas_C
1301 e3d_renderer_target_set(renderer, drawable); 1301 e3d_renderer_target_set(renderer, drawable);
1302 e3d_renderer_clear(renderer, &data->bg_color); 1302 e3d_renderer_clear(renderer, &data->bg_color);
1303 1303
1304 /*Render scene data*/ 1304 if (data->post_processing)
1305 _scene_render(drawable, renderer, data); 1305 e3d_drawable_scene_render_to_texture(drawable, renderer, data);//Render to additional texture
1306 else
1307 _scene_render(drawable, renderer, data);//Common main render
1308}
1309
1310void
1311_scene_post_render(E3D_Drawable *drawable, E3D_Renderer *renderer, Evas_Canvas3D_Scene_Public_Data *data)
1312{
1313 E3D_Draw_Data drawable_data;
1314 float vertices_of_square[] = {-1.0, 1.0, 0.0, 1.0, 1.0, 0.0,
1315 -1.0, -1.0, 0.0, 1.0, -1.0, 0.0};
1316 unsigned short indices_of_square[] = {0, 1, 2, 2, 1, 3};
1317
1318 memset(&drawable_data, 0x00, sizeof(E3D_Draw_Data));
1319
1320 drawable_data.flags |= E3D_SHADER_FLAG_VERTEX_POSITION;
1321 drawable_data.mode = data->post_processing_type;
1322 drawable_data.assembly = EVAS_CANVAS3D_VERTEX_ASSEMBLY_TRIANGLES;
1323 drawable_data.indices = indices_of_square;
1324 drawable_data.vertex_count = 4;
1325 drawable_data.index_count = 6;
1326 drawable_data.index_format = EVAS_CANVAS3D_INDEX_FORMAT_UNSIGNED_SHORT;
1327 eina_matrix4_identity(&drawable_data.matrix_mv);
1328 eina_matrix4_identity(&drawable_data.matrix_mvp);
1329 drawable_data.frame_size_h = (Evas_Real)drawable->h;
1330 drawable_data.frame_size_w = (Evas_Real)drawable->w;
1331 /*Initialize Evas_Canvas3D_Vertex_Buffer for full screen quard*/
1332 drawable_data.vertices[EVAS_CANVAS3D_VERTEX_ATTRIB_POSITION].vertex0.data = (void *)vertices_of_square;
1333 drawable_data.vertices[EVAS_CANVAS3D_VERTEX_ATTRIB_POSITION].vertex0.element_count = 3;
1334 drawable_data.vertices[EVAS_CANVAS3D_VERTEX_ATTRIB_POSITION].vertex0.stride = 3 * sizeof(float);
1335 drawable_data.vertices[EVAS_CANVAS3D_VERTEX_ATTRIB_POSITION].vertex0.owns_data = EINA_FALSE;
1336 drawable_data.vertices[EVAS_CANVAS3D_VERTEX_ATTRIB_POSITION].vertex0.size = 0;
1337
1338 e3d_renderer_clear(renderer, &data->bg_color);
1339
1340 /*Initialize texture units*/
1341 drawable_data.smap_sampler = e3d_renderer_sampler_shadowmap_get(renderer);
1342 drawable_data.colortex_sampler = e3d_renderer_sampler_colortexture_get(renderer);
1343
1344 /*Render full screen quard with color pick texture unit*/
1345 e3d_renderer_draw(renderer, &drawable_data);
1346 e3d_renderer_flush(renderer);
1306} 1347}
1307 1348
1308Eina_Bool 1349Eina_Bool
@@ -1315,10 +1356,10 @@ e3d_drawable_scene_render_to_texture(E3D_Drawable *drawable, E3D_Renderer *rende
1315 Eina_Iterator *itmn; 1356 Eina_Iterator *itmn;
1316 void *ptrmn; 1357 void *ptrmn;
1317 Eina_List *repeat_node = NULL; 1358 Eina_List *repeat_node = NULL;
1318 Evas_Color c = {0.0, 0.0, 0.0, 0.0}, *unic_color = NULL; 1359 Evas_Color *unic_color = NULL;
1319 1360
1320 e3d_renderer_color_pick_target_set(renderer, drawable); 1361 e3d_renderer_color_pick_target_set(renderer, drawable);
1321 e3d_renderer_clear(renderer, &c); 1362 e3d_renderer_clear(renderer, &data->bg_color);
1322 1363
1323 if (data->color_pick_enabled) //Use rendering to texture in color pick mechanism 1364 if (data->color_pick_enabled) //Use rendering to texture in color pick mechanism
1324 { 1365 {
@@ -1374,10 +1415,12 @@ e3d_drawable_scene_render_to_texture(E3D_Drawable *drawable, E3D_Renderer *rende
1374 else 1415 else
1375 { 1416 {
1376 _scene_render(drawable, renderer, data); //Just render scene in texture 1417 _scene_render(drawable, renderer, data); //Just render scene in texture
1418 glBindFramebuffer(GL_FRAMEBUFFER, drawable->fbo);
1419 /*Render full screen quard*/
1420 if (data->post_processing)
1421 _scene_post_render(drawable, renderer, data);
1377 } 1422 }
1378 1423
1379 glBindFramebuffer(GL_FRAMEBUFFER, drawable->fbo);
1380
1381 return EINA_TRUE; 1424 return EINA_TRUE;
1382} 1425}
1383 1426
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 da508d2354..cbdb0f7711 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
@@ -114,6 +114,9 @@ struct _E3D_Draw_Data
114 Evas_Real constant_bias; 114 Evas_Real constant_bias;
115 115
116 Eina_Bool render_to_texture; 116 Eina_Bool render_to_texture;
117
118 Evas_Real frame_size_h;
119 Evas_Real frame_size_w;
117}; 120};
118 121
119struct _E3D_Texture 122struct _E3D_Texture
@@ -175,4 +178,6 @@ void e3d_renderer_draw(E3D_Renderer *renderer, E3D_Draw_Data *da
175void e3d_renderer_flush(E3D_Renderer *renderer); 178void e3d_renderer_flush(E3D_Renderer *renderer);
176void e3d_renderer_color_pick_target_set(E3D_Renderer *renderer, E3D_Drawable *drawable); 179void e3d_renderer_color_pick_target_set(E3D_Renderer *renderer, E3D_Drawable *drawable);
177Eina_Bool e3d_renderer_rendering_to_texture_get(E3D_Renderer *renderer); 180Eina_Bool e3d_renderer_rendering_to_texture_get(E3D_Renderer *renderer);
181GLint e3d_renderer_sampler_colortexture_get(E3D_Renderer *renderer);
182GLint e3d_renderer_sampler_shadowmap_get(E3D_Renderer *renderer);
178#endif /* EVAS_GL_3D_PRIVATE_H */ 183#endif /* EVAS_GL_3D_PRIVATE_H */
diff --git a/src/modules/evas/engines/gl_common/evas_gl_3d_renderer.c b/src/modules/evas/engines/gl_common/evas_gl_3d_renderer.c
index 05e6e97acf..0fc0f896d2 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_3d_renderer.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_3d_renderer.c
@@ -414,3 +414,15 @@ e3d_renderer_flush(E3D_Renderer *renderer EINA_UNUSED)
414{ 414{
415 glFlush(); 415 glFlush();
416} 416}
417
418GLint
419e3d_renderer_sampler_colortexture_get(E3D_Renderer *renderer)
420{
421 return renderer->colortex_sampler;
422}
423
424GLint
425e3d_renderer_sampler_shadowmap_get(E3D_Renderer *renderer)
426{
427 return renderer->smap_sampler;
428}
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 9fca4a161b..5f5c0a60ce 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
@@ -69,7 +69,8 @@ typedef enum _E3D_Uniform
69 E3D_UNIFORM_ALPHATEST_COMPARISON, 69 E3D_UNIFORM_ALPHATEST_COMPARISON,
70 E3D_UNIFORM_ALPHATEST_REFVALUE, 70 E3D_UNIFORM_ALPHATEST_REFVALUE,
71 E3D_UNIFORM_RENDER_TO_TEXTURE, 71 E3D_UNIFORM_RENDER_TO_TEXTURE,
72 72 E3D_UNIFORM_FRAME_SIZE_H,
73 E3D_UNIFORM_FRAME_SIZE_W,
73 E3D_UNIFORM_COUNT, 74 E3D_UNIFORM_COUNT,
74} E3D_Uniform; 75} E3D_Uniform;
75 76
@@ -363,6 +364,8 @@ static const char *uniform_names[] =
363 "uAlphaTestComparison", 364 "uAlphaTestComparison",
364 "uAlphaTestRefValue", 365 "uAlphaTestRefValue",
365 "uColorTexture", 366 "uColorTexture",
367 "uFrameSizeH",
368 "uFrameSizeW"
366}; 369};
367 370
368static inline void 371static inline void
@@ -635,6 +638,12 @@ _uniform_upload(E3D_Uniform u, GLint loc, const E3D_Draw_Data *data)
635 case E3D_UNIFORM_RENDER_TO_TEXTURE: 638 case E3D_UNIFORM_RENDER_TO_TEXTURE:
636 glUniform1i(loc, data->colortex_sampler); 639 glUniform1i(loc, data->colortex_sampler);
637 break; 640 break;
641 case E3D_UNIFORM_FRAME_SIZE_H:
642 glUniform1f(loc, data->frame_size_h);
643 break;
644 case E3D_UNIFORM_FRAME_SIZE_W:
645 glUniform1f(loc, data->frame_size_w);
646 break;
638 default: 647 default:
639 ERR("Invalid uniform ID."); 648 ERR("Invalid uniform ID.");
640 break; 649 break;
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 c03d8b5983..90aafabd4e 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
@@ -2112,6 +2112,94 @@ static const char parallax_occlusion_frag_glsl[] =
2112 "#endif //FOG_ENABLED\n" 2112 "#endif //FOG_ENABLED\n"
2113 "}\n"; 2113 "}\n";
2114 2114
2115static const char post_processing_fxaa_vert_glsl[] =
2116 "#ifdef GL_ES\n"
2117 "precision mediump float;\n"
2118 "precision mediump int;\n"
2119 "precision lowp sampler2D;\n"
2120 "#endif\n"
2121 "uniform mat4 uMatrixMvp;\n"
2122 "#ifdef VERTEX_POSITION\n"
2123 "attribute vec4 aPosition0;\n"
2124 "#endif //VERTEX_POSITION\n"
2125 "#ifdef VERTEX_POSITION_BLEND\n"
2126 "attribute vec4 aPosition1;\n"
2127 "uniform float uPositionWeight;\n"
2128 "#endif //VERTEX_POSITION_BLEND\n"
2129 "varying vec2 tc0;\n"
2130 "void main()\n"
2131 "{\n"
2132 " #ifdef VERTEX_POSITION_BLEND\n"
2133 " vec4 position = mix(aPosition1, aPosition0, uPositionWeight);\n"
2134 " position = vec4(position.xyz, 1.0);\n"
2135 "#else\n"
2136 "#ifdef VERTEX_POSITION\n"
2137 " vec4 position = vec4(aPosition0.xyz, 1.0);\n"
2138 "#endif // VERTEX_POSITION\n"
2139 "#endif //VERTEX_POSITION_BLEND\n"
2140 " gl_Position = uMatrixMvp * position;\n"
2141 " tc0 = position.xy * 0.5 + 0.5;\n"
2142 "}\n";
2143
2144static const char post_processing_fxaa_frag_glsl[] =
2145 "#ifdef GL_ES\n"
2146 "precision mediump float;\n"
2147 "precision mediump int;\n"
2148 "precision lowp sampler2D;\n"
2149 "#endif\n"
2150 "//FXAA fragment shader by Timothy Lottes\n"
2151 "//http://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf\n"
2152 "//modified and adapted to www.enlightenment.org by Oleksander Shcherbina\n"
2153 "uniform sampler2D uColorTexture;\n"
2154 "uniform float uFrameSizeH;\n"
2155 "uniform float uFrameSizeW;\n"
2156 "varying vec2 tc0;\n"
2157 "vec4 fxaa()\n"
2158 "{\n"
2159 " float _SPAN_MAX_ = 8.0;\n"
2160 " float _REDUCE_MUL_ = (1.0/8.0);\n"
2161 " float _REDUCE_MIN_ = (1.0/128.0);\n"
2162 " vec4 l = vec4(0.299, 0.587, 0.114, 0.0);\n"
2163 " vec2 frameBufSize = vec2(uFrameSizeW, uFrameSizeH);\n"
2164 " vec2 direction;\n"
2165 " vec4 colorNW = texture2D(uColorTexture, tc0 + (vec2(-1.0, -1.0)/frameBufSize));\n"
2166 " vec4 colorNE = texture2D(uColorTexture, tc0 + (vec2(1.0, -1.0)/frameBufSize));\n"
2167 " vec4 colorSW = texture2D(uColorTexture, tc0 + (vec2(-1.0, 1.0)/frameBufSize));\n"
2168 " vec4 colorSE = texture2D(uColorTexture, tc0 + (vec2(1.0, 1.0)/frameBufSize));\n"
2169 " vec4 colorM = texture2D(uColorTexture,tc0);\n"
2170 " float lNW = dot(colorNW, l);\n"
2171 " float lNE = dot(colorNE, l);\n"
2172 " float lSW = dot(colorSW, l);\n"
2173 " float lSE = dot(colorSE, l);\n"
2174 " float lM = dot(colorM, l);\n"
2175 " float lMin = min(lM, min(min(lNW, lNE), min(lSW, lSE)));\n"
2176 " float lMax = max(lM, max(max(lNW, lNE), max(lSW, lSE)));\n"
2177 " direction.x = -((lNW + lNE) - (lSW + lSE));\n"
2178 " direction.y = ((lNW + lSW) - (lNE + lSE));\n"
2179 " float directionReduce = max(\n"
2180 " (lNW + lNE + lSW + lSE) * (0.25 * _REDUCE_MUL_),\n"
2181 " _REDUCE_MIN_);\n"
2182 " float rcpDirMin = 1.0/(min(abs(direction.x), abs(direction.y)) + directionReduce);\n"
2183 " direction = min(vec2(_SPAN_MAX_, _SPAN_MAX_),\n"
2184 " max(vec2(-_SPAN_MAX_, -_SPAN_MAX_),\n"
2185 " direction * rcpDirMin)) / frameBufSize;\n"
2186 " vec4 colorA = 0.5 * (\n"
2187 " texture2D(uColorTexture, tc0.xy + direction * (1.0/3.0 - 0.5)) +\n"
2188 " texture2D(uColorTexture, tc0.xy + direction * (2.0/3.0 - 0.5)));\n"
2189 " vec4 colorB = colorA * 0.5 + 0.25 * (\n"
2190 " texture2D(uColorTexture, tc0.xy + direction * (- 0.5)) +\n"
2191 " texture2D(uColorTexture, tc0.xy + direction * 0.5));\n"
2192 " float lB = dot(colorB, l);\n"
2193 " if((lB < lMin) || (lB > lMax))\n"
2194 " return colorA;\n"
2195 " else\n"
2196 " return colorB;\n"
2197 "}\n"
2198 "void main()\n"
2199 "{\n"
2200 " gl_FragColor = fxaa();\n"
2201 "}\n";
2202
2115static const char *vertex_shaders[] = 2203static const char *vertex_shaders[] =
2116{ 2204{
2117 vertex_color_vert_glsl, 2205 vertex_color_vert_glsl,
@@ -2122,6 +2210,7 @@ static const char *vertex_shaders[] =
2122 shadow_map_vert_glsl, 2210 shadow_map_vert_glsl,
2123 color_pick_vert_glsl, 2211 color_pick_vert_glsl,
2124 parallax_occlusion_vert_glsl, 2212 parallax_occlusion_vert_glsl,
2213 post_processing_fxaa_vert_glsl,
2125}; 2214};
2126 2215
2127static const char *fragment_shaders[] = 2216static const char *fragment_shaders[] =
@@ -2134,4 +2223,5 @@ static const char *fragment_shaders[] =
2134 shadow_map_frag_glsl, 2223 shadow_map_frag_glsl,
2135 color_pick_frag_glsl, 2224 color_pick_frag_glsl,
2136 parallax_occlusion_frag_glsl, 2225 parallax_occlusion_frag_glsl,
2226 post_processing_fxaa_frag_glsl,
2137}; 2227};
diff --git a/src/modules/evas/engines/gl_common/shader_3d/post_processing_fxaa_frag.shd b/src/modules/evas/engines/gl_common/shader_3d/post_processing_fxaa_frag.shd
new file mode 100644
index 0000000000..b78a09177b
--- /dev/null
+++ b/src/modules/evas/engines/gl_common/shader_3d/post_processing_fxaa_frag.shd
@@ -0,0 +1,63 @@
1//FXAA fragment shader by Timothy Lottes
2//http://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf
3//modified and adapted to www.enlightenment.org by Oleksander Shcherbina
4uniform sampler2D uColorTexture;
5uniform float uFrameSizeH;
6uniform float uFrameSizeW;
7varying vec2 tc0;
8
9vec4 fxaa()
10{
11 float _SPAN_MAX_ = 8.0;
12 float _REDUCE_MUL_ = (1.0/8.0);
13 float _REDUCE_MIN_ = (1.0/128.0);
14 vec4 l = vec4(0.299, 0.587, 0.114, 0.0);
15 vec2 frameBufSize = vec2(uFrameSizeW, uFrameSizeH);
16 vec2 direction;
17
18 vec4 colorNW = texture2D(uColorTexture, tc0 + (vec2(-1.0, -1.0)/frameBufSize));
19 vec4 colorNE = texture2D(uColorTexture, tc0 + (vec2(1.0, -1.0)/frameBufSize));
20 vec4 colorSW = texture2D(uColorTexture, tc0 + (vec2(-1.0, 1.0)/frameBufSize));
21 vec4 colorSE = texture2D(uColorTexture, tc0 + (vec2(1.0, 1.0)/frameBufSize));
22 vec4 colorM = texture2D(uColorTexture,tc0);
23
24 float lNW = dot(colorNW, l);
25 float lNE = dot(colorNE, l);
26 float lSW = dot(colorSW, l);
27 float lSE = dot(colorSE, l);
28 float lM = dot(colorM, l);
29
30 float lMin = min(lM, min(min(lNW, lNE), min(lSW, lSE)));
31 float lMax = max(lM, max(max(lNW, lNE), max(lSW, lSE)));
32
33 direction.x = -((lNW + lNE) - (lSW + lSE));
34 direction.y = ((lNW + lSW) - (lNE + lSE));
35
36 float directionReduce = max(
37 (lNW + lNE + lSW + lSE) * (0.25 * _REDUCE_MUL_),
38 _REDUCE_MIN_);
39
40 float rcpDirMin = 1.0/(min(abs(direction.x), abs(direction.y)) + directionReduce);
41
42 direction = min(vec2(_SPAN_MAX_, _SPAN_MAX_),
43 max(vec2(-_SPAN_MAX_, -_SPAN_MAX_),
44 direction * rcpDirMin)) / frameBufSize;
45
46 vec4 colorA = 0.5 * (
47 texture2D(uColorTexture, tc0.xy + direction * (1.0/3.0 - 0.5)) +
48 texture2D(uColorTexture, tc0.xy + direction * (2.0/3.0 - 0.5)));
49 vec4 colorB = colorA * 0.5 + 0.25 * (
50 texture2D(uColorTexture, tc0.xy + direction * (- 0.5)) +
51 texture2D(uColorTexture, tc0.xy + direction * 0.5));
52 float lB = dot(colorB, l);
53
54 if((lB < lMin) || (lB > lMax))
55 return colorA;
56 else
57 return colorB;
58}
59
60void main()
61{
62 gl_FragColor = fxaa();
63}
diff --git a/src/modules/evas/engines/gl_common/shader_3d/post_processing_fxaa_vert.shd b/src/modules/evas/engines/gl_common/shader_3d/post_processing_fxaa_vert.shd
new file mode 100644
index 0000000000..8464fdcc82
--- /dev/null
+++ b/src/modules/evas/engines/gl_common/shader_3d/post_processing_fxaa_vert.shd
@@ -0,0 +1,12 @@
1uniform mat4 uMatrixMvp;
2
3VERTEX_SHADER_USE_POSITION
4
5varying vec2 tc0;
6void main()
7{
8 VERTEX_SHADER_POSITION
9
10 gl_Position = uMatrixMvp * position;
11 tc0 = position.xy * 0.5 + 0.5;
12}