[Bf-blender-cvs] [46d0e93b547] greasepencil-object: GPencil: Opti: Merge AntiAliasing pass with compositing pass

Clément Foucault noreply at git.blender.org
Thu Feb 13 21:09:01 CET 2020


Commit: 46d0e93b5474e12eb8244fcceac15771ac7131c3
Author: Clément Foucault
Date:   Thu Feb 13 20:40:27 2020 +0100
Branches: greasepencil-object
https://developer.blender.org/rB46d0e93b5474e12eb8244fcceac15771ac7131c3

GPencil: Opti: Merge AntiAliasing pass with compositing pass

This avoid a useless memory write operation.

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

M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/gpencil/gpencil_antialiasing.c
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_shader.c
M	source/blender/draw/engines/gpencil/gpencil_shader_fx.c
M	source/blender/draw/engines/gpencil/shaders/gpencil_antialiasing_frag.glsl
D	source/blender/draw/engines/gpencil/shaders/gpencil_composite_frag.glsl

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

diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index e76d58bef90..c03b2cf46ba 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -283,7 +283,6 @@ data_to_c_simple(engines/gpencil/shaders/gpencil_vert.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_antialiasing_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_antialiasing_vert.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_common_lib.glsl SRC)
-data_to_c_simple(engines/gpencil/shaders/gpencil_composite_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_layer_blend_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_mask_invert_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_depth_merge_frag.glsl SRC)
diff --git a/source/blender/draw/engines/gpencil/gpencil_antialiasing.c b/source/blender/draw/engines/gpencil/gpencil_antialiasing.c
index f53746b922b..e81073db4a5 100644
--- a/source/blender/draw/engines/gpencil/gpencil_antialiasing.c
+++ b/source/blender/draw/engines/gpencil/gpencil_antialiasing.c
@@ -34,8 +34,26 @@ void GPENCIL_antialiasing_init(struct GPENCIL_Data *vedata)
   GPENCIL_PassList *psl = vedata->psl;
   DRWShadingGroup *grp;
 
