summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDmytro Dadyka <d.dadyka@samsung.com>2015-03-24 10:50:40 -0700
committerJean-Philippe ANDRE <jpeg@videolan.org>2015-03-24 10:50:41 -0700
commit06978b210bf37430532cf6a4662c9a4be03397d0 (patch)
tree67571dff00653f919197c6c92fa8587e66e9a4b6 /src
parent02da66541f1f35c777297470fc49182227eac501 (diff)
downloadefl-06978b210bf37430532cf6a4662c9a4be03397d0.tar.gz
[Evas: Evas_3D] Refactor shader system: refactored normal map shade mode.
Reviewers: cedric, jpeg Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2232
Diffstat (limited to 'src')
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/evas_gl_3d_shaders.x66
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/normal_map_frag.shd168
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/normal_map_vert.shd79
3 files changed, 57 insertions, 256 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 ed9780b3bf..8377e39f05 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
@@ -844,7 +844,7 @@ static const char const normal_map_vert_glsl[] =
"#endif //VERTEX_TANGENT\n"
"void main()\n"
"{\n"
- "#ifdef VERTEX_POSITION_BLEND\n"
+ " #ifdef VERTEX_POSITION_BLEND\n"
" vec4 position = aPosition0 * uPositionWeight +\n"
" aPosition1 * (1.0 - uPositionWeight);\n"
" position = vec4(position.xyz, 1.0);\n"
@@ -853,7 +853,7 @@ static const char const normal_map_vert_glsl[] =
" vec4 position = vec4(aPosition0.xyz, 1.0);\n"
"#endif // VERTEX_POSITION\n"
"#endif //VERTEX_POSITION_BLEND\n"
- "#ifdef VERTEX_NORMAL_BLEND\n"
+ " #ifdef VERTEX_NORMAL_BLEND\n"
" vec3 normal = aNormal0.xyz * uNormalWeight +\n"
" aNormal1.xyz * (1.0 - uNormalWeight);\n"
"#else\n"
@@ -869,7 +869,7 @@ static const char const normal_map_vert_glsl[] =
" vec3 tangent = aTangent0.xyz;\n"
"#endif //VERTEX_TANGENT\n"
"#endif //VERTEX_TANGENT_BLEND\n"
- "#ifdef VERTEX_TEXCOORD_BLEND\n"
+ " #ifdef VERTEX_TEXCOORD_BLEND\n"
" vTexCoord = aTexCoord0.st * uTexCoordWeight +\n"
" aTexCoord1.st * (1.0 - uTexCoordWeight);\n"
"#else\n"
@@ -909,6 +909,16 @@ static const char const normal_map_frag_glsl[] =
"varying vec4 vLightPosition;\n"
"uniform sampler2D uShadowMap;\n"
"float shadow;\n"
+ "float pcf(vec4 lpos, float size)\n"
+ " {\n"
+ " vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;\n"
+ " float i, j, randx, randy, shadow;\n"
+ " shadow = 0.0;\n"
+ " for (i = -4.0; i < 4.0; i++)\n"
+ " for (j = -4.0; j < 4.0; j++)\n"
+ " shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0)*size).x);\n"
+ " return shadow / 64.0;\n"
+ "}\n"
"#endif //SHADOWED\n"
"#ifdef NORMAL_TEXTURE_BLEND\n"
"uniform sampler2D uTextureNormal1;\n"
@@ -1018,14 +1028,15 @@ static const char const normal_map_frag_glsl[] =
" if (factor > 0.0)\n"
" {\n"
"#ifdef DIFFUSE\n"
- "#ifdef DIFFUSE_TEXTURE_BLEND\n"
- " color = texture2D(uTextureDiffuse0, vTexCoord) * uTextureDiffuseWeight +\n"
- " texture2D(uTextureDiffuse1, vTexCoord) * (1.0 - uTextureDiffuseWeight);\n"
+ " \n"
+ "#ifdef DIFFUSE_TEXTURE_BLEND\n"
+ " color = texture2D(uTextureDiffuse0, vTexCoord) * uTextureDiffuseWeight +\n"
+ " texture2D(uTextureDiffuse1, vTexCoord) * (1.0 - uTextureDiffuseWeight);\n"
"#else\n"
- "#ifdef DIFFUSE_TEXTURE\n"
- " color = texture2D(uTextureDiffuse0, vTexCoord);\n"
+ "#ifdef DIFFUSE_TEXTURE\n"
+ " color = texture2D(uTextureDiffuse0, vTexCoord);\n"
"#else\n"
- " color = uMaterialDiffuse;\n"
+ " color = uMaterialDiffuse;\n"
"#endif //DIFFUSE_TEXTURE\n"
"#endif //DIFFUSE_TEXTURE_BLEND\n"
" gl_FragColor = uLightDiffuse * color * factor;\n"
@@ -1037,14 +1048,15 @@ static const char const normal_map_frag_glsl[] =
" if (factor > 0.0)\n"
" {\n"
" factor = pow(factor, uMaterialShininess);\n"
- "#ifdef SPECULAR_TEXTURE_BLEND\n"
- " color = texture2D(uTextureSpecular0, vTexCoord) * uTextureSpecularWeight +\n"
- " texture2D(uTextureSpecular1, vTexCoord) * (1.0 - uTextureSpecularWeight);\n"
+ " \n"
+ "#ifdef SPECULAR_TEXTURE_BLEND\n"
+ " color = texture2D(uTextureSpecular0, vTexCoord) * uTextureSpecularWeight +\n"
+ " texture2D(uTextureSpecular1, vTexCoord) * (1.0 - uTextureSpecularWeight);\n"
"#else\n"
- "#ifdef SPECULAR_TEXTURE\n"
- " color = texture2D(uTextureSpecular0, vTexCoord);\n"
+ "#ifdef SPECULAR_TEXTURE\n"
+ " color = texture2D(uTextureSpecular0, vTexCoord);\n"
"#else\n"
- " color = uMaterialSpecular;\n"
+ " color = uMaterialSpecular;\n"
"#endif //SPECULAR_TEXTURE\n"
"#endif //SPECULAR_TEXTURE_BLEND\n"
" gl_FragColor += uLightSpecular * color * factor;\n"
@@ -1057,11 +1069,12 @@ static const char const normal_map_frag_glsl[] =
" else\n"
" gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);\n"
"#ifdef AMBIENT\n"
- "#ifdef AMBIENT_TEXTURE_BLEND\n"
+ " \n"
+ "#ifdef AMBIENT_TEXTURE_BLEND\n"
" color = texture2D(uTextureAmbient0, vTexCoord) * uTextureAmbientWeight +\n"
" texture2D(uTextureAmbient1, vTexCoord) * (1.0 - uTextureAmbientWeight);\n"
"#else\n"
- "#ifdef AMBIENT_TEXTURE\n"
+ "#ifdef AMBIENT_TEXTURE\n"
" color = texture2D(uTextureAmbient0, vTexCoord);\n"
"#else\n"
" color = uMaterialAmbient;\n"
@@ -1073,11 +1086,12 @@ static const char const normal_map_frag_glsl[] =
" gl_FragColor /= dot(uLightAtten, vec3(1.0, vLightDist, vLightDist * vLightDist));\n"
"#endif //LIGHT_ATTENUATION\n"
"#ifdef EMISSION\n"
- "#ifdef EMISSION_TEXTURE_BLEND\n"
+ " \n"
+ "#ifdef EMISSION_TEXTURE_BLEND\n"
" color = texture2D(uTextureEmission0, vTexCoord) * uTextureEmissionWeight +\n"
" texture2D(uTextureEmission1, vTexCoord) * (1.0 - uTextureEmissionWeight);\n"
"#else\n"
- "#ifdef EMISSION_TEXTURE\n"
+ "#ifdef EMISSION_TEXTURE\n"
" color = texture2D(uTextureEmission0, vTexCoord);\n"
"#else\n"
" color = uMaterialEmission;\n"
@@ -1086,18 +1100,6 @@ static const char const normal_map_frag_glsl[] =
" gl_FragColor += color;\n"
"#endif //EMISSION\n"
"}\n"
- "#ifdef SHADOWED\n"
- "float pcf(vec4 lpos, float size)\n"
- "{\n"
- " vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;\n"
- " float i, j, randx, randy, shadow;\n"
- " shadow = 0.0;\n"
- " for (i = -4.0; i < 4.0; i++)\n"
- " for (j = -4.0; j < 4.0; j++)\n"
- " shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0)*size).x);\n"
- " return shadow / 64.0;\n"
- "}\n"
- "#endif //SHADOWED\n"
"void main() {\n"
"#ifdef SHADOWED\n"
" shadow = pcf(vLightPosition, 1.0 / 200.0);\n"
@@ -1105,7 +1107,7 @@ static const char const normal_map_frag_glsl[] =
" fragmentNormalMap();\n"
"#ifdef FOG_ENABLED\n"
" float z = gl_FragCoord.z / gl_FragCoord.w;\n"
- " float fogFactor = exp2( -uFogFactor * uFogFactor * z * z * 1.44);\n"
+ " float fogFactor = exp2(-uFogFactor * uFogFactor * z * z * 1.44);\n"
" fogFactor = clamp(fogFactor, 0.0, 1.0);\n"
" gl_FragColor = mix(uFogColor, gl_FragColor, fogFactor);\n"
"#endif //FOG_ENABLED\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
index 4e2d8267b5..10b51e4249 100644
--- 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
@@ -3,20 +3,9 @@ varying vec3 vLightHalfVector;
uniform sampler2D uTextureNormal0;
varying vec3 vEyeVector;
-#ifdef NEED_TEX_COORD
-varying vec2 vTexCoord;
-#endif //TEX_COORD
-
-#ifdef FOG_ENABLED
-uniform float uFogFactor;
-uniform vec4 uFogColor;
-#endif //FOG_ENABLED
-
-#ifdef SHADOWED
-varying vec4 vLightPosition;
-uniform sampler2D uShadowMap;
-float shadow;
-#endif //SHADOWED
+FRAGMENT_SHADER_USE_TEX_COORD
+FRAGMENT_SHADER_USE_FOG
+FRAGMENT_SHADER_USE_SHADOWS
#ifdef NORMAL_TEXTURE_BLEND
uniform sampler2D uTextureNormal1;
@@ -27,75 +16,11 @@ uniform float uTextureNormalWeight;
varying vec3 vNormal;
#endif //VERTEX_TANGENT
-#ifdef DIFFUSE
-uniform vec4 uMaterialDiffuse;
-uniform vec4 uLightDiffuse;
-
-#ifdef DIFFUSE_TEXTURE
-uniform sampler2D uTextureDiffuse0;
-#endif //DIFFUSE_TEXTURE
-
-#ifdef DIFFUSE_TEXTURE_BLEND
-uniform sampler2D uTextureDiffuse1;
-uniform float uTextureDiffuseWeight;
-#endif //DIFFUSE_TEXTURE_BLEND
-
-#endif //DIFFUSE
-
-#ifdef SPECULAR
-uniform vec4 uLightSpecular;
-uniform float uMaterialShininess;
-uniform vec4 uMaterialSpecular;
-
-#ifdef SPECULAR_TEXTURE
-uniform sampler2D uTextureSpecular0;
-#endif //SPECULAR_TEXTURE
-
-#ifdef SPECULAR_TEXTURE_BLEND
-uniform sampler2D uTextureSpecular1;
-uniform float uTextureSpecularWeight;
-#endif //SPECULAR_TEXTURE_BLEND
-
-#endif //SPECULAR
-
-#ifdef AMBIENT
-uniform vec4 uMaterialAmbient;
-uniform vec4 uLightAmbient;
-
-#ifdef AMBIENT_TEXTURE
-uniform sampler2D uTextureAmbient0;
-#endif //AMBIENT_TEXTURE
-
-#ifdef AMBIENT_TEXTURE_BLEND
-uniform sampler2D uTextureAmbient1;
-uniform float uTextureAmbientWeight;
-#endif //AMBIENT_TEXTURE_BLEND
-
-#endif //AMBIENT
-
-#ifdef EMISSION
-uniform vec4 uMaterialEmission;
-
-#ifdef EMISSION_TEXTURE
-uniform sampler2D uTextureEmission0;
-#endif //EMISSION_TEXTURE
-
-#ifdef EMISSION_TEXTURE_BLEND
-uniform sampler2D uTextureEmission1;
-uniform float uTextureEmissionWeight;
-#endif //EMISSION_TEXTURE_BLEND
-
-#endif //EMISSION
-
-#ifdef LIGHT_SPOT
-uniform vec3 uLightSpotDir;
-uniform float uLightSpotExp;
-uniform float uLightSpotCutoffCos;
-#endif //LIGHT_SPOT
-
-#ifdef LIGHT_ATTENUATION
-varying float vLightDist;
-#endif //LIGHT_ATTENUATION
+FRAGMENT_SHADER_USE_DIFFUSE_TERM
+FRAGMENT_SHADER_USE_SPECULAR_TERM
+FRAGMENT_SHADER_USE_AMBIENT_TERM
+FRAGMENT_SHADER_USE_EMISSION_TERM
+FRAGMENT_SHADER_USE_LIGHT
#ifndef VERTEX_TANGENT
@@ -159,19 +84,7 @@ void fragmentNormalMap()
#ifdef DIFFUSE
-#ifdef DIFFUSE_TEXTURE_BLEND
- color = texture2D(uTextureDiffuse0, vTexCoord) * uTextureDiffuseWeight +
- texture2D(uTextureDiffuse1, vTexCoord) * (1.0 - uTextureDiffuseWeight);
-#else
-
-#ifdef DIFFUSE_TEXTURE
- color = texture2D(uTextureDiffuse0, vTexCoord);
-#else
- color = uMaterialDiffuse;
-#endif //DIFFUSE_TEXTURE
-
-#endif //DIFFUSE_TEXTURE_BLEND
-
+ FRAGMENT_SHADER_TEXTURE_BLEND(DIFFUSE, Diffuse)
gl_FragColor = uLightDiffuse * color * factor;
#else
@@ -184,19 +97,7 @@ void fragmentNormalMap()
if (factor > 0.0)
{
factor = pow(factor, uMaterialShininess);
-
-#ifdef SPECULAR_TEXTURE_BLEND
- color = texture2D(uTextureSpecular0, vTexCoord) * uTextureSpecularWeight +
- texture2D(uTextureSpecular1, vTexCoord) * (1.0 - uTextureSpecularWeight);
-#else
-#ifdef SPECULAR_TEXTURE
- color = texture2D(uTextureSpecular0, vTexCoord);
-#else
- color = uMaterialSpecular;
-#endif //SPECULAR_TEXTURE
-
-#endif //SPECULAR_TEXTURE_BLEND
-
+ FRAGMENT_SHADER_TEXTURE_BLEND(SPECULAR, Specular)
gl_FragColor += uLightSpecular * color * factor;
}
@@ -211,19 +112,7 @@ void fragmentNormalMap()
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
#ifdef AMBIENT
-#ifdef AMBIENT_TEXTURE_BLEND
- color = texture2D(uTextureAmbient0, vTexCoord) * uTextureAmbientWeight +
- texture2D(uTextureAmbient1, vTexCoord) * (1.0 - uTextureAmbientWeight);
-#else
-
-#ifdef AMBIENT_TEXTURE
- color = texture2D(uTextureAmbient0, vTexCoord);
-#else
- color = uMaterialAmbient;
-#endif //AMBIENT_TEXTURE
-
-#endif //AMBIENT_TEXTURE_BLEND
-
+ FRAGMENT_SHADER_TEXTURE_BLEND(AMBIENT, Ambient)
gl_FragColor += uLightAmbient * color;
#endif //AMBIENT
@@ -233,37 +122,13 @@ void fragmentNormalMap()
#ifdef EMISSION
-#ifdef EMISSION_TEXTURE_BLEND
- color = texture2D(uTextureEmission0, vTexCoord) * uTextureEmissionWeight +
- texture2D(uTextureEmission1, vTexCoord) * (1.0 - uTextureEmissionWeight);
-#else
-
-#ifdef EMISSION_TEXTURE
- color = texture2D(uTextureEmission0, vTexCoord);
-#else
- color = uMaterialEmission;
-#endif //EMISSION_TEXTURE
-
-#endif //EMISSION_TEXTURE_BLEND
-
+ FRAGMENT_SHADER_TEXTURE_BLEND(EMISSION, Emission)
gl_FragColor += color;
+
#endif //EMISSION
}
-#ifdef SHADOWED
-float pcf(vec4 lpos, float size)
-{
- vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;
- float i, j, randx, randy, shadow;
- shadow = 0.0;
- for (i = -4.0; i < 4.0; i++)
- for (j = -4.0; j < 4.0; j++)
- shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0)*size).x);
- return shadow / 64.0;
-}
-#endif //SHADOWED
-
void main() {
#ifdef SHADOWED
@@ -272,12 +137,7 @@ void main() {
fragmentNormalMap();
-#ifdef FOG_ENABLED
- float z = gl_FragCoord.z / gl_FragCoord.w;
- float fogFactor = exp2( -uFogFactor * uFogFactor * z * z * 1.44);
- fogFactor = clamp(fogFactor, 0.0, 1.0);
- gl_FragColor = mix(uFogColor, gl_FragColor, fogFactor);
-#endif //FOG_ENABLED
+FRAGMENT_SHADER_FOG_APPLY
}
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
index 3dc42d288f..0c9e557390 100644
--- 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
@@ -10,28 +10,9 @@ varying vec3 vEyeVector;
varying vec3 vNormal;
#endif //VERTEX_TANGENT
-#ifdef SHADOWED
-uniform mat4 uMatrixLight;
-varying vec4 vLightPosition;
-#endif //SHADOWED
-
-#ifdef VERTEX_POSITION
-attribute vec4 aPosition0;
-#endif //VERTEX_POSITION
-
-#ifdef VERTEX_POSITION_BLEND
-attribute vec4 aPosition1;
-uniform float uPositionWeight;
-#endif //VERTEX_POSITION_BLEND
-
-#ifdef VERTEX_NORMAL
-attribute vec4 aNormal0;
-#endif //VERTEX_NORMAL
-
-#ifdef VERTEX_NORMAL_BLEND
-attribute vec4 aNormal1;
-uniform float uNormalWeight;
-#endif //VERTEX_NORMAL_BLEND
+VERTEX_SHADER_USE_SHADOWS
+VERTEX_SHADER_USE_POSITION
+VERTEX_SHADER_USE_NORMALS
#ifdef VERTEX_TANGENT
attribute vec4 aTangent0;
@@ -42,22 +23,9 @@ attribute vec4 aTangent1;
uniform float uTangentWeight;
#endif //VERTEX_TANGENT_BLEND
-#ifdef VERTEX_TEXCOORD
-attribute vec4 aTexCoord0;
-#endif //VERTEX_TEXCOORD
-
-#ifdef VERTEX_TEXCOORD_BLEND
-attribute vec4 aTexCoord1;
-uniform float uTexCoordWeight;
-#endif //VERTEX_TEXCOORD_BLEND
-
-#ifdef NEED_TEX_COORD
-varying vec2 vTexCoord;
-#endif //NEED_TEX_COORD
-
-#ifdef LIGHT_ATTENUATION
-varying float vLightDist;
-#endif //LIGHT_ATTENUATION
+VERTEX_SHADER_USE_TEXCOORD
+VERTEX_SHADER_NEED_TEX_COORD
+VERTEX_SHADER_USE_LIGHT_ATTENUATION
#ifndef VERTEX_TANGENT
void vertexNormalMap(vec4 position, vec3 normal)
@@ -130,28 +98,8 @@ void vertexNormalMap(vec4 position, vec3 normal, vec3 tangent)
void main()
{
-#ifdef VERTEX_POSITION_BLEND
- vec4 position = aPosition0 * uPositionWeight +
- aPosition1 * (1.0 - uPositionWeight);
- position = vec4(position.xyz, 1.0);
-#else
-
-#ifdef VERTEX_POSITION
- vec4 position = vec4(aPosition0.xyz, 1.0);
-#endif // VERTEX_POSITION
-
-#endif //VERTEX_POSITION_BLEND
-
-#ifdef VERTEX_NORMAL_BLEND
- vec3 normal = aNormal0.xyz * uNormalWeight +
- aNormal1.xyz * (1.0 - uNormalWeight);
-#else
-
-#ifdef VERTEX_NORMAL
- vec3 normal = aNormal0.xyz;
-#endif //VERTEX_NORMAL
-
-#endif //VERTEX_NORMAL_BLEND
+ VERTEX_SHADER_POSITION
+ VERTEX_SHADER_NORMAL
#ifdef VERTEX_TANGENT_BLEND
vec3 tangent = aTangent0.xyz * uTangentWeight +
@@ -164,16 +112,7 @@ void main()
#endif //VERTEX_TANGENT_BLEND
-#ifdef VERTEX_TEXCOORD_BLEND
- vTexCoord = aTexCoord0.st * uTexCoordWeight +
- aTexCoord1.st * (1.0 - uTexCoordWeight);
-#else
-
-#ifdef VERTEX_TEXCOORD
- vTexCoord = aTexCoord0.st;
-#endif //VERTEX_TEXCOORD
-
-#endif //VERTEX_TEXCOORD_BLEND
+ VERTEX_SHADER_TEXCOORD
gl_Position = uMatrixMvp * position;