[Bf-blender-cvs] [417f0d720b0] eevee-motionblur-object: EEVEE: Motion Blur: Make motion blur closer to cycles by evaluating 3 step

Clément Foucault noreply at git.blender.org
Tue Apr 14 19:09:14 CEST 2020


Commit: 417f0d720b0d612eed31a8dff2b7f2ce37fe7232
Author: Clément Foucault
Date:   Tue Apr 7 01:02:53 2020 +0200
Branches: eevee-motionblur-object
https://developer.blender.org/rB417f0d720b0d612eed31a8dff2b7f2ce37fe7232

EEVEE: Motion Blur: Make motion blur closer to cycles by evaluating 3 step

For now we always center the delta around the frame time. We store 2 motion
steps, one before and one after the current frame. However, this also means
storing 2 motion vectors for each pixels, doubling the vram usage of the
motion vector buffer.

This patch also cleanup some uneeded complexity. We use the motion vectors
as is and don't use a multiplier.

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

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_motion_blur.c
M	source/blender/draw/engines/eevee/eevee_private.h
M	source/blender/draw/engines/eevee/shaders/effect_motion_blur_frag.glsl
M	source/blender/draw/engines/eevee/shaders/effect_velocity_resolve_frag.glsl
M	source/blender/draw/engines/eevee/shaders/object_motion_frag.glsl
M	source/blender/draw/engines/eevee/shaders/object_motion_vert.glsl

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

diff --git a/source/blender/draw/engines/eevee/eevee_effects.c b/source/blender/draw/engines/eevee/eevee_effects.c
index 1a0b7c4f610..ef80f63fe90 100644
--- a/source/blender/draw/engines/eevee/eevee_effects.c
+++ b/source/blender/draw/engines/eevee/eevee_effects.c
@@ -147,8 +147,6 @@ void EEVEE_effects_init(EEVEE_ViewLayerData *sldata,
 
   if (!stl->effects) {
     stl->effects = MEM_callocN(sizeof(EEVEE_EffectsInfo), "EEVEE_EffectsInfo");
-    stl->effects->current_time = INT_MIN;
-    stl->effects->past_time = INT_MIN;
   }
 
   effects = stl->effects;
@@ -227,7 +225,7 @@ 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);
 
     GPU_framebuffer_ensure_config(&fbl->velocity_fb,
                                   {
@@ -333,6 +331,8 @@ 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);
@@ -340,8 +340,10 @@ void EEVEE_effects_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
     DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
     DRW_shgroup_uniform_block(
         grp, "renderpass_block", EEVEE_material_default_render_pass_ubo_get(sldata));
-    DRW_shgroup_uniform_mat4(grp, "currPersinv", effects->current_ndc_to_world);
-    DRW_shgroup_uniform_mat4(grp, "pastPersmat", effects->past_world_to_ndc);
+
+    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);
   }
 }
