diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2019-12-05 13:57:51 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2019-12-05 13:58:24 +0300 |
commit | 5356c90a46ef14262ec97b4479e2888894e25628 (patch) | |
tree | 1dbfedc1bd4017bcdbdec1a310ce8518d309328a | |
parent | cf77b67c459d481f6d8d34d13e14d22a6cad0842 (diff) |
Overlay Engine: Outlines: Bypass antialias path when not needed
Improve performance on low end hardware.
-rw-r--r-- | source/blender/draw/engines/overlay/overlay_outline.c | 1 | ||||
-rw-r--r-- | source/blender/draw/engines/overlay/shaders/outline_detect_frag.glsl | 32 |
2 files changed, 22 insertions, 11 deletions
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); |