[Bf-blender-cvs] [8c18f79bd30] temp-eeveelightcache: Eevee: Remove old lightprobe implementation & start fresh.
Clément Foucault
noreply at git.blender.org
Fri Jun 15 18:03:14 CEST 2018
Commit: 8c18f79bd30a572dbcee64292cbdd8601837d8c6
Author: Clément Foucault
Date: Thu Jun 14 18:54:51 2018 +0200
Branches: temp-eeveelightcache
https://developer.blender.org/rB8c18f79bd30a572dbcee64292cbdd8601837d8c6
Eevee: Remove old lightprobe implementation & start fresh.
===================================================================
M source/blender/draw/engines/eevee/eevee_data.c
M source/blender/draw/engines/eevee/eevee_engine.c
M source/blender/draw/engines/eevee/eevee_lightcache.c
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_volumes.c
===================================================================
diff --git a/source/blender/draw/engines/eevee/eevee_data.c b/source/blender/draw/engines/eevee/eevee_data.c
index da7f58bd332..85b2109e618 100644
--- a/source/blender/draw/engines/eevee/eevee_data.c
+++ b/source/blender/draw/engines/eevee/eevee_data.c
@@ -69,11 +69,6 @@ static void eevee_view_layer_data_free(void *storage)
for (int i = 0; i < 6; ++i) {
GPU_FRAMEBUFFER_FREE_SAFE(sldata->probe_face_fb[i]);
}
- DRW_TEXTURE_FREE_SAFE(sldata->probe_rt);
- DRW_TEXTURE_FREE_SAFE(sldata->probe_depth_rt);
- DRW_TEXTURE_FREE_SAFE(sldata->probe_pool);
- DRW_TEXTURE_FREE_SAFE(sldata->irradiance_pool);
- DRW_TEXTURE_FREE_SAFE(sldata->irradiance_rt);
}
EEVEE_ViewLayerData *EEVEE_view_layer_data_get(void)
diff --git a/source/blender/draw/engines/eevee/eevee_engine.c b/source/blender/draw/engines/eevee/eevee_engine.c
index d7c6684f086..cecc76ec96a 100644
--- a/source/blender/draw/engines/eevee/eevee_engine.c
+++ b/source/blender/draw/engines/eevee/eevee_engine.c
@@ -289,7 +289,7 @@ static void eevee_draw_background(void *vedata)
EEVEE_subsurface_compute(sldata, vedata);
EEVEE_reflection_compute(sldata, vedata);
EEVEE_occlusion_draw_debug(sldata, vedata);
- DRW_draw_pass(psl->probe_display);
+ // DRW_draw_pass(psl->probe_display);
EEVEE_refraction_compute(sldata, vedata);
/* Opaque refraction */
diff --git a/source/blender/draw/engines/eevee/eevee_lightcache.c b/source/blender/draw/engines/eevee/eevee_lightcache.c
index 6c8cfc06bac..d4a21fd6d6b 100644
--- a/source/blender/draw/engines/eevee/eevee_lightcache.c
+++ b/source/blender/draw/engines/eevee/eevee_lightcache.c
@@ -44,6 +44,24 @@
#include "WM_api.h"
+/* Rounded to nearest PowerOfTwo */
+#if defined(IRRADIANCE_SH_L2)
+#define IRRADIANCE_SAMPLE_SIZE_X 4 /* 3 in reality */
+#define IRRADIANCE_SAMPLE_SIZE_Y 4 /* 3 in reality */
+#elif defined(IRRADIANCE_CUBEMAP)
+#define IRRADIANCE_SAMPLE_SIZE_X 8
+#define IRRADIANCE_SAMPLE_SIZE_Y 8
+#elif defined(IRRADIANCE_HL2)
+#define IRRADIANCE_SAMPLE_SIZE_X 4 /* 3 in reality */
+#define IRRADIANCE_SAMPLE_SIZE_Y 2
+#endif
+
+#define IRRADIANCE_MAX_POOL_LAYER 256 /* OpenGL 3.3 core requirement, can be extended but it's already very big */
+#define IRRADIANCE_MAX_POOL_SIZE 1024
+#define MAX_IRRADIANCE_SAMPLES \
+ (IRRADIANCE_MAX_POOL_SIZE / IRRADIANCE_SAMPLE_SIZE_X) * \
+ (IRRADIANCE_MAX_POOL_SIZE / IRRADIANCE_SAMPLE_SIZE_Y)
+
/* TODO should be replace by a more elegant alternative. */
extern void DRW_opengl_context_enable(void);
extern void DRW_opengl_context_disable(void);
@@ -125,6 +143,21 @@ void EEVEE_lightcache_job_data_free(void *custom_data)
MEM_freeN(lbake);
}
+static void eevee_irradiance_pool_size_get(int visibility_size, int total_samples, int r_size[3])
+{
+ /* Compute how many irradiance samples we can store per visibility sample. */
+ int irr_per_vis = (visibility_size / IRRADIANCE_SAMPLE_SIZE_X) *
+ (visibility_size / IRRADIANCE_SAMPLE_SIZE_Y);
+
+ /* The irradiance itself take one layer, hence the +1 */
+ int layer_ct = MIN2(irr_per_vis + 1, IRRADIANCE_MAX_POOL_LAYER);
+
+ int texel_ct = (int)ceilf((float)total_samples / (float)(layer_ct - 1));
+ r_size[0] = visibility_size * max_ii(1, min_ii(texel_ct, (IRRADIANCE_MAX_POOL_SIZE / visibility_size)));
+ r_size[1] = visibility_size * max_ii(1, (texel_ct / (IRRADIANCE_MAX_POOL_SIZE / visibility_size)));
+ r_size[2] = layer_ct;
+}
+
static void eevee_lightcache_create_resources(const SceneEEVEE *eevee, EEVEE_LightBake *lbake, EEVEE_LightCache *lcache)
{
lbake->bounce_count = eevee->gi_diffuse_bounces;
@@ -158,7 +191,7 @@ static void eevee_lightcache_create_resources(const SceneEEVEE *eevee, EEVEE_Lig
}
int irr_size[3];
- EEVEE_irradiance_pool_size_get(lbake->vis_res, lbake->total_irr_samples, irr_size);
+ eevee_irradiance_pool_size_get(lbake->vis_res, lbake->total_irr_samples, irr_size);
#ifdef IRRADIANCE_SH_L2
/* we need a signed format for Spherical Harmonics */
@@ -166,10 +199,15 @@ static void eevee_lightcache_create_resources(const SceneEEVEE *eevee, EEVEE_Lig
#else
int irradiance_format = GPU_RGBA8;
#endif
-
lbake->grid_prev = DRW_texture_create_2D_array(irr_size[0], irr_size[1], irr_size[2], irradiance_format, DRW_TEX_FILTER, NULL);
- lcache->grid_tex = DRW_texture_create_2D_array(irr_size[0], irr_size[1], irr_size[2], irradiance_format, DRW_TEX_FILTER, NULL);
- lcache->cube_tex = DRW_texture_create_2D_array(lbake->ref_cube_res, lbake->ref_cube_res, lcache->cube_count, GPU_RGBA8, DRW_TEX_FILTER, NULL);
+ // lcache->grid_tx = DRW_texture_create_2D_array(irr_size[0], irr_size[1], irr_size[2], irradiance_format, DRW_TEX_FILTER, NULL);
+ // lcache->cube_tx = DRW_texture_create_2D_array(lbake->ref_cube_res, lbake->ref_cube_res, lcache->cube_count, GPU_RGBA8, DRW_TEX_FILTER, NULL);
+ /* XXX */
+ float rgba[4] = {1.5f, 0.5f, 0.5f, 0.5f};
+ lcache->grid_tx = DRW_texture_create_2D_array(1, 1, 1, irradiance_format, DRW_TEX_FILTER, rgba);
+ lcache->cube_tx = DRW_texture_create_2D_array(1, 1, 1, GPU_RGBA8, DRW_TEX_FILTER, rgba);
+ DRW_TEXTURE_FREE_SAFE(lcache->cube_tx);
+ DRW_TEXTURE_FREE_SAFE(lcache->grid_tx);
if (lbake->gl_context) {
DRW_opengl_render_context_disable(lbake->gl_context);
@@ -193,6 +231,9 @@ static void eevee_lightcache_delete_resources(EEVEE_LightBake *lbake)
DRW_TEXTURE_FREE_SAFE(lbake->rt_depth);
DRW_TEXTURE_FREE_SAFE(lbake->rt_color);
DRW_TEXTURE_FREE_SAFE(lbake->grid_prev);
+ for (int i = 0; i < 6; ++i) {
+ GPU_FRAMEBUFFER_FREE_SAFE(lbake->rt_fb[i]);
+ }
if (lbake->gl_context) {
/* Delete the baking context. */
@@ -280,8 +321,10 @@ static void eevee_lightcache_gather_probes(EEVEE_LightBake *lbake, EEVEE_LightCa
/* First convert all lightprobes to tight UBO data from all lightprobes in the scene.
* This allows a large number of probe to be precomputed. */
- lcache->cube_data = MEM_callocN(1, "EEVEE Cube Data Cache");
- lcache->grid_data = MEM_callocN(1, "EEVEE Grid Data Cache");
+ if (lcache->cube_data == NULL) {
+ lcache->cube_data = MEM_callocN(1, "EEVEE Cube Data Cache");
+ lcache->grid_data = MEM_callocN(1, "EEVEE Grid Data Cache");
+ }
lbake->cube_prb = MEM_callocN(sizeof(LightProbe *), "EEVEE Cube visgroup ptr");
lbake->grid_prb = MEM_callocN(sizeof(LightProbe *), "EEVEE Grid visgroup ptr");
@@ -346,6 +389,7 @@ void EEVEE_lightcache_bake_job(void *custom_data, short *UNUSED(stop), short *UN
if (lcache->flag & LIGHTCACHE_UPDATE_WORLD) {
eevee_lightcache_context_enable(lbake);
DRW_custom_pipeline(&draw_engine_eevee_type, depsgraph, eevee_lightcache_render_world, lbake);
+ DEG_id_tag_update(&lbake->scene->id, DEG_TAG_COPY_ON_WRITE);
eevee_lightcache_context_disable(lbake);
}
@@ -413,8 +457,8 @@ void EEVEE_lightcache_free(EEVEE_LightCache *lcache)
lcache->refcount--;
if (lcache->refcount == 0) {
- DRW_TEXTURE_FREE_SAFE(lcache->cube_tex);
- DRW_TEXTURE_FREE_SAFE(lcache->grid_tex);
+ DRW_TEXTURE_FREE_SAFE(lcache->cube_tx);
+ DRW_TEXTURE_FREE_SAFE(lcache->grid_tx);
MEM_SAFE_FREE(lcache->cube_data);
MEM_SAFE_FREE(lcache->grid_data);
diff --git a/source/blender/draw/engines/eevee/eevee_lightprobes.c b/source/blender/draw/engines/eevee/eevee_lightprobes.c
index 058318f0ba0..8332da780f5 100644
--- a/source/blender/draw/engines/eevee/eevee_lightprobes.c
+++ b/source/blender/draw/engines/eevee/eevee_lightprobes.c
@@ -20,7 +20,7 @@
*/
/** \file eevee_lightprobes.c
- * \ingroup DNA
+ * \ingroup draw_engine
*/
#include "DRW_render.h"
@@ -50,23 +50,6 @@
#include "ED_screen.h"
-/* Rounded to nearest PowerOfTwo */
-#if defined(IRRADIANCE_SH_L2)
-#define IRRADIANCE_SAMPLE_SIZE_X 4 /* 3 in reality */
-#define IRRADIANCE_SAMPLE_SIZE_Y 4 /* 3 in reality */
-#elif defined(IRRADIANCE_CUBEMAP)
-#define IRRADIANCE_SAMPLE_SIZE_X 8
-#define IRRADIANCE_SAMPLE_SIZE_Y 8
-#elif defined(IRRADIANCE_HL2)
-#define IRRADIANCE_SAMPLE_SIZE_X 4 /* 3 in reality */
-#define IRRADIANCE_SAMPLE_SIZE_Y 2
-#endif
-
-#define IRRADIANCE_MAX_POOL_LAYER 256 /* OpenGL 3.3 core requirement, can be extended but it's already very big */
-#define IRRADIANCE_MAX_POOL_SIZE 1024
-#define MAX_IRRADIANCE_SAMPLES \
- (IRRADIANCE_MAX_POOL_SIZE / IRRADIANCE_SAMPLE_SIZE_X) * \
- (IRRADIANCE_MAX_POOL_SIZE / IRRADIANCE_SAMPLE_SIZE_Y)
#define HAMMERSLEY_SIZE 1024
static struct {
@@ -89,6 +72,8 @@ static struct {
struct Gwn_VertFormat *format_probe_display_cube;
struct Gwn_VertFormat *format_probe_display_planar;
+
+ EEVEE_LightCache dummy_cache;
} e_data = {NULL}; /* Engine data */
extern char datatoc_background_vert_glsl[];
@@ -120,692 +105,62 @@ extern GlobalsUboStorage ts;
/* *********** FUNCTIONS *********** */
-/* TODO put it in eevee_lightcache.c */
-void EEVEE_irradiance_pool_size_get(int visibility_size, int total_samples, int r_size[3])
+void EEVEE_lightprobes_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
{
- /* Compute how many irradiance samples we can store per visibility sample. */
- int irr_per_vis = (visibility_size / IRRADIANCE_SAMPLE_SIZE_X) *
- (visibility_size / IRRADIANCE_SAMPLE_SIZE_Y);
-
- /* The irradiance itself take one layer, hence the +1 */
- int layer_ct = MIN2(irr_per_vis + 1, IRRADIANCE_MAX_POOL_LAYER);
-
- int texel_ct = (int)ceilf((float)total_samples / (float)(layer_ct - 1));
- r_size[0] = visibility_size * max_ii(1, min_ii(texel_ct, (IRRADIANCE_MAX_POOL_SIZE / visibility_size)));
- r_size[1] = visibility_size * max_ii(1, (texel_ct / (IRRADIANCE_MAX_POOL_SIZE / visibility_size)));
- r_size[2] = layer_ct;
-}
-
-static struct GPUTexture *create_hammersley_sample_texture(int samples)
-{
- struct GPUTexture *tex;
- float (*texels)[2] = MEM_mallocN(sizeof(float[2]) * samples, "hammersley_tex");
- int i;
-
- for (i = 0; i < samples; i++) {
- double dphi;
- BLI_hammersley_1D(i, &dphi);
- float phi = (float)dphi * 2.0f * M_PI;
- texels[i][0] = cosf(phi);
- texels[i][1] = sinf(phi);
- }
-
- tex = DRW_texture_create_1D(samples, GPU_RG16F, DRW_TEX_WRAP, (float *)texels);
- MEM_freeN(texels);
- return tex;
-}
-
-static void planar_pool_ensure_alloc(EEVEE_Data *vedata, int num_planar_ref)
-{
- /* XXX TODO OPTIMISATION : This is a complete waist of texture memory.
- * Instead of allocating eac
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list