Convert shaders in devel-api header files to use shader compilation tool 22/251622/1
authorRichard Huang <r.huang@samsung.com>
Fri, 15 Jan 2021 16:35:44 +0000 (16:35 +0000)
committerRichard Huang <r.huang@samsung.com>
Fri, 15 Jan 2021 16:35:44 +0000 (16:35 +0000)
Change-Id: Id63f2e1835b9dbab93a2d2b885bb3bf6156032a5

13 files changed:
dali-toolkit/devel-api/file.list
dali-toolkit/devel-api/shader-effects/alpha-discard-effect.cpp [new file with mode: 0644]
dali-toolkit/devel-api/shader-effects/alpha-discard-effect.h
dali-toolkit/devel-api/shader-effects/dissolve-effect.cpp [new file with mode: 0644]
dali-toolkit/devel-api/shader-effects/dissolve-effect.h
dali-toolkit/devel-api/shader-effects/distance-field-effect.cpp [new file with mode: 0644]
dali-toolkit/devel-api/shader-effects/distance-field-effect.h
dali-toolkit/devel-api/shader-effects/image-region-effect.cpp [new file with mode: 0644]
dali-toolkit/devel-api/shader-effects/image-region-effect.h
dali-toolkit/devel-api/shader-effects/motion-blur-effect.cpp [new file with mode: 0644]
dali-toolkit/devel-api/shader-effects/motion-blur-effect.h
dali-toolkit/devel-api/shader-effects/motion-stretch-effect.cpp [new file with mode: 0644]
dali-toolkit/devel-api/shader-effects/motion-stretch-effect.h

index 7315172..c8445cf 100755 (executable)
@@ -44,6 +44,12 @@ SET( devel_api_src_files
   ${devel_api_src_dir}/image-loader/image-atlas.cpp
   ${devel_api_src_dir}/image-loader/texture-manager.cpp
   ${devel_api_src_dir}/layouting/flex-node.cpp
   ${devel_api_src_dir}/image-loader/image-atlas.cpp
   ${devel_api_src_dir}/image-loader/texture-manager.cpp
   ${devel_api_src_dir}/layouting/flex-node.cpp
+  ${devel_api_src_dir}/shader-effects/alpha-discard-effect.cpp
+  ${devel_api_src_dir}/shader-effects/dissolve-effect.cpp
+  ${devel_api_src_dir}/shader-effects/distance-field-effect.cpp
+  ${devel_api_src_dir}/shader-effects/image-region-effect.cpp
+  ${devel_api_src_dir}/shader-effects/motion-blur-effect.cpp
+  ${devel_api_src_dir}/shader-effects/motion-stretch-effect.cpp
   ${devel_api_src_dir}/styling/style-manager-devel.cpp
   ${devel_api_src_dir}/text/bitmap-font.cpp
   ${devel_api_src_dir}/text/text-utils-devel.cpp
   ${devel_api_src_dir}/styling/style-manager-devel.cpp
   ${devel_api_src_dir}/text/bitmap-font.cpp
   ${devel_api_src_dir}/text/text-utils-devel.cpp
diff --git a/dali-toolkit/devel-api/shader-effects/alpha-discard-effect.cpp b/dali-toolkit/devel-api/shader-effects/alpha-discard-effect.cpp
new file mode 100644 (file)
index 0000000..2e049f1
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2021 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/devel-api/shader-effects/alpha-discard-effect.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+
+Property::Map CreateAlphaDiscardEffect()
+{
+  Property::Map map;
+
+  Property::Map customShader;
+  customShader[Visual::Shader::Property::FRAGMENT_SHADER] = SHADER_ALPHA_DISCARD_EFFECT_FRAG.data();
+
+  map[Toolkit::Visual::Property::SHADER] = customShader;
+  return map;
+}
+
+} // namespace Toolkit
+} // namespace Dali
index fafd889..e782f78 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_ALPHA_DISCARD_EFFECT_H
 
 /*
 #define DALI_TOOLKIT_ALPHA_DISCARD_EFFECT_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
 #include <dali/public-api/object/property-map.h>
 
 // INTERNAL INCLUDES
 #include <dali/public-api/object/property-map.h>
 
 // INTERNAL INCLUDES
-#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/public-api/dali-toolkit-common.h>
 
 namespace Dali
 {
 
 namespace Dali
 {
@@ -42,31 +42,7 @@ namespace Toolkit
  *
  * @return A property map of the required shaders.
  */
  *
  * @return A property map of the required shaders.
  */
-inline Property::Map CreateAlphaDiscardEffect()
-{
-  const char* ALPHA_DISCARD_FRAGMENT_SHADER_SOURCE =
-    "varying mediump vec2 vTexCoord;                                \n"
-    "                                                               \n"
-    "uniform sampler2D sTexture;                                    \n"
-    "uniform lowp vec4 uColor;                                      \n"
-    "void main()                                                    \n"
-    "{                                                              \n"
-    "  mediump vec4 color = texture2D( sTexture, vTexCoord );       \n"
-    "  if(color.a <= 0.0001)                                        \n"
-    "  {                                                            \n"
-    "    discard;                                                   \n"
-    "  }                                                            \n"
-    "  gl_FragColor = color * uColor;                               \n"
-    "}                                                              \n";
-
-  Property::Map map;
-
-  Property::Map customShader;
-  customShader[Visual::Shader::Property::FRAGMENT_SHADER] = ALPHA_DISCARD_FRAGMENT_SHADER_SOURCE;
-
-  map[Toolkit::Visual::Property::SHADER] = customShader;
-  return map;
-}
+DALI_TOOLKIT_API Property::Map CreateAlphaDiscardEffect();
 
 } // namespace Toolkit
 
 
 } // namespace Toolkit
 
