From f95136f13901a43385697e477a099cc44c84fc5a Mon Sep 17 00:00:00 2001 From: Dmytro Dadyka Date: Tue, 24 Mar 2015 10:50:31 -0700 Subject: [PATCH] [Evas: Evas_3D] Refactor shader system: refactored diffuse shade mode. Reviewers: cedric, jpeg Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2229 --- .../engines/gl_common/shader_3d/diffuse_frag.shd | 52 ++++------------------ .../engines/gl_common/shader_3d/diffuse_vert.shd | 49 +++----------------- .../gl_common/shader_3d/evas_gl_3d_shaders.x | 24 +++++----- 3 files changed, 27 insertions(+), 98 deletions(-) diff --git a/src/modules/evas/engines/gl_common/shader_3d/diffuse_frag.shd b/src/modules/evas/engines/gl_common/shader_3d/diffuse_frag.shd index 7b6dc2b..b08bf40 100644 --- a/src/modules/evas/engines/gl_common/shader_3d/diffuse_frag.shd +++ b/src/modules/evas/engines/gl_common/shader_3d/diffuse_frag.shd @@ -1,47 +1,11 @@ -#ifdef NEED_TEX_COORD -varying vec2 vTexCoord; -#endif //TEX_COORD - -#ifdef FOG_ENABLED -uniform float uFogFactor; -uniform vec4 uFogColor; -#endif //FOG_ENABLED - -#ifdef DIFFUSE -uniform vec4 uMaterialDiffuse; - -#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 +FRAGMENT_SHADER_USE_TEX_COORD +FRAGMENT_SHADER_USE_FOG +FRAGMENT_SHADER_USE_DIFFUSE_TERM void main() { - -#ifdef DIFFUSE_TEXTURE_BLEND - gl_FragColor = (texture2D(uTextureDiffuse0, vTexCoord) * - uTextureDiffuseWeight + texture2D(uTextureDiffuse1, vTexCoord) * - (1.0 - uTextureDiffuseWeight)) * uMaterialDiffuse; -#else - -#ifdef DIFFUSE_TEXTURE - gl_FragColor = texture2D(uTextureDiffuse0, vTexCoord) * uMaterialDiffuse; -#else - gl_FragColor = uMaterialDiffuse; -#endif //DIFFUSE_TEXTURE - -#endif //DIFFUSE_TEXTURE_BLEND - -#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 - + vec4 color; + FRAGMENT_SHADER_TEXTURE_BLEND(DIFFUSE, Diffuse) + gl_FragColor = color; + FRAGMENT_SHADER_FOG_APPLY } + diff --git a/src/modules/evas/engines/gl_common/shader_3d/diffuse_vert.shd b/src/modules/evas/engines/gl_common/shader_3d/diffuse_vert.shd index 2b62b82..1a68155 100644 --- a/src/modules/evas/engines/gl_common/shader_3d/diffuse_vert.shd +++ b/src/modules/evas/engines/gl_common/shader_3d/diffuse_vert.shd @@ -1,52 +1,13 @@ uniform mat4 uMatrixMvp; -#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_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 +VERTEX_SHADER_USE_POSITION +VERTEX_SHADER_USE_TEXCOORD +VERTEX_SHADER_NEED_TEX_COORD 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_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_POSITION + VERTEX_SHADER_TEXCOORD gl_Position = uMatrixMvp * position; } 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 b8a5edb..40c7749 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 @@ -94,7 +94,7 @@ static const char const diffuse_vert_glsl[] = "#endif //NEED_TEX_COORD\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" @@ -103,7 +103,7 @@ static const char const diffuse_vert_glsl[] = " vec4 position = vec4(aPosition0.xyz, 1.0);\n" "#endif // VERTEX_POSITION\n" "#endif //VERTEX_POSITION_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" @@ -129,6 +129,7 @@ static const char const diffuse_frag_glsl[] = "#endif //FOG_ENABLED\n" "#ifdef DIFFUSE\n" "uniform vec4 uMaterialDiffuse;\n" + "uniform vec4 uLightDiffuse;\n" "#ifdef DIFFUSE_TEXTURE\n" "uniform sampler2D uTextureDiffuse0;\n" "#endif //DIFFUSE_TEXTURE\n" @@ -138,20 +139,23 @@ static const char const diffuse_frag_glsl[] = "#endif //DIFFUSE_TEXTURE_BLEND\n" "#endif //DIFFUSE\n" "void main() {\n" - "#ifdef DIFFUSE_TEXTURE_BLEND\n" - " gl_FragColor = (texture2D(uTextureDiffuse0, vTexCoord) *\n" - " uTextureDiffuseWeight + texture2D(uTextureDiffuse1, vTexCoord) *\n" - " (1.0 - uTextureDiffuseWeight)) * uMaterialDiffuse;\n" + " vec4 color;\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" - " gl_FragColor = texture2D(uTextureDiffuse0, vTexCoord) * uMaterialDiffuse;\n" + "#ifdef DIFFUSE_TEXTURE\n" + " color = texture2D(uTextureDiffuse0, vTexCoord);\n" "#else\n" - " gl_FragColor = uMaterialDiffuse;\n" + " color = uMaterialDiffuse;\n" "#endif //DIFFUSE_TEXTURE\n" "#endif //DIFFUSE_TEXTURE_BLEND\n" + " gl_FragColor = color;\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" -- 2.7.4