-  /* We need a temporary buffer to output result. */
-  BLI_assert(pd->color_layer_tx && pd->reveal_layer_tx);
+  const float *size = DRW_viewport_size_get();
+  const float *sizeinv = DRW_viewport_invert_size_get();
+  float metrics[4] = {sizeinv[0], sizeinv[1], size[0], size[1]};
+
+  if (pd->simplify_antialias) {
+    /* No AA fallback. */
+    DRW_PASS_CREATE(psl->smaa_resolve_ps, DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_CUSTOM);
+
+    GPUShader *sh = GPENCIL_shader_antialiasing(2);
+    grp = DRW_shgroup_create(sh, psl->smaa_resolve_ps);
+    DRW_shgroup_uniform_texture(grp, "blendTex", pd->color_tx);
+    DRW_shgroup_uniform_texture(grp, "colorTex", pd->color_tx);
+    DRW_shgroup_uniform_texture(grp, "revealTex", pd->reveal_tx);
+    DRW_shgroup_uniform_bool_copy(grp, "doAntiAliasing", false);
+    DRW_shgroup_uniform_bool_copy(grp, "onlyAlpha", pd->draw_wireframe);
+    DRW_shgroup_uniform_vec4_copy(grp, "viewportMetrics", metrics);
+
+    DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
+    return;
+  }
 
   if (txl->smaa_search_tx == NULL) {
     txl->smaa_search_tx = GPU_texture_create_nD(SEARCHTEX_WIDTH,
@@ -69,9 +87,6 @@ void GPENCIL_antialiasing_init(struct GPENCIL_Data *vedata)
     GPU_texture_unbind(txl->smaa_area_tx);
   }
 
-  const float *size = DRW_viewport_size_get();
-  float metrics[4] = {1.0f / size[0], 1.0f / size[1], size[0], size[1]};
-
   {
     pd->smaa_edge_tx = DRW_texture_pool_query_2d(
         size[0], size[1], GPU_RG8, &draw_engine_gpencil_type);
@@ -120,14 +135,15 @@ void GPENCIL_antialiasing_init(struct GPENCIL_Data *vedata)
   }
   {
     /* Stage 3: Resolve. */
-    /* TODO merge it with the main composite pass. */
-    DRW_PASS_CREATE(psl->smaa_resolve_ps, DRW_STATE_WRITE_COLOR);
+    DRW_PASS_CREATE(psl->smaa_resolve_ps, DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_CUSTOM);
 
     GPUShader *sh = GPENCIL_shader_antialiasing(2);
     grp = DRW_shgroup_create(sh, psl->smaa_resolve_ps);
     DRW_shgroup_uniform_texture(grp, "blendTex", pd->smaa_weight_tx);
     DRW_shgroup_uniform_texture(grp, "colorTex", pd->color_tx);
     DRW_shgroup_uniform_texture(grp, "revealTex", pd->reveal_tx);
+    DRW_shgroup_uniform_bool_copy(grp, "doAntiAliasing", true);
+    DRW_shgroup_uniform_bool_copy(grp, "onlyAlpha", pd->draw_wireframe);
     DRW_shgroup_uniform_vec4_copy(grp, "viewportMetrics", metrics);
 
     DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
@@ -140,16 +156,14 @@ void GPENCIL_antialiasing_draw(struct GPENCIL_Data *vedata)
   GPENCIL_PrivateData *pd = vedata->stl->pd;
   GPENCIL_PassList *psl = vedata->psl;
 
-  GPU_framebuffer_bind(fbl->smaa_edge_fb);
-  DRW_draw_pass(psl->smaa_edge_ps);
+  if (!pd->simplify_antialias) {
+    GPU_framebuffer_bind(fbl->smaa_edge_fb);
+    DRW_draw_pass(psl->smaa_edge_ps);
 
-  GPU_framebuffer_bind(fbl->smaa_weight_fb);
-  DRW_draw_pass(psl->smaa_weight_ps);
+    GPU_framebuffer_bind(fbl->smaa_weight_fb);
+    DRW_draw_pass(psl->smaa_weight_ps);
+  }
 
-  GPU_framebuffer_bind(fbl->layer_fb);
+  GPU_framebuffer_bind(pd->scene_fb);
   DRW_draw_pass(psl->smaa_resolve_ps);
-
-  /* Swap buffers */
-  SWAP(GPUTexture *, pd->color_tx, pd->color_layer_tx);
-  SWAP(GPUTexture *, pd->reveal_tx, pd->reveal_layer_tx);
 }
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index b4fa194b98d..ba2c33ebe3f 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -189,8 +189,7 @@ void GPENCIL_cache_init(void *ved)
   const DRWContextState *draw_ctx = DRW_context_state_get();
   pd->cfra = (int)DEG_get_ctime(draw_ctx->depsgraph);
   pd->simplify_antialias = GPENCIL_SIMPLIFY_AA(draw_ctx->scene);
-  /* Antialiasing needs the layer buffer to output to. */
-  pd->use_layer_fb = false || !pd->simplify_antialias;
+  pd->use_layer_fb = false;
   pd->use_object_fb = false;
   pd->use_mask_fb = false;
   pd->use_signed_fb = false;
@@ -273,17 +272,6 @@ void GPENCIL_cache_init(void *ved)
     DRW_TEXTURE_FREE_SAFE(txl->snapshot_reveal_tx);
   }
 
-  {
-    DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_CUSTOM;
-    DRW_PASS_CREATE(psl->composite_ps, state);
-
-    GPUShader *sh = GPENCIL_shader_composite_get();
-    grp = DRW_shgroup_create(sh, psl->composite_ps);
-    DRW_shgroup_uniform_texture_ref(grp, "colorBuf", &pd->color_tx);
-    DRW_shgroup_uniform_texture_ref(grp, "revealBuf", &pd->reveal_tx);
-    DRW_shgroup_uniform_bool_copy(grp, "onlyAlpha", pd->draw_wireframe);
-    DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
-  }
   {
     DRWState state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
     DRW_PASS_CREATE(psl->merge_depth_ps, state);
@@ -728,9 +716,7 @@ void GPENCIL_cache_finish(void *ved)
                                     });
     }
 
-    if (!pd->simplify_antialias) {
-      GPENCIL_antialiasing_init(vedata);
-    }
+    GPENCIL_antialiasing_init(vedata);
   }
 }
 