diff --git a/dali-toolkit/devel-api/shader-effects/dissolve-effect.cpp b/dali-toolkit/devel-api/shader-effects/dissolve-effect.cpp
new file mode 100644 (file)
index 0000000..e8c1b7e
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2021 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/devel-api/shader-effects/dissolve-effect.h>
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/rendering/shader.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+void DissolveEffectSetCentralLine( Actor& actor, const Vector2& position, const Vector2& displacement, float initialProgress )
+{
+  // the line passes through 'position' and has the direction of 'displacement'
+  float coefA, coefB, coefC; //line equation: Ax+By+C=0;
+  coefA = displacement.y;
+  coefB = -displacement.x;
+  coefC = -displacement.y * position.x + displacement.x * position.y;
+
+  float inversedAABB     = 1.f / (coefA * coefA + coefB * coefB);
+  float inversedSqrtAABB = sqrtf(inversedAABB);
+  float saddleA;
+
+  //saddle surface(Hyperbolic paraboloid)function, used to calculate the dissolve starting time
+  //z = y*y/a/a - x*x/b/b
+  //with our selection of parameters(a and b), this value for any texture coordinate is between -1.0 and 1.0
+
+  Vector3 saddleParam; // [0]: a*a, [1]: b*b, [2] b
+  Vector2 translation;
+  Vector2 rotation;
+  float   toNext = -1.f;
+  if(displacement.x > 0.f || (EqualsZero(displacement.x) && displacement.y > 0.f))
+  {
+    toNext = 1.f;
+  }
+
+  if((displacement.y * displacement.x < 0.0f))
+  {
+    //distance from (0,0) to the line
+    float distanceTopLeft = fabsf(coefC) * inversedSqrtAABB;
+    //distance from (1, 1 ) to the line
+    float distanceBottomRight = fabsf(coefA + coefB + coefC) * inversedSqrtAABB;
+    saddleA                   = std::max(distanceTopLeft, distanceBottomRight);
+
+    //foot of a perpendicular: (1,0) to the line
+    float footX1 = (coefB * coefB - coefA * coefC) * inversedAABB;
+    float footY1 = (-coefA * coefB - coefB * coefC) * inversedAABB;
+    //foot of a perpendicular: (0,1) to the line
+    float footX2   = (-coefA * coefB - coefA * coefC) * inversedAABB;
+    float footY2   = (coefA * coefA - coefB * coefC) * inversedAABB;
+    saddleParam[1] = (footX1 - footX2) * (footX1 - footX2) + (footY1 - footY2) * (footY1 - footY2);
+    translation    = Vector2(-footX2, -footY2);
+  }
+  else
+  {
+    //distance from(1,0) to the line
+    float distanceTopRight = fabsf(coefA + coefC) * inversedSqrtAABB;
+    //distance from(0,1) to the line
+    float distanceBottomLeft = fabsf(coefB + coefC) * inversedSqrtAABB;
+    saddleA                  = std::max(distanceTopRight, distanceBottomLeft);
+    //foot of a perpendicular: (0,0) to the line
+    float footX3 = (-coefA * coefC) * inversedAABB;
+    float footY3 = (-coefB * coefC) * inversedAABB;
+    //foot of a perpendicular: (1.0,1.0) to the line
+    float footX4   = (coefB * coefB - coefA * coefB - coefA * coefC) * inversedAABB;
+    float footY4   = (-coefA * coefB + coefA * coefA - coefB * coefC) * inversedAABB;
+    saddleParam[1] = (footX3 - footX4) * (footX3 - footX4) + (footY3 - footY4) * (footY3 - footY4);
+    translation    = Vector2(-footX3, -footY3);
+  }
+
+  saddleParam[2] = sqrtf(saddleParam[1]);
+  saddleParam[0] = saddleA * saddleA;
+  rotation       = Vector2(-displacement.x, displacement.y);
+  rotation.Normalize();
+
+  actor.RegisterProperty("uSaddleParam", saddleParam);
+  actor.RegisterProperty("uTranslation", translation);
+  actor.RegisterProperty("uRotation", rotation);
+  actor.RegisterProperty("uToNext", toNext);
+  actor.RegisterProperty("uPercentage", initialProgress, Dali::Property::ANIMATABLE);
+}
+
+Property::Map CreateDissolveEffect( bool useHighPrecision )
+{
+  const char* prefixHighPrecision("precision highp float;\n");
+  const char* prefixMediumPrecision("precision mediump float;\n");
+
+  const char* vertexShader = SHADER_DISSOLVE_EFFECT_VERT.data();
+  const char* fragmentShader = SHADER_DISSOLVE_EFFECT_FRAG.data();
+
+  Property::Map map;
+
+  Property::Map customShader;
+
+  std::string vertexShaderString;
+  std::string fragmentShaderString;
+  if(useHighPrecision)
+  {
+    vertexShaderString.reserve(strlen(prefixHighPrecision) + strlen(vertexShader));
+    vertexShaderString.append(prefixHighPrecision);
+
+    fragmentShaderString.reserve(strlen(prefixHighPrecision) + strlen(fragmentShader));
+    fragmentShaderString.append(prefixHighPrecision);
+  }
+  else
+  {
+    vertexShaderString.reserve(strlen(prefixMediumPrecision) + strlen(vertexShader));
+    vertexShaderString.append(prefixMediumPrecision);
+
+    fragmentShaderString.reserve(strlen(prefixMediumPrecision) + strlen(fragmentShader));
+    fragmentShaderString.append(prefixMediumPrecision);
+  }
+
+  vertexShaderString.append(vertexShader);
+  fragmentShaderString.append(fragmentShader);
+
+  customShader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShaderString;
+  customShader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShaderString;
+
+  customShader[Visual::Shader::Property::SUBDIVIDE_GRID_X] = 20;
+  customShader[Visual::Shader::Property::SUBDIVIDE_GRID_Y] = 20;
+
+  customShader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
+
+  map[Toolkit::Visual::Property::SHADER] = customShader;
+  return map;
+}
+
+} // namespace Toolkit
+
+} // namespace Dali
index ba7cb1c..47c171f 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_SHADER_EFFECT_DISSOLVE_H
 
 /*
 #define DALI_TOOLKIT_SHADER_EFFECT_DISSOLVE_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 
 // EXTERNAL INCLUDES
  */
 
 // EXTERNAL INCLUDES
-#include <dali/public-api/rendering/shader.h>
 #include <string.h>
 #include <string.h>
+#include <dali/public-api/actors/actor.h>
+#include <dali/public-api/math/vector2.h>
+#include <dali/public-api/object/property-map.h>
 
 // INTERNAL INCLUDES
 
 // INTERNAL INCLUDES
+#include <dali-toolkit/public-api/dali-toolkit-common.h>
 #include <dali-toolkit/public-api/visuals/visual-properties.h>
 
 namespace Dali
 #include <dali-toolkit/public-api/visuals/visual-properties.h>
 
 namespace Dali
@@ -41,76 +44,8 @@ namespace Toolkit
  * @param[in] displacement The direction of the central line
  * @param[in] initialProgress The normalised initial progress of the shader
  */
  * @param[in] displacement The direction of the central line
  * @param[in] initialProgress The normalised initial progress of the shader
  */
