2017-03-17 00:00:46 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2016, Blender Foundation.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Contributor(s): Blender Institute
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-04-26 17:42:39 +10:00
|
|
|
/** \file eevee_engine.c
|
|
|
|
* \ingroup draw_engine
|
2017-03-17 00:00:46 +01:00
|
|
|
*/
|
|
|
|
|
2017-04-25 23:48:26 +02:00
|
|
|
#include "DNA_world_types.h"
|
2017-06-04 12:12:58 +02:00
|
|
|
#include "DRW_render.h"
|
2017-04-25 23:48:26 +02:00
|
|
|
|
2017-03-28 00:09:45 +02:00
|
|
|
#include "BLI_dynstr.h"
|
2017-04-18 12:50:09 +02:00
|
|
|
#include "BLI_rand.h"
|
2017-04-27 22:27:09 +02:00
|
|
|
|
|
|
|
#include "GPU_material.h"
|
2017-04-18 12:50:09 +02:00
|
|
|
#include "GPU_glew.h"
|
2017-03-28 00:09:45 +02:00
|
|
|
|
2017-04-26 17:42:39 +10:00
|
|
|
#include "eevee_engine.h"
|
2017-03-17 00:00:46 +01:00
|
|
|
#include "eevee_private.h"
|
|
|
|
|
|
|
|
#define EEVEE_ENGINE "BLENDER_EEVEE"
|
|
|
|
|
2017-04-25 23:48:26 +02:00
|
|
|
extern GlobalsUboStorage ts;
|
2017-04-25 18:46:59 +02:00
|
|
|
|
2017-03-17 00:00:46 +01:00
|
|
|
/* *********** FUNCTIONS *********** */
|
|
|
|
|
2017-04-18 12:50:09 +02: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-03 00:53:47 +02:00
|
|
|
EEVEE_SceneLayerData *sldata = EEVEE_scene_layer_data_get();
|
2017-03-17 00:00:46 +01:00
|
|
|
|
2017-05-16 20:18:57 +02:00
|
|
|
DRWFboTexture tex = {&txl->color, DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER};
|
2017-03-17 00:00:46 +01:00
|
|
|
|
2017-04-12 12:10:01 +10:00
|
|
|
const float *viewport_size = DRW_viewport_size_get();
|
2017-05-16 03:03:58 +02:00
|
|
|
DRW_framebuffer_init(&fbl->main, &draw_engine_eevee_type,
|
2017-03-17 00:00:46 +01:00
|
|
|
(int)viewport_size[0], (int)viewport_size[1],
|
|
|
|
&tex, 1);
|
|
|
|
|
2017-06-04 12:12:58 +02:00
|
|
|
EEVEE_materials_init();
|
2017-06-03 00:53:47 +02:00
|
|
|
EEVEE_lights_init(sldata);
|
|
|
|
EEVEE_probes_init(sldata);
|
2017-05-04 17:36:40 +02:00
|
|
|
EEVEE_effects_init(vedata);
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
|
|
|
|
2017-03-26 19:10:53 +02:00
|
|
|
static void EEVEE_cache_init(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;
|
|
|
|
EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl;
|
2017-06-03 00:53:47 +02:00
|
|
|
EEVEE_SceneLayerData *sldata = EEVEE_scene_layer_data_get();
|
2017-05-30 22:29:20 +02:00
|
|
|
|
2017-03-26 20:13:34 +02:00
|
|
|
if (!stl->g_data) {
|
|
|
|
/* Alloc transient pointers */
|
2017-04-29 16:52:12 +10:00
|
|
|
stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
|
2017-03-26 20:13:34 +02:00
|
|
|
}
|
|
|
|
|
2017-06-04 12:12:58 +02:00
|
|
|
EEVEE_materials_cache_init(vedata);
|
2017-05-30 22:29:20 +02:00
|
|
|
EEVEE_lights_cache_init(sldata, psl);
|
2017-06-04 12:12:58 +02:00
|
|
|
EEVEE_probes_cache_init(sldata, psl);
|
2017-05-04 17:36:40 +02:00
|
|
|
EEVEE_effects_cache_init(vedata);
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
|
|
|
|
2017-03-26 19:10:53 +02:00
|
|
|
static void EEVEE_cache_populate(void *vedata, Object *ob)
|
2017-03-17 00:00:46 +01:00
|
|
|
{
|
2017-04-19 22:07:53 +02:00
|
|
|
EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
|
2017-06-03 00:53:47 +02:00
|
|
|
EEVEE_SceneLayerData *sldata = EEVEE_scene_layer_data_get();
|
2017-03-17 00:00:46 +01:00
|
|
|
|
2017-05-17 17:06:55 +10:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
const bool is_active = (ob == draw_ctx->obact);
|
|
|
|
if (is_active) {
|
|
|
|
if (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-05-12 17:54:14 +02:00
|
|
|
|
2017-04-21 02:18:14 +10:00
|
|
|
struct Batch *geom = DRW_cache_object_surface_get(ob);
|
|
|
|
if (geom) {
|
2017-06-04 12:12:58 +02:00
|
|
|
EEVEE_materials_cache_populate(vedata, sldata, ob, geom);
|
2017-04-25 18:46:59 +02:00
|
|
|
|
2017-05-20 13:16:14 +02:00
|
|
|
const bool cast_shadow = true;
|
|
|
|
|
|
|
|
if (cast_shadow) {
|
2017-05-30 22:29:20 +02:00
|
|
|
EEVEE_lights_cache_shcaster_add(sldata, psl, geom, ob->obmat);
|
2017-06-01 18:20:44 +02:00
|
|
|
BLI_addtail(&sldata->shadow_casters, BLI_genericNodeN(ob));
|
2017-06-03 00:53:47 +02:00
|
|
|
EEVEE_ObjectEngineData *oedata = EEVEE_object_data_get(ob);
|
2017-06-01 18:20:44 +02:00
|
|
|
oedata->need_update = ((ob->deg_update_flag & DEG_RUNTIME_DATA_UPDATE) != 0);
|
2017-05-20 13:16:14 +02:00
|
|
|
}
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
2017-06-08 21:48:50 +02:00
|
|
|
else if (ob->type == OB_PROBE) {
|
|
|
|
EEVEE_probes_cache_add(sldata, ob);
|
|
|
|
}
|
2017-03-17 00:00:46 +01:00
|
|
|
else if (ob->type == OB_LAMP) {
|
2017-05-30 22:29:20 +02:00
|
|
|
EEVEE_lights_cache_add(sldata, ob);
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-05 22:05:21 +02:00
|
|
|
static void EEVEE_cache_finish(void *vedata)
|
2017-05-02 19:25:25 +02:00
|
|
|
{
|
2017-06-03 00:53:47 +02:00
|
|
|
EEVEE_SceneLayerData *sldata = EEVEE_scene_layer_data_get();
|
2017-03-17 00:00:46 +01:00
|
|
|
|
2017-06-05 22:05:21 +02:00
|
|
|
EEVEE_materials_cache_finish(vedata);
|
2017-05-30 22:29:20 +02:00
|
|
|
EEVEE_lights_cache_finish(sldata);
|
|
|
|
EEVEE_probes_cache_finish(sldata);
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
|
|
|
|
2017-03-26 19:10:53 +02:00
|
|
|
static void EEVEE_draw_scene(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;
|
|
|
|
EEVEE_FramebufferList *fbl = ((EEVEE_Data *)vedata)->fbl;
|
2017-06-03 00:53:47 +02:00
|
|
|
EEVEE_SceneLayerData *sldata = EEVEE_scene_layer_data_get();
|
2017-03-17 00:00:46 +01:00
|
|
|
|
|
|
|
/* Default framebuffer and texture */
|
|
|
|
DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
|
|
|
|
|
2017-04-10 12:06:17 +02:00
|
|
|
/* Refresh shadows */
|
2017-05-30 22:29:20 +02:00
|
|
|
EEVEE_draw_shadows(sldata, psl);
|
2017-04-10 12:06:17 +02:00
|
|
|
|
2017-06-04 12:12:58 +02:00
|
|
|
/* Refresh Probes */
|
|
|
|
EEVEE_probes_refresh(sldata, psl);
|
|
|
|
|
2017-03-17 00:00:46 +01:00
|
|
|
/* Attach depth to the hdr buffer and bind it */
|
|
|
|
DRW_framebuffer_texture_detach(dtxl->depth);
|
2017-04-18 11:28:11 +02:00
|
|
|
DRW_framebuffer_texture_attach(fbl->main, dtxl->depth, 0, 0);
|
2017-03-17 00:00:46 +01:00
|
|
|
DRW_framebuffer_bind(fbl->main);
|
2017-05-10 10:31:17 +02:00
|
|
|
DRW_framebuffer_clear(false, true, false, NULL, 1.0f);
|
2017-03-17 00:00:46 +01:00
|
|
|
|
2017-05-04 17:39:50 +02:00
|
|
|
DRW_draw_pass(psl->background_pass);
|
2017-06-04 12:12:58 +02:00
|
|
|
|
|
|
|
/* Depth prepass */
|
2017-03-18 01:55:41 +01:00
|
|
|
DRW_draw_pass(psl->depth_pass);
|
|
|
|
DRW_draw_pass(psl->depth_pass_cull);
|
2017-06-04 12:12:58 +02:00
|
|
|
|
|
|
|
/* Shading pass */
|
2017-04-25 18:46:59 +02:00
|
|
|
DRW_draw_pass(psl->default_pass);
|
2017-06-04 12:12:58 +02:00
|
|
|
DRW_draw_pass(psl->default_flat_pass);
|
2017-04-25 18:46:59 +02:00
|
|
|
DRW_draw_pass(psl->material_pass);
|
2017-03-17 00:00:46 +01:00
|
|
|
|
2017-06-04 12:12:58 +02:00
|
|
|
/* Post Process */
|
2017-05-04 17:36:40 +02:00
|
|
|
EEVEE_draw_effects(vedata);
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void EEVEE_engine_free(void)
|
|
|
|
{
|
2017-06-04 12:12:58 +02:00
|
|
|
EEVEE_materials_free();
|
2017-05-04 17:36:40 +02:00
|
|
|
EEVEE_effects_free();
|
2017-05-20 13:16:14 +02:00
|
|
|
EEVEE_lights_free();
|
2017-05-29 22:03:57 +02:00
|
|
|
EEVEE_probes_free();
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
|
|
|
|
2017-05-05 16:27:31 +02:00
|
|
|
static void EEVEE_layer_collection_settings_create(RenderEngine *UNUSED(engine), IDProperty *props)
|
2017-03-17 00:00:46 +01:00
|
|
|
{
|
2017-03-30 17:01:23 +02:00
|
|
|
BLI_assert(props &&
|
|
|
|
props->type == IDP_GROUP &&
|
|
|
|
props->subtype == IDP_GROUP_SUB_ENGINE_RENDER);
|
|
|
|
// BKE_collection_engine_property_add_int(props, "high_quality_sphere_lamps", false);
|
2017-05-05 16:27:31 +02:00
|
|
|
UNUSED_VARS_NDEBUG(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void EEVEE_scene_layer_settings_create(RenderEngine *UNUSED(engine), IDProperty *props)
|
|
|
|
{
|
|
|
|
BLI_assert(props &&
|
|
|
|
props->type == IDP_GROUP &&
|
|
|
|
props->subtype == IDP_GROUP_SUB_ENGINE_RENDER);
|
2017-05-10 15:58:18 +02:00
|
|
|
|
|
|
|
BKE_collection_engine_property_add_bool(props, "dof_enable", false);
|
|
|
|
BKE_collection_engine_property_add_float(props, "bokeh_max_size", 100.0f);
|
|
|
|
BKE_collection_engine_property_add_float(props, "bokeh_threshold", 1.0f);
|
|
|
|
|
|
|
|
BKE_collection_engine_property_add_bool(props, "bloom_enable", false);
|
|
|
|
BKE_collection_engine_property_add_float(props, "bloom_threshold", 0.8f);
|
|
|
|
BKE_collection_engine_property_add_float(props, "bloom_knee", 0.5f);
|
|
|
|
BKE_collection_engine_property_add_float(props, "bloom_intensity", 0.8f);
|
|
|
|
BKE_collection_engine_property_add_float(props, "bloom_radius", 6.5f);
|
|
|
|
|
|
|
|
BKE_collection_engine_property_add_bool(props, "motion_blur_enable", false);
|
|
|
|
BKE_collection_engine_property_add_int(props, "motion_blur_samples", 8);
|
|
|
|
BKE_collection_engine_property_add_float(props, "motion_blur_shutter", 1.0f);
|
2017-03-17 00:00:46 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 19:49:19 +10:00
|
|
|
static const DrawEngineDataSize EEVEE_data_size = DRW_VIEWPORT_DATA_SIZE(EEVEE_Data);
|
|
|
|
|
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-04-12 19:49:19 +10:00
|
|
|
&EEVEE_data_size,
|
2017-03-17 00:00:46 +01:00
|
|
|
&EEVEE_engine_init,
|
|
|
|
&EEVEE_engine_free,
|
|
|
|
&EEVEE_cache_init,
|
|
|
|
&EEVEE_cache_populate,
|
|
|
|
&EEVEE_cache_finish,
|
|
|
|
&EEVEE_draw_scene,
|
|
|
|
NULL//&EEVEE_draw_scene
|
|
|
|
};
|
|
|
|
|
2017-04-26 17:42:39 +10:00
|
|
|
RenderEngineType DRW_engine_viewport_eevee_type = {
|
2017-03-17 00:00:46 +01:00
|
|
|
NULL, NULL,
|
2017-05-01 14:55:59 +02:00
|
|
|
EEVEE_ENGINE, N_("Eevee"), RE_INTERNAL | RE_USE_SHADING_NODES,
|
2017-05-05 16:27:31 +02:00
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
|
|
|
&EEVEE_layer_collection_settings_create, &EEVEE_scene_layer_settings_create,
|
2017-03-17 00:00:46 +01:00
|
|
|
&draw_engine_eevee_type,
|
|
|
|
{NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#undef EEVEE_ENGINE
|