[Bf-blender-cvs] [f84414d6e14] master: EEEVEE: Object Motion Blur: Initial Implementation

Clément Foucault noreply at git.blender.org
Fri Jun 19 17:06:47 CEST 2020


Commit: f84414d6e14c42bf0f96b128c35d29bc2da59087
Author: Clément Foucault
Date:   Fri Jun 19 17:02:55 2020 +0200
Branches: master
https://developer.blender.org/rBf84414d6e14c42bf0f96b128c35d29bc2da59087

EEEVEE: Object Motion Blur: Initial Implementation

This adds object motion blur vectors for EEVEE as well as better noise
reduction for it.

For TAA reprojection we just compute the motion vector on the fly based on
camera motion and depth buffer. This makes possible to store another motion
vector only for the blurring which is not useful for TAA history fetching.

Motion Data is saved per object & per geometry if using deformation blur.
We support deformation motion blur by saving previous VBO and modifying the
actual GPUBatch for the geometry to include theses VBOs.

We store Previous and Next frame motion in the same motion vector buffer
(RG for prev and BA for next). This makes non linear motion blur (like
rotating objects) less prone to outward/inward blur.

We also improve the motion blur post process to expand outside the objects
border. We use a tile base approach and the max size of the blur is set via
a new render setting.

We use a background reconstruction method that needs another setting
(Background Separation).

Sampling is done using a fixed 8 dithered samples per direction. The final
render samples will clear the noise like other stochastic effects.

One caveat is that hair particles are not yet supported. Support will
come in another patch.

Reviewed By: jbakker

Differential Revision: https://developer.blender.org/D7297

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

M	release/scripts/startup/bl_ui/properties_render.py
M	source/blender/blenloader/intern/versioning_290.c
M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/eevee/eevee_data.c
M	source/blender/draw/engines/eevee/eevee_effects.c
M	source/blender/draw/engines/eevee/eevee_engine.c
M	source/blender/draw/engines/eevee/eevee_materials.c
M	source/blender/draw/engines/eevee/eevee_motion_blur.c
M	source/blender/draw/engines/eevee/eevee_private.h
M	source/blender/draw/engines/eevee/eevee_render.c
M	source/blender/draw/engines/eevee/eevee_temporal_sampling.c
M	source/blender/draw/engines/eevee/shaders/effect_motion_blur_frag.glsl
M	source/blender/draw/engines/eevee/shaders/effect_temporal_aa.glsl
M	source/blender/draw/engines/eevee/shaders/effect_velocity_resolve_frag.glsl
A	source/blender/draw/engines/eevee/shaders/effect_velocity_tile_frag.glsl
A	source/blender/draw/engines/eevee/shaders/object_motion_frag.glsl
A	source/blender/draw/engines/eevee/shaders/object_motion_vert.glsl
M	source/blender/draw/intern/DRW_render.h
M	source/blender/draw/intern/draw_cache.c
M	source/blender/draw/intern/draw_cache.h
M	source/blender/draw/intern/draw_cache_impl.h
M	source/blender/draw/intern/draw_cache_impl_curve.c
M	source/blender/draw/intern/draw_cache_impl_mesh.c
M	source/blender/draw/intern/draw_cache_impl_metaball.c
M	source/blender/draw/intern/draw_cache_inline.h
M	source/blender/draw/intern/draw_manager.c
M	source/blender/draw/intern/draw_manager_data.c
M	source/blender/gpu/GPU_vertex_buffer.h
M	source/blender/gpu/GPU_vertex_format.h
M	source/blender/gpu/intern/gpu_vertex_buffer.c
M	source/blender/gpu/intern/gpu_vertex_format.c
M	source/blender/makesdna/DNA_scene_defaults.h
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/release/scripts/startup/bl_ui/properties_render.py b/release/scripts/startup/bl_ui/properties_render.py
index 11b02cfb552..70d4e3c275d 100644
--- a/release/scripts/startup/bl_ui/properties_render.py
+++ b/release/scripts/startup/bl_ui/properties_render.py
@@ -173,8 +173,9 @@ class RENDER_PT_eevee_motion_blur(RenderButtonsPanel, Panel):
 
         layout.active = props.use_motion_blur
         col = layout.column()
