[Bf-blender-cvs] [5356c90a46e] master: Overlay Engine: Outlines: Bypass antialias path when not needed

Clément Foucault noreply at git.blender.org
Thu Dec 5 11:29:11 CET 2019


Commit: 5356c90a46ef14262ec97b4479e2888894e25628
Author: Clément Foucault
Date:   Thu Dec 5 11:57:51 2019 +0100
Branches: master
https://developer.blender.org/rB5356c90a46ef14262ec97b4479e2888894e25628

Overlay Engine: Outlines: Bypass antialias path when not needed

Improve performance on low end hardware.

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

M	source/blender/draw/engines/overlay/overlay_outline.c
M	source/blender/draw/engines/overlay/shaders/outline_detect_frag.glsl

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

diff --git a/source/blender/draw/engines/overlay/overlay_outline.c b/source/blender/draw/engines/overlay/overlay_outline.c
index bfef682568f..0d89471c90c 100644
--- a/source/blender/draw/engines/overlay/overlay_outline.c
+++ b/source/blender/draw/engines/overlay/overlay_outline.c
@@ -97,6 +97,7 @@ void OVERLAY_outline_cache_init(OVERLAY_Data *vedata)
     /* Don't occlude the "outline" detection pass if in xray mode (too much flickering). */
     DRW_shgroup_uniform_float_copy(grp, "alphaOcclu", (pd->xray_enabled) ? 1.0f : 0.125f);
     DRW_shgroup_uniform_bool_copy(grp, "doThickOutlines", do_expand);
+    DRW_shgroup_uniform_bool_copy(grp, "doAntiAliasing", pd->antialiasing.enabled);
     DRW_shgroup_uniform_bool_copy(grp, "isXrayWires", pd->xray_enabled_and_not_wire);
     DRW_shgroup_uniform_texture_ref(grp, "outlineId", &txl->outlines_id_tx);
     DRW_shgroup_uniform_texture_ref(grp, "sceneDepth", &dtxl->depth);
diff --git a/source/blender/draw/engines/overlay/shaders/outline_detect_frag.glsl b/source/blender/draw/engines/overlay/shaders/outline_detect_frag.glsl
index 6b4d424c700..dea053a7c8a 100644
--- a/source/blender/draw/engines/overlay/shaders/outline_detect_frag.glsl
+++ b/source/blender/draw/engines/overlay/shaders/outline_detect_frag.glsl
@@ -1,6 +1,7 @@
 
 uniform float alphaOcclu;
 uniform bool isXrayWires;
+uniform bool doAntiAliasing;
 uniform bool doThickOutlines;
 uniform usampler2D outlineId;
 uniform sampler2D outlineDepth;
@@ -11,10 +12,10 @@ in vec4 uvcoordsvar;
 layout(location = 0) out vec4 fragColor;
 layout(location = 1) out vec4 lineOutput;
 
-#define XPOS 1
-#define XNEG 2
-#define YPOS 4
-#define YNEG 8
+#define XPOS (1 << 0)
+#define XNEG (1 << 1)
+#define YPOS (1 << 2)
+#define YNEG (1 << 3)
 
 #define ALL (XPOS | XNEG | YPOS | YNEG)
 #define NONE 0
@@ -234,17 +235,26 @@ void main()
   /* NOTE: We never set alpha to 1.0 to avoid Antialiasing destroying the line. */
   fragColor *= (occluded) ? alphaOcclu : (254.0 / 255.0);
 
-  float edge_case = 0.0;
-  edge_case += float(has_edge_pos_x) * 1.0;
-  edge_case += float(has_edge_neg_x) * 2.0;
-  edge_case += float(has_edge_pos_y) * 4.0;
-  edge_case += float(has_edge_neg_y) * 8.0;
+  int edge_case = 0;
+  edge_case += int(has_edge_pos_x) * XPOS;
+  edge_case += int(has_edge_neg_x) * XNEG;
+  edge_case += int(has_edge_pos_y) * YPOS;
+  edge_case += int(has_edge_neg_y) * YNEG;
+
+  if (edge_case == ALL || edge_case == NONE) {
+    discard;
+  }
+
+  if (!doAntiAliasing) {
+    lineOutput = vec4(0.0);
+    return;
+  }
 
   vec2 line_start, line_end;
   vec2 line_ofs;
   bvec4 extra_edges, extra_edges2;
   /* TODO simplify this branching hell. */
-  switch (int(edge_case)) {
+  switch (edge_case) {
       /* Straight lines. */
     case YPOS:
       extra_edges = gather_edges(uvs + sizeViewportInv.xy * vec2(2.5, 0.5), ref);
@@ -318,7 +328,7 @@ void main()
       line_end = vec2(0.0, 0.5);
       break;
     default:
-      discard;
+      break;
   }
 
   lineOutput = pack_line_data(vec2(0.0), line_start, line_end);



More information about the Bf-blender-cvs mailing list