[Bf-blender-cvs] [1a43e081873] blender2.8: Eevee: LightCache: Initial Implementation

Clément Foucault noreply at git.blender.org
Tue Jul 10 15:40:47 CEST 2018


Commit: 1a43e081873415754950766edaddad220adf67bc
Author: Clément Foucault
Date:   Tue Jul 10 15:02:25 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB1a43e081873415754950766edaddad220adf67bc

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.

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

M	release/scripts/startup/bl_ui/properties_render.py
M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenloader/CMakeLists.txt
M	source/blender/blenloader/intern/readblenentry.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/readfile.h
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/eevee/eevee_data.c
M	source/blender/draw/engines/eevee/eevee_engine.c
A	source/blender/draw/engines/eevee/eevee_lightcache.c
A	source/blender/draw/engines/eevee/eevee_lightcache.h
M	source/blender/draw/engines/eevee/eevee_lightprobes.c
M	source/blender/draw/engines/eevee/eevee_lights.c
M	source/blender/draw/engines/eevee/eevee_lookdev.c
M	source/blender/draw/engines/eevee/eevee_materials.c
M	source/blender/draw/engines/eevee/eevee_private.h
M	source/blender/draw/engines/eevee/eevee_render.c
M	source/blender/draw/engines/eevee/eevee_screen_raytrace.c
M	source/blender/draw/engines/eevee/eevee_volumes.c
M	source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_frag.glsl
M	source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_vert.glsl
M	source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_frag.glsl
M	source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl
M	source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl
M	source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
M	source/blender/editors/render/render_intern.h
M	source/blender/editors/render/render_ops.c
M	source/blender/editors/render/render_shading.c
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/makesdna/DNA_lightprobe_types.h
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_scene.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/WM_types.h

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

diff --git a/release/scripts/startup/bl_ui/properties_render.py b/release/scripts/startup/bl_ui/properties_render.py
index 580c31465b3..ff36d2494ea 100644
--- a/release/scripts/startup/bl_ui/properties_render.py
+++ b/release/scripts/startup/bl_ui/properties_render.py
@@ -712,15 +712,49 @@ class RENDER_PT_eevee_indirect_lighting(RenderButtonsPanel, Panel):
     def draw(self, context):
         layout = self.layout
         layout.use_property_split = True
+        layout.use_property_decorate = False  # No animation.
 
         scene = context.scene
         props = scene.eevee
 
         col = layout.column()
+        col.operator("scene.light_cache_bake", text="Bake Indirect Lighting", icon='RENDER_STILL')
+        col.operator("scene.light_cache_bake", text="Bake Cubemap Only", icon='LIGHTPROBE_CUBEMAP').subset = "CUBEMAPS"
+        col.operator("scene.light_cache_free", text="Free Lighting Cache")
+
+        cache_info = scene.eevee.gi_cache_info
+        if cache_info:
+            col.label(text=cache_info)
+
+        col.prop(props, "gi_auto_bake")
+
         col.prop(props, "gi_diffuse_bounces")
         col.prop(props, "gi_cubemap_resolution")
         col.prop(props, "gi_visibility_resolution", text="Diffuse Occlusion")
 
+        layout.use_property_split = False
+        row = layout.split(percentage=0.5)
+        row.alignment = 'RIGHT'
+        row.label("Cubemap Display")
+
+        sub = row.row(align=True)
+        sub.prop(props, "gi_cubemap_draw_size", text="Size")
+        if props.gi_show_cubemaps :
+            sub.prop(props, "gi_show_cubemaps", text="", toggle=True, icon='HIDE_OFF')
+        else:
+            sub.prop(props, "gi_show_cubemaps", text="", toggle=True, icon='HIDE_ON')
+
+        row = layout.split(percentage=0.5)
+        row.alignment = 'RIGHT'
+        row.label("Irradiance Display")
+
+        sub = row.row(align=True)
+        sub.prop(props, "gi_irradiance_draw_size", text="Size")
+        if props.gi_show_irradiance :
+            sub.prop(props, "gi_show_irradiance", text="", toggle=True, icon='HIDE_OFF')
+        else:
+            sub.prop(props, "gi_show_irradiance", text="", toggle=True, icon='HIDE_ON')
+
 
 class RENDER_PT_eevee_film(RenderButtonsPanel, Panel):
     bl_label = "Film"
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 1b309d76f61..2b2fc2fc767 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -102,6 +102,9 @@
 #include "DEG_depsgraph_query.h"
 
 #include "RE_engine.h"
+#include "RE_engine.h"
+
+#include "engines/eevee/eevee_lightcache.h"
 
 #include "PIL_time.h"
 
@@ -316,6 +319,9 @@ void BKE_scene_copy_data(Main *bmain, Scene *sce_dst, const Scene *sce_src, cons
 	else {
 		sce_dst->preview = NULL;
 	}
+
+	sce_dst->eevee.light_cache = NULL;
+	/* TODO Copy the cache. */
 }
 
 Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type)
@@ -511,6 +517,11 @@ void BKE_scene_free_ex(Scene *sce, const bool do_id_user)
 		sce->master_collection = NULL;
 	}
 
+	if (sce->eevee.light_cache) {
+		EEVEE_lightcache_free(sce->eevee.light_cache);
+		sce->eevee.light_cache = NULL;
+	}
+
 	/* These are freed on doversion. */
 	BLI_assert(sce->layer_properties == NULL);
 }
@@ -814,6 +825,8 @@ void BKE_scene_init(Scene *sce)
 	sce->eevee.gi_diffuse_bounces = 3;
 	sce->eevee.gi_cubemap_resolution = 512;
 	sce->eevee.gi_visibility_resolution = 32;
+	sce->eevee.gi_cubemap_draw_size = 0.3f;
+	sce->eevee.gi_irradiance_draw_size = 0.1f;
 
 	sce->eevee.taa_samples = 16;
 	sce->eevee.taa_render_samples = 64;
@@ -856,6 +869,8 @@ void BKE_scene_init(Scene *sce)
 	sce->eevee.shadow_cube_size = 512;
 	sce->eevee.shadow_cascade_size = 1024;
 
+	sce->eevee.light_cache = NULL;
+
 	sce->eevee.flag =
 	        SCE_EEVEE_VOLUMETRIC_LIGHTS |
 	        SCE_EEVEE_VOLUMETRIC_COLORED |
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/s

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list