-        col.prop(props, "motion_blur_samples")
         col.prop(props, "motion_blur_shutter")
+        col.prop(props, "motion_blur_depth_scale")
+        col.prop(props, "motion_blur_max")
 
 
 class RENDER_PT_eevee_depth_of_field(RenderButtonsPanel, Panel):
diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c
index c5628b43960..8d57ef25c4d 100644
--- a/source/blender/blenloader/intern/versioning_290.c
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -279,5 +279,13 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
         }
       }
     }
+
+    /* EEVEE Motion blur new parameters. */
+    if (!DNA_struct_elem_find(fd->filesdna, "SceneEEVEE", "float", "motion_blur_depth_scale")) {
+      LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
+        scene->eevee.motion_blur_depth_scale = 100.0f;
+        scene->eevee.motion_blur_max = 32;
+      }
+    }
   }
 }
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index a26c150cb51..d18717c85e7 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -214,6 +214,7 @@ data_to_c_simple(engines/eevee/shaders/effect_downsample_frag.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/effect_downsample_cube_frag.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/effect_gtao_frag.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/effect_velocity_resolve_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/effect_velocity_tile_frag.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/effect_minmaxz_frag.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/effect_mist_frag.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/effect_motion_blur_frag.glsl SRC)
@@ -224,6 +225,8 @@ data_to_c_simple(engines/eevee/shaders/effect_temporal_aa.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/lightprobe_planar_downsample_frag.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/lightprobe_planar_downsample_geom.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/lightprobe_planar_downsample_vert.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/object_motion_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/object_motion_vert.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/prepass_frag.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/prepass_vert.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/shadow_accum_frag.glsl SRC)
diff --git a/source/blender/draw/engines/eevee/eevee_data.c b/source/blender/draw/engines/eevee/eevee_data.c
index a19af77124f..5ca24d296c5 100644
--- a/source/blender/draw/engines/eevee/eevee_data.c
+++ b/source/blender/draw/engines/eevee/eevee_data.c
@@ -24,11 +24,135 @@
 
 #include "DRW_render.h"
 
+#include "BLI_ghash.h"
 #include "BLI_memblock.h"
 
+#include "BKE_duplilist.h"
+
+#include "DEG_depsgraph_query.h"
+
+#include "GPU_vertex_buffer.h"
+
 #include "eevee_lightcache.h"
 #include "eevee_private.h"
 
