[Bf-blender-cvs] [4926e7413d5] tmp-overlay-engine: Overlay Engine: Add SMAA to replace FXAA

Clément Foucault noreply at git.blender.org
Fri Nov 29 15:20:25 CET 2019


Commit: 4926e7413d5b58fba264cdd267586174f8fab816
Author: Clément Foucault
Date:   Fri Nov 29 15:02:03 2019 +0100
Branches: tmp-overlay-engine
https://developer.blender.org/rB4926e7413d5b58fba264cdd267586174f8fab816

Overlay Engine: Add SMAA to replace FXAA

This gets rid of the TAA which needs to be added back

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

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
A	source/blender/draw/engines/overlay/shaders/antialiasing_vert.glsl
A	source/blender/draw/intern/shaders/common_smaa_lib.glsl
A	source/blender/draw/intern/smaa_textures.h

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

diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 13aecba515d..667f56b47b5 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -153,6 +153,7 @@ set(SRC
   intern/draw_manager_profiling.h
   intern/draw_manager_text.h
   intern/draw_view.h
+  intern/smaa_textures.h
   engines/basic/basic_engine.h
   engines/eevee/eevee_engine.h
   engines/eevee/eevee_lightcache.h
@@ -267,6 +268,7 @@ data_to_c_simple(intern/shaders/common_hair_lib.glsl SRC)
 data_to_c_simple(intern/shaders/common_hair_refine_vert.glsl SRC)
 data_to_c_simple(intern/shaders/common_view_lib.glsl SRC)
 data_to_c_simple(intern/shaders/common_fxaa_lib.glsl SRC)
+data_to_c_simple(intern/shaders/common_smaa_lib.glsl SRC)
 data_to_c_simple(intern/shaders/common_fullscreen_vert.glsl SRC)
 
 data_to_c_simple(engines/gpencil/shaders/gpencil_fill_vert.glsl SRC)
@@ -304,6 +306,7 @@ data_to_c_simple(engines/select/shaders/selection_id_3D_vert.glsl SRC)
 data_to_c_simple(engines/select/shaders/selection_id_frag.glsl SRC)
 
 data_to_c_simple(engines/overlay/shaders/antialiasing_frag.glsl SRC)
+data_to_c_simple(engines/overlay/shaders/antialiasing_vert.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/armature_dof_vert.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/armature_envelope_outline_vert.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/armature_envelope_solid_frag.glsl SRC)
diff --git a/source/blender/draw/engines/overlay/overlay_antialiasing.c b/source/blender/draw/engines/overlay/overlay_antialiasing.c
index 28e20d89718..779ec1035a3 100644
--- a/source/blender/draw/engines/overlay/overlay_antialiasing.c
+++ b/source/blender/draw/engines/overlay/overlay_antialiasing.c
@@ -25,6 +25,12 @@
 #include "ED_screen.h"
 
 #include "overlay_private.h"
+#include "smaa_textures.h"
+
+struct {
+  GPUTexture *smaa_search_tx;
+  GPUTexture *smaa_area_tx;
+} e_data = {NULL};
 
 void OVERLAY_antialiasing_reset(OVERLAY_Data *vedata)
 {
@@ -50,6 +56,38 @@ void OVERLAY_antialiasing_init(OVERLAY_Data *vedata)
   pd->antialiasing.enabled = dtxl->multisample_color != NULL;
 
   if (pd->antialiasing.enabled) {
+
+    if (e_data.smaa_search_tx == NULL) {
+      e_data.smaa_search_tx = GPU_texture_create_nD(SEARCHTEX_WIDTH,
+                                                    SEARCHTEX_HEIGHT,
+                                                    0,
+                                                    2,
+                                                    searchTexBytes,
+                                                    GPU_R8,
+                                                    GPU_DATA_UNSIGNED_BYTE,
+                                                    0,
+                                                    false,
+                                                    NULL);
+
+      e_data.smaa_area_tx = GPU_texture_create_nD(AREATEX_WIDTH,
+                                                  AREATEX_HEIGHT,
+                                                  0,
+                                                  2,
+                                                  areaTexBytes,
+                                                  GPU_RG8,
+                                                  GPU_DATA_UNSIGNED_BYTE,
+                                                  0,
+                                                  false,
+                                                  NULL);
+      GPU_texture_bind(e_data.smaa_area_tx, 0);
+      GPU_texture_filter_mode(e_data.smaa_area_tx, true);
+      GPU_texture_unbind(e_data.smaa_area_tx);
+
+      GPU_texture_bind(e_data.smaa_search_tx, 0);
+      GPU_texture_filter_mode(e_data.smaa_search_tx, true);
+      GPU_texture_unbind(e_data.smaa_search_tx);
+    }
+
     pd->antialiasing.target_sample = 4;
 
     bool valid_history = true;
@@ -57,8 +95,11 @@ void OVERLAY_antialiasing_init(OVERLAY_Data *vedata)
       valid_history = false;
     }
 
+    DRW_texture_ensure_fullscreen_2d(&txl->temp_depth_tx, GPU_DEPTH24_STENCIL8, 0);
     DRW_texture_ensure_fullscreen_2d(&txl->overlay_color_tx, GPU_RGBA8, DRW_TEX_FILTER);
     DRW_texture_ensure_fullscreen_2d(&txl->overlay_color_history_tx, GPU_RGBA8, DRW_TEX_FILTER);
+    DRW_texture_ensure_fullscreen_2d(&txl->smaa_edge_tx, GPU_RG8, DRW_TEX_FILTER);
+    DRW_texture_ensure_fullscreen_2d(&txl->smaa_blend_tx, GPU_RGBA8, DRW_TEX_FILTER);
 
     GPU_framebuffer_ensure_config(
         &fbl->overlay_color_only_fb,
@@ -73,6 +114,12 @@ void OVERLAY_antialiasing_init(OVERLAY_Data *vedata)
     GPU_framebuffer_ensure_config(
         &fbl->overlay_color_history_fb,
         {GPU_ATTACHMENT_NONE, GPU_ATTACHMENT_TEXTURE(txl->overlay_color_history_tx)});
+    GPU_framebuffer_ensure_config(
+        &fbl->smaa_edge_fb,
+        {GPU_ATTACHMENT_TEXTURE(txl->temp_depth_tx), GPU_ATTACHMENT_TEXTURE(txl->smaa_edge_tx)});
+    GPU_framebuffer_ensure_config(
+        &fbl->smaa_blend_fb,
+        {GPU_ATTACHMENT_TEXTURE(txl->temp_depth_tx), GPU_ATTACHMENT_TEXTURE(txl->smaa_blend_tx)});
 
     /* Test if we can do TAA */
     if (valid_history) {
@@ -102,7 +149,8 @@ void OVERLAY_antialiasing_init(OVERLAY_Data *vedata)
       /* For nr = 0,we should sample {0, 0} (goes through the FXAA branch). */
       float ofs[2] = {samples_pos[nr][0] / 6.0f, samples_pos[nr][1] / 6.0f};
 
-      window_translate_m4(winmat, persmat, ofs[0] / viewport_size[0], ofs[1] / viewport_size[1]);
+      // window_translate_m4(winmat, persmat, ofs[0] / viewport_size[0], ofs[1] /
+      // viewport_size[1]);
 
       const DRWView *default_view = DRW_view_default_get();
       pd->view_default = DRW_view_create_sub(default_view, viewmat, winmat);
@@ -143,48 +191,33 @@ void OVERLAY_antialiasing_cache_init(OVERLAY_Data *vedata)
   DRWShadingGroup *grp;
 
   if (pd->antialiasing.enabled) {
-    bool do_fxaa = (pd->antialiasing.sample == 0);
-    if (do_fxaa) {
-      DRW_PASS_CREATE(psl->antialiasing_merge_ps,
-                      DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA_UNDER_PREMUL);
-
-      sh = OVERLAY_shader_antialiasing_merge();
-      grp = DRW_shgroup_create(sh, psl->antialiasing_merge_ps);
-      DRW_shgroup_uniform_texture_ref(grp, "srcTexture", &dtxl->color);
-      DRW_shgroup_uniform_float_copy(grp, "alpha", 1.0f);
-      DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
-
-      DRW_PASS_CREATE(psl->antialiasing_ps, DRW_STATE_WRITE_COLOR);
-
-      sh = OVERLAY_shader_antialiasing();
-      grp = DRW_shgroup_create(sh, psl->antialiasing_ps);
-      DRW_shgroup_uniform_texture_ref(grp, "srcTexture", &txl->overlay_color_tx);
-      DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
-    }
-    else {
-      DRW_PASS_CREATE(psl->antialiasing_merge_ps, DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_CUSTOM);
-
-      /* TODO do not even render if not necessary. */
-      float alpha = 0.0f;
-      if (pd->antialiasing.sample <= pd->antialiasing.target_sample) {
-        alpha = 1.0f / (pd->antialiasing.sample + 1);
-      }
-
-      sh = OVERLAY_shader_antialiasing_accum();
-      grp = DRW_shgroup_create(sh, psl->antialiasing_merge_ps);
-      DRW_shgroup_uniform_texture_ref(grp, "srcTexture", &txl->overlay_color_tx);
-      DRW_shgroup_uniform_float_copy(grp, "alpha", alpha);
-      DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
-
-      DRW_PASS_CREATE(psl->antialiasing_ps, DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA_PREMUL);
-
-      /* Reuse merge shader. */
-      sh = OVERLAY_shader_antialiasing_merge();
-      grp = DRW_shgroup_create(sh, psl->antialiasing_ps);
-      DRW_shgroup_uniform_texture_ref(grp, "srcTexture", &txl->overlay_color_history_tx);
-      DRW_shgroup_uniform_float_copy(grp, "alpha", 1.0f);
-      DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
-    }
+    DRW_PASS_CREATE(psl->smaa_edge_detect_ps,
+                    DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_STENCIL | DRW_STATE_STENCIL_ALWAYS);
+    DRW_PASS_CREATE(psl->smaa_blend_weight_ps, DRW_STATE_WRITE_COLOR | DRW_STATE_STENCIL_EQUAL);
+    DRW_PASS_CREATE(psl->smaa_resolve_ps, DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA_PREMUL);
+
+    sh = OVERLAY_shader_antialiasing(0);
+    grp = DRW_shgroup_create(sh, psl->smaa_edge_detect_ps);
+    DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
+    DRW_shgroup_uniform_texture_ref(grp, "colorTex", &txl->overlay_color_tx);
+    DRW_shgroup_stencil_mask(grp, 0xFF);
+    DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
+
+    sh = OVERLAY_shader_antialiasing(1);
+    grp = DRW_shgroup_create(sh, psl->smaa_blend_weight_ps);
+    DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
+    DRW_shgroup_uniform_texture_ref(grp, "edgesTex", &txl->smaa_edge_tx);
+    DRW_shgroup_uniform_texture(grp, "areaTex", e_data.smaa_area_tx);
+    DRW_shgroup_uniform_texture(grp, "searchTex", e_data.smaa_search_tx);
+    DRW_shgroup_stencil_mask(grp, 0xFF);
+    DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
+
+    sh = OVERLAY_shader_antialiasing(2);
+    grp = DRW_shgroup_create(sh, psl->smaa_resolve_ps);
+    DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
+    DRW_shgroup_uniform_texture_ref(grp, "blendTex", &txl->smaa_blend_tx);
+    DRW_shgroup_uniform_texture_ref(grp, "colorTex", &txl->overlay_color_tx);
+    DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
   }
 }
 
@@ -208,34 +241,24 @@ void OVERLAY_antialiasing_end(OVERLAY_Data *vedata)
   DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
 
   if (pd->antialiasing.enabled) {
-    if (pd->antialiasing.sample == 0) {
-      /* First sample: Copy to history buffer and apply FXAA. */
-      GPU_framebuffer_blit(
-          fbl->overlay_color_only_fb, 0, fbl->overlay_color_history_fb, 0, GPU_COLOR_BIT);
-      /* We merge default framebuffer with the overlay framebuffer to apply
-       * FXAA pass on the final image */
-      GPU_framebuffer_bind(fbl->overlay_color_only_fb);
-      DRW_draw_pass(psl->antialiasing_merge_ps);
-      /* Do FXAA */
-      GPU_framebuffer_bind(dfbl->default_fb);
-      DRW_draw_pass(psl->antialiasing_ps);
-
-      pd->antialiasing.sample++;
-
-      DRW_viewport_request_redraw();
-    }
-    else {


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list