-inline void DissolveEffectSetCentralLine(Actor& actor, const Vector2& position, const Vector2& displacement, float initialProgress)
-{
-  // the line passes through 'position' and has the direction of 'displacement'
-  float coefA, coefB, coefC; //line equation: Ax+By+C=0;
-  coefA = displacement.y;
-  coefB = -displacement.x;
-  coefC = -displacement.y * position.x + displacement.x * position.y;
-
-  float inversedAABB     = 1.f / (coefA * coefA + coefB * coefB);
-  float inversedSqrtAABB = sqrtf(inversedAABB);
-  float saddleA;
-
-  //saddle surface(Hyperbolic paraboloid)function, used to calculate the dissolve starting time
-  //z = y*y/a/a - x*x/b/b
-  //with our selection of parameters(a and b), this value for any texture coordinate is between -1.0 and 1.0
-
-  Vector3 saddleParam; // [0]: a*a, [1]: b*b, [2] b
-  Vector2 translation;
-  Vector2 rotation;
-  float   toNext = -1.f;
-  if(displacement.x > 0.f || (EqualsZero(displacement.x) && displacement.y > 0.f))
-  {
-    toNext = 1.f;
-  }
-
-  if((displacement.y * displacement.x < 0.0f))
-  {
-    //distance from (0,0) to the line
-    float distanceTopLeft = fabsf(coefC) * inversedSqrtAABB;
-    //distance from (1, 1 ) to the line
-    float distanceBottomRight = fabsf(coefA + coefB + coefC) * inversedSqrtAABB;
-    saddleA                   = std::max(distanceTopLeft, distanceBottomRight);
+DALI_TOOLKIT_API void DissolveEffectSetCentralLine( Actor& actor, const Vector2& position, const Vector2& displacement, float initialProgress );
 
 
-    //foot of a perpendicular: (1,0) to the line
-    float footX1 = (coefB * coefB - coefA * coefC) * inversedAABB;
-    float footY1 = (-coefA * coefB - coefB * coefC) * inversedAABB;
-    //foot of a perpendicular: (0,1) to the line
-    float footX2   = (-coefA * coefB - coefA * coefC) * inversedAABB;
-    float footY2   = (coefA * coefA - coefB * coefC) * inversedAABB;
-    saddleParam[1] = (footX1 - footX2) * (footX1 - footX2) + (footY1 - footY2) * (footY1 - footY2);
-    translation    = Vector2(-footX2, -footY2);
-  }
-  else
-  {
-    //distance from(1,0) to the line
-    float distanceTopRight = fabsf(coefA + coefC) * inversedSqrtAABB;
-    //distance from(0,1) to the line
-    float distanceBottomLeft = fabsf(coefB + coefC) * inversedSqrtAABB;
-    saddleA                  = std::max(distanceTopRight, distanceBottomLeft);
-    //foot of a perpendicular: (0,0) to the line
-    float footX3 = (-coefA * coefC) * inversedAABB;
-    float footY3 = (-coefB * coefC) * inversedAABB;
-    //foot of a perpendicular: (1.0,1.0) to the line
-    float footX4   = (coefB * coefB - coefA * coefB - coefA * coefC) * inversedAABB;
-    float footY4   = (-coefA * coefB + coefA * coefA - coefB * coefC) * inversedAABB;
-    saddleParam[1] = (footX3 - footX4) * (footX3 - footX4) + (footY3 - footY4) * (footY3 - footY4);
-    translation    = Vector2(-footX3, -footY3);
-  }
-
-  saddleParam[2] = sqrtf(saddleParam[1]);
-  saddleParam[0] = saddleA * saddleA;
-  rotation       = Vector2(-displacement.x, displacement.y);
-  rotation.Normalize();
-
-  actor.RegisterProperty("uSaddleParam", saddleParam);
-  actor.RegisterProperty("uTranslation", translation);
-  actor.RegisterProperty("uRotation", rotation);
-  actor.RegisterProperty("uToNext", toNext);
-  actor.RegisterProperty("uPercentage", initialProgress, Dali::Property::ANIMATABLE);
-}
 /**
  * @brief Create a new Dissolve effect
  *
 /**
  * @brief Create a new Dissolve effect
  *
@@ -123,105 +58,7 @@ inline void DissolveEffectSetCentralLine(Actor& actor, const Vector2& position,
  *  @return The newly created Property::Map with the dissolve effect
  */
 
  *  @return The newly created Property::Map with the dissolve effect
  */
 
-inline Property::Map CreateDissolveEffect(bool useHighPrecision = true)
-{
-  const char* prefixHighPrecision("precision highp float;\n");
-  const char* prefixMediumPrecision("precision mediump float;\n");
-
-  const char* vertexShader(
-    "attribute mediump vec2 aPosition;\n"
-    "\n"
-    "uniform mediump mat4   uMvpMatrix;\n"
-    "uniform vec3           uSize;\n"
-    "uniform vec4           uTextureRect;"
-    "\n"
-    "uniform float          uPercentage;\n"
-    "uniform vec3           uSaddleParam;\n"
-    "uniform vec2           uTranslation;\n"
-    "uniform vec2           uRotation; \n"
-    "uniform float          uToNext;\n"
-    "\n"
-    "varying float          vPercentage;\n"
-    "varying vec2           vTexCoord;\n"
-    "\n"
-    "void main()\n"
-    "{\n"
-    "  mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n"
-    "  vertexPosition.xyz *= uSize;\n"
-    "  vertexPosition = uMvpMatrix * vertexPosition;\n"
-    "  gl_Position = vertexPosition;\n"
-    "\n"
-    "  vec2 texCoord = aPosition + vec2(0.5);\n"
-    "  vTexCoord = texCoord;\n"
-    "\n"
-    "  //Calculate the distortion value given the dissolve central line\n"
-    "  vec2 value = texCoord + uTranslation;\n"
-    "  mat2 rotateMatrix = mat2(uRotation.s, uRotation.t, -uRotation.t, uRotation.s);\n"
-    "  value = rotateMatrix * value;\n"
-    "  if(uToNext == 1.0)\n"
-    "    value.s = uSaddleParam[2] + value.s;\n"
-    "  float delay = value.t * value.t / uSaddleParam[0] - value.s * value.s / uSaddleParam[1];\n"
-    "  vPercentage = clamp(uPercentage * 2.0 - 0.5 * sin(delay * 1.571) - 0.5, 0.0, 1.0);\n"
-    "}\n");
-
-  const char* fragmentShader(
-    "varying float           vPercentage;\n"
-    "varying mediump vec2  vTexCoord;\n"
-    "\n"
-    "uniform sampler2D   sTexture;\n"
-    "uniform lowp vec4 uColor;\n"
-    "uniform vec4 uTextureRect;\n"
-    "float rand(vec2 co)\n"
-    "{\n"
-    "  return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);\n"
-    "}\n"
-    "void main()\n"
-    "{\n"
-    "  //Calculate the randomness\n"
-    "  float  offsetS = rand(vTexCoord * vPercentage) - vTexCoord.s;\n"
-    "  float offsetT = rand(vec2(vTexCoord.t * vPercentage, vTexCoord.s * vPercentage)) - vTexCoord.t;\n"
-    "  vec2 lookupCoord = vTexCoord + vec2(offsetS, offsetT) * vPercentage;\n"
-    "  gl_FragColor = texture2D(sTexture, lookupCoord) * uColor;\n"
-    "  gl_FragColor.a *= 1.0 - vPercentage;\n"
-    "}\n");
-
-  Property::Map map;
-
-  Property::Map customShader;
-
-  std::string vertexShaderString;
-  std::string fragmentShaderString;
-  if(useHighPrecision)
-  {
-    vertexShaderString.reserve(strlen(prefixHighPrecision) + strlen(vertexShader));
-    vertexShaderString.append(prefixHighPrecision);
-
-    fragmentShaderString.reserve(strlen(prefixHighPrecision) + strlen(fragmentShader));
-    fragmentShaderString.append(prefixHighPrecision);
-  }
-  else
-  {
-    vertexShaderString.reserve(strlen(prefixMediumPrecision) + strlen(vertexShader));
-    vertexShaderString.append(prefixMediumPrecision);
-
-    fragmentShaderString.reserve(strlen(prefixMediumPrecision) + strlen(fragmentShader));
-    fragmentShaderString.append(prefixMediumPrecision);
-  }
-
-  vertexShaderString.append(vertexShader);
-  fragmentShaderString.append(fragmentShader);
-
-  customShader[Visual::Shader::Property::VERTEX_SHADER]   = vertexShaderString;
-  customShader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShaderString;
-
-  customShader[Visual::Shader::Property::SUBDIVIDE_GRID_X] = 20;
-  customShader[Visual::Shader::Property::SUBDIVIDE_GRID_Y] = 20;
-
-  customShader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
-
-  map[Toolkit::Visual::Property::SHADER] = customShader;
-  return map;
-}
+DALI_TOOLKIT_API Property::Map CreateDissolveEffect( bool useHighPrecision = true);
 
 } // namespace Toolkit
 
 
 } // namespace Toolkit
 
