[Bf-blender-cvs] [ed4b0321553] master: UI: Improve node drop shadow

Leon Schittek noreply at git.blender.org
Fri Feb 11 18:53:09 CET 2022


Commit: ed4b03215533e601a7a47bc949aae7e49d53e5b7
Author: Leon Schittek
Date:   Fri Feb 11 11:52:56 2022 -0600
Branches: master
https://developer.blender.org/rBed4b03215533e601a7a47bc949aae7e49d53e5b7

UI: Improve node drop shadow

Improve the nodes' drop shadow by making it scale with the view
and replace the loop for the alpha calculation with something more
explicit.

The amount of drop shadow softness was scaled with the zoom level
and therefore had a fixed screen space size. DPI and UI scale
weren't taken into account either. This patch fixes both issues by
basing the shadow softness on the `widget_unit` that scales correctly
in zoomable views and takes UI scale etc. into account.

Differential Revision: https://developer.blender.org/D13356

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

M	source/blender/editors/interface/interface_draw.c

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

diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c
index 23ae8915e93..9a51aa5cb9d 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -2293,54 +2293,29 @@ void UI_draw_box_shadow(const rctf *rect, uchar alpha)
 void ui_draw_dropshadow(
     const rctf *rct, float radius, float aspect, float alpha, int UNUSED(select))
 {
-  float rad;
+  const float max_radius = (BLI_rctf_size_y(rct) - 10.0f) * 0.5f;
+  const float rad = min_ff(radius, max_radius);
 
-  if (radius > (BLI_rctf_size_y(rct) - 10.0f) * 0.5f) {
-    rad = (BLI_rctf_size_y(rct) - 10.0f) * 0.5f;
-  }
-  else {
-    rad = radius;
-  }
+  /* This undoes the scale of the view for higher zoom factors to clamp the shadow size. */
+  const float clamped_aspect = smoothminf(aspect, 1.0f, 0.5f);
 
-  int a, i = 12;
-#if 0
-  if (select) {
-    a = i * aspect; /* same as below */
-  }
-  else
-#endif
-  {
-    a = i * aspect;
-  }
+  const float shadow_softness = 0.6f * U.widget_unit * clamped_aspect;
+  const float shadow_offset = 0.5f * U.widget_unit * clamped_aspect;
+  const float shadow_alpha = 0.5f * alpha;
 
   GPU_blend(GPU_BLEND_ALPHA);
-  const float dalpha = alpha * 2.0f / 255.0f;
-  float calpha = dalpha;
-  float visibility = 1.0f;
-  for (; i--;) {
-    /* alpha ranges from 2 to 20 or so */
-#if 0 /* Old Method (pre 2.8) */
-    float color[4] = {0.0f, 0.0f, 0.0f, calpha};
-    UI_draw_roundbox_4fv(
-        true, rct->xmin - a, rct->ymin - a, rct->xmax + a, rct->ymax - 10.0f + a, rad + a, color);
-#endif
-    /* Compute final visibility to match old method result. */
-    /* TODO: we could just find a better fit function inside the shader instead of this. */
-    visibility = visibility * (1.0f - calpha);
-    calpha += dalpha;
-  }
 
   uiWidgetBaseParameters widget_params = {
       .recti.xmin = rct->xmin,
       .recti.ymin = rct->ymin,
       .recti.xmax = rct->xmax,
-      .recti.ymax = rct->ymax - 10.0f,
-      .rect.xmin = rct->xmin - a,
-      .rect.ymin = rct->ymin - a,
-      .rect.xmax = rct->xmax + a,
-      .rect.ymax = rct->ymax - 10.0f + a,
+      .recti.ymax = rct->ymax - shadow_offset,
+      .rect.xmin = rct->xmin - shadow_softness,
+      .rect.ymin = rct->ymin - shadow_softness,
+      .rect.xmax = rct->xmax + shadow_softness,
+      .rect.ymax = rct->ymax - shadow_offset + shadow_softness,
       .radi = rad,
-      .rad = rad + a,
+      .rad = rad + shadow_softness,
       .round_corners[0] = (roundboxtype & UI_CNR_BOTTOM_LEFT) ? 1.0f : 0.0f,
       .round_corners[1] = (roundboxtype & UI_CNR_BOTTOM_RIGHT) ? 1.0f : 0.0f,
       .round_corners[2] = (roundboxtype & UI_CNR_TOP_RIGHT) ? 1.0f : 0.0f,
@@ -2351,7 +2326,7 @@ void ui_draw_dropshadow(
   GPUBatch *batch = ui_batch_roundbox_shadow_get();
   GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_SHADOW);
   GPU_batch_uniform_4fv_array(batch, "parameters", 4, (const float(*)[4]) & widget_params);
-  GPU_batch_uniform_1f(batch, "alpha", 1.0f - visibility);
+  GPU_batch_uniform_1f(batch, "alpha", shadow_alpha);
   GPU_batch_draw(batch);
 
   /* outline emphasis */



More information about the Bf-blender-cvs mailing list