[Bf-blender-cvs] [f417787ee11] blender-v2.82-release: Gizmo: draw dial arc only over one rotation to avoid artifacts

David noreply at git.blender.org
Fri Jan 17 17:09:08 CET 2020


Commit: f417787ee116f25889f853a98319d4e351edb3b5
Author: David
Date:   Sat Jan 18 03:03:58 2020 +1100
Branches: blender-v2.82-release
https://developer.blender.org/rBf417787ee116f25889f853a98319d4e351edb3b5

Gizmo: draw dial arc only over one rotation to avoid artifacts

There were some visual artifacts when the spin gizmo had a rotation
greater than 360 degrees.

Avoids this by drawing the arc over the span of one rotation only
and adjusting the background color based on the rotation count.

===================================================================

M	source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c

===================================================================

diff --git a/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c
index 25a066ae36b..6dc81e26bf1 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c
@@ -235,7 +235,7 @@ static void dial_ghostarc_draw_incremental_angle(const float incremental_angle,
 }
 
 static void dial_ghostarc_draw(const float angle_ofs,
-                               const float angle_delta,
+                               float angle_delta,
                                const float arc_inner_factor,
                                const float color[4])
 {
@@ -244,21 +244,36 @@ static void dial_ghostarc_draw(const float angle_ofs,
   uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
   immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
 
+  /* Avoid artifacts by drawing the main arc over the span of one rotation only. */
+  const float pi2 = (float)(M_PI * 2.0);
+  int rotation_count = (int)floorf(fabsf(angle_delta) / pi2);
+  angle_delta = fmod(angle_delta, pi2);
+
+  /* Calculate the remaining angle that can be filled with the background color. */
+  const float angle_background = angle_delta >= 0 ? (pi2 - angle_delta) : -(pi2 + angle_delta);
+
+  float color_background[4] = {0};
   if (arc_inner_factor != 0.0) {
-    float color_dark[4] = {0};
-    color_dark[3] = color[3] / 2;
-    immUniformColor4fv(color_dark);
-    imm_draw_disk_partial_fill_2d(pos,
-                                  0,
-                                  0,
-                                  arc_inner_factor,
-                                  width_inner,
-                                  DIAL_RESOLUTION,
-                                  RAD2DEGF(angle_ofs),
-                                  RAD2DEGF(M_PI * 2));
+    color_background[3] = color[3] / 2.0f;
   }
 
-  immUniformColor4fv(color);
+  if (rotation_count != 0) {
+    /* Calculate the background color to visualize the rotation count. */
+    copy_v4_v4(color_background, color);
+    color_background[3] = color[3] * rotation_count;
+  }
+
+  immUniformColor4fv(color_background);
+  imm_draw_disk_partial_fill_2d(pos,
+                                0,
+                                0,
+                                arc_inner_factor,
+                                width_inner,
+                                DIAL_RESOLUTION,
+                                RAD2DEGF(angle_ofs + angle_delta),
+                                RAD2DEGF(angle_background));
+
+  immUniformColor4f(UNPACK3(color), color[3] * (rotation_count + 1));
   imm_draw_disk_partial_fill_2d(pos,
                                 0,
                                 0,



More information about the Bf-blender-cvs mailing list