+/* Motion Blur data. */
+
+static void eevee_motion_blur_mesh_data_free(void *val)
+{
+  EEVEE_GeometryMotionData *geom_mb = (EEVEE_GeometryMotionData *)val;
+  for (int i = 0; i < ARRAY_SIZE(geom_mb->vbo); i++) {
+    GPU_VERTBUF_DISCARD_SAFE(geom_mb->vbo[i]);
+  }
+  MEM_freeN(val);
+}
+
+static uint eevee_object_key_hash(const void *key)
+{
+  EEVEE_ObjectKey *ob_key = (EEVEE_ObjectKey *)key;
+  uint hash = BLI_ghashutil_ptrhash(ob_key->ob);
+  hash = BLI_ghashutil_combine_hash(hash, BLI_ghashutil_ptrhash(ob_key->parent));
+  for (int i = 0; i < 16; i++) {
+    if (ob_key->id[i] != 0) {
+      hash = BLI_ghashutil_combine_hash(hash, BLI_ghashutil_inthash(ob_key->id[i]));
+    }
+    else {
+      break;
+    }
+  }
+  return hash;
+}
+
+/* Return false if equal. */
+static bool eevee_object_key_cmp(const void *a, const void *b)
+{
+  EEVEE_ObjectKey *key_a = (EEVEE_ObjectKey *)a;
+  EEVEE_ObjectKey *key_b = (EEVEE_ObjectKey *)b;
+
+  if (key_a->ob != key_b->ob) {
+    return true;
+  }
+  if (key_a->parent != key_b->parent) {
+    return true;
+  }
+  if (memcmp(key_a->id, key_b->id, sizeof(key_a->id)) != 0) {
+    return true;
+  }
+  return false;
+}
+
+void EEVEE_motion_blur_data_init(EEVEE_MotionBlurData *mb)
+{
+  if (mb->object == NULL) {
+    mb->object = BLI_ghash_new(eevee_object_key_hash, eevee_object_key_cmp, "EEVEE Object Motion");
+  }
+  if (mb->geom == NULL) {
+    mb->geom = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "EEVEE Mesh Motion");
+  }
+}
+
+void EEVEE_motion_blur_data_free(EEVEE_MotionBlurData *mb)
+{
+  if (mb->object) {
+    BLI_ghash_free(mb->object, MEM_freeN, MEM_freeN);
+    mb->object = NULL;
+  }
+  if (mb->geom) {
+    BLI_ghash_free(mb->geom, NULL, eevee_motion_blur_mesh_data_free);
+    mb->geom = NULL;
+  }
+}
+
+EEVEE_ObjectMotionData *EEVEE_motion_blur_object_data_get(EEVEE_MotionBlurData *mb, Object *ob)
+{
+  if (mb->object == NULL) {
+    return NULL;
+  }
+
+  EEVEE_ObjectKey key, *key_p;
+  key.ob = ob;
+  DupliObject *dup = DRW_object_get_dupli(ob);
+  if (dup) {
+    key.parent = DRW_object_get_dupli_parent(ob);
+    memcpy(key.id, dup->persistent_id, sizeof(key.id));
+  }
+  else {
+    key.parent = key.ob;
+    memset(key.id, 0, sizeof(key.id));
+  }
+
+  EEVEE_ObjectMotionData *ob_step = BLI_ghash_lookup(mb->object, &key);
+  if (ob_step == NULL) {
+    key_p = MEM_mallocN(sizeof(*key_p), __func__);
+    memcpy(key_p, &key, sizeof(*key_p));
+
+    ob_step = MEM_callocN(sizeof(EEVEE_ObjectMotionData), __func__);
+
+    BLI_ghash_insert(mb->object, key_p, ob_step);
+  }
+  return ob_step;
+}
+
+EEVEE_GeometryMotionData *EEVEE_motion_blur_geometry_data_get(EEVEE_MotionBlurData *mb, Object *ob)
+{
+  if (mb->geom == NULL) {
+    return NULL;
+  }
+
+  /* Use original data as key to ensure matching accross update. */
+  Object *ob_orig = DEG_get_original_object(ob);
+
+  EEVEE_GeometryMotionData *geom_step = BLI_ghash_lookup(mb->geom, ob_orig->data);
+  if (geom_step == NULL) {
+    geom_step = MEM_callocN(sizeof(EEVEE_GeometryMotionData), __func__);
+    BLI_ghash_insert(mb->geom, ob_orig->data, geom_step);
+  }
+
+  return geom_step;
+}
+
+/* View Layer data. */
+
 void EEVEE_view_layer_data_free(void *storage)
 {
   EEVEE_ViewLayerData *sldata = (EEVEE_ViewLayerData *)storage;
diff --git a/source/blender/draw/engines/eevee/eevee_effects.c b/source/blender/draw/engines/eevee/eevee_effects.c
index ab846fe0f11..6826b645971 100644
--- a/source/blender/draw/engines/eevee/eevee_effects.c
+++ b/source/blender/draw/engines/eevee/eevee_effects.c
@@ -225,10 +225,13 @@ void EEVEE_effects_init(EEVEE_ViewLayerData *sldata,
    */
   if ((effects->enabled_effects & EFFECT_VELOCITY_BUFFER) != 0) {
     effects->velocity_tx = DRW_texture_pool_query_2d(
-        size_fs[0], size_fs[1], GPU_RG16, &draw_engine_eevee_type);
+        size_fs[0], size_fs[1], GPU_RGBA16, &draw_engine_eevee_type);
 
-    /* TODO output objects velocity during the mainpass. */
-    // GPU_framebuffer_texture_attach(fbl->main_fb, effects->velocity_tx, 1, 0);
+    GPU_framebuffer_ensure_config(&fbl->velocity_fb,
+                                  {
+                                      GPU_ATTACHMENT_TEXTURE(dtxl->depth),
+                                      GPU_ATTACHMENT_TEXTURE(effects->velocity_tx),
+                                  });
 
     GPU_framebuffer_ensure_config(
         &fbl->velocity_resolve_fb,
@@ -328,14 +331,18 @@ void EEVEE_effects_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
   }
 
   if ((effects->enabled_effects & EFFECT_VELOCITY_BUFFER) != 0) {
+    EEVEE_MotionBlurData *mb_data = &effects->motion_blur;
+
     /* This pass compute camera motions to the non moving objects. */
     DRW_PASS_CREATE(psl->velocity_resolve, DRW_STATE_WRITE_COLOR);
     grp = DRW_shgroup_create(EEVEE_shaders_velocity_resolve_sh_get(), psl->velocity_resolve);
     DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &e_data.depth_src);
     DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
     DRW_shgroup_uniform_block(grp, "renderpass_block", sldata->renderpass_ubo.combined);
-    DRW_shgroup_uniform_mat4(grp, "currPersinv", effects->velocity_curr_persinv);
-    DRW_shgroup_uniform_mat4(grp, "pastPersmat", effects->velocity_past_persmat);
+
+    DRW_shgroup_uniform_mat4(grp, "prevViewProjMatrix", mb_data->camera[MB_PREV].persmat);
+    DRW_shgroup_uniform_mat4(grp, "currViewProjMatrixInv", mb_data->camera[MB_CURR].persinv);
+    DRW_shgroup_uniform_mat4(grp, "nextViewProjMatrix", mb_data->camera[MB_NEXT].persmat);
     DRW_shgroup_call(grp, quad, NULL);
   }
 }