diff --git a/dali-toolkit/devel-api/shader-effects/distance-field-effect.cpp b/dali-toolkit/devel-api/shader-effects/distance-field-effect.cpp
new file mode 100644 (file)
index 0000000..597dc7c
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2021 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/devel-api/shader-effects/distance-field-effect.h>
+
+// EXTERNAL INCLUDES
+#include <string.h>
+#include <dali/public-api/rendering/shader.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+Dali::Property::Map CreateDistanceFieldEffect()
+{
+  const char* fragmentShaderPrefix("#extension GL_OES_standard_derivatives : enable\n");
+
+  const char* fragmentShader = SHADER_DISTANCE_FIELD_EFFECT_FRAG.data();
+
+  Property::Map map;
+
+  Property::Map customShader;
+
+  std::string fragmentShaderString;
+  fragmentShaderString.reserve(strlen(fragmentShaderPrefix) + strlen(fragmentShader));
+  fragmentShaderString.append(fragmentShaderPrefix);
+  fragmentShaderString.append(fragmentShader);
+
+  customShader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShaderString;
+  customShader[Visual::Shader::Property::HINTS]           = Shader::Hint::OUTPUT_IS_TRANSPARENT;
+
+  map[Toolkit::Visual::Property::SHADER] = customShader;
+  return map;
+}
+
+} // namespace Toolkit
+
+} // namespace Dali
index b963693..2a233f3 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_SHADER_EFFECT_DISTANCEFIELD_H
 
 /*
 #define DALI_TOOLKIT_SHADER_EFFECT_DISTANCEFIELD_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  *
  */
 
  *
  */
 
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/dali-toolkit-common.h>
+
 // EXTERNAL INCLUDES
 #include <dali/public-api/object/property-map.h>
 // EXTERNAL INCLUDES
 #include <dali/public-api/object/property-map.h>
-#include <string.h>
-
-// INTERNAL INCLUDES
-#include <dali-toolkit/public-api/visuals/visual-properties.h>
 
 namespace Dali
 {
 
 namespace Dali
 {
@@ -52,125 +51,7 @@ namespace Toolkit
  *
  *  @return The newly created Property::Map with the distance field effect
  */
  *
  *  @return The newly created Property::Map with the distance field effect
  */
-inline Dali::Property::Map CreateDistanceFieldEffect()
-{
-  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);
-
-  customShader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShaderString;
-  customShader[Visual::Shader::Property::HINTS]           = Shader::Hint::OUTPUT_IS_TRANSPARENT;
-
-  map[Toolkit::Visual::Property::SHADER] = customShader;
-  return map;
-}
+DALI_TOOLKIT_API Dali::Property::Map CreateDistanceFieldEffect();
 
 } // namespace Toolkit
 
 
 } // namespace Toolkit
 
diff --git a/dali-toolkit/devel-api/shader-effects/image-region-effect.cpp b/dali-toolkit/devel-api/shader-effects/image-region-effect.cpp
new file mode 100644 (file)
index 0000000..bab97f2
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2021 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/devel-api/shader-effects/image-region-effect.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+
+Property::Map CreateImageRegionEffect()
+{
+  Property::Map map;
+
+  Property::Map customShader;
+  customShader[Visual::Shader::Property::VERTEX_SHADER] = SHADER_IMAGE_REGION_EFFECT_VERT.data();
+
+  map[Toolkit::Visual::Property::SHADER] = customShader;
+  return map;
+}
+
+} // Toolkit
+
+} // Dali
index 30d5f4e..65504c1 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_IMAGE_REGION_EFFECT_H
 
 /*
 #define DALI_TOOLKIT_IMAGE_REGION_EFFECT_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
 #include <dali/public-api/object/property-map.h>
 
 // INTERNAL INCLUDES
 #include <dali/public-api/object/property-map.h>
 
 // INTERNAL INCLUDES
-#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/public-api/dali-toolkit-common.h>
 
 namespace Dali
 {
 
 namespace Dali
 {
@@ -41,43 +41,7 @@ namespace Toolkit
  *
  * @return A property map of the required shader
  */
  *
  * @return A property map of the required shader
  */
