2017-03-17 00:00:46 +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-03-17 00:00:46 +01:00
|
|
|
*/
|
|
|
|
|
2017-04-26 17:42:39 +10:00
|
|
|
/** \file eevee_engine.c
|
|
|
|
* \ingroup draw_engine
|
2017-03-17 00:00:46 +01:00
|
|
|
*/
|
|
|
|
|
2017-06-04 12:12:58 +02:00
|
|
|
#include "DRW_render.h"
|
2017-04-25 23:48:26 +02:00
|
|
|
|
2017-04-18 12:50:09 +02:00
|
|
|
#include "BLI_rand.h"
|
2017-04-27 22:27:09 +02:00
|
|
|
|
2017-09-21 12:55:14 +02:00
|
|
|
#include "BKE_object.h"
|
2018-01-29 18:16:11 +01:00
|
|
|
#include "BKE_global.h" /* for G.debug_value */
|
2017-09-21 12:55:14 +02:00
|
|
|
|
2017-11-20 14:11:45 +11:00
|
|
|
#include "DNA_world_types.h"
|
|
|
|
|
2017-03-17 00:00:46 +01:00
|
|
|
#include "eevee_private.h"
|
|
|
|
|
|
|
|
#define EEVEE_ENGINE "BLENDER_EEVEE"
|
|
|
|
|
|
|
|
/* *********** FUNCTIONS *********** */
|
|
|
|
|
2017-11-29 12:28:40 +01:00
|
|
|
static void eevee_engine_init(void *ved)
|
2017-03-17 00:00:46 +01:00
|
|
|
{
|
2017-04-18 12:50:09 +02:00
|
|
|
EEVEE_Data *vedata = (EEVEE_Data *)ved;
|
|
|
|
EEVEE_TextureList *txl = vedata->txl;
|
|
|
|
EEVEE_FramebufferList *fbl = vedata->fbl;
|
2017-06-22 02:28:49 +02:00
|
|
|
EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl;
|
2017-11-29 10:36:58 +01:00
|
|
|
EEVEE_ViewLayerData *sldata = EEVEE_view_layer_data_ensure();
|
2018-03-25 17:46:48 +02:00
|
|
|
DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
|
2017-03-17 00:00:46 +01:00
|
|
|
|
2018-01-29 18:16:11 +01:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
View3D *v3d = draw_ctx->v3d;
|
|
|
|
RegionView3D *rv3d = draw_ctx->rv3d;
|
|
|
|
Object *camera = (rv3d->persp == RV3D_CAMOB) ? v3d->camera : NULL;
|
|
|
|
|
2017-07-19 14:22:03 +02:00
|
|
|
if (!stl->g_data) {
|
|
|
|
/* Alloc transient pointers */
|
2017-08-30 11:09:07 +02:00
|
|
|
stl->g_data = MEM_callocN(sizeof(*stl->g_data), __func__);
|
2017-07-19 14:22:03 +02:00
|
|
|
}
|
2019-02-01 20:30:10 +01:00
|
|
|
stl->g_data->use_color_render_settings = USE_SCENE_LIGHT(v3d) || !LOOK_DEV_STUDIO_LIGHT_ENABLED(v3d);
|
2017-12-20 15:28:12 -02:00
|
|
|
stl->g_data->background_alpha = DRW_state_draw_background() ? 1.0f : 0.0f;
|
2017-07-19 14:22:03 +02:00
|
|
|
stl->g_data->valid_double_buffer = (txl->color_double_buffer != NULL);
|
2018-09-09 23:24:06 +02:00
|
|
|
stl->g_data->valid_taa_history = (txl->taa_history != NULL);
|
2017-07-19 14:22:03 +02:00
|
|
|
|
2018-03-25 17:46:48 +02:00
|
|
|
/* Main Buffer */
|
2018-04-30 16:02:24 +02:00
|
|
|
DRW_texture_ensure_fullscreen_2D(&txl->color, GPU_RGBA16F, DRW_TEX_FILTER | DRW_TEX_MIPMAP);
|
2018-03-25 17:46:48 +02:00
|
|
|
|
|
|
|
GPU_framebuffer_ensure_config(&fbl->main_fb, {
|
|
|
|
GPU_ATTACHMENT_TEXTURE(dtxl->depth),
|
|
|
|
GPU_ATTACHMENT_TEXTURE(txl->color),
|
|
|
|
GPU_ATTACHMENT_LEAVE,
|
|
|
|
GPU_ATTACHMENT_LEAVE,
|
|
|
|
GPU_ATTACHMENT_LEAVE,
|
|
|
|
GPU_ATTACHMENT_LEAVE
|
|
|
|
});
|
2017-03-17 00:00:46 +01:00
|
|
|
|
2018-03-25 17:46:48 +02:00
|
|
|
GPU_framebuffer_ensure_config(&fbl->main_color_fb, {
|
|
|
|
GPU_ATTACHMENT_NONE,
|
|
|
|
GPU_ATTACHMENT_TEXTURE(txl->color)
|
|
|
|
});
|
2017-03-17 00:00:46 +01:00
|
|
|
|
2018-01-21 17:25:10 +01:00
|
|
|
if (sldata->common_ubo == NULL) {
|
|
|
|
sldata->common_ubo = DRW_uniformbuffer_create(sizeof(sldata->common_data), &sldata->common_data);
|
|
|
|
}
|
2018-03-10 00:02:01 +01:00
|
|
|
if (sldata->clip_ubo == NULL) {
|
|
|
|
sldata->clip_ubo = DRW_uniformbuffer_create(sizeof(sldata->clip_data), &sldata->clip_data);
|
|
|
|
}
|
2018-01-21 17:25:10 +01:00
|
|
|
|
2017-09-25 20:14:07 +02:00
|
|
|
/* EEVEE_effects_init needs to go first for TAA */
|
2018-10-23 15:52:04 +02:00
|
|
|
EEVEE_effects_init(sldata, vedata, camera, false);
|
2018-01-21 17:25:10 +01:00
|
|
|
EEVEE_materials_init(sldata, stl, fbl);
|
2017-06-03 00:53:47 +02:00
|
|
|
EEVEE_lights_init(sldata);
|
2017-06-17 00:08:03 +02:00
|
|
|
EEVEE_lightprobes_init(sldata, vedata);
|
2017-09-25 20:14:07 +02:00
|
|
|
|
2018-01-05 10:25:00 +01:00
|
|
|
if ((stl->effects->taa_current_sample > 1) && !DRW_state_is_image_render()) {
|
2017-09-25 20:14:07 +02:00
|
|
|
/* XXX otherwise it would break the other engines. */
|
2018-03-02 18:08:40 +01:00
|
|
|
DRW_viewport_matrix_override_unset_all();
|
2017-09-25 20:14:07 +02:00
|
|
|
}
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
|
|
|
|
2017-11-29 12:28:40 +01:00
|
|
|
static void eevee_cache_init(void *vedata)
|
2017-03-17 00:00:46 +01:00
|
|
|
{
|
2017-11-29 10:36:58 +01:00
|
|
|
EEVEE_ViewLayerData *sldata = EEVEE_view_layer_data_ensure();
|
2017-05-30 22:29:20 +02:00
|
|
|
|
2017-11-01 01:03:36 +01:00
|
|
|
EEVEE_bloom_cache_init(sldata, vedata);
|
|
|
|
EEVEE_depth_of_field_cache_init(sldata, vedata);
|
2017-07-03 16:38:14 +02:00
|
|
|
EEVEE_effects_cache_init(sldata, vedata);
|
2017-11-01 01:03:36 +01:00
|
|
|
EEVEE_lightprobes_cache_init(sldata, vedata);
|
2018-03-01 19:27:38 +01:00
|
|
|
EEVEE_lights_cache_init(sldata, vedata);
|
2018-03-06 02:19:28 +01:00
|
|
|
EEVEE_materials_cache_init(sldata, vedata);
|
2017-11-01 01:03:36 +01:00
|
|
|
EEVEE_motion_blur_cache_init(sldata, vedata);
|
|
|
|
EEVEE_occlusion_cache_init(sldata, vedata);
|
|
|
|
EEVEE_screen_raytrace_cache_init(sldata, vedata);
|
2017-11-14 00:49:54 +01:00
|
|
|
EEVEE_subsurface_cache_init(sldata, vedata);
|
2017-11-01 01:03:36 +01:00
|
|
|
EEVEE_temporal_sampling_cache_init(sldata, vedata);
|
|
|
|
EEVEE_volumes_cache_init(sldata, vedata);
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
|
|
|
|
2018-07-10 15:02:25 +02:00
|
|
|
void EEVEE_cache_populate(void *vedata, Object *ob)
|
2017-03-17 00:00:46 +01:00
|
|
|
{
|
2017-11-29 10:36:58 +01:00
|
|
|
EEVEE_ViewLayerData *sldata = EEVEE_view_layer_data_ensure();
|
2017-03-17 00:00:46 +01:00
|
|
|
|
2017-05-17 17:06:55 +10:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
2018-12-18 18:18:00 +01:00
|
|
|
const int ob_visibility = DRW_object_visibility_in_active_context(ob);
|
2018-06-02 12:06:24 +02:00
|
|
|
bool cast_shadow = false;
|
|
|
|
|
2018-12-18 18:18:00 +01:00
|
|
|
if (ob_visibility & OB_VISIBLE_PARTICLES) {
|
2018-06-02 12:06:24 +02:00
|
|
|
EEVEE_hair_cache_populate(vedata, sldata, ob, &cast_shadow);
|
2017-12-21 13:29:14 -02:00
|
|
|
}
|
|
|
|
|
2018-12-18 18:18:00 +01:00
|
|
|
if (DRW_object_is_renderable(ob) && (ob_visibility & OB_VISIBLE_SELF)) {
|
2018-06-11 08:37:56 +02:00
|
|
|
if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL)) {
|
2018-06-02 12:06:24 +02:00
|
|
|
EEVEE_materials_cache_populate(vedata, sldata, ob, &cast_shadow);
|
2017-05-20 13:16:14 +02:00
|
|
|
}
|
2018-06-02 12:06:24 +02:00
|
|
|
else if (!USE_SCENE_LIGHT(draw_ctx->v3d)) {
|
|
|
|
/* do not add any scene light sources to the cache */
|
|
|
|
}
|
|
|
|
else if (ob->type == OB_LIGHTPROBE) {
|
2019-01-15 23:27:54 +11:00
|
|
|
if ((ob->base_flag & BASE_FROM_DUPLI) != 0) {
|
2018-06-02 12:06:24 +02:00
|
|
|
/* TODO: Special case for dupli objects because we cannot save the object pointer. */
|
|
|
|
}
|
|
|
|
else {
|
2018-07-10 15:02:25 +02:00
|
|
|
EEVEE_lightprobes_cache_add(sldata, vedata, ob);
|
2018-06-02 12:06:24 +02:00
|
|
|
}
|
2017-07-19 18:15:27 +02:00
|
|
|
}
|
2018-06-02 12:06:24 +02:00
|
|
|
else if (ob->type == OB_LAMP) {
|
|
|
|
EEVEE_lights_cache_add(sldata, ob);
|
2017-07-19 18:15:27 +02:00
|
|
|
}
|
2017-06-08 21:48:50 +02:00
|
|
|
}
|
2018-06-02 12:06:24 +02:00
|
|
|
|
|
|
|
if (cast_shadow) {
|
|
|
|
EEVEE_lights_cache_shcaster_object_add(sldata, ob);
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-29 12:28:40 +01:00
|
|
|
static void eevee_cache_finish(void *vedata)
|
2017-05-02 19:25:25 +02:00
|
|
|
{
|
2017-11-29 10:36:58 +01:00
|
|
|
EEVEE_ViewLayerData *sldata = EEVEE_view_layer_data_ensure();
|
2017-03-17 00:00:46 +01:00
|
|
|
|
2017-06-05 22:05:21 +02:00
|
|
|
EEVEE_materials_cache_finish(vedata);
|
2018-10-28 21:41:40 +01:00
|
|
|
EEVEE_lights_cache_finish(sldata, vedata);
|
2017-06-15 00:10:34 +02:00
|
|
|
EEVEE_lightprobes_cache_finish(sldata, vedata);
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
|
|
|
|
2018-01-02 14:15:33 +01:00
|
|
|
/* As renders in an HDR offscreen buffer, we need draw everything once
|
|
|
|
* during the background pass. This way the other drawing callback between
|
|
|
|
* the background and the scene pass are visible.
|
|
|
|
* Note: we could break it up in two passes using some depth test
|
|
|
|
* to reduce the fillrate */
|
|
|
|
static void eevee_draw_background(void *vedata)
|
2017-03-17 00:00:46 +01:00
|
|
|
{
|
2017-03-26 19:10:53 +02:00
|
|
|
EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
|
2018-01-29 18:16:11 +01:00
|
|
|
EEVEE_TextureList *txl = ((EEVEE_Data *)vedata)->txl;
|
2017-09-25 20:14:07 +02:00
|
|
|
EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl;
|
2017-03-26 19:10:53 +02:00
|
|
|
EEVEE_FramebufferList *fbl = ((EEVEE_Data *)vedata)->fbl;
|
2018-03-25 17:46:48 +02:00
|
|
|
EEVEE_EffectsInfo *effects = stl->effects;
|
2017-11-29 10:36:58 +01:00
|
|
|
EEVEE_ViewLayerData *sldata = EEVEE_view_layer_data_ensure();
|
2017-03-17 00:00:46 +01:00
|
|
|
|
|
|
|
/* Default framebuffer and texture */
|
|
|
|
DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
|
2018-01-29 18:16:11 +01:00
|
|
|
DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
|
2018-05-29 12:25:43 +02:00
|
|
|
|
2018-02-03 01:49:29 +01:00
|
|
|
/* Sort transparents before the loop. */
|
|
|
|
DRW_pass_sort_shgroup_z(psl->transparent_pass);
|
|
|
|
|
2018-03-14 03:27:22 +01:00
|
|
|
/* Number of iteration: needed for all temporal effect (SSR, volumetrics)
|
2017-07-22 20:36:34 +02:00
|
|
|
* when using opengl render. */
|
2018-07-08 12:45:53 +02:00
|
|
|
int loop_len = (DRW_state_is_image_render() &&
|
2018-03-14 03:27:22 +01:00
|
|
|
(stl->effects->enabled_effects & (EFFECT_VOLUMETRIC | EFFECT_SSR)) != 0) ? 4 : 1;
|
2017-04-10 12:06:17 +02:00
|
|
|
|
2018-07-08 12:45:53 +02:00
|
|
|
while (loop_len--) {
|
2018-03-25 17:46:48 +02:00
|
|
|
float clear_col[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
float clear_depth = 1.0f;
|
2018-08-15 17:41:36 +02:00
|
|
|
uint clear_stencil = 0x0;
|
2018-05-11 07:48:52 +02:00
|
|
|
uint primes[3] = {2, 3, 7};
|
2018-01-15 17:14:49 +01:00
|
|
|
double offset[3] = {0.0, 0.0, 0.0};
|
|
|
|
double r[3];
|
2017-08-21 01:38:14 +02:00
|
|
|
|
2018-04-20 18:24:14 +02:00
|
|
|
bool taa_use_reprojection = (stl->effects->enabled_effects & EFFECT_TAA_REPROJECT) != 0;
|
|
|
|
|
2018-01-29 18:16:11 +01:00
|
|
|
if (DRW_state_is_image_render() ||
|
2018-04-21 20:42:27 +02:00
|
|
|
taa_use_reprojection ||
|
2018-02-15 18:03:55 +11:00
|
|
|
((stl->effects->enabled_effects & EFFECT_TAA) != 0))
|
2018-01-29 18:16:11 +01:00
|
|
|
{
|
2018-04-20 18:24:14 +02:00
|
|
|
int samp = taa_use_reprojection
|
|
|
|
? stl->effects->taa_reproject_sample + 1
|
|
|
|
: stl->effects->taa_current_sample;
|
|
|
|
BLI_halton_3D(primes, offset, samp, r);
|
2018-01-17 14:02:48 +01:00
|
|
|
EEVEE_update_noise(psl, fbl, r);
|
2018-04-20 18:24:14 +02:00
|
|
|
EEVEE_volumes_set_jitter(sldata, samp - 1);
|
2018-02-03 02:14:36 +01:00
|
|
|
EEVEE_materials_init(sldata, stl, fbl);
|
2018-01-05 10:25:00 +01:00
|
|
|
}
|
2018-02-26 20:08:48 +01:00
|
|
|
/* Copy previous persmat to UBO data */
|
|
|
|
copy_m4_m4(sldata->common_data.prev_persmat, stl->effects->prev_persmat);
|
2017-08-18 15:06:51 +02:00
|
|
|
|
2018-03-07 23:25:49 +01:00
|
|
|
if (((stl->effects->enabled_effects & EFFECT_TAA) != 0) &&
|
|
|
|
(stl->effects->taa_current_sample > 1) &&
|
2018-04-20 18:24:14 +02:00
|
|
|
!DRW_state_is_image_render() &&
|
|
|
|
!taa_use_reprojection)
|
2018-03-07 23:25:49 +01:00
|
|
|
{
|
|
|
|
DRW_viewport_matrix_override_set(stl->effects->overide_persmat, DRW_MAT_PERS);
|
|
|
|
DRW_viewport_matrix_override_set(stl->effects->overide_persinv, DRW_MAT_PERSINV);
|
|
|
|
DRW_viewport_matrix_override_set(stl->effects->overide_winmat, DRW_MAT_WIN);
|
|
|
|
DRW_viewport_matrix_override_set(stl->effects->overide_wininv, DRW_MAT_WININV);
|
|
|
|
}
|
|
|
|
|
2017-07-22 20:36:34 +02:00
|
|
|
/* Refresh Probes */
|
2017-07-26 19:58:15 +02:00
|
|
|
DRW_stats_group_start("Probes Refresh");
|
2017-07-22 20:36:34 +02:00
|
|
|
EEVEE_lightprobes_refresh(sldata, vedata);
|
2018-03-13 01:24:51 +01:00
|
|
|
/* Probes refresh can have reset the current sample. */
|
|
|
|
if (stl->effects->taa_current_sample == 1) {
|
|
|
|
DRW_viewport_matrix_override_unset_all();
|
|
|
|
}
|
2018-02-03 01:50:38 +01:00
|
|
|
EEVEE_lightprobes_refresh_planar(sldata, vedata);
|
2017-07-26 19:58:15 +02:00
|
|
|
DRW_stats_group_end();
|
2017-03-17 00:00:46 +01:00
|
|
|
|
2017-09-10 03:07:55 +02:00
|
|
|
/* Refresh shadows */
|
|
|
|
DRW_stats_group_start("Shadows");
|
2018-10-28 21:41:40 +01:00
|
|
|
EEVEE_draw_shadows(sldata, vedata);
|
2017-09-10 03:07:55 +02:00
|
|
|
DRW_stats_group_end();
|
|
|
|
|
2018-11-08 19:17:41 +01:00
|
|
|
/* Set ray type. */
|
|
|
|
sldata->common_data.ray_type = EEVEE_RAY_CAMERA;
|
|
|
|
sldata->common_data.ray_depth = 0.0f;
|
|
|
|
DRW_uniformbuffer_update(sldata->common_ubo, &sldata->common_data);
|
|
|
|
|
2018-03-25 17:46:48 +02:00
|
|
|
GPU_framebuffer_bind(fbl->main_fb);
|
2019-01-23 14:15:43 +11:00
|
|
|
eGPUFrameBufferBits clear_bits = GPU_DEPTH_BIT;
|
2018-03-25 17:46:48 +02:00
|
|
|
clear_bits |= (DRW_state_draw_background()) ? 0 : GPU_COLOR_BIT;
|
|
|
|
clear_bits |= ((stl->effects->enabled_effects & EFFECT_SSS) != 0) ? GPU_STENCIL_BIT : 0;
|
|
|
|
GPU_framebuffer_clear(fbl->main_fb, clear_bits, clear_col, clear_depth, clear_stencil);
|
2017-06-04 12:12:58 +02:00
|
|
|
|
2017-07-22 20:36:34 +02:00
|
|
|
/* Depth prepass */
|
2017-07-26 19:58:15 +02:00
|
|
|
DRW_stats_group_start("Prepass");
|
2017-07-22 20:36:34 +02:00
|
|
|
DRW_draw_pass(psl->depth_pass);
|
|
|
|
DRW_draw_pass(psl->depth_pass_cull);
|
2017-07-26 19:58:15 +02:00
|
|
|
DRW_stats_group_end();
|
2017-06-22 02:28:49 +02:00
|
|
|
|
2017-07-22 20:36:34 +02:00
|
|
|
/* Create minmax texture */
|
2017-07-26 19:58:15 +02:00
|
|
|
DRW_stats_group_start("Main MinMax buffer");
|
2017-07-23 20:33:29 +02:00
|
|
|
EEVEE_create_minmax_buffer(vedata, dtxl->depth, -1);
|
2017-07-26 19:58:15 +02:00
|
|
|
DRW_stats_group_end();
|
2017-06-22 02:28:49 +02:00
|
|
|
|
2018-01-09 19:01:24 +01:00
|
|
|
EEVEE_occlusion_compute(sldata, vedata, dtxl->depth, -1);
|
2017-11-01 01:03:36 +01:00
|
|
|
EEVEE_volumes_compute(sldata, vedata);
|
2017-03-17 00:00:46 +01:00
|
|
|
|
2017-07-22 20:36:34 +02:00
|
|
|
/* Shading pass */
|
2017-07-26 19:58:15 +02:00
|
|
|
DRW_stats_group_start("Shading");
|
2018-01-03 13:24:04 +01:00
|
|
|
if (DRW_state_draw_background()) {
|
|
|
|
DRW_draw_pass(psl->background_pass);
|
|
|
|
}
|
2017-07-22 20:36:34 +02:00
|
|
|
EEVEE_draw_default_passes(psl);
|
|
|
|
DRW_draw_pass(psl->material_pass);
|
2017-11-14 00:49:54 +01:00
|
|
|
EEVEE_subsurface_data_render(sldata, vedata);
|
2017-07-26 19:58:15 +02:00
|
|
|
DRW_stats_group_end();
|
2017-07-16 23:49:25 +02:00
|
|
|
|
2017-11-01 01:03:36 +01:00
|
|
|
/* Effects pre-transparency */
|
2017-11-14 00:49:54 +01:00
|
|
|
EEVEE_subsurface_compute(sldata, vedata);
|
2017-11-01 01:03:36 +01:00
|
|
|
EEVEE_reflection_compute(sldata, vedata);
|
|
|
|
EEVEE_occlusion_draw_debug(sldata, vedata);
|
2018-07-10 15:02:25 +02:00
|
|
|
if (psl->probe_display) {
|
|
|
|
DRW_draw_pass(psl->probe_display);
|
|
|
|
}
|
2017-11-01 01:03:36 +01:00
|
|
|
EEVEE_refraction_compute(sldata, vedata);
|
2017-08-09 16:54:18 +02:00
|
|
|
|
2017-08-09 23:48:42 +02:00
|
|
|
/* Opaque refraction */
|
|
|
|
DRW_stats_group_start("Opaque Refraction");
|
|
|
|
DRW_draw_pass(psl->refract_depth_pass);
|
|
|
|
DRW_draw_pass(psl->refract_depth_pass_cull);
|
|
|
|
DRW_draw_pass(psl->refract_pass);
|
|
|
|
DRW_stats_group_end();
|
|
|
|
|
2017-11-01 01:03:36 +01:00
|
|
|
/* Volumetrics Resolve Opaque */
|
|
|
|
EEVEE_volumes_resolve(sldata, vedata);
|
2017-10-24 14:49:00 +02:00
|
|
|
|
2017-07-22 20:36:34 +02:00
|
|
|
/* Transparent */
|
|
|
|
DRW_draw_pass(psl->transparent_pass);
|
|
|
|
|
|
|
|
/* Post Process */
|
2017-07-26 19:58:15 +02:00
|
|
|
DRW_stats_group_start("Post FX");
|
2018-01-21 17:25:10 +01:00
|
|
|
EEVEE_draw_effects(sldata, vedata);
|
2017-07-26 19:58:15 +02:00
|
|
|
DRW_stats_group_end();
|
2017-09-25 20:14:07 +02:00
|
|
|
|
2018-01-05 10:25:00 +01:00
|
|
|
if ((stl->effects->taa_current_sample > 1) && !DRW_state_is_image_render()) {
|
2018-03-07 23:25:49 +01:00
|
|
|
DRW_viewport_matrix_override_unset_all();
|
2017-09-25 20:14:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-25 08:06:36 +02:00
|
|
|
/* LookDev */
|
|
|
|
EEVEE_lookdev_draw_background(vedata);
|
|
|
|
/* END */
|
2018-05-30 15:26:37 +02:00
|
|
|
|
2018-05-25 08:06:36 +02:00
|
|
|
|
2018-03-25 17:46:48 +02:00
|
|
|
/* Tonemapping and transfer result to default framebuffer. */
|
2019-02-01 20:30:10 +01:00
|
|
|
bool use_render_settings = stl->g_data->use_color_render_settings;
|
2018-07-30 15:44:25 +02:00
|
|
|
|
2018-03-25 17:46:48 +02:00
|
|
|
GPU_framebuffer_bind(dfbl->default_fb);
|
2019-02-01 20:30:10 +01:00
|
|
|
DRW_transform_to_display(stl->effects->final_tx, true, use_render_settings);
|
2018-01-29 18:16:11 +01:00
|
|
|
|
2018-09-19 18:19:49 +02:00
|
|
|
/* Debug : Output buffer to view. */
|
2018-01-29 18:16:11 +01:00
|
|
|
switch (G.debug_value) {
|
|
|
|
case 1:
|
2019-02-01 20:30:10 +01:00
|
|
|
if (txl->maxzbuffer) DRW_transform_to_display(txl->maxzbuffer, false, false);
|
2018-01-29 18:16:11 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2019-02-01 20:30:10 +01:00
|
|
|
if (effects->ssr_pdf_output) DRW_transform_to_display(effects->ssr_pdf_output, false, false);
|
2018-01-29 18:16:11 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
2019-02-01 20:30:10 +01:00
|
|
|
if (effects->ssr_normal_input) DRW_transform_to_display(effects->ssr_normal_input, false, false);
|
2018-01-29 18:16:11 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
2019-02-01 20:30:10 +01:00
|
|
|
if (effects->ssr_specrough_input) DRW_transform_to_display(effects->ssr_specrough_input, false, false);
|
2018-01-29 18:16:11 +01:00
|
|
|
break;
|
|
|
|
case 5:
|
2019-02-01 20:30:10 +01:00
|
|
|
if (txl->color_double_buffer) DRW_transform_to_display(txl->color_double_buffer, false, false);
|
2018-01-29 18:16:11 +01:00
|
|
|
break;
|
|
|
|
case 6:
|
2019-02-01 20:30:10 +01:00
|
|
|
if (effects->gtao_horizons_debug) DRW_transform_to_display(effects->gtao_horizons_debug, false, false);
|
2018-01-29 18:16:11 +01:00
|
|
|
break;
|
|
|
|
case 7:
|
2019-02-01 20:30:10 +01:00
|
|
|
if (effects->gtao_horizons) DRW_transform_to_display(effects->gtao_horizons, false, false);
|
2018-01-29 18:16:11 +01:00
|
|
|
break;
|
|
|
|
case 8:
|
2019-02-01 20:30:10 +01:00
|
|
|
if (effects->sss_data) DRW_transform_to_display(effects->sss_data, false, false);
|
2018-01-29 18:16:11 +01:00
|
|
|
break;
|
2018-04-20 18:18:33 +02:00
|
|
|
case 9:
|
2019-02-01 20:30:10 +01:00
|
|
|
if (effects->velocity_tx) DRW_transform_to_display(effects->velocity_tx, false, false);
|
2018-04-20 18:18:33 +02:00
|
|
|
break;
|
2018-01-29 18:16:11 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-11-01 01:03:36 +01:00
|
|
|
EEVEE_volumes_free_smoke_textures();
|
2017-10-27 22:35:48 +02:00
|
|
|
|
2017-09-25 20:14:07 +02:00
|
|
|
stl->g_data->view_updated = false;
|
|
|
|
}
|
|
|
|
|
2017-11-29 12:28:40 +01:00
|
|
|
static void eevee_view_update(void *vedata)
|
2017-09-25 20:14:07 +02:00
|
|
|
{
|
|
|
|
EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl;
|
|
|
|
if (stl->g_data) {
|
|
|
|
stl->g_data->view_updated = true;
|
2017-07-22 20:36:34 +02:00
|
|
|
}
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
|
|
|
|
2018-01-29 16:42:04 +01:00
|
|
|
static void eevee_id_object_update(void *UNUSED(vedata), Object *object)
|
2017-11-28 17:05:52 +01:00
|
|
|
{
|
2018-01-29 16:42:04 +01:00
|
|
|
EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_get(object);
|
2018-07-10 14:14:55 +02:00
|
|
|
if (ped != NULL && ped->dd.recalc != 0) {
|
2018-07-10 15:02:25 +02:00
|
|
|
ped->need_update = (ped->dd.recalc & (ID_RECALC_TRANSFORM | ID_RECALC_COPY_ON_WRITE)) != 0;
|
2018-07-10 14:14:55 +02:00
|
|
|
ped->dd.recalc = 0;
|
2018-01-29 16:42:04 +01:00
|
|
|
}
|
|
|
|
EEVEE_LampEngineData *led = EEVEE_lamp_data_get(object);
|
2018-07-10 14:14:55 +02:00
|
|
|
if (led != NULL && led->dd.recalc != 0) {
|
2018-01-29 16:42:04 +01:00
|
|
|
led->need_update = true;
|
2018-07-10 14:14:55 +02:00
|
|
|
led->dd.recalc = 0;
|
2018-01-29 16:42:04 +01:00
|
|
|
}
|
|
|
|
EEVEE_ObjectEngineData *oedata = EEVEE_object_data_get(object);
|
2018-07-10 14:14:55 +02:00
|
|
|
if (oedata != NULL && oedata->dd.recalc != 0) {
|
2018-01-29 16:42:04 +01:00
|
|
|
oedata->need_update = true;
|
2018-07-10 14:14:55 +02:00
|
|
|
oedata->dd.recalc = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void eevee_id_world_update(void *vedata, World *wo)
|
|
|
|
{
|
|
|
|
EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl;
|
2018-07-10 15:02:25 +02:00
|
|
|
LightCache *lcache = stl->g_data->light_cache;
|
2018-07-10 14:14:55 +02:00
|
|
|
|
|
|
|
EEVEE_WorldEngineData *wedata = EEVEE_world_data_ensure(wo);
|
|
|
|
|
|
|
|
if (wedata != NULL && wedata->dd.recalc != 0) {
|
2018-07-10 15:02:25 +02:00
|
|
|
if ((lcache->flag & (LIGHTCACHE_BAKED | LIGHTCACHE_BAKING)) == 0) {
|
|
|
|
lcache->flag |= LIGHTCACHE_UPDATE_WORLD;
|
|
|
|
}
|
2018-07-10 14:14:55 +02:00
|
|
|
wedata->dd.recalc = 0;
|
2017-12-19 11:46:53 +01:00
|
|
|
}
|
2018-01-29 16:42:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void eevee_id_update(void *vedata, ID *id)
|
|
|
|
{
|
2017-12-19 11:46:53 +01:00
|
|
|
/* Handle updates based on ID type. */
|
2018-01-29 16:42:04 +01:00
|
|
|
switch (GS(id->name)) {
|
2018-07-10 14:14:55 +02:00
|
|
|
case ID_WO:
|
|
|
|
eevee_id_world_update(vedata, (World *)id);
|
|
|
|
break;
|
2018-01-29 16:42:04 +01:00
|
|
|
case ID_OB:
|
|
|
|
eevee_id_object_update(vedata, (Object *)id);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* pass */
|
|
|
|
break;
|
2017-11-28 17:05:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-23 13:26:28 -03:00
|
|
|
static void eevee_render_to_image(void *vedata, RenderEngine *engine, struct RenderLayer *render_layer, const rcti *rect)
|
2018-01-29 18:16:11 +01:00
|
|
|
{
|
2018-02-20 10:14:23 -03:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
EEVEE_render_init(vedata, engine, draw_ctx->depsgraph);
|
2018-01-29 18:16:11 +01:00
|
|
|
|
2018-02-20 10:14:23 -03:00
|
|
|
DRW_render_object_iter(vedata, engine, draw_ctx->depsgraph, EEVEE_render_cache);
|
2018-01-31 01:09:38 +01:00
|
|
|
|
2018-01-29 18:16:11 +01:00
|
|
|
/* Actually do the rendering. */
|
2018-02-23 13:26:28 -03:00
|
|
|
EEVEE_render_draw(vedata, engine, render_layer, rect);
|
2018-01-29 18:16:11 +01:00
|
|
|
}
|
|
|
|
|
2017-11-29 12:28:40 +01:00
|
|
|
static void eevee_engine_free(void)
|
2017-03-17 00:00:46 +01:00
|
|
|
{
|
2018-11-16 13:46:13 -02:00
|
|
|
EEVEE_shaders_free();
|
2017-11-01 01:03:36 +01:00
|
|
|
EEVEE_bloom_free();
|
|
|
|
EEVEE_depth_of_field_free();
|
2017-05-04 17:36:40 +02:00
|
|
|
EEVEE_effects_free();
|
2017-06-12 20:59:54 +10:00
|
|
|
EEVEE_lightprobes_free();
|
2017-11-01 01:03:36 +01:00
|
|
|
EEVEE_lights_free();
|
|
|
|
EEVEE_materials_free();
|
2018-02-01 18:09:06 +01:00
|
|
|
EEVEE_mist_free();
|
2017-11-01 01:03:36 +01:00
|
|
|
EEVEE_motion_blur_free();
|
|
|
|
EEVEE_occlusion_free();
|
|
|
|
EEVEE_screen_raytrace_free();
|
2017-11-14 00:49:54 +01:00
|
|
|
EEVEE_subsurface_free();
|
2017-11-01 01:03:36 +01:00
|
|
|
EEVEE_volumes_free();
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
|
|
|
|
2017-11-29 12:28:40 +01:00
|
|
|
static const DrawEngineDataSize eevee_data_size = DRW_VIEWPORT_DATA_SIZE(EEVEE_Data);
|
2017-04-12 19:49:19 +10:00
|
|
|
|
2017-03-17 00:00:46 +01:00
|
|
|
DrawEngineType draw_engine_eevee_type = {
|
|
|
|
NULL, NULL,
|
2017-03-26 19:10:53 +02:00
|
|
|
N_("Eevee"),
|
2017-11-29 12:28:40 +01:00
|
|
|
&eevee_data_size,
|
|
|
|
&eevee_engine_init,
|
|
|
|
&eevee_engine_free,
|
|
|
|
&eevee_cache_init,
|
2018-07-10 15:02:25 +02:00
|
|
|
&EEVEE_cache_populate,
|
2017-11-29 12:28:40 +01:00
|
|
|
&eevee_cache_finish,
|
2018-01-02 14:15:33 +01:00
|
|
|
&eevee_draw_background,
|
|
|
|
NULL, /* Everything is drawn in the background pass (see comment on function) */
|
2017-11-29 12:28:40 +01:00
|
|
|
&eevee_view_update,
|
|
|
|
&eevee_id_update,
|
2018-01-29 18:16:11 +01:00
|
|
|
&eevee_render_to_image,
|
2017-03-17 00:00:46 +01:00
|
|
|
};
|
|
|
|
|
2017-04-26 17:42:39 +10:00
|
|
|
RenderEngineType DRW_engine_viewport_eevee_type = {
|
2017-03-17 00:00:46 +01:00
|
|
|
NULL, NULL,
|
2018-02-27 09:21:54 -03:00
|
|
|
EEVEE_ENGINE, N_("Eevee"), RE_INTERNAL | RE_USE_SHADING_NODES | RE_USE_PREVIEW,
|
2018-02-01 21:38:16 +01:00
|
|
|
NULL, &DRW_render_to_image, NULL, NULL, NULL, NULL,
|
|
|
|
&EEVEE_render_update_passes,
|
2017-03-17 00:00:46 +01:00
|
|
|
&draw_engine_eevee_type,
|
2019-01-31 08:28:56 +11:00
|
|
|
{NULL, NULL, NULL},
|
2017-03-17 00:00:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#undef EEVEE_ENGINE
|