Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2018-07-10 16:02:25 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-07-10 16:31:34 +0300
commit1a43e081873415754950766edaddad220adf67bc (patch)
tree6a4e61b2337606daf442973d9f82e1d56b906a98 /source/blender/blenloader
parent97f90d48a02eef89949532b166f57ea178ee5a87 (diff)
Eevee: LightCache: Initial Implementation
This separate probe rendering from viewport rendering, making possible to run the baking in another thread (non blocking and faster). The baked lighting is saved in the blend file. Nothing needs to be recomputed on load. There is a few missing bits / bugs: - Cache cannot be saved to disk as a separate file, it is saved in the DNA for now making file larger and memory usage higher. - Auto update only cubemaps does update the grids (bug). - Probes cannot be updated individually (considered as dynamic). - Light Cache cannot be (re)generated during render.
Diffstat (limited to 'source/blender/blenloader')
-rw-r--r--source/blender/blenloader/CMakeLists.txt1
-rw-r--r--source/blender/blenloader/intern/readblenentry.c6
-rw-r--r--source/blender/blenloader/intern/readfile.c96
-rw-r--r--source/blender/blenloader/intern/readfile.h3
-rw-r--r--source/blender/blenloader/intern/versioning_280.c7
-rw-r--r--source/blender/blenloader/intern/writefile.c36
6 files changed, 148 insertions, 1 deletions
diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt
index b340aa28324..72fa155553d 100644
--- a/source/blender/blenloader/CMakeLists.txt
+++ b/source/blender/blenloader/CMakeLists.txt
@@ -30,6 +30,7 @@ set(INC
../blenlib
../blentranslation
../depsgraph
+ ../draw
../imbuf
../makesdna
../makesrna
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index 7488d62bb3c..6fd77c34977 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -393,6 +393,9 @@ BlendFileData *BLO_read_from_memfile(
/* makes lookup of existing images in old main */
blo_make_image_pointer_map(fd, oldmain);
+ /* makes lookup of existing light caches in old main */
+ blo_make_scene_pointer_map(fd, oldmain);
+
/* makes lookup of existing video clips in old main */
blo_make_movieclip_pointer_map(fd, oldmain);
@@ -403,6 +406,9 @@ BlendFileData *BLO_read_from_memfile(
bfd = blo_read_file_internal(fd, filename);
+ /* ensures relinked light caches are not freed */
+ blo_end_scene_pointer_map(fd, oldmain);
+
/* ensures relinked images are not freed */
blo_end_image_pointer_map(fd, oldmain);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 3eb0626307b..db3c1894e8c 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -158,6 +158,8 @@
#include "BKE_colortools.h"
#include "BKE_workspace.h"
+#include "DRW_engine.h"
+
#include "DEG_depsgraph.h"
#include "NOD_common.h"
@@ -1339,6 +1341,8 @@ void blo_freefiledata(FileData *fd)
oldnewmap_free(fd->imamap);
if (fd->movieclipmap)
oldnewmap_free(fd->movieclipmap);
+ if (fd->scenemap)
+ oldnewmap_free(fd->scenemap);
if (fd->soundmap)
oldnewmap_free(fd->soundmap);
if (fd->packedmap)
@@ -1526,6 +1530,13 @@ static void *newimaadr(FileData *fd, const void *adr) /* used to restore im
return NULL;
}
+static void *newsceadr(FileData *fd, const void *adr) /* used to restore scene data after undo */
+{
+ if (fd->scenemap && adr)
+ return oldnewmap_lookup_and_inc(fd->scenemap, adr, true);
+ return NULL;
+}
+
static void *newmclipadr(FileData *fd, const void *adr) /* used to restore movie clip data after undo */
{
if (fd->movieclipmap && adr)
@@ -1631,6 +1642,37 @@ void blo_clear_proxy_pointers_from_lib(Main *oldmain)
}
}
+void blo_make_scene_pointer_map(FileData *fd, Main *oldmain)
+{
+ Scene *sce = oldmain->scene.first;
+
+ fd->scenemap = oldnewmap_new();
+
+ for (; sce; sce = sce->id.next) {
+ if (sce->eevee.light_cache) {
+ struct LightCache *light_cache = sce->eevee.light_cache;
+ oldnewmap_insert(fd->scenemap, light_cache, light_cache, 0);
+ }
+ }
+}
+
+void blo_end_scene_pointer_map(FileData *fd, Main *oldmain)
+{
+ OldNew *entry = fd->scenemap->entries;
+ Scene *sce = oldmain->scene.first;
+ int i;
+
+ /* used entries were restored, so we put them to zero */
+ for (i = 0; i < fd->scenemap->nentries; i++, entry++) {
+ if (entry->nr > 0)
+ entry->newp = NULL;
+ }
+
+ for (; sce; sce = sce->id.next) {
+ sce->eevee.light_cache = newsceadr(fd, sce->eevee.light_cache);
+ }
+}
+
void blo_make_image_pointer_map(FileData *fd, Main *oldmain)
{
Image *ima = oldmain->image.first;
@@ -2301,6 +2343,11 @@ static void direct_link_id(FileData *fd, ID *id)
id->override_static = newdataadr(fd, id->override_static);
link_list_ex(fd, &id->override_static->properties, direct_link_id_override_property_cb);
}
+
+ DrawDataList *drawdata = DRW_drawdatalist_from_id(id);
+ if (drawdata) {
+ BLI_listbase_clear((ListBase *)drawdata);
+ }
}
/* ************ READ CurveMapping *************** */
@@ -5492,7 +5539,6 @@ static void direct_link_object(FileData *fd, Object *ob)
ob->derivedFinal = NULL;
BKE_object_runtime_reset(ob);
BLI_listbase_clear(&ob->gpulamp);
- BLI_listbase_clear(&ob->drawdata);
link_list(fd, &ob->pc_ids);
/* Runtime curve data */
@@ -5739,6 +5785,41 @@ static void lib_link_sequence_modifiers(FileData *fd, Scene *scene, ListBase *lb
}
}
+static void direct_link_lightcache_texture(FileData *fd, LightCacheTexture *lctex)
+{
+ lctex->tex = NULL;
+
+ if (lctex->data) {
+ lctex->data = newdataadr(fd, lctex->data);
+ if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
+ int data_size = lctex->components * lctex->tex_size[0] * lctex->tex_size[1] * lctex->tex_size[2];
+
+ if (lctex->data_type == LIGHTCACHETEX_FLOAT) {
+ BLI_endian_switch_float_array((float *)lctex->data, data_size * sizeof(float));
+ }
+ else if (lctex->data_type == LIGHTCACHETEX_UINT) {
+ BLI_endian_switch_uint32_array((unsigned int *)lctex->data, data_size * sizeof(unsigned int));
+ }
+ }
+ }
+}
+
+static void direct_link_lightcache(FileData *fd, LightCache *cache)
+{
+ direct_link_lightcache_texture(fd, &cache->cube_tx);
+ direct_link_lightcache_texture(fd, &cache->grid_tx);
+
+ if (cache->cube_mips) {
+ cache->cube_mips = newdataadr(fd, cache->cube_mips);
+ for (int i = 0; i < cache->mips_len; ++i) {
+ direct_link_lightcache_texture(fd, &cache->cube_mips[i]);
+ }
+ }
+
+ cache->cube_data = newdataadr(fd, cache->cube_data);
+ cache->grid_data = newdataadr(fd, cache->grid_data);
+}
+
/* check for cyclic set-scene,
* libs can cause this case which is normally prevented, see (T#####) */
#define USE_SETSCENE_CHECK
@@ -6299,6 +6380,19 @@ static void direct_link_scene(FileData *fd, Scene *sce)
direct_link_view_layer(fd, view_layer);
}
+ if (fd->memfile) {
+ /* If it's undo try to recover the cache. */
+ if (fd->scenemap) sce->eevee.light_cache = newsceadr(fd, sce->eevee.light_cache);
+ else sce->eevee.light_cache = NULL;
+ }
+ else {
+ /* else read the cache from file. */
+ if (sce->eevee.light_cache) {
+ sce->eevee.light_cache = newdataadr(fd, sce->eevee.light_cache);
+ direct_link_lightcache(fd, sce->eevee.light_cache);
+ }
+ }
+
sce->layer_properties = newdataadr(fd, sce->layer_properties);
IDP_DirectLinkGroup_OrFree(&sce->layer_properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
}
diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h
index 9c699db5583..10f0c7a2942 100644
--- a/source/blender/blenloader/intern/readfile.h
+++ b/source/blender/blenloader/intern/readfile.h
@@ -90,6 +90,7 @@ typedef struct FileData {
struct OldNewMap *libmap;
struct OldNewMap *imamap;
struct OldNewMap *movieclipmap;
+ struct OldNewMap *scenemap;
struct OldNewMap *soundmap;
struct OldNewMap *packedmap;
@@ -140,6 +141,8 @@ FileData *blo_openblendermemfile(struct MemFile *memfile, struct ReportList *rep
void blo_clear_proxy_pointers_from_lib(Main *oldmain);
void blo_make_image_pointer_map(FileData *fd, Main *oldmain);
void blo_end_image_pointer_map(FileData *fd, Main *oldmain);
+void blo_make_scene_pointer_map(FileData *fd, Main *oldmain);
+void blo_end_scene_pointer_map(FileData *fd, Main *oldmain);
void blo_make_movieclip_pointer_map(FileData *fd, Main *oldmain);
void blo_end_movieclip_pointer_map(FileData *fd, Main *oldmain);
void blo_make_sound_pointer_map(FileData *fd, Main *oldmain);
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 5e27d72caa2..c9ab174d5e2 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -1541,6 +1541,13 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
+ if (!DNA_struct_elem_find(fd->filesdna, "SceneEEVEE", "float", "gi_cubemap_draw_size")) {
+ for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
+ scene->eevee.gi_irradiance_draw_size = 0.1f;
+ scene->eevee.gi_cubemap_draw_size = 0.3f;
+ }
+ }
+
for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
if (scene->toolsettings->manipulator_flag == 0) {
scene->toolsettings->manipulator_flag = SCE_MANIP_TRANSLATE | SCE_MANIP_ROTATE | SCE_MANIP_SCALE;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 0a2d09d0c86..049b2e8617c 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2479,6 +2479,36 @@ static void write_view_layer(WriteData *wd, ViewLayer *view_layer)
write_layer_collections(wd, &view_layer->layer_collections);
}
+static void write_lightcache_texture(WriteData *wd, LightCacheTexture *tex)
+{
+ if (tex->data) {
+ size_t data_size = tex->components * tex->tex_size[0] * tex->tex_size[1] * tex->tex_size[2];
+ if (tex->data_type == LIGHTCACHETEX_FLOAT) {
+ data_size *= sizeof(float);
+ }
+ else if (tex->data_type == LIGHTCACHETEX_UINT) {
+ data_size *= sizeof(unsigned int);
+ }
+ writedata(wd, DATA, data_size, tex->data);
+ }
+}
+
+static void write_lightcache(WriteData *wd, LightCache *cache)
+{
+ write_lightcache_texture(wd, &cache->grid_tx);
+ write_lightcache_texture(wd, &cache->cube_tx);
+
+ if (cache->cube_mips) {
+ writestruct(wd, DATA, LightCacheTexture, cache->mips_len, cache->cube_mips);
+ for (int i = 0; i < cache->mips_len; ++i) {
+ write_lightcache_texture(wd, &cache->cube_mips[i]);
+ }
+ }
+
+ writestruct(wd, DATA, LightGridCache, cache->grid_len, cache->grid_data);
+ writestruct(wd, DATA, LightProbeCache, cache->cube_len, cache->cube_data);
+}
+
static void write_scene(WriteData *wd, Scene *sce)
{
/* write LibData */
@@ -2679,6 +2709,12 @@ static void write_scene(WriteData *wd, Scene *sce)
write_collection_nolib(wd, sce->master_collection);
}
+ /* Eevee Lightcache */
+ if (sce->eevee.light_cache && !wd->use_memfile) {
+ writestruct(wd, DATA, LightCache, 1, sce->eevee.light_cache);
+ write_lightcache(wd, sce->eevee.light_cache);
+ }
+
/* Freed on doversion. */
BLI_assert(sce->layer_properties == NULL);
}