[Bf-blender-cvs] [7dd0be9554a] master: EEVEE: Replace octahedron reflection probe by cubemap array

Clément Foucault noreply at git.blender.org
Wed Mar 11 17:14:24 CET 2020


Commit: 7dd0be9554ae7a728ded1a95d4709a93b68301b4
Author: Clément Foucault
Date:   Wed Mar 11 17:12:01 2020 +0100
Branches: master
https://developer.blender.org/rB7dd0be9554ae7a728ded1a95d4709a93b68301b4

EEVEE: Replace octahedron reflection probe by cubemap array

We implement cubemap array support for EEVEE's lightcache reflection probes.
This removes stretched texels and bottom hemisphere seams artifacts caused
by the octahedral projection previously used.

This introduce versioning code for the lightcache which will discard any
lightcache version that is not compatible.

Differential Revision: https://developer.blender.org/D7066

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

M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenloader/intern/readfile.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_lightcache.c
M	source/blender/draw/engines/eevee/eevee_lightcache.h
M	source/blender/draw/engines/eevee/eevee_lightprobes.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_screen_raytrace.c
M	source/blender/draw/engines/eevee/eevee_shaders.c
M	source/blender/draw/engines/eevee/eevee_subsurface.c
M	source/blender/draw/engines/eevee/eevee_volumes.c
A	source/blender/draw/engines/eevee/shaders/cubemap_lib.glsl
M	source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_frag.glsl
M	source/blender/draw/engines/eevee/shaders/lightprobe_filter_glossy_frag.glsl
M	source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl
M	source/blender/draw/engines/eevee/shaders/octahedron_lib.glsl
M	source/blender/draw/intern/DRW_render.h
M	source/blender/draw/intern/draw_manager_texture.c
M	source/blender/editors/render/render_shading.c
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/gpu/GPU_extensions.h
M	source/blender/gpu/GPU_texture.h
M	source/blender/gpu/intern/gpu_extensions.c
M	source/blender/gpu/intern/gpu_shader.c
M	source/blender/gpu/intern/gpu_texture.c
M	source/blender/makesdna/DNA_lightprobe_types.h
M	source/blender/makesdna/DNA_scene_defaults.h
M	source/blender/makesdna/DNA_scene_types.h

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

diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 027933e17c6..6ca14ec9197 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -395,9 +395,9 @@ static void scene_free_data(ID *id)
     scene->master_collection = NULL;
   }
 
-  if (scene->eevee.light_cache) {
-    EEVEE_lightcache_free(scene->eevee.light_cache);
-    scene->eevee.light_cache = NULL;
+  if (scene->eevee.light_cache_data) {
+    EEVEE_lightcache_free(scene->eevee.light_cache_data);
+    scene->eevee.light_cache_data = NULL;
   }
 
   if (scene->display.shading.prop) {
@@ -583,7 +583,7 @@ void BKE_scene_copy_data_eevee(Scene *sce_dst, const Scene *sce_src)
 {
   /* Copy eevee data between scenes. */
   sce_dst->eevee = sce_src->eevee;
-  sce_dst->eevee.light_cache = NULL;
+  sce_dst->eevee.light_cache_data = NULL;
   sce_dst->eevee.light_cache_info[0] = '\0';
   /* TODO Copy the cache. */
 }
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index f73dc9a5466..49b51c34562 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -157,6 +157,8 @@
 
 #include "RE_engine.h"
 
+#include "engines/eevee/eevee_lightcache.h"
+
 #include "readfile.h"
 
 #include <errno.h>
@@ -1852,8 +1854,8 @@ void blo_make_scene_pointer_map(FileData *fd, Main *oldmain)
   fd->scenemap = oldnewmap_new();
 
   for (; sce; sce = sce->id.next) {
-    if (sce->eevee.light_cache) {
-      struct LightCache *light_cache = sce->eevee.light_cache;
+    if (sce->eevee.light_cache_data) {
+      struct LightCache *light_cache = sce->eevee.light_cache_data;
       oldnewmap_insert(fd->scenemap, light_cache, light_cache, 0);
     }
   }
@@ -1873,7 +1875,7 @@ void blo_end_scene_pointer_map(FileData *fd, Main *oldmain)
   }
 
   for (; sce; sce = sce->id.next) {
-    sce->eevee.light_cache = newsceadr(fd, sce->eevee.light_cache);
+    sce->eevee.light_cache_data = newsceadr(fd, sce->eevee.light_cache_data);
   }
 }
 
@@ -6927,19 +6929,20 @@ static void direct_link_scene(FileData *fd, Scene *sce)
   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);
