[Bf-blender-cvs] [6d3eb85f66a] master: Overlay Engine: Simplify outline rendering by using the antialiasing pass

Clément Foucault noreply at git.blender.org
Thu Dec 5 00:44:09 CET 2019


Commit: 6d3eb85f66ae93d9d4859ef3264f1a1b2ae4fa36
Author: Clément Foucault
Date:   Wed Dec 4 01:31:36 2019 +0100
Branches: master
https://developer.blender.org/rB6d3eb85f66ae93d9d4859ef3264f1a1b2ae4fa36

Overlay Engine: Simplify outline rendering by using the antialiasing pass

This use the overlay AA pass to antialias the selection outlines.

This also do all search and expand in one pass and reduce the computation
time and memory used (2 x 32bit/pixel buffer less).

Note that the aliasing is a bit worse than the old FXAA that we used to have.

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

M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/overlay/overlay_antialiasing.c
M	source/blender/draw/engines/overlay/overlay_engine.c
M	source/blender/draw/engines/overlay/overlay_outline.c
M	source/blender/draw/engines/overlay/overlay_private.h
M	source/blender/draw/engines/overlay/overlay_shader.c
M	source/blender/draw/engines/overlay/shaders/antialiasing_frag.glsl
M	source/blender/draw/engines/overlay/shaders/outline_detect_frag.glsl
D	source/blender/draw/engines/overlay/shaders/outline_expand_frag.glsl
D	source/blender/draw/engines/overlay/shaders/outline_resolve_frag.glsl

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

diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index ea52d8e8f1f..88caafb0c00 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -360,12 +360,10 @@ data_to_c_simple(engines/overlay/shaders/motion_path_line_geom.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/motion_path_line_vert.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/motion_path_point_vert.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/outline_detect_frag.glsl SRC)
-data_to_c_simple(engines/overlay/shaders/outline_expand_frag.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/outline_prepass_frag.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/outline_prepass_geom.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/outline_prepass_vert.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/outline_lightprobe_grid_vert.glsl SRC)
-data_to_c_simple(engines/overlay/shaders/outline_resolve_frag.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/paint_face_vert.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/paint_point_vert.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/paint_texture_frag.glsl SRC)
diff --git a/source/blender/draw/engines/overlay/overlay_antialiasing.c b/source/blender/draw/engines/overlay/overlay_antialiasing.c
index 569d47bf3a2..8f357d37768 100644
--- a/source/blender/draw/engines/overlay/overlay_antialiasing.c
+++ b/source/blender/draw/engines/overlay/overlay_antialiasing.c
@@ -60,12 +60,6 @@
 
 #include "overlay_private.h"
 
-void OVERLAY_antialiasing_reset(OVERLAY_Data *vedata)
-{
-  OVERLAY_PrivateData *pd = vedata->stl->pd;
-  pd->antialiasing.sample = 0;
-}
-
 void OVERLAY_antialiasing_init(OVERLAY_Data *vedata)
 {
   OVERLAY_FramebufferList *fbl = vedata->fbl;
diff --git a/source/blender/draw/engines/overlay/overlay_engine.c b/source/blender/draw/engines/overlay/overlay_engine.c
index e83a5c04eaf..24e2c4441e3 100644
--- a/source/blender/draw/engines/overlay/overlay_engine.c
+++ b/source/blender/draw/engines/overlay/overlay_engine.c
@@ -50,37 +50,27 @@ static void OVERLAY_engine_init(void *vedata)
   }
 
   OVERLAY_PrivateData *pd = stl->pd;
