From 68188cd284a5fad8f4db394d15c29b734ef5ea1a Mon Sep 17 00:00:00 2001
From: samuel <53528911+samuel-jimenez@users.noreply.github.com>
Date: Wed, 6 Nov 2024 13:58:11 -0600
Subject: [PATCH] Extract shadow mask

---
 package/contents/ui/LunaIcon.qml | 88 ++++++++++++++++++--------------
 src/shadow.frag                  | 13 +++--
 2 files changed, 59 insertions(+), 42 deletions(-)

diff --git a/package/contents/ui/LunaIcon.qml b/package/contents/ui/LunaIcon.qml
index f62fd6a..26d2790 100644
--- a/package/contents/ui/LunaIcon.qml
+++ b/package/contents/ui/LunaIcon.qml
@@ -104,44 +104,6 @@ Item {
 
         }
 
-        Canvas {
-            id: shadow
-
-            property int theta: lunaIcon.theta
-            property bool showShadow: lunaIcon.showShadow
-
-            width: lunaBackground.width
-            height: lunaBackground.height
-            visible: true
-            anchors.centerIn: parent
-            contextType: "2d"
-            onThetaChanged: requestPaint()
-            onShowShadowChanged: requestPaint()
-            onWidthChanged: requestPaint()
-            onPaint: {
-                context.reset();
-                if (showShadow) {
-                    var cosTheta = Math.cos(theta / 180 * Math.PI);
-                    var counterclockwisep = (theta < 180);
-                    context.globalAlpha = 0.9;
-                    context.translate(radius, radius);
-                    if (theta != 180) {
-                        context.beginPath();
-                        context.fillStyle = '#000000';
-                        context.strokeStyle = '#000000';
-                        context.arc(0, 0, radius, -0.5 * Math.PI, 0.5 * Math.PI, counterclockwisep);
-                        if ((theta % 180) != 90) {
-                            context.scale(cosTheta, 1);
-                            context.arc(0, 0, radius, 0.5 * Math.PI, -0.5 * Math.PI, counterclockwisep);
-                        }
-                        context.closePath();
-                        context.fill();
-                        context.stroke();
-                    }
-                }
-            }
-        }
-
         Canvas {
             id: markers
 
@@ -223,6 +185,54 @@ Item {
 
     }
 
+    ShaderEffectSource {
+        id: shadow
+
+        anchors.centerIn: parent
+        width: lunaBackground.width
+        height: lunaBackground.height
+        visible: false
+        antialiasing: false
+
+        sourceItem: Canvas {
+            property int theta: lunaIcon.theta
+            property bool showShadow: lunaIcon.showShadow
+
+            antialiasing: true
+            width: lunaBackground.width
+            height: lunaBackground.height
+            visible: true
+            anchors.centerIn: parent
+            contextType: "2d"
+            onThetaChanged: requestPaint()
+            onShowShadowChanged: requestPaint()
+            onWidthChanged: requestPaint()
+            onPaint: {
+                context.reset();
+                if (showShadow) {
+                    var cosTheta = Math.cos(theta / 180 * Math.PI);
+                    var counterclockwisep = (theta < 180);
+                    context.globalAlpha = 0.9;
+                    context.translate(radius, radius);
+                    if (theta != 180) {
+                        context.beginPath();
+                        context.fillStyle = '#ffffff';
+                        context.strokeStyle = '#ffffff';
+                        context.arc(0, 0, radius, -0.5 * Math.PI, 0.5 * Math.PI, counterclockwisep);
+                        if ((theta % 180) != 90) {
+                            context.scale(cosTheta, 1);
+                            context.arc(0, 0, radius, 0.5 * Math.PI, -0.5 * Math.PI, counterclockwisep);
+                        }
+                        context.closePath();
+                        context.fill();
+                        context.stroke();
+                    }
+                }
+            }
+        }
+
+    }
+
     ShaderEffectSource {
         id: lunaMask
 
@@ -230,6 +240,7 @@ Item {
         width: lunaBackground.width
         height: lunaBackground.height
         visible: false
+        antialiasing: false
 
         sourceItem: Shape {
             opacity: 1
@@ -264,6 +275,7 @@ Item {
         property variant mask: lunaMask
         property int transparent: transparentShadow
 
+        opacity: 1
         rotation: latitude - 90
         visible: true
         antialiasing: true
diff --git a/src/shadow.frag b/src/shadow.frag
index 60b3f89..9f0e5d2 100644
--- a/src/shadow.frag
+++ b/src/shadow.frag
@@ -11,9 +11,14 @@ layout(binding = 1) uniform sampler2D source;
 layout(binding = 2) uniform sampler2D shadow;
 layout(binding = 3) uniform sampler2D mask;
 
-void main() {    fragColor = texture(source, qt_TexCoord0)
-                    * texture(mask, qt_TexCoord0).a
-                    * (1 - texture(shadow, qt_TexCoord0).a * transparent)
-                    * qt_Opacity ;
+void main() {
+    fragColor = vec4(
+        ((1 - transparent)* texture(source, qt_TexCoord0) * (1- texture(shadow, qt_TexCoord0))
+        + transparent * texture(source, qt_TexCoord0)).rgb,
+                     texture(source, qt_TexCoord0).a)
+    * texture(mask, qt_TexCoord0).a
+    * (1 - texture(shadow, qt_TexCoord0).a * transparent)
+    * qt_Opacity ;
 }
 
+
-- 
GitLab