2017-11-01 01:03:36 +01:00
|
|
|
/*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
2019-01-23 11:29:18 +11:00
|
|
|
* Copyright 2016, Blender Foundation.
|
2017-11-01 01:03:36 +01:00
|
|
|
*/
|
|
|
|
|
|
2019-02-06 15:42:22 +11:00
|
|
|
/** \file \ingroup draw_engine
|
2017-11-20 14:11:45 +11:00
|
|
|
*
|
|
|
|
|
* Gather all screen space effects technique such as Bloom, Motion Blur, DoF, SSAO, SSR, ...
|
2017-11-01 01:03:36 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "DRW_render.h"
|
|
|
|
|
|
|
|
|
|
#include "BKE_camera.h"
|
|
|
|
|
#include "BKE_object.h"
|
|
|
|
|
#include "BKE_animsys.h"
|
|
|
|
|
|
2017-11-20 14:11:45 +11:00
|
|
|
#include "DNA_anim_types.h"
|
|
|
|
|
#include "DNA_camera_types.h"
|
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
|
2017-11-01 01:03:36 +01:00
|
|
|
|
|
|
|
|
#include "DEG_depsgraph.h"
|
2018-01-18 15:58:02 +01:00
|
|
|
#include "DEG_depsgraph_query.h"
|
2017-11-01 01:03:36 +01:00
|
|
|
|
|
|
|
|
#include "eevee_private.h"
|
|
|
|
|
#include "GPU_texture.h"
|
|
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
|
/* Motion Blur */
|
|
|
|
|
struct GPUShader *motion_blur_sh;
|
|
|
|
|
} e_data = {NULL}; /* Engine data */
|
|
|
|
|
|
|
|
|
|
extern char datatoc_effect_motion_blur_frag_glsl[];
|
|
|
|
|
|
|
|
|
|
static void eevee_motion_blur_camera_get_matrix_at_time(
|
2018-01-12 15:56:29 +01:00
|
|
|
Scene *scene,
|
|
|
|
|
ARegion *ar, RegionView3D *rv3d, View3D *v3d,
|
|
|
|
|
Object *camera,
|
|
|
|
|
float time,
|
|
|
|
|
float r_mat[4][4])
|
2017-11-01 01:03:36 +01:00
|
|
|
{
|
|
|
|
|
float obmat[4][4];
|
|
|
|
|
|
|
|
|
|
/* HACK */
|
|
|
|
|
Object cam_cpy; Camera camdata_cpy;
|
|
|
|
|
memcpy(&cam_cpy, camera, sizeof(cam_cpy));
|
|
|
|
|
memcpy(&camdata_cpy, camera->data, sizeof(camdata_cpy));
|
|
|
|
|
cam_cpy.data = &camdata_cpy;
|
|
|
|
|
|
2018-01-12 15:56:29 +01:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
2017-11-01 01:03:36 +01:00
|
|
|
|
|
|
|
|
/* Past matrix */
|
|
|
|
|
/* FIXME : This is a temporal solution that does not take care of parent animations */
|
2018-09-19 18:19:49 +02:00
|
|
|
/* Recalc Anim manually */
|
2018-05-31 12:52:13 +02:00
|
|
|
BKE_animsys_evaluate_animdata(draw_ctx->depsgraph, scene, &camdata_cpy.id, camdata_cpy.adt, time, ADT_RECALC_ALL);
|
2018-04-06 12:07:27 +02:00
|
|
|
BKE_object_where_is_calc_time(draw_ctx->depsgraph, scene, &cam_cpy, time);
|
2017-11-01 01:03:36 +01:00
|
|
|
|
|
|
|
|
/* Compute winmat */
|
|
|
|
|
CameraParams params;
|
|
|
|
|
BKE_camera_params_init(¶ms);
|
|
|
|
|
|
2018-01-29 18:16:11 +01:00
|
|
|
if (v3d != NULL) {
|
|
|
|
|
BKE_camera_params_from_view3d(¶ms, draw_ctx->depsgraph, v3d, rv3d);
|
|
|
|
|
BKE_camera_params_compute_viewplane(¶ms, ar->winx, ar->winy, 1.0f, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2017-11-01 01:03:36 +01:00
|
|
|
BKE_camera_params_from_object(¶ms, &cam_cpy);
|
2018-01-29 18:16:11 +01:00
|
|
|
BKE_camera_params_compute_viewplane(¶ms, scene->r.xsch, scene->r.ysch, scene->r.xasp, scene->r.yasp);
|
2017-11-01 01:03:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BKE_camera_params_compute_matrix(¶ms);
|
|
|
|
|
|
|
|
|
|
/* FIXME Should be done per view (MULTIVIEW) */
|
|
|
|
|
normalize_m4_m4(obmat, cam_cpy.obmat);
|
|
|
|
|
invert_m4(obmat);
|
|
|
|
|
mul_m4_m4m4(r_mat, params.winmat, obmat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void eevee_create_shader_motion_blur(void)
|
|
|
|
|
{
|
|
|
|
|
e_data.motion_blur_sh = DRW_shader_create_fullscreen(datatoc_effect_motion_blur_frag_glsl, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-29 18:16:11 +01:00
|
|
|
int EEVEE_motion_blur_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata, Object *camera)
|
2017-11-01 01:03:36 +01:00
|
|
|
{
|
|
|
|
|
EEVEE_StorageList *stl = vedata->stl;
|
|
|
|
|
EEVEE_EffectsInfo *effects = stl->effects;
|
|
|
|
|
|
|
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
2018-05-16 19:34:24 +02:00
|
|
|
const Scene *scene_eval = DEG_get_evaluated_scene(draw_ctx->depsgraph);
|
2017-11-01 01:03:36 +01:00
|
|
|
Scene *scene = draw_ctx->scene;
|
2018-05-16 19:34:24 +02:00
|
|
|
|
2017-11-01 01:03:36 +01:00
|
|
|
View3D *v3d = draw_ctx->v3d;
|
|
|
|
|
RegionView3D *rv3d = draw_ctx->rv3d;
|
|
|
|
|
ARegion *ar = draw_ctx->ar;
|
|
|
|
|
|
2018-05-16 19:34:24 +02:00
|
|
|
if (scene_eval->eevee.flag & SCE_EEVEE_MOTION_BLUR_ENABLED) {
|
2017-11-01 01:03:36 +01:00
|
|
|
/* Update Motion Blur Matrices */
|
2018-01-29 18:16:11 +01:00
|
|
|
if (camera) {
|
2017-11-01 01:03:36 +01:00
|
|
|
float persmat[4][4];
|
2018-05-17 15:20:41 +02:00
|
|
|
float ctime = DEG_get_ctime(draw_ctx->depsgraph);
|
2018-05-16 19:34:24 +02:00
|
|
|
float delta = scene_eval->eevee.motion_blur_shutter;
|
2018-05-22 07:48:12 +02:00
|
|
|
Object *ob_camera_eval = DEG_get_evaluated_object(draw_ctx->depsgraph, camera);
|
2017-11-01 01:03:36 +01:00
|
|
|
|
|
|
|
|
/* Current matrix */
|
2018-05-22 07:48:12 +02:00
|
|
|
eevee_motion_blur_camera_get_matrix_at_time(
|
|
|
|
|
scene,
|
|
|
|
|
ar, rv3d, v3d,
|
|
|
|
|
ob_camera_eval,
|
|
|
|
|
ctime,
|
|
|
|
|
effects->current_ndc_to_world);
|
2017-11-01 01:03:36 +01:00
|
|
|
|
|
|
|
|
/* Viewport Matrix */
|
|
|
|
|
DRW_viewport_matrix_get(persmat, DRW_MAT_PERS);
|
|
|
|
|
|
|
|
|
|
/* Only continue if camera is not being keyed */
|
2018-01-12 15:56:29 +01:00
|
|
|
if (DRW_state_is_image_render() ||
|
|
|
|
|
compare_m4m4(persmat, effects->current_ndc_to_world, 0.0001f))
|
|
|
|
|
{
|
2017-11-01 01:03:36 +01:00
|
|
|
/* Past matrix */
|
2018-05-22 07:48:12 +02:00
|
|
|
eevee_motion_blur_camera_get_matrix_at_time(
|
|
|
|
|
scene,
|
|
|
|
|
ar, rv3d, v3d,
|
|
|
|
|
ob_camera_eval,
|
|
|
|
|
ctime - delta,
|
|
|
|
|
effects->past_world_to_ndc);
|
2017-11-01 01:03:36 +01:00
|
|
|
|
|
|
|
|
#if 0 /* for future high quality blur */
|
|
|
|
|
/* Future matrix */
|
2018-05-22 07:48:12 +02:00
|
|
|
eevee_motion_blur_camera_get_matrix_at_time(
|
|
|
|
|
scene,
|
|
|
|
|
ar, rv3d, v3d,
|
|
|
|
|
ob_camera_eval,
|
|
|
|
|
ctime + delta,
|
|
|
|
|
effects->future_world_to_ndc);
|
2017-11-01 01:03:36 +01:00
|
|
|
#endif
|
|
|
|
|
invert_m4(effects->current_ndc_to_world);
|
|
|
|
|
|
2018-05-16 19:34:24 +02:00
|
|
|
effects->motion_blur_samples = scene_eval->eevee.motion_blur_samples;
|
2017-11-01 01:03:36 +01:00
|
|
|
|
|
|
|
|
if (!e_data.motion_blur_sh) {
|
|
|
|
|
eevee_create_shader_motion_blur();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return EFFECT_MOTION_BLUR | EFFECT_POST_BUFFER;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
void EEVEE_motion_blur_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
|
2017-11-01 01:03:36 +01:00
|
|
|
{
|
|
|
|
|
EEVEE_PassList *psl = vedata->psl;
|
|
|
|
|
EEVEE_StorageList *stl = vedata->stl;
|
|
|
|
|
EEVEE_EffectsInfo *effects = stl->effects;
|
|
|
|
|
DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
|
|
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
struct GPUBatch *quad = DRW_cache_fullscreen_quad_get();
|
2017-11-01 01:03:36 +01:00
|
|
|
|
|
|
|
|
if ((effects->enabled_effects & EFFECT_MOTION_BLUR) != 0) {
|
|
|
|
|
psl->motion_blur = DRW_pass_create("Motion Blur", DRW_STATE_WRITE_COLOR);
|
|
|
|
|
|
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_create(e_data.motion_blur_sh, psl->motion_blur);
|
|
|
|
|
DRW_shgroup_uniform_int(grp, "samples", &effects->motion_blur_samples, 1);
|
2018-04-20 18:10:00 +02:00
|
|
|
DRW_shgroup_uniform_mat4(grp, "currInvViewProjMatrix", effects->current_ndc_to_world);
|
|
|
|
|
DRW_shgroup_uniform_mat4(grp, "pastViewProjMatrix", effects->past_world_to_ndc);
|
2018-03-25 19:24:19 +02:00
|
|
|
DRW_shgroup_uniform_texture_ref(grp, "colorBuffer", &effects->source_buffer);
|
|
|
|
|
DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
|
2017-11-01 01:03:36 +01:00
|
|
|
DRW_shgroup_call_add(grp, quad, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EEVEE_motion_blur_draw(EEVEE_Data *vedata)
|
|
|
|
|
{
|
|
|
|
|
EEVEE_PassList *psl = vedata->psl;
|
|
|
|
|
EEVEE_TextureList *txl = vedata->txl;
|
|
|
|
|
EEVEE_FramebufferList *fbl = vedata->fbl;
|
|
|
|
|
EEVEE_StorageList *stl = vedata->stl;
|
|
|
|
|
EEVEE_EffectsInfo *effects = stl->effects;
|
|
|
|
|
|
|
|
|
|
/* Motion Blur */
|
|
|
|
|
if ((effects->enabled_effects & EFFECT_MOTION_BLUR) != 0) {
|
2018-03-25 17:46:48 +02:00
|
|
|
GPU_framebuffer_bind(effects->target_buffer);
|
2017-11-01 01:03:36 +01:00
|
|
|
DRW_draw_pass(psl->motion_blur);
|
|
|
|
|
SWAP_BUFFERS();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EEVEE_motion_blur_free(void)
|
|
|
|
|
{
|
|
|
|
|
DRW_SHADER_FREE_SAFE(e_data.motion_blur_sh);
|
|
|
|
|
}
|