-  View3DOverlay overlay;
-  short v3d_flag, v3d_gridflag;
 
   pd->hide_overlays = (v3d->flag2 & V3D_HIDE_OVERLAYS) != 0;
   pd->ctx_mode = CTX_data_mode_enum_ex(
       draw_ctx->object_edit, draw_ctx->obact, draw_ctx->object_mode);
 
   if (!pd->hide_overlays) {
-    overlay = v3d->overlay;
-    v3d_flag = v3d->flag;
-    v3d_gridflag = v3d->gridflag;
+    pd->overlay = v3d->overlay;
+    pd->v3d_flag = v3d->flag;
+    pd->v3d_gridflag = v3d->gridflag;
   }
   else {
-    memset(&overlay, 0, sizeof(overlay));
-    v3d_flag = 0;
-    v3d_gridflag = 0;
-    overlay.flag = V3D_OVERLAY_HIDE_TEXT | V3D_OVERLAY_HIDE_MOTION_PATHS | V3D_OVERLAY_HIDE_BONES |
-                   V3D_OVERLAY_HIDE_OBJECT_XTRAS | V3D_OVERLAY_HIDE_OBJECT_ORIGINS;
+    memset(&pd->overlay, 0, sizeof(pd->overlay));
+    pd->v3d_flag = 0;
+    pd->v3d_gridflag = 0;
+    pd->overlay.flag = V3D_OVERLAY_HIDE_TEXT | V3D_OVERLAY_HIDE_MOTION_PATHS |
+                       V3D_OVERLAY_HIDE_BONES | V3D_OVERLAY_HIDE_OBJECT_XTRAS |
+                       V3D_OVERLAY_HIDE_OBJECT_ORIGINS;
   }
 
   if (v3d->shading.type == OB_WIRE) {
-    overlay.flag |= V3D_OVERLAY_WIREFRAMES;
-  }
-
-  /* Check if anything changed, and if so, reset AA. */
-  if (v3d_flag != pd->v3d_flag || pd->v3d_gridflag != v3d_gridflag ||
-      memcmp(&pd->overlay, &overlay, sizeof(overlay))) {
-    pd->overlay = overlay;
-    pd->v3d_flag = v3d_flag;
-    pd->v3d_gridflag = v3d_gridflag;
-    OVERLAY_antialiasing_reset(vedata);
+    pd->overlay.flag |= V3D_OVERLAY_WIREFRAMES;
   }
 
   pd->wireframe_mode = (v3d->shading.type == OB_WIRE);
@@ -376,6 +366,9 @@ static void OVERLAY_draw_scene(void *vedata)
 
   OVERLAY_antialiasing_start(vedata);
 
+  DRW_view_set_active(NULL);
+  OVERLAY_outline_draw(vedata);
+
   DRW_view_set_active(pd->view_default);
 
   OVERLAY_image_draw(vedata);
@@ -387,9 +380,7 @@ static void OVERLAY_draw_scene(void *vedata)
   OVERLAY_extra_draw(vedata);
 
   DRW_view_set_active(NULL);
-
   OVERLAY_grid_draw(vedata);
-  OVERLAY_outline_draw(vedata);
 
   DRW_view_set_active(pd->view_default);
 
diff --git a/source/blender/draw/engines/overlay/overlay_outline.c b/source/blender/draw/engines/overlay/overlay_outline.c
index cb5344630c3..706dcc95288 100644
--- a/source/blender/draw/engines/overlay/overlay_outline.c
+++ b/source/blender/draw/engines/overlay/overlay_outline.c
@@ -32,23 +32,28 @@ void OVERLAY_outline_init(OVERLAY_Data *vedata)
 {
   OVERLAY_FramebufferList *fbl = vedata->fbl;
   OVERLAY_TextureList *txl = vedata->txl;
+  OVERLAY_PrivateData *pd = vedata->stl->pd;
+  DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
 
   if (DRW_state_is_fbo()) {
     /* TODO only alloc if needed. */
-    /* XXX TODO GPU_R16UI can overflow, it would cause no harm
-     * (only bad colored or missing outlines) but we should
-     * use 32bits only if the scene have that many objects */
     DRW_texture_ensure_fullscreen_2d(&txl->temp_depth_tx, GPU_DEPTH24_STENCIL8, 0);
     DRW_texture_ensure_fullscreen_2d(&txl->outlines_id_tx, GPU_R16UI, 0);
+
     GPU_framebuffer_ensure_config(
         &fbl->outlines_prepass_fb,
         {GPU_ATTACHMENT_TEXTURE(txl->temp_depth_tx), GPU_ATTACHMENT_TEXTURE(txl->outlines_id_tx)});
 
-    for (int i = 0; i < 2; i++) {
-      DRW_texture_ensure_fullscreen_2d(&txl->outlines_color_tx[i], GPU_RGBA8, DRW_TEX_FILTER);
+    if (pd->antialiasing.enabled) {
+      GPU_framebuffer_ensure_config(&fbl->outlines_resolve_fb,
+                                    {GPU_ATTACHMENT_NONE,
+                                     GPU_ATTACHMENT_TEXTURE(txl->overlay_color_tx),
+                                     GPU_ATTACHMENT_TEXTURE(txl->overlay_line_tx)});
+    }
+    else {
       GPU_framebuffer_ensure_config(
-          &fbl->outlines_process_fb[i],
-          {GPU_ATTACHMENT_NONE, GPU_ATTACHMENT_TEXTURE(txl->outlines_color_tx[i])});
+          &fbl->outlines_resolve_fb,
+          {GPU_ATTACHMENT_TEXTURE(txl->temp_depth_tx), GPU_ATTACHMENT_TEXTURE(dtxl->color)});
     }
   }
 }
