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)
[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[] =
1328 "}\n" 1328 "}\n"
1329 "void main()\n" 1329 "void main()\n"
1330 "{\n" 1330 "{\n"
1331 "#ifdef VERTEX_POSITION_BLEND\n" 1331 " #ifdef VERTEX_POSITION_BLEND\n"
1332 " vec4 position = aPosition0 * uPositionWeight +\n" 1332 " vec4 position = aPosition0 * uPositionWeight +\n"
1333 " aPosition1 * (1.0 - uPositionWeight);\n" 1333 " aPosition1 * (1.0 - uPositionWeight);\n"
1334 " position = vec4(position.xyz, 1.0);\n" 1334 " position = vec4(position.xyz, 1.0);\n"
@@ -1337,7 +1337,7 @@ static const char const parallax_occlusion_vert_glsl[] =
1337 " vec4 position = vec4(aPosition0.xyz, 1.0);\n" 1337 " vec4 position = vec4(aPosition0.xyz, 1.0);\n"
1338 "#endif // VERTEX_POSITION\n" 1338 "#endif // VERTEX_POSITION\n"
1339 "#endif //VERTEX_POSITION_BLEND\n" 1339 "#endif //VERTEX_POSITION_BLEND\n"
1340 "#ifdef VERTEX_NORMAL_BLEND\n" 1340 " #ifdef VERTEX_NORMAL_BLEND\n"
1341 " vec3 normal = aNormal0.xyz * uNormalWeight +\n" 1341 " vec3 normal = aNormal0.xyz * uNormalWeight +\n"
1342 " aNormal1.xyz * (1.0 - uNormalWeight);\n" 1342 " aNormal1.xyz * (1.0 - uNormalWeight);\n"
1343 "#else\n" 1343 "#else\n"
@@ -1353,7 +1353,7 @@ static const char const parallax_occlusion_vert_glsl[] =
1353 " vec3 tangent = aTangent0.xyz;\n" 1353 " vec3 tangent = aTangent0.xyz;\n"
1354 "#endif //VERTEX_TANGENT\n" 1354 "#endif //VERTEX_TANGENT\n"
1355 "#endif //VERTEX_TANGENT_BLEND\n" 1355 "#endif //VERTEX_TANGENT_BLEND\n"
1356 "#ifdef VERTEX_TEXCOORD_BLEND\n" 1356 " #ifdef VERTEX_TEXCOORD_BLEND\n"
1357 " vTexCoord = aTexCoord0.st * uTexCoordWeight +\n" 1357 " vTexCoord = aTexCoord0.st * uTexCoordWeight +\n"
1358 " aTexCoord1.st * (1.0 - uTexCoordWeight);\n" 1358 " aTexCoord1.st * (1.0 - uTexCoordWeight);\n"
1359 "#else\n" 1359 "#else\n"
@@ -1363,7 +1363,7 @@ static const char const parallax_occlusion_vert_glsl[] =
1363 "#endif //VERTEX_TEXCOORD_BLEND\n" 1363 "#endif //VERTEX_TEXCOORD_BLEND\n"
1364 " gl_Position = uMatrixMvp * position;\n" 1364 " gl_Position = uMatrixMvp * position;\n"
1365 " vertexParallaxOcclusion(position, normal, tangent);\n" 1365 " vertexParallaxOcclusion(position, normal, tangent);\n"
1366 "#ifdef SHADOWED\n" 1366 " #ifdef SHADOWED\n"
1367 " vLightPosition = uMatrixLight * position;\n" 1367 " vLightPosition = uMatrixLight * position;\n"
1368 "#endif //SHADOWED\n" 1368 "#endif //SHADOWED\n"
1369 "}\n"; 1369 "}\n";
@@ -1389,6 +1389,16 @@ static const char const parallax_occlusion_frag_glsl[] =
1389 "varying vec4 vLightPosition;\n" 1389 "varying vec4 vLightPosition;\n"
1390 "uniform sampler2D uShadowMap;\n" 1390 "uniform sampler2D uShadowMap;\n"
1391 "float shadow;\n" 1391 "float shadow;\n"
1392 "float pcf(vec4 lpos, float size)\n"
1393 " {\n"
1394 " vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;\n"
1395 " float i, j, randx, randy, shadow;\n"
1396 " shadow = 0.0;\n"
1397 " for (i = -4.0; i < 4.0; i++)\n"
1398 " for (j = -4.0; j < 4.0; j++)\n"
1399 " shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy + vec2(i / 8.0, j / 8.0)*size).x);\n"
1400 " return shadow / 64.0;\n"
1401 "}\n"
1392 "#endif //SHADOWED\n" 1402 "#endif //SHADOWED\n"
1393 "#ifdef NORMAL_TEXTURE_BLEND\n" 1403 "#ifdef NORMAL_TEXTURE_BLEND\n"
1394 "uniform sampler2D uTextureNormal1;\n" 1404 "uniform sampler2D uTextureNormal1;\n"
@@ -1449,9 +1459,7 @@ static const char const parallax_occlusion_frag_glsl[] =
1449 "const float parallaxScale = 0.2;\n" 1459 "const float parallaxScale = 0.2;\n"
1450 "vec2 parallaxMapping(in vec3 view, in vec2 tex, out float parallaxHeight)\n" 1460 "vec2 parallaxMapping(in vec3 view, in vec2 tex, out float parallaxHeight)\n"
1451 "{\n" 1461 "{\n"
1452 " const float minLayers = 10.0;\n" 1462 " const float numLayers = 15.0;\n"
1453 " const float maxLayers = 30.0;\n"
1454 " float numLayers = mix(maxLayers, minLayers, abs(dot(vec3(0, 0, 1), view)));\n"
1455 " vec2 texStep = parallaxScale * view.xy / view.z / numLayers;\n" 1463 " vec2 texStep = parallaxScale * view.xy / view.z / numLayers;\n"
1456 " float layerHeight = 1.0 / numLayers;\n" 1464 " float layerHeight = 1.0 / numLayers;\n"
1457 " float curLayerHeight = 0.0;\n" 1465 " float curLayerHeight = 0.0;\n"
@@ -1588,26 +1596,15 @@ static const char const parallax_occlusion_frag_glsl[] =
1588 " gl_FragColor += color;\n" 1596 " gl_FragColor += color;\n"
1589 "#endif //EMISSION\n" 1597 "#endif //EMISSION\n"
1590 "}\n" 1598 "}\n"
1591 "#ifdef SHADOWED\n"
1592 "float pcf(vec4 lpos, float size)\n"
1593 "{\n"
1594 " vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;\n"
1595 " float i, j, randx, randy, shadow;\n"
1596 " shadow = 0.0;\n"
1597 " for (i = -4.0; i < 4.0; i++)\n"
1598 " for (j = -4.0; j < 4.0; j++)\n"
1599 " shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy +vec2(i / 8.0, j / 8.0)*size).x);\n"
1600 " return shadow / 64.0;\n"
1601 "}\n"
1602 "#endif //SHADOWED\n"
1603 "void main() {\n" 1599 "void main() {\n"
1604 "#ifdef SHADOWED\n" 1600 "#ifdef SHADOWED\n"
1605 " shadow = pcf(vLightPosition, 1.0 / 200.0);\n" 1601 " shadow = pcf(vLightPosition, 1.0 / 200.0);\n"
1606 "#endif //SHADOWED\n" 1602 "#endif //SHADOWED\n"
1607 " fragmentParallaxMap();\n" 1603 " fragmentParallaxMap();\n"
1604 " \n"
1608 "#ifdef FOG_ENABLED\n" 1605 "#ifdef FOG_ENABLED\n"
1609 " float z = gl_FragCoord.z / gl_FragCoord.w;\n" 1606 " float z = gl_FragCoord.z / gl_FragCoord.w;\n"
1610 " float fogFactor = exp2( -uFogFactor * uFogFactor * z * z * 1.44);\n" 1607 " float fogFactor = exp2(-uFogFactor * uFogFactor * z * z * 1.44);\n"
1611 " fogFactor = clamp(fogFactor, 0.0, 1.0);\n" 1608 " fogFactor = clamp(fogFactor, 0.0, 1.0);\n"
1612 " gl_FragColor = mix(uFogColor, gl_FragColor, fogFactor);\n" 1609 " gl_FragColor = mix(uFogColor, gl_FragColor, fogFactor);\n"
1613 "#endif //FOG_ENABLED\n" 1610 "#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;
7varying vec2 vTexCoord; 7varying vec2 vTexCoord;
8#endif //TEX_COORD 8#endif //TEX_COORD
9 9
10#ifdef FOG_ENABLED 10FRAGMENT_SHADER_USE_FOG
11uniform float uFogFactor; 11FRAGMENT_SHADER_USE_SHADOWS
12uniform vec4 uFogColor;
13#endif //FOG_ENABLED
14
15#ifdef SHADOWED
16varying vec4 vLightPosition;
17uniform sampler2D uShadowMap;
18float shadow;
19#endif //SHADOWED
20 12
21#ifdef NORMAL_TEXTURE_BLEND 13#ifdef NORMAL_TEXTURE_BLEND
22uniform sampler2D uTextureNormal1; 14uniform sampler2D uTextureNormal1;
23uniform float uTextureNormalWeight; 15uniform float uTextureNormalWeight;
24#endif //NORMAL_TEXTURE_BLEND 16#endif //NORMAL_TEXTURE_BLEND
25 17
26#ifdef DIFFUSE 18FRAGMENT_SHADER_USE_DIFFUSE_TERM
27uniform vec4 uMaterialDiffuse; 19FRAGMENT_SHADER_USE_SPECULAR_TERM
28uniform vec4 uLightDiffuse; 20FRAGMENT_SHADER_USE_AMBIENT_TERM
29 21FRAGMENT_SHADER_USE_EMISSION_TERM
30#ifdef DIFFUSE_TEXTURE 22FRAGMENT_SHADER_USE_LIGHT
31uniform sampler2D uTextureDiffuse0;
32#endif //DIFFUSE_TEXTURE
33
34#ifdef DIFFUSE_TEXTURE_BLEND
35uniform sampler2D uTextureDiffuse1;
36uniform float uTextureDiffuseWeight;
37#endif //DIFFUSE_TEXTURE_BLEND
38
39#endif //DIFFUSE
40
41#ifdef SPECULAR
42uniform vec4 uLightSpecular;
43uniform float uMaterialShininess;
44uniform vec4 uMaterialSpecular;
45
46#ifdef SPECULAR_TEXTURE
47uniform sampler2D uTextureSpecular0;
48#endif //SPECULAR_TEXTURE
49
50#ifdef SPECULAR_TEXTURE_BLEND
51uniform sampler2D uTextureSpecular1;
52uniform float uTextureSpecularWeight;
53#endif //SPECULAR_TEXTURE_BLEND
54
55#endif //SPECULAR
56
57#ifdef AMBIENT
58uniform vec4 uMaterialAmbient;
59uniform vec4 uLightAmbient;
60
61#ifdef AMBIENT_TEXTURE
62uniform sampler2D uTextureAmbient0;
63#endif //AMBIENT_TEXTURE
64
65#ifdef AMBIENT_TEXTURE_BLEND
66uniform sampler2D uTextureAmbient1;
67uniform float uTextureAmbientWeight;
68#endif //AMBIENT_TEXTURE_BLEND
69
70#endif //AMBIENT
71
72#ifdef EMISSION
73uniform vec4 uMaterialEmission;
74
75#ifdef EMISSION_TEXTURE
76uniform sampler2D uTextureEmission0;
77#endif //EMISSION_TEXTURE
78
79#ifdef EMISSION_TEXTURE_BLEND
80uniform sampler2D uTextureEmission1;
81uniform float uTextureEmissionWeight;
82#endif //EMISSION_TEXTURE_BLEND
83
84#endif //EMISSION
85
86#ifdef LIGHT_SPOT
87uniform vec3 uLightSpotDir;
88uniform float uLightSpotExp;
89uniform float uLightSpotCutoffCos;
90#endif //LIGHT_SPOT
91
92#ifdef LIGHT_ATTENUATION
93varying float vLightDist;
94#endif //LIGHT_ATTENUATION
95 23
96const float parallaxScale = 0.2; 24const float parallaxScale = 0.2;
97 25
98vec2 parallaxMapping(in vec3 view, in vec2 tex, out float parallaxHeight) 26vec2 parallaxMapping(in vec3 view, in vec2 tex, out float parallaxHeight)
99{ 27{
100 const float minLayers = 10.0; 28 const float numLayers = 15.0;
101 const float maxLayers = 30.0;
102 float numLayers = mix(maxLayers, minLayers, abs(dot(vec3(0, 0, 1), view)));
103 vec2 texStep = parallaxScale * view.xy / view.z / numLayers; 29 vec2 texStep = parallaxScale * view.xy / view.z / numLayers;
104 30
105 float layerHeight = 1.0 / numLayers; 31 float layerHeight = 1.0 / numLayers;
@@ -281,19 +207,6 @@ void fragmentParallaxMap()
281 207
282} 208}
283 209
284#ifdef SHADOWED
285float pcf(vec4 lpos, float size)
286{
287 vec3 smcoord = lpos.xyz / lpos.w * 0.5 + 0.5;
288 float i, j, randx, randy, shadow;
289 shadow = 0.0;
290 for (i = -4.0; i < 4.0; i++)
291 for (j = -4.0; j < 4.0; j++)
292 shadow += float(smcoord.z <= texture2D(uShadowMap, smcoord.xy +vec2(i / 8.0, j / 8.0)*size).x);
293 return shadow / 64.0;
294}
295#endif //SHADOWED
296
297void main() { 210void main() {
298 211
299#ifdef SHADOWED 212#ifdef SHADOWED
@@ -302,12 +215,7 @@ void main() {
302 215
303 fragmentParallaxMap(); 216 fragmentParallaxMap();
304 217
305#ifdef FOG_ENABLED 218 FRAGMENT_SHADER_FOG_APPLY
306 float z = gl_FragCoord.z / gl_FragCoord.w;
307 float fogFactor = exp2( -uFogFactor * uFogFactor * z * z * 1.44);
308 fogFactor = clamp(fogFactor, 0.0, 1.0);
309 gl_FragColor = mix(uFogColor, gl_FragColor, fogFactor);
310#endif //FOG_ENABLED
311 219
312} 220}
313 221
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;
6varying vec3 vLightHalfVector; 6varying vec3 vLightHalfVector;
7varying vec3 vEyeVector; 7varying vec3 vEyeVector;
8 8
9#ifdef SHADOWED 9VERTEX_SHADER_USE_SHADOWS
10uniform mat4 uMatrixLight; 10VERTEX_SHADER_USE_POSITION
11varying vec4 vLightPosition; 11VERTEX_SHADER_USE_NORMALS
12#endif //SHADOWED
13
14#ifdef VERTEX_POSITION
15attribute vec4 aPosition0;
16#endif //VERTEX_POSITION
17
18#ifdef VERTEX_POSITION_BLEND
19attribute vec4 aPosition1;
20uniform float uPositionWeight;
21#endif //VERTEX_POSITION_BLEND
22
23#ifdef VERTEX_NORMAL
24attribute vec4 aNormal0;
25#endif //VERTEX_NORMAL
26
27#ifdef VERTEX_NORMAL_BLEND
28attribute vec4 aNormal1;
29uniform float uNormalWeight;
30#endif //VERTEX_NORMAL_BLEND
31 12
32#ifdef VERTEX_TANGENT 13#ifdef VERTEX_TANGENT
33attribute vec4 aTangent0; 14attribute vec4 aTangent0;
@@ -38,22 +19,9 @@ attribute vec4 aTangent1;
38uniform float uTangentWeight; 19uniform float uTangentWeight;
39#endif //VERTEX_TANGENT_BLEND 20#endif //VERTEX_TANGENT_BLEND
40 21
41#ifdef VERTEX_TEXCOORD 22VERTEX_SHADER_USE_TEXCOORD
42attribute vec4 aTexCoord0; 23VERTEX_SHADER_NEED_TEX_COORD
43#endif //VERTEX_TEXCOORD 24VERTEX_SHADER_USE_LIGHT_ATTENUATION
44
45#ifdef VERTEX_TEXCOORD_BLEND
46attribute vec4 aTexCoord1;
47uniform float uTexCoordWeight;
48#endif //VERTEX_TEXCOORD_BLEND
49
50#ifdef NEED_TEX_COORD
51varying vec2 vTexCoord;
52#endif //NEED_TEX_COORD
53
54#ifdef LIGHT_ATTENUATION
55varying float vLightDist;
56#endif //LIGHT_ATTENUATION
57 25
58void vertexParallaxOcclusion(vec4 position, vec3 normal, vec3 tangent) 26void vertexParallaxOcclusion(vec4 position, vec3 normal, vec3 tangent)
59{ 27{
@@ -96,28 +64,8 @@ void vertexParallaxOcclusion(vec4 position, vec3 normal, vec3 tangent)
96void main() 64void main()
97{ 65{
98 66
99#ifdef VERTEX_POSITION_BLEND 67 VERTEX_SHADER_POSITION
100 vec4 position = aPosition0 * uPositionWeight + 68 VERTEX_SHADER_NORMAL
101 aPosition1 * (1.0 - uPositionWeight);
102 position = vec4(position.xyz, 1.0);
103#else
104
105#ifdef VERTEX_POSITION
106 vec4 position = vec4(aPosition0.xyz, 1.0);
107#endif // VERTEX_POSITION
108
109#endif //VERTEX_POSITION_BLEND
110
111#ifdef VERTEX_NORMAL_BLEND
112 vec3 normal = aNormal0.xyz * uNormalWeight +
113 aNormal1.xyz * (1.0 - uNormalWeight);
114#else
115
116#ifdef VERTEX_NORMAL
117 vec3 normal = aNormal0.xyz;
118#endif //VERTEX_NORMAL
119
120#endif //VERTEX_NORMAL_BLEND
121 69
122#ifdef VERTEX_TANGENT_BLEND 70#ifdef VERTEX_TANGENT_BLEND
123 vec3 tangent = aTangent0.xyz * uTangentWeight + 71 vec3 tangent = aTangent0.xyz * uTangentWeight +
@@ -130,22 +78,11 @@ void main()
130 78
131#endif //VERTEX_TANGENT_BLEND 79#endif //VERTEX_TANGENT_BLEND
132 80
133#ifdef VERTEX_TEXCOORD_BLEND 81 VERTEX_SHADER_TEXCOORD
134 vTexCoord = aTexCoord0.st * uTexCoordWeight +
135 aTexCoord1.st * (1.0 - uTexCoordWeight);
136#else
137
138#ifdef VERTEX_TEXCOORD
139 vTexCoord = aTexCoord0.st;
140#endif //VERTEX_TEXCOORD
141
142#endif //VERTEX_TEXCOORD_BLEND
143 82
144 gl_Position = uMatrixMvp * position; 83 gl_Position = uMatrixMvp * position;
145 84
146 vertexParallaxOcclusion(position, normal, tangent); 85 vertexParallaxOcclusion(position, normal, tangent);
147 86
148#ifdef SHADOWED 87 VERTEX_SHADER_SHADOWED
149 vLightPosition = uMatrixLight * position;
150#endif //SHADOWED
151} 88}