-inline Property::Map CreateImageRegionEffect()
-{
-  std::string vertexShader(
-    "attribute mediump vec2 aPosition;\n"
-    "\n"
-    "uniform mediump mat4 uMvpMatrix;\n"
-    "uniform vec3 uSize;\n"
-    "uniform vec4 uTextureRect;"
-    "\n"
-    "varying vec2 vTexCoord;\n"
-
-    "uniform mediump vec2 uTopLeft;\n"
-    "uniform mediump vec2 uBottomRight;\n"
-    "void main()\n"
-    "{\n"
-    "  mediump vec4 position = vec4(aPosition, 0.0, 1.0);\n"
-    "  position.xyz *= uSize;\n"
-    "  gl_Position = uMvpMatrix * position;\n"
-    // The line below is doing the same as the following commented lines:
-    //"  vec2 imageSize = uTextureRect.zw - uTextureRect.xy;\n"
-    //"  vec2 topLeft = uTextureRect.xy + uTopLeft * imageSize;\n"
-    //"  vec2 bottomRight = uTextureRect.xy + uBottomRight * imageSize;\n"
-    //"  vec2 texCoord = (aTexCoord - uTextureRect.xy) / imageSize;\n"
-    //"  vTexCoord = topLeft + texCoord * ( bottomRight - topLeft );\n"
-
-    "  vec2 texCoord = aPosition + vec2(0.5);\n"
-    "  vTexCoord = uTextureRect.xy + uTopLeft * ( uTextureRect.zw - uTextureRect.xy ) + ( texCoord - uTextureRect.xy ) * ( uBottomRight - uTopLeft );\n"
-    "}\n");
-
-  Property::Map map;
-
-  Property::Map customShader;
-  customShader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
-
-  map[Toolkit::Visual::Property::SHADER] = customShader;
-  return map;
-}
+DALI_TOOLKIT_API Property::Map CreateImageRegionEffect();
 
 } // namespace Toolkit
 
 
 } // namespace Toolkit
 
diff --git a/dali-toolkit/devel-api/shader-effects/motion-blur-effect.cpp b/dali-toolkit/devel-api/shader-effects/motion-blur-effect.cpp
new file mode 100644 (file)
index 0000000..430832e
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2021 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/devel-api/shader-effects/motion-blur-effect.h>
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/animation/constraints.h>
+#include <dali/public-api/rendering/shader.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+
+void SetMotionBlurProperties( Actor& actor, unsigned int numBlurSamples )
+{
+  actor.RegisterProperty("uBlurTexCoordScale", 0.125f);
+  actor.RegisterProperty("uGeometryStretchFactor", 0.05f);
+  actor.RegisterProperty("uSpeedScalingFactor", 0.5f);
+  actor.RegisterProperty("uObjectFadeStart", Vector2(0.25f, 0.25f));
+  actor.RegisterProperty("uObjectFadeEnd", Vector2(0.5f, 0.5f));
+  actor.RegisterProperty("uAlphaScale", 0.75f);
+  actor.RegisterProperty("uNumSamples", static_cast<float>(numBlurSamples));
+  actor.RegisterProperty("uRecipNumSamples", 1.0f / static_cast<float>(numBlurSamples));
+  actor.RegisterProperty("uRecipNumSamplesMinusOne", 1.0f / static_cast<float>(numBlurSamples - 1.0f));
+  Property::Index uModelProperty = actor.RegisterProperty("uModelLastFrame", Matrix::IDENTITY);
+
+  Constraint constraint = Constraint::New<Matrix>(actor, uModelProperty, EqualToConstraint());
+  constraint.AddSource(Source(actor, Actor::Property::WORLD_MATRIX));
+  constraint.Apply();
+}
+
+
+Property::Map CreateMotionBlurEffect()
+{
+  Property::Map map;
+
+  Property::Map customShader;
+  customShader[Visual::Shader::Property::VERTEX_SHADER]   = SHADER_MOTION_BLUR_EFFECT_VERT.data();
+  customShader[Visual::Shader::Property::FRAGMENT_SHADER] = SHADER_MOTION_BLUR_EFFECT_FRAG.data();
+
+  customShader[Visual::Shader::Property::SUBDIVIDE_GRID_X] = 10;
+  customShader[Visual::Shader::Property::SUBDIVIDE_GRID_Y] = 10;
+
+  customShader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
+
+  map[Toolkit::Visual::Property::SHADER] = customShader;
+  return map;
+}
+
+} // Toolkit
+} // Dali
index b800943..8201976 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_SHADER_EFFECT_MOTION_BLUR_H
 
 /*
 #define DALI_TOOLKIT_SHADER_EFFECT_MOTION_BLUR_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 // EXTERNAL INCLUDES
 #include <dali/public-api/actors/actor.h>
 
 // EXTERNAL INCLUDES
 #include <dali/public-api/actors/actor.h>
-#include <dali/public-api/animation/constraint.h>
 #include <dali/public-api/object/property-map.h>
 #include <dali/public-api/object/property-map.h>
-#include <dali/public-api/rendering/shader.h>
 
 // INTERNAL INCLUDES
 
 // INTERNAL INCLUDES
-#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/public-api/dali-toolkit-common.h>
 
 namespace Dali
 {
 
 namespace Dali
 {
@@ -37,23 +35,7 @@ namespace Toolkit
  * @param[in] actor The actor that registers the uniform properties
  * @param[in] numBlurSamples Number of samples used by the shader
  */
  * @param[in] actor The actor that registers the uniform properties
  * @param[in] numBlurSamples Number of samples used by the shader
  */
-inline void SetMotionBlurProperties(Actor& actor, unsigned int numBlurSamples = 8)
-{
-  actor.RegisterProperty("uBlurTexCoordScale", 0.125f);
-  actor.RegisterProperty("uGeometryStretchFactor", 0.05f);
-  actor.RegisterProperty("uSpeedScalingFactor", 0.5f);
-  actor.RegisterProperty("uObjectFadeStart", Vector2(0.25f, 0.25f));
-  actor.RegisterProperty("uObjectFadeEnd", Vector2(0.5f, 0.5f));
-  actor.RegisterProperty("uAlphaScale", 0.75f);
-  actor.RegisterProperty("uNumSamples", static_cast<float>(numBlurSamples));
-  actor.RegisterProperty("uRecipNumSamples", 1.0f / static_cast<float>(numBlurSamples));
-  actor.RegisterProperty("uRecipNumSamplesMinusOne", 1.0f / static_cast<float>(numBlurSamples - 1.0f));
-  Property::Index uModelProperty = actor.RegisterProperty("uModelLastFrame", Matrix::IDENTITY);
-
-  Constraint constraint = Constraint::New<Matrix>(actor, uModelProperty, EqualToConstraint());
-  constraint.AddSource(Source(actor, Actor::Property::WORLD_MATRIX));
-  constraint.Apply();
-}
+DALI_TOOLKIT_API void SetMotionBlurProperties( Actor& actor, unsigned int numBlurSamples = 8 );
 
 /**
  * @brief Create a new MotionBlurEffect
 
 /**
  * @brief Create a new MotionBlurEffect
@@ -95,147 +77,7 @@ inline void SetMotionBlurProperties(Actor& actor, unsigned int numBlurSamples =
  *
  * @return The newly created Property::Map with the motion blur effect
  */
  *
  * @return The newly created Property::Map with the motion blur effect
  */