@@ -133,9 +138,8 @@ void OVERLAY_outline_cache_init(OVERLAY_Data *vedata)
   DRWShadingGroup *grp = NULL;
 
   const float outline_width = UI_GetThemeValuef(TH_OUTLINE_WIDTH);
-  const bool do_outline_expand = (U.pixelsize > 1.0) || (outline_width > 2.0f);
-  const bool do_large_expand = ((U.pixelsize > 1.0) && (outline_width > 2.0f)) ||
-                               (outline_width > 4.0f);
+  const bool do_expand = (U.pixelsize > 1.0) || (outline_width > 2.0f);
+
   {
     DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL;
     DRW_PASS_CREATE(psl->outlines_prepass_ps, state | pd->clipping_state);
@@ -164,50 +168,22 @@ void OVERLAY_outline_cache_init(OVERLAY_Data *vedata)
   }
 
   {
-    DRW_PASS_CREATE(psl->outlines_detect_ps, DRW_STATE_WRITE_COLOR);
-    DRW_PASS_CREATE(psl->outlines_expand_ps, DRW_STATE_WRITE_COLOR);
-    DRW_PASS_CREATE(psl->outlines_bleed_ps, DRW_STATE_WRITE_COLOR);
-    DRW_PASS_CREATE(psl->outlines_resolve_ps, DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA);
+    /* We can only do alpha blending with lineOutput just after clearing the buffer. */
+    DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA_PREMUL;
+    DRW_PASS_CREATE(psl->outlines_detect_ps, state);
 
-    GPUShader *sh = OVERLAY_shader_outline_detect(pd->xray_enabled_and_not_wire);
+    GPUShader *sh = OVERLAY_shader_outline_detect();
 
     grp = DRW_shgroup_create(sh, psl->outlines_detect_ps);
     /* 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.35f);
+    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, "isXrayWires", pd->xray_enabled_and_not_wire);
     DRW_shgroup_uniform_texture_ref(grp, "outlineId", &txl->outlines_id_tx);
-    DRW_shgroup_uniform_texture_ref(grp, "outlineDepth", &txl->temp_depth_tx);
     DRW_shgroup_uniform_texture_ref(grp, "sceneDepth", &dtxl->depth);
+    DRW_shgroup_uniform_texture_ref(grp, "outlineDepth", &txl->temp_depth_tx);
     DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
     DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
-
-    if (do_outline_expand) {
-      sh = OVERLAY_shader_outline_expand(do_large_expand);
-      grp = DRW_shgroup_create(sh, psl->outlines_expand_ps);
-      DRW_shgroup_uniform_texture_ref(grp, "outlineColor", &txl->outlines_color_tx[0]);
-      DRW_shgroup_uniform_bool_copy(grp, "doExpand", true);
-      DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
-
-      sh = OVERLAY_shader_outline_expand(false);
-      grp = DRW_shgroup_create(sh, psl->outlines_bleed_ps);
-      DRW_shgroup_uniform_texture_ref(grp, "outlineColor", &txl->outlines_color_tx[1]);
-      DRW_shgroup_uniform_bool_copy(grp, "doExpand", false);
-      DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
-    }
-    else {
-      sh = OVERLAY_shader_outline_expand(false);
-      grp = DRW_shgroup_create(sh, psl->outlines_expand_ps);
-      DRW_shgroup_uniform_texture_ref(grp, "outlineColor", &txl->outlines_color_tx[0]);
-      DRW_shgroup_uniform_bool_copy(grp, "doExpand", false);
-      DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
-    }
-
-    GPUTexture **outline_tx = &txl->outlines_color_tx[do_outline_expand ? 0 : 1];
-    sh = OVERLAY_shader_outline_resolve();
-
-    grp = DRW_shgroup_create(sh, psl->outlines_resolve_ps);
-    DRW_shgroup_uniform_texture_ref(grp, "outlineBluredColor", outline_tx);
-    DRW_shgroup_uniform_vec2_copy(grp, "rcpDimensions", DRW_viewport_invert_size_get());
-    DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
   }
 }
 
@@ -331,25 +307,13 @@ void OVERLAY_outline_draw(OVERLAY_Data *vedata)
 
     /* Render filled polygon on a separate framebuffer */
     GPU_framebuffer_bind(fbl->outlines_prepass_fb);
-    GPU_framebuffer_clear_color_depth(fbl->outlines_prepass_fb, clearcol

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list