X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Fdevel-api%2Fshader-effects%2Fdistance-field-effect.h;h=b963693841e96798241adf0328a948d976582824;hb=5178b0e51437699c0e2196c88712a79032a2732b;hp=d495030711550dd7acc7e572f5a5f3dc2890b8ee;hpb=a073ebfd862b49692c8e6d7dff2b128e62a4f6df;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/devel-api/shader-effects/distance-field-effect.h b/dali-toolkit/devel-api/shader-effects/distance-field-effect.h index d495030..b963693 100644 --- a/dali-toolkit/devel-api/shader-effects/distance-field-effect.h +++ b/dali-toolkit/devel-api/shader-effects/distance-field-effect.h @@ -1,8 +1,8 @@ -#ifndef __DALI_TOOLKIT_SHADER_EFFECT_DISTANCEFIELD_H__ -#define __DALI_TOOLKIT_SHADER_EFFECT_DISTANCEFIELD_H__ +#ifndef DALI_TOOLKIT_SHADER_EFFECT_DISTANCEFIELD_H +#define DALI_TOOLKIT_SHADER_EFFECT_DISTANCEFIELD_H /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,15 +19,16 @@ */ // EXTERNAL INCLUDES +#include #include -#include + +// INTERNAL INCLUDES +#include namespace Dali { - namespace Toolkit { - /** * Creates a new DistanceFieldEffect * @@ -53,128 +54,126 @@ namespace Toolkit */ inline Dali::Property::Map CreateDistanceFieldEffect() { - const char* fragmentShaderPrefix( "#extension GL_OES_standard_derivatives : enable\n" ); - - const char* fragmentShader( DALI_COMPOSE_SHADER( - varying mediump vec2 vTexCoord;\n - \n - uniform mediump float uGlowBoundary;\n - uniform mediump vec2 uOutlineParams;\n - uniform lowp vec4 uOutlineColor;\n - uniform lowp vec4 uShadowColor;\n - uniform mediump vec2 uShadowOffset;\n - uniform lowp vec4 uGlowColor;\n - uniform lowp float uDoOutline;\n - uniform lowp float uDoShadow;\n - uniform lowp float uDoGlow;\n - \n - uniform sampler2D sTexture;\n - uniform lowp vec4 uColor;\n - \n - void main()\n - {\n - // sample distance field\n - mediump float smoothing = 0.5;\n - - mediump float distance = texture2D(sTexture, vTexCoord).a;\n - mediump float smoothWidth = fwidth(distance);\n - mediump float alphaFactor = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, distance);\n - lowp vec4 color;\n - if (uDoShadow == 0.0)\n - {\n - mediump float alpha = uColor.a * alphaFactor;\n - lowp vec4 rgb = uColor;\n - \n - if (uDoOutline > 0.0)\n - {\n - mediump float outlineWidth = uOutlineParams[1] + smoothWidth;\n - mediump float outlineBlend = smoothstep(uOutlineParams[0] - outlineWidth, uOutlineParams[0] + outlineWidth, distance);\n - alpha = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, distance);\n - rgb = mix(uOutlineColor, uColor, outlineBlend);\n - }\n - \n - if (uDoGlow > 0.0)\n - {\n - rgb = mix(uGlowColor, rgb, alphaFactor);\n - alpha = smoothstep(uGlowBoundary, smoothing, distance);\n - }\n - \n - // set fragment color\n - color = vec4(rgb.rgb, alpha);\n - }\n - \n - else // (uDoShadow > 0.0)\n - {\n - mediump float shadowDistance = texture2D(sTexture, vTexCoord - uShadowOffset).a;\n - mediump float inText = alphaFactor;\n - mediump float inShadow = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, shadowDistance);\n - \n - // inside object, outside shadow\n - if (inText == 1.0)\n - {\n - color = uColor;\n - }\n - // inside object, outside shadow\n - else if ((inText != 0.0) && (inShadow == 0.0))\n - {\n - color = uColor;\n - color.a *= inText;\n - }\n - // outside object, completely inside shadow\n - else if ((inText == 0.0) && (inShadow == 1.0))\n - {\n - color = uShadowColor;\n - }\n - // inside object, completely inside shadow\n - else if ((inText != 0.0) && (inShadow == 1.0))\n - {\n - color = mix(uShadowColor, uColor, inText);\n - color.a = uShadowColor.a;\n - }\n - // inside object, inside shadow's border\n - else if ((inText != 0.0) && (inShadow != 0.0))\n - {\n - color = mix(uShadowColor, uColor, inText);\n - color.a *= max(inText, inShadow);\n - }\n - // inside shadow's border\n - else if (inShadow != 0.0)\n - {\n - color = uShadowColor;\n - color.a *= inShadow;\n - }\n - // outside shadow and object\n - else \n - {\n - color.a = 0.0;\n - }\n - \n - }\n - \n - gl_FragColor = color;\n - \n - } ) - ); + const char* fragmentShaderPrefix("#extension GL_OES_standard_derivatives : enable\n"); + + const char* fragmentShader( + "varying mediump vec2 vTexCoord;\n" + "\n" + "uniform mediump float uGlowBoundary;\n" + "uniform mediump vec2 uOutlineParams;\n" + "uniform lowp vec4 uOutlineColor;\n" + "uniform lowp vec4 uShadowColor;\n" + "uniform mediump vec2 uShadowOffset;\n" + "uniform lowp vec4 uGlowColor;\n" + "uniform lowp float uDoOutline;\n" + "uniform lowp float uDoShadow;\n" + "uniform lowp float uDoGlow;\n" + "\n" + "uniform sampler2D sTexture;\n" + "uniform lowp vec4 uColor;\n" + "\n" + "void main()\n" + "{\n" + " // sample distance field\n" + " mediump float smoothing = 0.5;\n" + " \n" + " mediump float distance = texture2D(sTexture, vTexCoord).a;\n" + " mediump float smoothWidth = fwidth(distance);\n" + " mediump float alphaFactor = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, distance);\n" + " lowp vec4 color;\n" + " if (uDoShadow == 0.0)\n" + " {\n" + " mediump float alpha = uColor.a * alphaFactor;\n" + " lowp vec4 rgb = uColor;\n" + "\n" + " if (uDoOutline > 0.0)\n" + " {\n" + " mediump float outlineWidth = uOutlineParams[1] + smoothWidth;\n" + " mediump float outlineBlend = smoothstep(uOutlineParams[0] - outlineWidth, uOutlineParams[0] + outlineWidth, distance);\n" + " alpha = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, distance);\n" + " rgb = mix(uOutlineColor, uColor, outlineBlend);\n" + " }\n" + "\n" + " if (uDoGlow > 0.0)\n" + " {\n" + " rgb = mix(uGlowColor, rgb, alphaFactor);\n" + " alpha = smoothstep(uGlowBoundary, smoothing, distance);\n" + " }\n" + "\n" + " // set fragment color\n" + " color = vec4(rgb.rgb, alpha);\n" + " }\n" + "\n" + " else // (uDoShadow > 0.0)\n" + " {\n" + " mediump float shadowDistance = texture2D(sTexture, vTexCoord - uShadowOffset).a;\n" + " mediump float inText = alphaFactor;\n" + " mediump float inShadow = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, shadowDistance);\n" + "\n" + " // inside object, outside shadow\n" + " if (inText == 1.0)\n" + " {\n" + " color = uColor;\n" + " }\n" + " // inside object, outside shadow\n" + " else if ((inText != 0.0) && (inShadow == 0.0))\n" + " {\n" + " color = uColor;\n" + " color.a *= inText;\n" + " }\n" + " // outside object, completely inside shadow\n" + " else if ((inText == 0.0) && (inShadow == 1.0))\n" + " {\n" + " color = uShadowColor;\n" + " }\n" + " // inside object, completely inside shadow\n" + " else if ((inText != 0.0) && (inShadow == 1.0))\n" + " {\n" + " color = mix(uShadowColor, uColor, inText);\n" + " color.a = uShadowColor.a;\n" + " }\n" + " // inside object, inside shadow's border\n" + " else if ((inText != 0.0) && (inShadow != 0.0))\n" + " {\n" + " color = mix(uShadowColor, uColor, inText);\n" + " color.a *= max(inText, inShadow);\n" + " }\n" + " // inside shadow's border\n" + " else if (inShadow != 0.0)\n" + " {\n" + " color = uShadowColor;\n" + " color.a *= inShadow;\n" + " }\n" + " // outside shadow and object\n" + " else \n" + " {\n" + " color.a = 0.0;\n" + " }\n" + "\n" + " }\n" + "\n" + " gl_FragColor = color;\n" + "\n" + "}\n"); Property::Map map; Property::Map customShader; std::string fragmentShaderString; - fragmentShaderString.reserve( strlen( fragmentShaderPrefix ) + strlen( fragmentShader ) ); - fragmentShaderString.append( fragmentShaderPrefix ); - fragmentShaderString.append( fragmentShader ); + fragmentShaderString.reserve(strlen(fragmentShaderPrefix) + strlen(fragmentShader)); + fragmentShaderString.append(fragmentShaderPrefix); + fragmentShaderString.append(fragmentShader); - customShader[ "fragmentShader" ] = fragmentShaderString; - customShader[ "hints" ] = "outputIsTransparent"; + customShader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShaderString; + customShader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT; - map[ "shader" ] = customShader; + map[Toolkit::Visual::Property::SHADER] = customShader; return map; } - } // namespace Toolkit } // namespace Dali -#endif // __DALI_TOOLKIT_SHADER_EFFECT_SPOT_H__ +#endif // DALI_TOOLKIT_SHADER_EFFECT_DISTANCEFIELD_H