-inline Property::Map CreateMotionBlurEffect()
-{
-  std::string vertexSource;
-  vertexSource =
-    "precision mediump float;\n"
-
-    "attribute vec2 aPosition;\n"
-
-    "uniform mat4 uMvpMatrix;\n"
-    "uniform mat4 uModelView;\n"
-    "uniform mat4 uViewMatrix;\n"
-    "uniform mat4 uProjection;\n"
-    "uniform vec3 uSize;\n"
-
-    "uniform mat4 uModelLastFrame;\n"
-    "float timeDelta = 0.0167;\n"
-
-    "uniform float uGeometryStretchFactor;\n"
-    "uniform float uSpeedScalingFactor;\n"
-
-    // outputs
-    "varying vec2 vModelSpaceCenterToPos;\n"
-    "varying vec2 vScreenSpaceVelocityVector;\n"
-    "varying float vSpeed;\n"
-    "varying vec2 vTexCoord;\n"
-
-    "void main()\n"
-    "{\n"
-    // get view space position of vertex this frame and last frame
-    " vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n"
-    " vertexPosition.xyz *= uSize;\n"
-
-    " vec4 viewSpaceVertex = uModelView * vertexPosition;\n"
-    " vec4 viewSpaceVertexLastFrame = (uViewMatrix * uModelLastFrame) * vertexPosition;\n"
-    " float reciprocalTimeDelta = 1.0 / timeDelta;\n"
-
-    // work out vertex's last movement in view space
-    " vec3 viewSpacePosDelta = viewSpaceVertex.xyz - viewSpaceVertexLastFrame.xyz;\n"
-
-    // get clip space position of vertex this frame and last frame
-    " vec4 clipSpaceVertex = uMvpMatrix * vertexPosition;\n"
-    " vec4 clipSpaceVertexLastFrame = uProjection * viewSpaceVertexLastFrame;\n"
-
-    // decide how much this vertex is 'trailing', i.e. at the back of the object relative to its direction of motion. We do this
-    // by assuming the objects model space origin is at its center and taking the dot product of the vector from center to vertex with the motion direction
-    " float t = 0.0;\n"
-    " float posDeltaLength = length(viewSpacePosDelta);\n"
-    " if(posDeltaLength > 0.001)\n" // avoid div by 0 if object has barely moved
-    " {\n"
-    "   vec4 viewSpaceCenterToPos = uModelView * vec4(vertexPosition.xy, 0.0, 0.0);\n"
-    "   float centerToVertexDist = length(viewSpaceCenterToPos);\n"
-    "   if(centerToVertexDist > 0.001)\n" // avoid div by 0 if object has vertex at model space origin
-    "   {\n"
-    "     vec3 viewSpacePosDeltaNormalised = viewSpacePosDelta / posDeltaLength;\n"
-    "     vec3 viewSpaceCenterToPosNormalised = viewSpaceCenterToPos.xyz / centerToVertexDist;\n"
-    "     t = (dot(viewSpacePosDeltaNormalised, viewSpaceCenterToPosNormalised) * 0.5 ) + 0.5;\n" // scale and bias from [-1..1] to [0..1]
-    "   }\n"
-    " }\n"
-    // output vertex position lerped with its last position, based on how much it is trailing,
-    // this stretches the geom back along where it has just been, giving a warping effect
-    // Note: we must take account of time delta to convert position delta into a velocity, so changes are smooth (take into account frame time correctly)
-    " gl_Position = mix(clipSpaceVertexLastFrame, clipSpaceVertex, t * uGeometryStretchFactor * reciprocalTimeDelta);\n"
-
-    // work out vertex's last movement in normalised device coordinates [-1..1] space, i.e. perspective divide
-    " vec2 ndcVertex = clipSpaceVertex.xy / clipSpaceVertex.w;\n"
-    " vec2 ndcVertexLastFrame = clipSpaceVertexLastFrame.xy / clipSpaceVertexLastFrame.w;\n"
-    // scale and bias so that a value of 1.0 corresponds to screen size (NDC is [-1..1] = 2)
-    " vScreenSpaceVelocityVector = ((ndcVertex - ndcVertexLastFrame) * 0.5 * reciprocalTimeDelta);\n"
-    " vScreenSpaceVelocityVector.y = -vScreenSpaceVelocityVector.y;\n" // TODO negated due to y being inverted in our coordinate system?
-    // calculate a scaling factor proportional to velocity, which we can use to tweak how things look
-    " vSpeed = length(vScreenSpaceVelocityVector) * uSpeedScalingFactor;\n"
-    " vSpeed = clamp(vSpeed, 0.0, 1.0);\n"
-
-    // provide fragment shader with vector from center of object to pixel (assumes the objects model space origin is at its center and verts have same z)
-    " vModelSpaceCenterToPos = viewSpaceVertex.xy;\n"
-
-    " vec2 texCoord = aPosition + vec2(0.5);"
-    " vTexCoord = texCoord;\n"
-    "}\n";
-
-  std::string fragmentSource;
-  fragmentSource =
-    "precision mediump float;\n"
-
-    "uniform sampler2D sTexture;\n"
-    "uniform vec4 uColor;\n"
-
-    "uniform vec2 uObjectFadeStart;\n"
-    "uniform vec2 uObjectFadeEnd;\n"
-    "uniform float uAlphaScale;\n"
-    "uniform float uBlurTexCoordScale;\n"
-    "uniform float uNumSamples;\n"
-    "uniform float uRecipNumSamples;\n"
-    "uniform float uRecipNumSamplesMinusOne;\n"
-    // inputs
-    "varying vec2 vModelSpaceCenterToPos;\n"
-    "varying vec2 vScreenSpaceVelocityVector;\n"
-    "varying float vSpeed;\n"
-    "varying vec2 vTexCoord;\n"
-
-    "void main()\n"
-    "{\n"
-    // calculate an alpha value that will fade the object towards its extremities, we need this to avoid an unsightly hard edge between color values of
-    // the blurred object and the unblurred background. Use smoothstep also to hide any hard edges (discontinuities) in rate of change of this alpha gradient
-    " vec2 centerToPixel = abs(vModelSpaceCenterToPos);\n"
-    " vec2 fadeToEdges = smoothstep(0.0, 1.0, 1.0 - ((centerToPixel - uObjectFadeStart) / (uObjectFadeEnd - uObjectFadeStart)));\n"
-    " float fadeToEdgesScale = fadeToEdges.x * fadeToEdges.y * uAlphaScale;\n" // apply global scaler
-    " fadeToEdgesScale = mix(1.0, fadeToEdgesScale, vSpeed);\n"                // fade proportional to speed, so opaque when at rest
-
-    // scale velocity vector by user requirements
-    " vec2 velocity = vScreenSpaceVelocityVector * uBlurTexCoordScale;\n"
-
-    // standard actor texel
-    " vec4 colActor = texture2D(sTexture, vTexCoord);\n"
-
-    // blurred actor - gather texture samples from the actor texture in the direction of motion
-    " vec4 col = colActor * uRecipNumSamples;\n"
-    " for(float i = 1.0; i < uNumSamples; i += 1.0)\n"
-    " {\n"
-    "   float t = i * uRecipNumSamplesMinusOne;\n"
-    "   col += texture2D(sTexture, vTexCoord + (velocity * t)) * uRecipNumSamples;\n"
-    " }\n"
-    " gl_FragColor = mix(colActor, col, vSpeed);\n"                         // lerp blurred and non-blurred actor based on speed of motion
-    " gl_FragColor.a = fadeToEdgesScale;//colActor.a * fadeToEdgesScale;\n" // fade blurred actor to its edges based on speed of motion
-    " gl_FragColor *= uColor;\n"
-    "}\n";
-
-  Property::Map map;
-
-  Property::Map customShader;
-  customShader[Visual::Shader::Property::VERTEX_SHADER]   = vertexSource;
-  customShader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentSource;
-
-  customShader[Visual::Shader::Property::SUBDIVIDE_GRID_X] = 10;
-  customShader[Visual::Shader::Property::SUBDIVIDE_GRID_Y] = 10;
-
-  customShader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
-
-  map[Toolkit::Visual::Property::SHADER] = customShader;
-  return map;
-}
+DALI_TOOLKIT_API Property::Map CreateMotionBlurEffect();
 
 } // namespace Toolkit
 
 
 } // namespace Toolkit
 
