Minor optimize for render effect shader (2) 53/317153/7
authorEunki, Hong <eunkiki.hong@samsung.com>
Thu, 5 Sep 2024 01:15:23 +0000 (10:15 +0900)
committerEunki Hong <eunkiki.hong@samsung.com>
Thu, 12 Sep 2024 02:40:42 +0000 (02:40 +0000)
It might not increase performance. We need to test it.

Change-Id: I2c58d3593330774396bb800c686df13a35fceeb4
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali-toolkit/internal/graphics/shaders/render-effect.frag

index b84ee1ff1c4632a966fbde3789b87d35730bf70c..077af761ac2030aecc09633f0e35bb33a7a4bb05 100644 (file)
@@ -23,7 +23,7 @@ vec3 applyDithering( vec3 inColor )
 
 // from https://iquilezles.org/articles/distfunctions
 float roundedBoxSDF(vec2 PixelPositionFromCenter, vec2 RectangleEdgePositionFromCenter, float Radius) {
-    return length(max(abs(PixelPositionFromCenter)
+    return length(max(PixelPositionFromCenter
                       - RectangleEdgePositionFromCenter
                       + Radius
                       , 0.0))
@@ -51,11 +51,23 @@ void main()
       );
 
     float edgeSoftness = min(1.0, radius);
-    float distance = roundedBoxSDF(location, uSize.xy * 0.5, radius);
 
-    float smoothedAlpha = 1.0 - smoothstep(-edgeSoftness, edgeSoftness, distance);
+    highp vec2 halfSize = uSize.xy * 0.5;
+    location = abs(location);
 
-    // Premultiply alpha feature used.
-    gl_FragColor *= smoothedAlpha;
+    // For test, let we just linear function.
+    if(location.x + location.y < halfSize.x + halfSize.y - radius - 2.0 * edgeSoftness)
+    {
+      // Do nothing
+    }
+    else
+    {
+      float distance = roundedBoxSDF(location, halfSize, radius);
+
+      float smoothedAlpha = 1.0 - smoothstep(-edgeSoftness, edgeSoftness, distance);
+
+      // Premultiply alpha feature used.
+      gl_FragColor *= smoothedAlpha;
+    }
   }
 }