summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmytro Dadyka <d.dadyka@samsung.com>2015-03-25 10:35:42 -0700
committerJean-Philippe ANDRE <jpeg@videolan.org>2015-03-25 10:35:43 -0700
commita4d1cfa6098e648592a86bc11da21381dbc9a9f9 (patch)
treed5540a1970243060788a53901c78e03b49b0ae32
parent7ba3a2bd7c54703f656e2b311ad7c2f74800291e (diff)
downloadefl-a4d1cfa6098e648592a86bc11da21381dbc9a9f9.tar.gz
[Evas: Evas_3D] Refactor shader system: refactored parallax shade mode.
Reviewers: cedric, jpeg Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2241
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/evas_gl_3d_shaders.x37
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/parallax_occlusion_frag.shd110
-rw-r--r--src/modules/evas/engines/gl_common/shader_3d/parallax_occlusion_vert.shd83
3 files changed, 36 insertions, 194 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 26501a6c28..d96ce653ef 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
@@ -1328,7 +1328,7 @@ static const char const parallax_occlusion_vert_glsl[] =
"}\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"
@@ -1337,7 +1337,7 @@ static const char const parallax_occlusion_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"
@@ -1353,7 +1353,7 @@ static const char const parallax_occlusion_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"
@@ -1363,7 +1363,7 @@ static const char const parallax_occlusion_vert_glsl[] =
"#endif //VERTEX_TEXCOORD_BLEND\n"
" gl_Position = uMatrixMvp * position;\n"
" vertexParallaxOcclusion(position, normal, tangent);\n"
- "#ifdef SHADOWED\n"
+ " #ifdef SHADOWED\n"
" vLightPosition = uMatrixLight * position;\n"
"#endif //SHADOWED\n"
"}\n";
@@ -1389,6 +1389,16 @@ static const char const parallax_occlusion_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"
@@ -1449,9 +1459,7 @@ static const char const parallax_occlusion_frag_glsl[] =
"const float parallaxScale = 0.2;\n"
"vec2 parallaxMapping(in vec3 view, in vec2 tex, out float parallaxHeight)\n"
"{\n"
- " const float minLayers = 10.0;\n"
- " const float maxLayers = 30.0;\n"
- " float numLayers = mix(maxLayers, minLayers, abs(dot(vec3(0, 0, 1), view)));\n"
+ " const float numLayers = 15.0;\n"
" vec2 texStep = parallaxScale * view.xy / view.z / numLayers;\n"
" float layerHeight = 1.0 / numLayers;\n"
" float curLayerHeight = 0.0;\n"
@@ -1588,26 +1596,15 @@ static const char const parallax_occlusion_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"
"#endif //SHADOWED\n"
" fragmentParallaxMap();\n"
+ " \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/parallax_occlusion_frag.shd b/src/modules/evas/engines/gl_common/shader_3d/parallax_occlusion_frag.shd
index 33568298f7..598343d43e 100644
--- a/src/modules/evas/engines/gl_common/shader_3d/parallax_occlusion_frag.shd
+++ b/src/modules/evas/engines/gl_common/shader_3d/parallax_occlusion_frag.shd
@@ -7,99 +7,25 @@ varying vec3 vEyeVector;
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_FOG
+FRAGMENT_SHADER_USE_SHADOWS
#ifdef NORMAL_TEXTURE_BLEND
uniform sampler2D uTextureNormal1;
uniform float uTextureNormalWeight;
#endif //NORMAL_TEXTURE_BLEND
-#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
const float parallaxScale = 0.2;
vec2 parallaxMapping(in vec3 view, in vec2 tex, out float parallaxHeight)
{
- const float minLayers = 10.0;
- const float maxLayers = 30.0;
- float numLayers = mix(maxLayers, minLayers, abs(dot(vec3(0, 0, 1), view)));
+ const float numLayers = 15.0;
vec2 texStep = parallaxScale * view.xy / view.z / numLayers;
float layerHeight = 1.0 / numLayers;
@@ -281,19 +207,6 @@ void fragmentParallaxMap()
}
-#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
@@ -302,12 +215,7 @@ void main() {
fragmentParallaxMap();
-#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/parallax_occlusion_vert.shd b/src/modules/evas/engines/gl_common/shader_3d/parallax_occlusion_vert.shd
index aec49a210d..dff4ff75d4 100644
--- a/src/modules/evas/engines/gl_common/shader_3d/parallax_occlusion_vert.shd
+++ b/src/modules/evas/engines/gl_common/shader_3d/parallax_occlusion_vert.shd
@@ -6,28 +6,9 @@ varying vec3 vLightVector;
varying vec3 vLightHalfVector;
varying vec3 vEyeVector;
-#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;
@@ -38,22 +19,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
void vertexParallaxOcclusion(vec4 position, vec3 normal, vec3 tangent)
{
@@ -96,28 +64,8 @@ void vertexParallaxOcclusion(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 +
@@ -130,22 +78,11 @@ 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;
vertexParallaxOcclusion(position, normal, tangent);
-#ifdef SHADOWED
- vLightPosition = uMatrixLight * position;
-#endif //SHADOWED
+ VERTEX_SHADER_SHADOWED
}