diff --git a/dali-toolkit/devel-api/shader-effects/motion-stretch-effect.cpp b/dali-toolkit/devel-api/shader-effects/motion-stretch-effect.cpp
new file mode 100644 (file)
index 0000000..bdd21f7
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2021 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/devel-api/shader-effects/motion-stretch-effect.h>
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/actors/actor.h>
+#include <dali/public-api/animation/constraints.h>
+#include <dali/public-api/object/property-map.h>
+#include <dali/public-api/rendering/shader.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+
+namespace Dali
+{
+namespace Toolkit
+{
+
+void SetMotionStretchProperties( Actor& actor )
+{
+  actor.RegisterProperty("uGeometryStretchFactor", 0.5f);
+  actor.RegisterProperty("uSpeedScalingFactor", 0.5f);
+  actor.RegisterProperty("uObjectFadeStart", Vector2(0.25f, 0.25f));
+  actor.RegisterProperty("uObjectFadeEnd", Vector2(0.5f, 0.5f));
+  actor.RegisterProperty("uAlphaScale", 0.75f);
+  Property::Index uModelProperty = actor.RegisterProperty("uModelLastFrame", Matrix::IDENTITY);
+
+  Constraint constraint = Constraint::New<Matrix>(actor, uModelProperty, EqualToConstraint());
+  constraint.AddSource(Source(actor, Actor::Property::WORLD_MATRIX));
+  constraint.Apply();
+}
+
+Property::Map CreateMotionStretchEffect()
+{
+  Property::Map map;
+
+  Property::Map customShader;
+  customShader[Visual::Shader::Property::VERTEX_SHADER]   = SHADER_MOTION_STRETCH_EFFECT_VERT.data();
+  customShader[Visual::Shader::Property::FRAGMENT_SHADER] = SHADER_MOTION_STRETCH_EFFECT_FRAG.data();
+
+  customShader[Visual::Shader::Property::SUBDIVIDE_GRID_X] = 10;
+  customShader[Visual::Shader::Property::SUBDIVIDE_GRID_Y] = 10;
+
+  customShader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
+
+  map[Toolkit::Visual::Property::SHADER] = customShader;
+  return map;
+}
+
+
+} // Toolkit
+} // Dali
index 8ad4c48..5f4976d 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_SHADER_EFFECT_MOTION_STRETCH_H
 
 /*
 #define DALI_TOOLKIT_SHADER_EFFECT_MOTION_STRETCH_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 // EXTERNAL INCLUDES
 #include <dali/public-api/actors/actor.h>
 
 // EXTERNAL INCLUDES
 #include <dali/public-api/actors/actor.h>
-#include <dali/public-api/animation/constraint.h>
 #include <dali/public-api/object/property-map.h>
 #include <dali/public-api/object/property-map.h>
-#include <dali/public-api/rendering/shader.h>
 
 // INTERNAL INCLUDES
 
 // INTERNAL INCLUDES
-#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/public-api/dali-toolkit-common.h>
 
 namespace Dali
 {
 
 namespace Dali
 {
@@ -34,19 +32,7 @@ namespace Toolkit
 /**
  * @brief Set the properties for the motion stretch
  */
 /**
  * @brief Set the properties for the motion stretch
  */
-inline void SetMotionStretchProperties(Actor& actor)
-{
-  actor.RegisterProperty("uGeometryStretchFactor", 0.5f);
-  actor.RegisterProperty("uSpeedScalingFactor", 0.5f);
-  actor.RegisterProperty("uObjectFadeStart", Vector2(0.25f, 0.25f));
-  actor.RegisterProperty("uObjectFadeEnd", Vector2(0.5f, 0.5f));
-  actor.RegisterProperty("uAlphaScale", 0.75f);
-  Property::Index uModelProperty = actor.RegisterProperty("uModelLastFrame", Matrix::IDENTITY);
-
-  Constraint constraint = Constraint::New<Matrix>(actor, uModelProperty, EqualToConstraint());
-  constraint.AddSource(Source(actor, Actor::Property::WORLD_MATRIX));
-  constraint.Apply();
-}
+DALI_TOOLKIT_API void SetMotionStretchProperties( Actor& actor );
 
 /**
  * @brief Creates a new MotionStretchEffect
 
 /**
  * @brief Creates a new MotionStretchEffect
@@ -74,134 +60,7 @@ inline void SetMotionStretchProperties(Actor& actor)
  *
  * @return The newly created Property::Map with the motion stretch effect
  */
  *
  * @return The newly created Property::Map with the motion stretch effect
  */
