aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmytro Dadyka <d.dadyka@gmail.com>2015-03-25 16:07:49 -0700
committerJean-Philippe ANDRE <jpeg@videolan.org>2015-03-25 16:08:32 -0700
commitefecbef773633653949e824d6a3a37576c191bd7 (patch)
treecec7e09e04d6342d56b1fb4afec368e2bf7eec9e
parentEcore: Use calloc() to initialize Ecore_Event_Key fully (diff)
downloadefl-efecbef773633653949e824d6a3a37576c191bd7.tar.gz
[Evas: Evas_3D] Improve shaders math
Reviewers: cedric, jpeg Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2244 On many platforms the built-in mix(x, y, a) function faster than its equivalent x * a + y * (1 - a)
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/evas_gl_3d_shaders.x106
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/include.shd13
2 files changed, 49 insertions, 70 deletions
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 f5b42e093d..eaf7ece7c9 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
@@ -26,8 +26,7 @@ static const char const vertex_color_vert_glsl[] =
"void main()\n"
"{\n"
" #ifdef VERTEX_POSITION_BLEND\n"
- " vec4 position = aPosition0 * uPositionWeight +\n"
- " aPosition1 * (1.0 - uPositionWeight);\n"
+ " vec4 position = mix(aPosition1, aPosition0, uPositionWeight);\n"
" position = vec4(position.xyz, 1.0);\n"
"#else\n"
"#ifdef VERTEX_POSITION\n"
@@ -95,8 +94,7 @@ static const char const diffuse_vert_glsl[] =
"void main()\n"
"{\n"
" #ifdef VERTEX_POSITION_BLEND\n"
- " vec4 position = aPosition0 * uPositionWeight +\n"
- " aPosition1 * (1.0 - uPositionWeight);\n"
+ " vec4 position = mix(aPosition1, aPosition0, uPositionWeight);\n"
" position = vec4(position.xyz, 1.0);\n"
"#else\n"
"#ifdef VERTEX_POSITION\n"
@@ -104,8 +102,7 @@ static const char const diffuse_vert_glsl[] =
"#endif // VERTEX_POSITION\n"
"#endif //VERTEX_POSITION_BLEND\n"
" #ifdef VERTEX_TEXCOORD_BLEND\n"
- " vTexCoord = aTexCoord0.st * uTexCoordWeight +\n"
- " aTexCoord1.st * (1.0 - uTexCoordWeight);\n"
+ " vTexCoord = mix(aTexCoord1.st, aTexCoord0.st, uTexCoordWeight);\n"
"#else\n"
"#ifdef VERTEX_TEXCOORD\n"
" vTexCoord = aTexCoord0.st;\n"
@@ -142,8 +139,8 @@ static const char const diffuse_frag_glsl[] =
" vec4 color;\n"
" \n"
"#ifdef DIFFUSE_TEXTURE_BLEND\n"
- " color = texture2D(uTextureDiffuse0, vTexCoord) * uTextureDiffuseWeight +\n"
- " texture2D(uTextureDiffuse1, vTexCoord) * (1.0 - uTextureDiffuseWeight);\n"
+ " color = mix(texture2D(uTextureDiffuse1, vTexCoord),\n"
+ " texture2D(uTextureDiffuse0, vTexCoord), uTextureDiffuseWeight);\n"
" color *= uMaterialDiffuse;\n"
"#else\n"
"#ifdef DIFFUSE_TEXTURE\n"
@@ -259,8 +256,7 @@ static const char const flat_vert_glsl[] =
"void main()\n"
"{\n"
" #ifdef VERTEX_POSITION_BLEND\n"
- " vec4 position = aPosition0 * uPositionWeight +\n"
- " aPosition1 * (1.0 - uPositionWeight);\n"
+ " vec4 position = mix(aPosition1, aPosition0, uPositionWeight);\n"
" position = vec4(position.xyz, 1.0);\n"
"#else\n"
"#ifdef VERTEX_POSITION\n"
@@ -268,16 +264,14 @@ static const char const flat_vert_glsl[] =
"#endif // VERTEX_POSITION\n"
"#endif //VERTEX_POSITION_BLEND\n"
" #ifdef VERTEX_NORMAL_BLEND\n"
- " vec3 normal = aNormal0.xyz * uNormalWeight +\n"
- " aNormal1.xyz * (1.0 - uNormalWeight);\n"
+ " vec3 normal = mix(aNormal1.xyz, aNormal0.xyz, uNormalWeight);\n"
"#else\n"
"#ifdef VERTEX_NORMAL\n"
" vec3 normal = aNormal0.xyz;\n"
"#endif //VERTEX_NORMAL\n"
"#endif //VERTEX_NORMAL_BLEND\n"
" #ifdef VERTEX_TEXCOORD_BLEND\n"
- " vTexCoord = aTexCoord0.st * uTexCoordWeight +\n"
- " aTexCoord1.st * (1.0 - uTexCoordWeight);\n"
+ " vTexCoord = mix(aTexCoord1.st, aTexCoord0.st, uTexCoordWeight);\n"
"#else\n"
"#ifdef VERTEX_TEXCOORD\n"
" vTexCoord = aTexCoord0.st;\n"
@@ -369,8 +363,8 @@ static const char const flat_frag_glsl[] =
"#ifdef DIFFUSE\n"
" \n"
"#ifdef DIFFUSE_TEXTURE_BLEND\n"
- " color = texture2D(uTextureDiffuse0, vTexCoord) * uTextureDiffuseWeight +\n"
- " texture2D(uTextureDiffuse1, vTexCoord) * (1.0 - uTextureDiffuseWeight);\n"
+ " color = mix(texture2D(uTextureDiffuse1, vTexCoord),\n"
+ " texture2D(uTextureDiffuse0, vTexCoord), uTextureDiffuseWeight);\n"
" color *= uMaterialDiffuse;\n"
"#else\n"
"#ifdef DIFFUSE_TEXTURE\n"
@@ -386,8 +380,8 @@ static const char const flat_frag_glsl[] =
"#ifdef SPECULAR\n"
" \n"
"#ifdef SPECULAR_TEXTURE_BLEND\n"
- " color = texture2D(uTextureSpecular0, vTexCoord) * uTextureSpecularWeight +\n"
- " texture2D(uTextureSpecular1, vTexCoord) * (1.0 - uTextureSpecularWeight);\n"
+ " color = mix(texture2D(uTextureSpecular1, vTexCoord),\n"
+ " texture2D(uTextureSpecular0, vTexCoord), uTextureSpecularWeight);\n"
" color *= uMaterialSpecular;\n"
"#else\n"
"#ifdef SPECULAR_TEXTURE\n"
@@ -404,8 +398,8 @@ static const char const flat_frag_glsl[] =
"#ifdef AMBIENT\n"
" \n"
"#ifdef AMBIENT_TEXTURE_BLEND\n"
- " color = texture2D(uTextureAmbient0, vTexCoord) * uTextureAmbientWeight +\n"
- " texture2D(uTextureAmbient1, vTexCoord) * (1.0 - uTextureAmbientWeight);\n"
+ " color = mix(texture2D(uTextureAmbient1, vTexCoord),\n"
+ " texture2D(uTextureAmbient0, vTexCoord), uTextureAmbientWeight);\n"
" color *= uMaterialAmbient;\n"
"#else\n"
"#ifdef AMBIENT_TEXTURE\n"
@@ -419,8 +413,8 @@ static const char const flat_frag_glsl[] =
"#ifdef EMISSION\n"
" \n"
"#ifdef EMISSION_TEXTURE_BLEND\n"
- " color = texture2D(uTextureEmission0, vTexCoord) * uTextureEmissionWeight +\n"
- " texture2D(uTextureEmission1, vTexCoord) * (1.0 - uTextureEmissionWeight);\n"
+ " color = mix(texture2D(uTextureEmission1, vTexCoord),\n"
+ " texture2D(uTextureEmission0, vTexCoord), uTextureEmissionWeight);\n"
" color *= uMaterialEmission;\n"
"#else\n"
"#ifdef EMISSION_TEXTURE\n"
@@ -511,8 +505,7 @@ static const char const phong_vert_glsl[] =
"}\n"
"void main() {\n"
" #ifdef VERTEX_POSITION_BLEND\n"
- " vec4 position = aPosition0 * uPositionWeight +\n"
- " aPosition1 * (1.0 - uPositionWeight);\n"
+ " vec4 position = mix(aPosition1, aPosition0, uPositionWeight);\n"
" position = vec4(position.xyz, 1.0);\n"
"#else\n"
"#ifdef VERTEX_POSITION\n"
@@ -520,16 +513,14 @@ static const char const phong_vert_glsl[] =
"#endif // VERTEX_POSITION\n"
"#endif //VERTEX_POSITION_BLEND\n"
" #ifdef VERTEX_NORMAL_BLEND\n"
- " vec3 normal = aNormal0.xyz * uNormalWeight +\n"
- " aNormal1.xyz * (1.0 - uNormalWeight);\n"
+ " vec3 normal = mix(aNormal1.xyz, aNormal0.xyz, uNormalWeight);\n"
"#else\n"
"#ifdef VERTEX_NORMAL\n"
" vec3 normal = aNormal0.xyz;\n"
"#endif //VERTEX_NORMAL\n"
"#endif //VERTEX_NORMAL_BLEND\n"
" #ifdef VERTEX_TEXCOORD_BLEND\n"
- " vTexCoord = aTexCoord0.st * uTexCoordWeight +\n"
- " aTexCoord1.st * (1.0 - uTexCoordWeight);\n"
+ " vTexCoord = mix(aTexCoord1.st, aTexCoord0.st, uTexCoordWeight);\n"
"#else\n"
"#ifdef VERTEX_TEXCOORD\n"
" vTexCoord = aTexCoord0.st;\n"
@@ -644,8 +635,8 @@ static const char const phong_frag_glsl[] =
"#ifdef DIFFUSE\n"
" \n"
"#ifdef DIFFUSE_TEXTURE_BLEND\n"
- " color = texture2D(uTextureDiffuse0, vTexCoord) * uTextureDiffuseWeight +\n"
- " texture2D(uTextureDiffuse1, vTexCoord) * (1.0 - uTextureDiffuseWeight);\n"
+ " color = mix(texture2D(uTextureDiffuse1, vTexCoord),\n"
+ " texture2D(uTextureDiffuse0, vTexCoord), uTextureDiffuseWeight);\n"
" color *= uMaterialDiffuse;\n"
"#else\n"
"#ifdef DIFFUSE_TEXTURE\n"
@@ -666,8 +657,8 @@ static const char const phong_frag_glsl[] =
" factor = pow(factor, uMaterialShininess);\n"
" \n"
"#ifdef SPECULAR_TEXTURE_BLEND\n"
- " color = texture2D(uTextureSpecular0, vTexCoord) * uTextureSpecularWeight +\n"
- " texture2D(uTextureSpecular1, vTexCoord) * (1.0 - uTextureSpecularWeight);\n"
+ " color = mix(texture2D(uTextureSpecular1, vTexCoord),\n"
+ " texture2D(uTextureSpecular0, vTexCoord), uTextureSpecularWeight);\n"
" color *= uMaterialSpecular;\n"
"#else\n"
"#ifdef SPECULAR_TEXTURE\n"
@@ -688,8 +679,8 @@ static const char const phong_frag_glsl[] =
"#ifdef AMBIENT\n"
" \n"
"#ifdef AMBIENT_TEXTURE_BLEND\n"
- " color = texture2D(uTextureAmbient0, vTexCoord) * uTextureAmbientWeight +\n"
- " texture2D(uTextureAmbient1, vTexCoord) * (1.0 - uTextureAmbientWeight);\n"
+ " color = mix(texture2D(uTextureAmbient1, vTexCoord),\n"
+ " texture2D(uTextureAmbient0, vTexCoord), uTextureAmbientWeight);\n"
" color *= uMaterialAmbient;\n"
"#else\n"
"#ifdef AMBIENT_TEXTURE\n"
@@ -708,8 +699,8 @@ static const char const phong_frag_glsl[] =
"#ifdef EMISSION\n"
" \n"
"#ifdef EMISSION_TEXTURE_BLEND\n"
- " color = texture2D(uTextureEmission0, vTexCoord) * uTextureEmissionWeight +\n"
- " texture2D(uTextureEmission1, vTexCoord) * (1.0 - uTextureEmissionWeight);\n"
+ " color = mix(texture2D(uTextureEmission1, vTexCoord),\n"
+ " texture2D(uTextureEmission0, vTexCoord), uTextureEmissionWeight);\n"
" color *= uMaterialEmission;\n"
"#else\n"
"#ifdef EMISSION_TEXTURE\n"
@@ -846,8 +837,7 @@ static const char const normal_map_vert_glsl[] =
"void main()\n"
"{\n"
" #ifdef VERTEX_POSITION_BLEND\n"
- " vec4 position = aPosition0 * uPositionWeight +\n"
- " aPosition1 * (1.0 - uPositionWeight);\n"
+ " vec4 position = mix(aPosition1, aPosition0, uPositionWeight);\n"
" position = vec4(position.xyz, 1.0);\n"
"#else\n"
"#ifdef VERTEX_POSITION\n"
@@ -855,8 +845,7 @@ static const char const normal_map_vert_glsl[] =
"#endif // VERTEX_POSITION\n"
"#endif //VERTEX_POSITION_BLEND\n"
" #ifdef VERTEX_NORMAL_BLEND\n"
- " vec3 normal = aNormal0.xyz * uNormalWeight +\n"
- " aNormal1.xyz * (1.0 - uNormalWeight);\n"
+ " vec3 normal = mix(aNormal1.xyz, aNormal0.xyz, uNormalWeight);\n"
"#else\n"
"#ifdef VERTEX_NORMAL\n"
" vec3 normal = aNormal0.xyz;\n"
@@ -871,8 +860,7 @@ static const char const normal_map_vert_glsl[] =
"#endif //VERTEX_TANGENT\n"
"#endif //VERTEX_TANGENT_BLEND\n"
" #ifdef VERTEX_TEXCOORD_BLEND\n"
- " vTexCoord = aTexCoord0.st * uTexCoordWeight +\n"
- " aTexCoord1.st * (1.0 - uTexCoordWeight);\n"
+ " vTexCoord = mix(aTexCoord1.st, aTexCoord0.st, uTexCoordWeight);\n"
"#else\n"
"#ifdef VERTEX_TEXCOORD\n"
" vTexCoord = aTexCoord0.st;\n"
@@ -1031,8 +1019,8 @@ static const char const normal_map_frag_glsl[] =
"#ifdef DIFFUSE\n"
" \n"
"#ifdef DIFFUSE_TEXTURE_BLEND\n"
- " color = texture2D(uTextureDiffuse0, vTexCoord) * uTextureDiffuseWeight +\n"
- " texture2D(uTextureDiffuse1, vTexCoord) * (1.0 - uTextureDiffuseWeight);\n"
+ " color = mix(texture2D(uTextureDiffuse1, vTexCoord),\n"
+ " texture2D(uTextureDiffuse0, vTexCoord), uTextureDiffuseWeight);\n"
" color *= uMaterialDiffuse;\n"
"#else\n"
"#ifdef DIFFUSE_TEXTURE\n"
@@ -1052,8 +1040,8 @@ static const char const normal_map_frag_glsl[] =
" factor = pow(factor, uMaterialShininess);\n"
" \n"
"#ifdef SPECULAR_TEXTURE_BLEND\n"
- " color = texture2D(uTextureSpecular0, vTexCoord) * uTextureSpecularWeight +\n"
- " texture2D(uTextureSpecular1, vTexCoord) * (1.0 - uTextureSpecularWeight);\n"
+ " color = mix(texture2D(uTextureSpecular1, vTexCoord),\n"
+ " texture2D(uTextureSpecular0, vTexCoord), uTextureSpecularWeight);\n"
" color *= uMaterialSpecular;\n"
"#else\n"
"#ifdef SPECULAR_TEXTURE\n"
@@ -1074,8 +1062,8 @@ static const char const normal_map_frag_glsl[] =
"#ifdef AMBIENT\n"
" \n"
"#ifdef AMBIENT_TEXTURE_BLEND\n"
- " color = texture2D(uTextureAmbient0, vTexCoord) * uTextureAmbientWeight +\n"
- " texture2D(uTextureAmbient1, vTexCoord) * (1.0 - uTextureAmbientWeight);\n"
+ " color = mix(texture2D(uTextureAmbient1, vTexCoord),\n"
+ " texture2D(uTextureAmbient0, vTexCoord), uTextureAmbientWeight);\n"
" color *= uMaterialAmbient;\n"
"#else\n"
"#ifdef AMBIENT_TEXTURE\n"
@@ -1092,8 +1080,8 @@ static const char const normal_map_frag_glsl[] =
"#ifdef EMISSION\n"
" \n"
"#ifdef EMISSION_TEXTURE_BLEND\n"
- " color = texture2D(uTextureEmission0, vTexCoord) * uTextureEmissionWeight +\n"
- " texture2D(uTextureEmission1, vTexCoord) * (1.0 - uTextureEmissionWeight);\n"
+ " color = mix(texture2D(uTextureEmission1, vTexCoord),\n"
+ " texture2D(uTextureEmission0, vTexCoord), uTextureEmissionWeight);\n"
" color *= uMaterialEmission;\n"
"#else\n"
"#ifdef EMISSION_TEXTURE\n"
@@ -1147,8 +1135,7 @@ static const char const shadow_map_vert_glsl[] =
"void main()\n"
"{\n"
"#ifdef VERTEX_POSITION_BLEND\n"
- " vec4 position = aPosition0 * uPositionWeight +\n"
- " aPosition1 * (1.0 - uPositionWeight);\n"
+ " vec4 position = mix(aPosition1, aPosition0, uPositionWeight);\n"
" position = vec4(position.xyz, 1.0);\n"
"#else\n"
"#ifdef VERTEX_POSITION\n"
@@ -1157,8 +1144,7 @@ static const char const shadow_map_vert_glsl[] =
"#endif //VERTEX_POSITION_BLEND\n"
"#ifdef ALPHA_TEST_ENABLED\n"
" #ifdef VERTEX_TEXCOORD_BLEND\n"
- " vTexCoord = aTexCoord0.st * uTexCoordWeight +\n"
- " aTexCoord1.st * (1.0 - uTexCoordWeight);\n"
+ " vTexCoord = mix(aTexCoord1.st, aTexCoord0.st, uTexCoordWeight);\n"
"#else\n"
"#ifdef VERTEX_TEXCOORD\n"
" vTexCoord = aTexCoord0.st;\n"
@@ -1222,8 +1208,7 @@ static const char const color_pick_vert_glsl[] =
"void main()\n"
"{\n"
" #ifdef VERTEX_POSITION_BLEND\n"
- " vec4 position = aPosition0 * uPositionWeight +\n"
- " aPosition1 * (1.0 - uPositionWeight);\n"
+ " vec4 position = mix(aPosition1, aPosition0, uPositionWeight);\n"
" position = vec4(position.xyz, 1.0);\n"
"#else\n"
"#ifdef VERTEX_POSITION\n"
@@ -1329,8 +1314,7 @@ static const char const parallax_occlusion_vert_glsl[] =
"void main()\n"
"{\n"
" #ifdef VERTEX_POSITION_BLEND\n"
- " vec4 position = aPosition0 * uPositionWeight +\n"
- " aPosition1 * (1.0 - uPositionWeight);\n"
+ " vec4 position = mix(aPosition1, aPosition0, uPositionWeight);\n"
" position = vec4(position.xyz, 1.0);\n"
"#else\n"
"#ifdef VERTEX_POSITION\n"
@@ -1338,8 +1322,7 @@ static const char const parallax_occlusion_vert_glsl[] =
"#endif // VERTEX_POSITION\n"
"#endif //VERTEX_POSITION_BLEND\n"
" #ifdef VERTEX_NORMAL_BLEND\n"
- " vec3 normal = aNormal0.xyz * uNormalWeight +\n"
- " aNormal1.xyz * (1.0 - uNormalWeight);\n"
+ " vec3 normal = mix(aNormal1.xyz, aNormal0.xyz, uNormalWeight);\n"
"#else\n"
"#ifdef VERTEX_NORMAL\n"
" vec3 normal = aNormal0.xyz;\n"
@@ -1354,8 +1337,7 @@ static const char const parallax_occlusion_vert_glsl[] =
"#endif //VERTEX_TANGENT\n"
"#endif //VERTEX_TANGENT_BLEND\n"
" #ifdef VERTEX_TEXCOORD_BLEND\n"
- " vTexCoord = aTexCoord0.st * uTexCoordWeight +\n"
- " aTexCoord1.st * (1.0 - uTexCoordWeight);\n"
+ " vTexCoord = mix(aTexCoord1.st, aTexCoord0.st, uTexCoordWeight);\n"
"#else\n"
"#ifdef VERTEX_TEXCOORD\n"
" vTexCoord = aTexCoord0.st;\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 aea3c8f658..489c4ff17e 100644
--- a/src/modules/evas/engines/gl_common/shader_3d/include.shd
+++ b/src/modules/evas/engines/gl_common/shader_3d/include.shd
@@ -61,8 +61,8 @@ varying float vLightDist;
define(`FRAGMENT_SHADER_TEXTURE_BLEND', `
#ifdef $1_TEXTURE_BLEND
- color = texture2D(uTexture$2`0', vTexCoord) * uTexture$2Weight +
- texture2D(uTexture$2`1', vTexCoord) * (1.0 - uTexture$2Weight);
+ color = mix(texture2D(uTexture$2`1', vTexCoord),
+ texture2D(uTexture$2`0', vTexCoord), uTexture$2Weight);
color *= uMaterial$2;
#else
#ifdef $1_TEXTURE
@@ -160,8 +160,7 @@ uniform float uColorWeight;
define(`VERTEX_SHADER_POSITION',
`#ifdef VERTEX_POSITION_BLEND'
- vec4 position = aPosition0 * uPositionWeight +
- aPosition1 * (1.0 - uPositionWeight);
+ vec4 position = mix(aPosition1, aPosition0, uPositionWeight);
position = vec4(position.xyz, 1.0);
`#else'
@@ -173,8 +172,7 @@ define(`VERTEX_SHADER_POSITION',
define(`VERTEX_SHADER_NORMAL',
`#ifdef VERTEX_NORMAL_BLEND'
- vec3 normal = aNormal0.xyz * uNormalWeight +
- aNormal1.xyz * (1.0 - uNormalWeight);
+ vec3 normal = mix(aNormal1.xyz, aNormal0.xyz, uNormalWeight);
`#else'
`#ifdef VERTEX_NORMAL'
@@ -184,8 +182,7 @@ define(`VERTEX_SHADER_NORMAL',
define(`VERTEX_SHADER_TEXCOORD',
`#ifdef VERTEX_TEXCOORD_BLEND'
- vTexCoord = aTexCoord0.st * uTexCoordWeight +
- aTexCoord1.st * (1.0 - uTexCoordWeight);
+ vTexCoord = mix(aTexCoord1.st, aTexCoord0.st, uTexCoordWeight);
`#else'
`#ifdef VERTEX_TEXCOORD'