+      sce->eevee.light_cache_data = newsceadr(fd, sce->eevee.light_cache_data);
     }
     else {
-      sce->eevee.light_cache = NULL;
+      sce->eevee.light_cache_data = NULL;
     }
   }
   else {
     /* else try to read the cache from file. */
-    sce->eevee.light_cache = newdataadr(fd, sce->eevee.light_cache);
-    if (sce->eevee.light_cache) {
-      direct_link_lightcache(fd, sce->eevee.light_cache);
+    sce->eevee.light_cache_data = newdataadr(fd, sce->eevee.light_cache_data);
+    if (sce->eevee.light_cache_data) {
+      direct_link_lightcache(fd, sce->eevee.light_cache_data);
     }
   }
+  EEVEE_lightcache_info_update(&sce->eevee);
 
   direct_link_view3dshading(fd, &sce->display.shading);
 
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 81df00ebdef..a9c5008062b 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2767,9 +2767,9 @@ static void write_scene(WriteData *wd, Scene *sce)
   }
 
   /* 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);
+  if (sce->eevee.light_cache_data && !wd->use_memfile) {
+    writestruct(wd, DATA, LightCache, 1, sce->eevee.light_cache_data);
+    write_lightcache(wd, sce->eevee.light_cache_data);
   }
 
   write_view3dshading(wd, &sce->display.shading);
diff --git a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
index 1841f5f024f..50870d1e4aa 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
+++ b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
@@ -804,7 +804,7 @@ void update_id_after_copy(const Depsgraph *depsgraph,
       Scene *scene_cow = (Scene *)id_cow;
       const Scene *scene_orig = (const Scene *)id_orig;
       scene_cow->toolsettings = scene_orig->toolsettings;
-      scene_cow->eevee.light_cache = scene_orig->eevee.light_cache;
+      scene_cow->eevee.light_cache_data = scene_orig->eevee.light_cache_data;
       scene_setup_view_layers_after_remap(depsgraph, id_node, reinterpret_cast<Scene *>(id_cow));
       update_scene_orig_pointers(scene_orig, scene_cow);
       break;
@@ -1000,7 +1000,7 @@ void discard_scene_pointers(ID *id_cow)
 {
   Scene *scene_cow = (Scene *)id_cow;
   scene_cow->toolsettings = nullptr;
-  scene_cow->eevee.light_cache = nullptr;
+  scene_cow->eevee.light_cache_data = nullptr;
 }
 
 /* nullptr-ify all edit mode pointers which points to data from
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index fe03a32fd07..a1213be4be0 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -230,6 +230,7 @@ data_to_c_simple(engines/eevee/shaders/btdf_lut_frag.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/bsdf_common_lib.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/irradiance_lib.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/octahedron_lib.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/cubemap_lib.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/bsdf_sampling_lib.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/raytrace_lib.glsl SRC)
 data_to_c_simple(engines/eevee/shaders/renderpass_postprocess_frag.glsl SRC)
diff --git a/source/blender/draw/engines/eevee/eevee_lightcache.c b/source/blender/draw/engines/eevee/eevee_lightcache.c
index 2b11a608bd0..ae4c7dec1e1 100644
--- a/source/blender/draw/engines/eevee/eevee_lightcache.c
+++ b/source/blender/draw/engines/eevee/eevee_lightcache.c
@@ -42,6 +42,7 @@
 #include "eevee_private.h"
 
 #include "GPU_context.h"
+#include "GPU_extensions.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -195,6 +196,16 @@ static uint eevee_lightcache_memsize_get(LightCache *lcache)
   return size;
 }
 
+static bool eevee_lightcache_version_check(LightCache *lcache)
+{
+  switch (lcache->type) {
+    case LIGHTCACHE_TYPE_STATIC:
+      return lcache->version == LIGHTCACHE_STATIC_VERSION;
+    default:
+      return false;
+  }
+}
+
 static int eevee_lightcache_irradiance_sample_count(LightCache *lcache)
 {
   int total_irr_samples = 0;
@@ -208,9 +219,23 @@ static int eevee_lightcache_irradiance_sample_count(LightCache *lcache)
 
 void EEVEE_lightcache_info_update(SceneEEVEE *eevee)
 {
-  LightCache *lcache = eevee->light_cache;
+  LightCache *lcache = eevee->light_cache_data;
 
   if (lcache != NULL) {
+    if (!eevee_lightcache_version_check(lcache)) {
+      BLI_strncpy(eevee->light_cache_info,
+                  TIP_("Incompatible Light cache version, please bake again"),
+                  sizeof(eevee->light_cache_info));
+      return;
+    }
+
+    if (lcache->cube_tx.tex_size[2] > GPU_max_texture_layers()) {
+      BLI_strncpy(eevee->light_cache_info,
+                  TIP_("Error: Light cache is too big for your GPU to be loaded"),
+                  sizeof(eevee->light_cache_info));
+      return;
+    }
+
     if (lcache->flag & LIGHTCACHE_BAKING) {
       BLI_strncpy(
           eevee->light_cache_info, TIP_("Baking light cache"), sizeof(eevee->light_cache_info));
@@ -266,8 +291,8 @@ static bool EEVEE_lightcache_validate(const LightCache *light_cache,
         (irr_size[2] == light_cache->grid_tx.tex_size[2]) && (grid_len == light_cache->grid_len)) {
       int mip_len = log2_floor_u(cube_res) - MIN_CUBE_LOD_LEVEL;
       if ((cube_res == light_cache->cube_tx.tex_size[0]) &&
-          (cube_len == light_cache->cube_tx.tex_size[2]) && (cube_len == light_cache->cube_len) &&
-          (mip_len == light_cache->mips_len)) {
+          (cube_len == light_cache->cube_tx.tex_size[2] / 6) &&
+          (cube_len == light_cache->cube_len) && (mip_len == light_cache->mips_len)) {
         return true;
       }
     }
@@ -283,6 +308,9 @@ LightCache *EEVEE_lightcache_create(const int grid_len,
 {
   LightCache *light_cache = MEM_callocN(sizeof(LightCache), "LightCache");
 
+  light_cache->version = LIGHTCACHE_STATIC_VERSION;
+  light_cache->type = LIGHTCACHE_TYPE_STATIC;
+
   light_cache->cube_data = MEM_callocN(sizeof(EEVEE_LightProbe) * cube_len, "EEVEE_LightProbe");
   light_cache->grid_data = MEM_callocN(sizeof(EEVEE_LightGrid) * grid_len, "EEVEE_LightGrid");
 
@@ -292,13 +320,26 @@ LightCache *EEVEE_lightcache_create(const int grid_len,
   light_cache->grid_tx.tex_size[1] = irr_size[1];
   light_cache->grid_tx.tex_size[2] = irr_size[2];
 
-  light_cache->cube_tx.tex = DRW_texture_create_2d_array(
-      cube_size, cube_size, cube_len, GPU_R11F_G11F_B10F, DRW_TEX_FILTER | DRW_TEX_MIPMAP, NULL);
+  int mips_len = log2_floor_u(cube_size) - MIN_CUBE_LOD_LEVEL;
+
+  if (GPU_arb_texture_cube_map_array_is_supported()) {
+    light_cache->cube_tx.tex = DRW_texture_create_cube_array(
+        cube_size, cube_len, GPU_R11F_G11F_B10F, DRW_TEX_FILTER | DRW_TEX_MIPMAP, NULL);
+  }
+  else {
+    light_cache->cube_tx.tex = DRW_texture_create_2d_array(cube_size,
+                                                           cube_size,
+                                                           cube_len * 6,
+                                                           GPU_R11F_G11F_B10F,
+                                                           DRW_TEX_FILTER | DRW_TEX_MIPMAP,
+                                                           NULL);
+  }
+
   light_cache->cube_tx.tex_size[0] = cube_size;
   light_cache->cube_tx.tex_size[1] = cube_size;
-  light_cache->cube_tx.tex_size[2] = cube_len;
+  light_cache->cube_tx.tex_size[2] = cube_len * 6;
 
-  light_cache->mips_len = log2_floor_u(cube_size) - MIN_CUBE_LOD_LEVEL;
+  light_cache->mips_len = mips_len;
   light_cache->vis_res = vis_size;
   light_cache->ref_res = cube_size;
 
@@ -315,9 +356,19 @@ LightCache *EEVEE_lightcache_create(const int grid_len,
  

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list