-inline Property::Map CreateMotionStretchEffect()
-{
-  std::string vertexSource;
-  vertexSource =
-    "precision mediump float;\n"
-
-    "attribute vec2 aPosition;\n"
-
-    "uniform mat4 uMvpMatrix;\n"
-    "uniform mat4 uModelView;\n"
-    "uniform mat4 uViewMatrix;\n"
-    "uniform mat4 uProjection;\n"
-    "uniform vec3 uSize;\n"
-
-    "uniform mat4  uModelLastFrame;\n"
-    "float timeDelta = 0.0167;\n"
-
-    "uniform float uGeometryStretchFactor;\n"
-    "uniform float uSpeedScalingFactor;\n"
-
-    // outputs
-    "varying vec2 vModelSpaceCenterToPos;\n"
-    "varying vec2 vScreenSpaceVelocityVector;\n"
-    "varying float vSpeed;\n"
-    "varying vec2 vTexCoord;\n"
-
-    "void main()\n"
-    "{\n"
-    // get view space position of vertex this frame and last frame
-    " vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n"
-    " vertexPosition.xyz *= uSize;\n"
-
-    " vec4 viewSpaceVertex = uModelView * vertexPosition;\n"
-    " vec4 viewSpaceVertexLastFrame = uViewMatrix * uModelLastFrame * vertexPosition;\n"
-
-    // work out vertex's last movement in view space
-    " vec3 viewSpacePosDelta = viewSpaceVertex.xyz - viewSpaceVertexLastFrame.xyz;\n"
-    " float reciprocalTimeDelta = 1.0 / timeDelta;\n"
-
-    // get clip space position of vertex this frame and last frame
-    " vec4 clipSpaceVertex = uMvpMatrix * vertexPosition;\n"
-    " vec4 clipSpaceVertexLastFrame = uProjection * viewSpaceVertexLastFrame;\n"
-
-    // decide how much this vertex is 'trailing', i.e. at the back of the object relative to its direction of motion. We do this
-    // by assuming the objects model space origin is at its center and taking the dot product of the vector from center to vertex with the motion direction
-    " float t = 0.0;\n"
-    " float posDeltaLength = length(viewSpacePosDelta);\n"
-    " if(posDeltaLength > 0.001)\n" // avoid div by 0 if object has barely moved
-    " {\n"
-    "   vec4 viewSpaceCenterToPos = uModelView * vec4(aPosition, 0.0, 0.0);\n"
-    "   float centerToVertexDist = length(viewSpaceCenterToPos);\n"
-    "   if(centerToVertexDist > 0.001)\n" // avoid div by 0 if object has vertex at model space origin
-    "   {\n"
-    "     vec3 viewSpacePosDeltaNormalised = viewSpacePosDelta / posDeltaLength;\n"
-    "     vec3 viewSpaceCenterToPosNormalised = viewSpaceCenterToPos.xyz / centerToVertexDist;\n"
-    "     t = (dot(viewSpacePosDeltaNormalised, viewSpaceCenterToPosNormalised) * 0.5 ) + 0.5;\n" // scale and bias from [-1..1] to [0..1]
-    "   }\n"
-    " }\n"
-    // output vertex position lerped with its last position, based on how much it is trailing,
-    // this stretches the geom back along where it has just been, giving a warping effect
-    // We raise t to a power in order that non-trailing vertices are effected much more than trailing ones
-    // Note: we must take account of time delta to convert position delta into a velocity, so changes are smooth (take into account frame time correctly)
-    " gl_Position = mix(clipSpaceVertexLastFrame, clipSpaceVertex, t * t * t * uGeometryStretchFactor * reciprocalTimeDelta);\n"
-
-    // work out vertex's last movement in normalised device coordinates [-1..1] space, i.e. perspective divide
-    " vec2 ndcVertex = clipSpaceVertex.xy / clipSpaceVertex.w;\n"
-    " vec2 ndcVertexLastFrame = clipSpaceVertexLastFrame.xy / clipSpaceVertexLastFrame.w;\n"
-    // scale and bias so that a value of 1.0 corresponds to screen size (NDC is [-1..1] = 2)
-    " vScreenSpaceVelocityVector = ((ndcVertex - ndcVertexLastFrame) * 0.5 * reciprocalTimeDelta);\n"
-    " vScreenSpaceVelocityVector.y = -vScreenSpaceVelocityVector.y;\n" // TODO negated due to y being inverted in our coordinate system?
-    // calculate a scaling factor proportional to velocity, which we can use to tweak how things look
-    " vSpeed = length(vScreenSpaceVelocityVector) * uSpeedScalingFactor;\n"
-    " vSpeed = clamp(vSpeed, 0.0, 1.0);\n"
-
-    // provide fragment shader with vector from center of object to pixel (assumes the objects model space origin is at its center and verts have same z)
-    " vModelSpaceCenterToPos = viewSpaceVertex.xy;\n"
-
-    " vec2 texCoord = aPosition + vec2(0.5);"
-    " vTexCoord = texCoord;\n"
-    "}\n";
-
-  std::string fragmentSource;
-  fragmentSource =
-    "precision mediump float;\n"
-
-    "uniform sampler2D sTexture;\n"
-    "uniform vec4 uColor;\n"
-
-    "uniform vec2 uObjectFadeStart;\n"
-    "uniform vec2 uObjectFadeEnd;\n"
-    "uniform float uAlphaScale;\n"
-
-    // inputs
-    "varying vec2 vModelSpaceCenterToPos;\n"
-    "varying vec2 vScreenSpaceVelocityVector;\n"
-    "varying float vSpeed;\n"
-    "varying vec2 vTexCoord;\n"
-
-    "void main()\n"
-    "{\n"
-    // calculate an alpha value that will fade the object towards its extremities, we need this to avoid an unsightly hard edge between color values of
-    // the stretched object and the background. Use smoothstep also to hide any hard edges (discontinuities) in rate of change of this alpha gradient
-    " vec2 centerToPixel = abs( vModelSpaceCenterToPos );\n"
-    " vec2 fadeToEdges = smoothstep(0.0, 1.0, 1.0 - ((centerToPixel - uObjectFadeStart) / (uObjectFadeEnd - uObjectFadeStart)));\n"
-    " float fadeToEdgesScale = fadeToEdges.x * fadeToEdges.y * uAlphaScale;\n" // apply global scaler
-    " fadeToEdgesScale = mix(1.0, fadeToEdgesScale, vSpeed);\n"                // fade proportional to speed, so opaque when at rest
-
-    // standard actor texel
-    " vec4 colActor = texture2D(sTexture, vTexCoord);\n"
-    " gl_FragColor = colActor;\n"
-    " gl_FragColor.a *= fadeToEdgesScale;\n" // fade actor to its edges based on speed of motion
-    " gl_FragColor *= uColor;\n"
-    "}";
-
-  Property::Map map;
-
-  Property::Map customShader;
-  customShader[Visual::Shader::Property::VERTEX_SHADER]   = vertexSource;
-  customShader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentSource;
-
-  customShader[Visual::Shader::Property::SUBDIVIDE_GRID_X] = 10;
-  customShader[Visual::Shader::Property::SUBDIVIDE_GRID_Y] = 10;
-
-  customShader[Visual::Shader::Property::HINTS] = Shader::Hint::OUTPUT_IS_TRANSPARENT;
-
-  map[Toolkit::Visual::Property::SHADER] = customShader;
-  return map;
-}
+DALI_TOOLKIT_API Property::Map CreateMotionStretchEffect();
 
 } // namespace Toolkit
 
 
 } // namespace Toolkit