@@ -901,7 +887,6 @@ static void GPENCIL_fast_draw_end(GPENCIL_Data *vedata)
 void GPENCIL_draw_scene(void *ved)
 {
   GPENCIL_Data *vedata = (GPENCIL_Data *)ved;
-  GPENCIL_PassList *psl = vedata->psl;
   GPENCIL_PrivateData *pd = vedata->stl->pd;
   GPENCIL_FramebufferList *fbl = vedata->fbl;
   float clear_cols[2][4] = {{0.0f, 0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}};
@@ -937,13 +922,8 @@ void GPENCIL_draw_scene(void *ved)
     GPENCIL_fast_draw_end(vedata);
   }
 
-  if (!pd->simplify_antialias) {
-    GPENCIL_antialiasing_draw(vedata);
-  }
-
   if (pd->scene_fb) {
-    GPU_framebuffer_bind(pd->scene_fb);
-    DRW_draw_pass(psl->composite_ps);
+    GPENCIL_antialiasing_draw(vedata);
   }
 
   pd->gp_object_pool = pd->gp_layer_pool = pd->gp_vfx_pool = pd->gp_maskbit_pool = NULL;
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader.c b/source/blender/draw/engines/gpencil/gpencil_shader.c
index 1cd1ffca333..523ede9428d 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader.c
@@ -28,7 +28,6 @@ extern char datatoc_gpencil_frag_glsl[];
 extern char datatoc_gpencil_vert_glsl[];
 extern char datatoc_gpencil_antialiasing_frag_glsl[];
 extern char datatoc_gpencil_antialiasing_vert_glsl[];
-extern char datatoc_gpencil_composite_frag_glsl[];
 extern char datatoc_gpencil_layer_blend_frag_glsl[];
 extern char datatoc_gpencil_mask_invert_frag_glsl[];
 extern char datatoc_gpencil_depth_merge_frag_glsl[];
@@ -156,15 +155,6 @@ GPUShader *GPENCIL_shader_geometry_get(void)
   return g_shaders.gpencil_sh;
 }
 
-GPUShader *GPENCIL_shader_composite_get(void)
-{
-  if (!g_shaders.composite_sh) {
-    g_shaders.composite_sh = DRW_shader_create_fullscreen(datatoc_gpencil_composite_frag_glsl,
-                                                          NULL);
-  }
-  return g_shaders.composite_sh;
-}
-
 GPUShader *GPENCIL_shader_layer_blend_get(void)
 {
   if (!g_shaders.layer_blend_sh) {
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
index 6e1eb4bfc47..5087f9ec885 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
@@ -617,5 +617,6 @@ void gpencil_vfx_cache_populate(GPENCIL_Data *vedata, Object *ob, GPENCIL_tObjec
     DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
 
     pd->use_object_fb = true;
+    pd->use_layer_fb = true;
   }
 }
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_antialiasing_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_antialiasing_frag.glsl
index cdcd978015c..b512b54e392 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_antialiasing_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_antialiasing_frag.glsl
@@ -5,6 +5,8 @@ uniform sampler2D searchTex;
 uniform sampler2D blendTex;
 uniform sampler2D colorTex;
 uniform sampler2D revealTex;
+uniform bool onlyAlpha;
+uniform bool doAntiAliasing;
 
 in vec2 uvs;
 in vec2 pixcoord;
@@ -15,8 +17,9 @@ out vec2 fragColor;
 #elif SMAA_STAGE == 1
 out vec4 fragColor;
 #elif SMAA_STAGE == 2
-layout(location = 0) out vec4 outColor;
-layout(location = 1) out vec4 outReveal;
+/* Reminder: Blending func is fragRevealage * DST + fragColor .*/
+layout(location = 0, index = 0) out vec4 outColor;
+layout(location = 0, index = 1) out vec4 outReveal;
 #endif
 
 void main()
@@ -36,8 +39,26 @@ void main()
 
 #elif SMAA_STAGE == 2
   /* Resolve both buffers. */
-  outColor = SMAANeighborhoodBlendingPS(uvs, offset[0], colorTex, blendTex);
-  outReveal = SMAANeighborhoodBlendingPS(uvs, offset[0], revealTex, blendTex);
+  if (doAntiAliasing) {
+    outColor = SMAANeighborhoodBlendingPS(uvs, offset[0], colorTex, blendTex);
+    outReveal = SMAANeighborhoodBlendingPS(uvs, offset[0], revealTex, blendTex);
+  }
+  else {
+    outColor = texture(colorTex, uvs);
+    outReveal = texture(reve

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list