diff --git a/source/blender/draw/engines/eevee/eevee_engine.c b/source/blender/draw/engines/eevee/eevee_engine.c
index 342e8641372..27cf2ef25a5 100644
--- a/source/blender/draw/engines/eevee/eevee_engine.c
+++ b/source/blender/draw/engines/eevee/eevee_engine.c
@@ -427,30 +427,53 @@ static void eevee_render_to_image(void *vedata,
   const DRWContextState *draw_ctx = DRW_context_state_get();
 
   if (EEVEE_render_do_motion_blur(draw_ctx->depsgraph)) {
+    Scene *scene = DEG_get_evaluated_scene(draw_ctx->depsgraph);
+
+    float shutter = scene->eevee.motion_blur_shutter;
     float time = DEG_get_ctime(draw_ctx->depsgraph);
-    RE_engine_frame_set(engine, time - 1.0f, 0.0f);
+    /* Centered on frame for now. */
+    float start_time = time - shutter;
+    float end_time = time + shutter;
 
-    if (!EEVEE_render_init(vedata, engine, draw_ctx->depsgraph)) {
-      return;
-    }
+    {
+      EEVEE_motion_blur_step_set(ved, MB_PREV);
+      RE_engine_frame_set(engine, floorf(start_time), fractf(start_time));
 
-    if (RE_engine_test_break(engine)) {
-      return;
+      if (!EEVEE_render_init(vedata, engine, draw_ctx->depsgraph)) {
+        return;
+      }
+
+      if (RE_engine_test_break(engine)) {
+        return;
+      }
+
+      DRW_render_object_iter(vedata, engine, draw_ctx->depsgraph, EEVEE_render_cache);
+      EEVEE_motion_blur_cache_finish(vedata);
+      /* Reset passlist. This is safe as they are stored into managed memory chunks. */
+      memset(ved->psl, 0, sizeof(*ved->psl));
+      /* Fix memleak */
+      BLI_ghash_free(ved->stl->g_data->material_hash, NULL, MEM_freeN);
+      ved->stl->g_data->material_hash = NULL;
     }
 
-    EEVEE_motion_blur_step_set(ved, 0);
+    {
+      EEVEE_motion_blur_step_set(ved, MB_NEXT);
+      RE_engine_frame_set(engine, floorf(end_time), fractf(end_time));
 
-    DRW_render_object_iter(vedata, engine, draw_ctx->depsgraph, EEVEE_render_cache);
+      EEVEE_render_init(vedata, engine, draw_ctx->depsgraph);
 
-    EEVEE_motion_blur_cache_finish(vedata);
+      DRW_render_object_iter(vedata, engine, draw_ctx->depsgraph, EEVEE_render_cache);
+      EEVEE_motion_blur_cache_finish(vedata);
+      /* Reset passlist. This is safe as they are stored into managed memory chunks. */
+      memset(ved->psl, 0, sizeof(*ved->psl));
+      /* Fix memleak */
+      BLI_ghash_free(ved->stl->g_data->material_hash, NULL, MEM_freeN);
+      ved->stl->g_data->material_hash = NULL;
+    }
 
+    /* Current frame. */
+    EEVEE_motion_blur_step_set(ved, MB_CURR);
     RE_engine_frame_set(engine, time, 0.0f);
-
-    /* Reset passlist. This is safe as they are stored into managed memory chunks. */
-    memset(ved->psl, 0, sizeof(*ved->psl));
-    /* Fix memleak */
-    BLI_ghash_free(ved->stl->g_data->material_hash, NULL, MEM_freeN);
-    ved->stl->g_data->material_hash = NULL;
   }
 
   if (!EEVEE_render_init(vedata, engine, draw_ctx->depsgraph)) {
@@ -461,8 +484,6 @@ static void eevee_render_to_image(void *vedata,
     return;
   }
 
-  EEVEE_motion_blur_step_set(ved, 1);
-
   DRW_render_object_iter(vedata, engine, draw_ctx->depsgraph, EEVEE_render_cache);
 
   EEVEE_motion_blur_cache_finish(vedata);
diff --git a/source/blender/draw/engines/eevee/eevee_motion_blur.c b/source/blender/draw/engines/eevee/eevee_motion_blur.c
index 2d215366447..44ca15f00f2 100644
--- a/source/blender/draw/engines/eevee/eevee_motion_blur.c
+++ b/source/blender/draw/engines/eevee/eevee_motion_blur.c
@@ -66,6 +66,7 @@ static void eevee_create_shader_motion_blur(void)
                                                             NULL);
 }
 
+#if 0
 static void eevee_motion_blur_past_persmat_get(const CameraParams *past_params,
                                                const CameraParams *current_params,
                                                const RegionView3D *rv3d,
@@ -87,8 +88,11 @@ static void eevee_motion_blur_past_persmat_get(const CameraParams *past_params,
 
   mul_m4_m4m4(r_world_to_ndc, params.winmat, world_to_view);
 }
+#endif
 
-int EEVEE_motion_blur_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata, Object *camera)
+int EEVEE_motion_blur_init(EEVEE_ViewLayerData *UNUSED(sldata),
+                           EEVEE_Data *vedata,
+                           Object *UNUSED(camera))
 {
   EEVEE_StorageList *stl = vedata->stl;
   EEVEE_EffectsInfo *effects = stl->effects;
@@ -101,15 +105,19 @@ int EEVEE_motion_blur_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *veda
     return 0;
   }
 
-  effects->motion_blur_step = 0;
-
   if (scene->eevee.flag & SCE_EEVEE_MOTION_BLUR_ENABLED) {
-    float ctime = DEG_get_ctime(draw_ctx->depsgraph);
-
     if (!e_data.motion_blur_sh) {
       eevee_create_shader_motion_blur();
     }
 
+    if (DRW_state_is_scene_render()) {
+      int mb_step = effects->motion_blur_step;
+      DRW_view_viewmat_get(NULL, effects->motion_blur.camera[mb_step].viewmat, false);
+      DRW_view_persmat_get(NULL, effects->motion_blur.camera[mb_step].persmat, false);
+      DRW_view_persmat_get(NULL, effects->motion_blur.camera[mb_step].persinv, true);
+    }
+
+#if 0 /* For when we can do viewport motion blur. */
     /* Update Motion Blur Matrices */
     if (camera && (camera->type == OB_CAMERA) && (camera->data != NULL)) {
       if (effects->current_time != ctime) {
@@ -158,6 +166,7 @@ int EEVEE_motion_blur_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *veda
       effects->past_time = effects->current_time = ctime;
       effects->cam_params_init = false;
     }
+#endif
     return EFFECT_MOTION_BLUR | EFFECT_POST_BUFFER | EFFECT_VELOCITY_BUFFER;
   }
   return 0;
@@ -165,8 +174,11 @@ int EEVEE_motion_blur_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *veda
 
 void EEVEE_motion_blur_step_set(EEVEE_Data *vedata, int step)
 {
-  /* This might do more things in the future. */
-  BLI_assert(step < MAX_MB_DATA_STEP);
+  BLI_assert(step < 3);
+  /* Meh, code duplication. Could be avoided if render init would not contain cache init. */
+  if (vedata->stl->effects == NULL) {
+    vedata->stl->effects = MEM_callocN(sizeof(*vedata->stl->effects), __func__);
+  }
   vedata->stl->effects->motion_blur_step = step;
 }
 
@@ -175,6 +187,7 @@ void EEVEE_motion_blur_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Dat
   EEVEE_PassList *psl = vedata->psl;
   EEVEE_StorageList *stl = vedata->stl;
   EEVEE_EffectsInfo *effects = stl->effects;
+  EEVEE_MotionBlurData *mb_data = &effects->motion_blur;
   const DRWContextState *draw_ctx = DRW_context_state_get();
   Scene *scene = draw_ctx->scene;
 
@@ -184,28 +197,22 @@ void EEVEE_motion_blur_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Dat
 
       DRWShadingGroup *grp = DRW_shgroup_create(e_data.motion_blur_sh, psl->motion_blur);
       DRW_shgroup_uniform_int_copy(grp, "samples", scene->eevee.motion_blur_samples);
-      DRW_shgroup_uniform_float_copy(grp, "shutter", scene->eevee.motion_blur_shutter);
       DRW_shgroup_uniform_float(grp, "sampleOffset", &effects->motion_blur_sample_offset, 1);
-      DRW_shgroup_uniform_mat4(grp, "currInvViewProjMatrix", effects->current_ndc_to_world);
-      DRW_shgroup_uniform_mat4(grp, "pastViewProjMatrix", effects->past_world_to_ndc);
       DRW_shgroup_uniform_texture_ref(grp, "colorBuffer", &effects->source_buffer);
       DRW_shgroup_uniform_texture_ref(grp, "velocityBuffer", &effects->velocity_tx);
       DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
     }
     {
-      float delta_time = fabsf(effects->current_time - effects->past_time);
-
       DRW_PASS_CREATE(psl->velocity_object, DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL);
 
       DRWShadingGroup *grp = DRW_shgroup_create(e_data.motion_blur_object_sh,
                                                 psl->velocity_object);
-
-      DRW_shgroup_uniform_mat4(grp, "prevViewProjectionMatrix", effects->past_world_to_ndc);
-      DRW_shgroup_uniform_mat4(grp, "currViewProjectionMatrix", effects->current_world_to_nd

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list