@@ -501,17 +508,19 @@ static void EEVEE_velocity_resolve(EEVEE_Data *vedata)
   EEVEE_FramebufferList *fbl = vedata->fbl;
   EEVEE_StorageList *stl = vedata->stl;
   EEVEE_EffectsInfo *effects = stl->effects;
-  struct DRWView *view = effects->taa_view;
 
   if ((effects->enabled_effects & EFFECT_VELOCITY_BUFFER) != 0) {
     DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
     e_data.depth_src = dtxl->depth;
-    DRW_view_persmat_get(view, effects->velocity_curr_persinv, true);
 
     GPU_framebuffer_bind(fbl->velocity_resolve_fb);
     DRW_draw_pass(psl->velocity_resolve);
+
+    if (psl->velocity_object) {
+      GPU_framebuffer_bind(fbl->velocity_fb);
+      DRW_draw_pass(psl->velocity_object);
+    }
   }
-  DRW_view_persmat_get(view, effects->velocity_past_persmat, false);
 }
 
 void EEVEE_draw_effects(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
@@ -529,6 +538,7 @@ void EEVEE_draw_effects(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
   effects->target_buffer = fbl->effect_color_fb; /* next target to render to */
 
   /* Post process stack (order matters) */
+  EEVEE_velocity_resolve(vedata);
   EEVEE_motion_blur_draw(vedata);
   EEVEE_depth_of_field_draw(vedata)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list