[Bf-blender-cvs] [0ca2f5affde] blender2.8: Eevee: Irradiance grid: support for non-blocking update and multiple bounces.
Clément Foucault
noreply at git.blender.org
Thu Jun 15 01:16:19 CEST 2017
Commit: 0ca2f5affde8cb8ce7fe4e93ae27063c7c577933
Author: Clément Foucault
Date: Wed Jun 14 18:52:53 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB0ca2f5affde8cb8ce7fe4e93ae27063c7c577933
Eevee: Irradiance grid: support for non-blocking update and multiple bounces.
===================================================================
M source/blender/draw/engines/eevee/eevee_data.c
M source/blender/draw/engines/eevee/eevee_lightprobes.c
M source/blender/draw/engines/eevee/eevee_private.h
M source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
M source/blender/makesrna/intern/rna_lightprobe.c
===================================================================
diff --git a/source/blender/draw/engines/eevee/eevee_data.c b/source/blender/draw/engines/eevee/eevee_data.c
index 5639250a076..9dfc3e5f07b 100644
--- a/source/blender/draw/engines/eevee/eevee_data.c
+++ b/source/blender/draw/engines/eevee/eevee_data.c
@@ -60,6 +60,7 @@ static void eevee_scene_layer_data_free(void *storage)
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);
}
static void eevee_lamp_data_free(void *storage)
diff --git a/source/blender/draw/engines/eevee/eevee_lightprobes.c b/source/blender/draw/engines/eevee/eevee_lightprobes.c
index f359ff2c3f7..cc37fb24dfc 100644
--- a/source/blender/draw/engines/eevee/eevee_lightprobes.c
+++ b/source/blender/draw/engines/eevee/eevee_lightprobes.c
@@ -198,7 +198,7 @@ void EEVEE_lightprobes_cache_init(EEVEE_SceneLayerData *sldata, EEVEE_PassList *
EEVEE_LightProbesInfo *pinfo = sldata->probes;
pinfo->num_cube = 1; /* at least one for the world */
- pinfo->num_grid = 0;
+ pinfo->num_grid = 1;
memset(pinfo->probes_cube_ref, 0, sizeof(pinfo->probes_cube_ref));
memset(pinfo->probes_grid_ref, 0, sizeof(pinfo->probes_grid_ref));
@@ -309,12 +309,18 @@ void EEVEE_lightprobes_cache_add(EEVEE_SceneLayerData *sldata, Object *ob)
EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_get(ob);
+ ped->num_cell = probe->grid_resolution_x * probe->grid_resolution_y * probe->grid_resolution_z;
+
if ((ob->deg_update_flag & DEG_RUNTIME_DATA_UPDATE) != 0) {
ped->need_update = true;
+ ped->updated_cells = 0;
+ pinfo->updated_bounce = 0;
}
if (e_data.update_world) {
ped->need_update = true;
+ ped->updated_cells = 0;
+ pinfo->updated_bounce = 0;
}
if (probe->type == LIGHTPROBE_TYPE_CUBE) {
@@ -366,15 +372,15 @@ static void EEVEE_lightprobes_updates(EEVEE_SceneLayerData *sldata, EEVEE_PassLi
}
int offset = 1; /* to account for the world probe */
- for (int i = 0; (ob = pinfo->probes_grid_ref[i]) && (i < MAX_GRID); i++) {
+ for (int i = 1; (ob = pinfo->probes_grid_ref[i]) && (i < MAX_GRID); i++) {
LightProbe *probe = (LightProbe *)ob->data;
EEVEE_LightGrid *egrid = &pinfo->grid_data[i];
+ EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_get(ob);
egrid->offset = offset;
/* Set offset for the next grid */
- int num_cell = probe->grid_resolution_x * probe->grid_resolution_y * probe->grid_resolution_z;
- offset += num_cell;
+ offset += ped->num_cell;
/* Update transforms */
float tmp[4][4] = {
@@ -384,40 +390,42 @@ static void EEVEE_lightprobes_updates(EEVEE_SceneLayerData *sldata, EEVEE_PassLi
{-1.0f, -1.0f, -1.0f, 1.0f}
};
float tmp_grid_mat[4][4] = {
- {1.0f / (float)(probe->grid_resolution_x + 1), 0.0f, 0.0f, 0.0f},
- {0.0f, 1.0f / (float)(probe->grid_resolution_y + 1), 0.0f, 0.0f},
- {0.0f, 0.0f, 1.0f / (float)(probe->grid_resolution_z + 1), 0.0f},
+ {1.0f / (float)(probe->grid_resolution_x), 0.0f, 0.0f, 0.0f},
+ {0.0f, 1.0f / (float)(probe->grid_resolution_y), 0.0f, 0.0f},
+ {0.0f, 0.0f, 1.0f / (float)(probe->grid_resolution_z), 0.0f},
{0.0f, 0.0f, 0.0f, 1.0f}
};
mul_m4_m4m4(tmp, tmp, tmp_grid_mat);
mul_m4_m4m4(egrid->mat, ob->obmat, tmp);
invert_m4(egrid->mat);
- float one_div_res[3];
- one_div_res[0] = 2.0f / (float)(probe->grid_resolution_x + 1);
- one_div_res[1] = 2.0f / (float)(probe->grid_resolution_y + 1);
- one_div_res[2] = 2.0f / (float)(probe->grid_resolution_z + 1);
+ float cell_dim[3], half_cell_dim[3];
+ cell_dim[0] = 2.0f / (float)(probe->grid_resolution_x);
+ cell_dim[1] = 2.0f / (float)(probe->grid_resolution_y);
+ cell_dim[2] = 2.0f / (float)(probe->grid_resolution_z);
+
+ mul_v3_v3fl(half_cell_dim, cell_dim, 0.5f);
/* First cell. */
- copy_v3_v3(egrid->corner, one_div_res);
- add_v3_fl(egrid->corner, -1.0f);
+ copy_v3_fl(egrid->corner, -1.0f);
+ add_v3_v3(egrid->corner, half_cell_dim);
mul_m4_v3(ob->obmat, egrid->corner);
/* Opposite neighbor cell. */
- copy_v3_fl3(egrid->increment_x, one_div_res[0], 0.0f, 0.0f);
- add_v3_v3(egrid->increment_x, one_div_res);
+ copy_v3_fl3(egrid->increment_x, cell_dim[0], 0.0f, 0.0f);
+ add_v3_v3(egrid->increment_x, half_cell_dim);
add_v3_fl(egrid->increment_x, -1.0f);
mul_m4_v3(ob->obmat, egrid->increment_x);
sub_v3_v3(egrid->increment_x, egrid->corner);
- copy_v3_fl3(egrid->increment_y, 0.0f, one_div_res[1], 0.0f);
- add_v3_v3(egrid->increment_y, one_div_res);
+ copy_v3_fl3(egrid->increment_y, 0.0f, cell_dim[1], 0.0f);
+ add_v3_v3(egrid->increment_y, half_cell_dim);
add_v3_fl(egrid->increment_y, -1.0f);
mul_m4_v3(ob->obmat, egrid->increment_y);
sub_v3_v3(egrid->increment_y, egrid->corner);
- copy_v3_fl3(egrid->increment_z, 0.0f, 0.0f, one_div_res[2]);
- add_v3_v3(egrid->increment_z, one_div_res);
+ copy_v3_fl3(egrid->increment_z, 0.0f, 0.0f, cell_dim[2]);
+ add_v3_v3(egrid->increment_z, half_cell_dim);
add_v3_fl(egrid->increment_z, -1.0f);
mul_m4_v3(ob->obmat, egrid->increment_z);
sub_v3_v3(egrid->increment_z, egrid->corner);
@@ -428,7 +436,7 @@ static void EEVEE_lightprobes_updates(EEVEE_SceneLayerData *sldata, EEVEE_PassLi
if ((probe->flag & LIGHTPROBE_FLAG_SHOW_INFLUENCE) != 0) {
struct Batch *geom = DRW_cache_sphere_get();
DRWShadingGroup *grp = DRW_shgroup_instance_create(e_data.probe_grid_display_sh, psl->probe_display, geom);
- DRW_shgroup_set_instance_count(grp, num_cell);
+ DRW_shgroup_set_instance_count(grp, ped->num_cell);
DRW_shgroup_uniform_int(grp, "offset", &egrid->offset, 1);
DRW_shgroup_uniform_ivec3(grp, "grid_resolution", egrid->resolution, 1);
DRW_shgroup_uniform_vec3(grp, "corner", egrid->corner, 1);
@@ -438,8 +446,6 @@ static void EEVEE_lightprobes_updates(EEVEE_SceneLayerData *sldata, EEVEE_PassLi
DRW_shgroup_uniform_buffer(grp, "irradianceGrid", &sldata->irradiance_pool);
}
}
-
- pinfo->num_render_grid = pinfo->num_grid;
}
void EEVEE_lightprobes_cache_finish(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl)
@@ -464,6 +470,8 @@ void EEVEE_lightprobes_cache_finish(EEVEE_SceneLayerData *sldata, EEVEE_PassList
e_data.update_world = true;
e_data.world_ready_to_shade = false;
pinfo->num_render_cube = 0;
+ pinfo->num_render_grid = 0;
+ pinfo->updated_bounce = 0;
pinfo->update_flag |= PROBE_UPDATE_CUBE;
pinfo->cache_num_cube = pinfo->num_cube;
@@ -472,18 +480,35 @@ void EEVEE_lightprobes_cache_finish(EEVEE_SceneLayerData *sldata, EEVEE_PassList
ped->need_update = true;
ped->ready_to_shade = false;
}
+
+ for (int i = 1; (ob = pinfo->probes_grid_ref[i]) && (i < MAX_PROBE); i++) {
+ EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_get(ob);
+ ped->need_update = true;
+ ped->updated_cells = 0;
+ }
}
DRWFboTexture tex_filter = {&sldata->probe_pool, DRW_TEX_RGBA_16, DRW_TEX_FILTER | DRW_TEX_MIPMAP};
DRW_framebuffer_init(&sldata->probe_filter_fb, &draw_engine_eevee_type, PROBE_OCTAHEDRON_SIZE, PROBE_OCTAHEDRON_SIZE, &tex_filter, 1);
+#ifdef IRRADIANCE_SH_L2
+ /* we need a signed format for Spherical Harmonics */
+ int irradiance_format = DRW_TEX_RGBA_16;
+#else
+ int irradiance_format = DRW_TEX_RGB_11_11_10;
+#endif
+
/* TODO Allocate bigger storage if needed. */
if (!sldata->irradiance_pool) {
- sldata->irradiance_pool = DRW_texture_create_2D(IRRADIANCE_POOL_SIZE, IRRADIANCE_POOL_SIZE, DRW_TEX_RGBA_16, DRW_TEX_FILTER, NULL);
+ sldata->irradiance_pool = DRW_texture_create_2D(IRRADIANCE_POOL_SIZE, IRRADIANCE_POOL_SIZE, irradiance_format, DRW_TEX_FILTER, NULL);
pinfo->num_render_grid = 0;
}
+ if (!sldata->irradiance_rt) {
+ sldata->irradiance_rt = DRW_texture_create_2D(IRRADIANCE_POOL_SIZE, IRRADIANCE_POOL_SIZE, irradiance_format, DRW_TEX_FILTER, NULL);
+ }
+
EEVEE_lightprobes_updates(sldata, psl);
DRW_uniformbuffer_update(sldata->probe_ubo, &sldata->probes->probe_data);
@@ -562,7 +587,7 @@ static void glossy_filter_probe(EEVEE_SceneLayerData *sldata, EEVEE_PassList *ps
}
/* Diffuse filter probe_rt to irradiance_pool at index probe_idx */
-static void diffuse_filter_probe(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl, int cell_idx)
+static void diffuse_filter_probe(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl, int offset)
{
EEVEE_LightProbesInfo *pinfo = sldata->probes;
@@ -576,7 +601,7 @@ static void diffuse_filter_probe(EEVEE_SceneLayerData *sldata, EEVEE_PassList *p
/* Bind the right texture layer (one layer per irradiance grid) */
DRW_framebuffer_texture_detach(sldata->probe_pool);
- DRW_framebuffer_texture_attach(sldata->probe_filter_fb, sldata->irradiance_pool, 0, 0);
+ DRW_framebuffer_texture_attach(sldata->probe_filter_fb, sldata->irradiance_rt, 0, 0);
/* find cell position on the virtual 3D texture */
/* NOTE : Keep in sync with load_irradiance_cell() */
@@ -591,8 +616,8 @@ static void diffuse_filter_probe(EEVEE_SceneLayerData *sldata, EEVEE_PassList *p
#endif
int cell_per_row = IRRADIANCE_POOL_SIZE / size[0];
- int x = size[0] * (cell_idx % cell_per_row);
- int y = size[1] * (cell_idx / cell_per_row);
+ int x = size[0] * (offset % cell_per_row);
+ int y = size[1] * (offset / cell_per_row);
#ifndef IRRADIANCE_SH_L2
const float bias = 0.0f;
@@ -608,7 +633,7 @@ static void diffuse_filter_probe(EEVEE_SceneLayerData *sldata, EEVEE_PassList *p
DRW_draw_pass(psl->probe_diffuse_compute);
/* reattach to have a valid framebuffer. */
- DRW_framebuffer_texture_detach(sldata->irradiance_pool);
+ DRW_framebuffer_texture_detach(sldata->irradiance_rt);
DRW_framebuffer_texture_attach(sldata->probe_filter_fb, sldata->probe_pool, 0, 0);
/* restore */
@@ -704,49 +729,21 @@ static void render_world_to_probe(EEVEE_SceneLayerData *sldata, EEVEE_PassList *
DRW_draw_pass(psl->probe_background);
}
-static void update_irradiance_probe(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl, int probe_idx)
+static void lightprobe_cell_location_get(EEVEE_LightGrid *egrid, int cell_idx, float r_pos[3])
{
- EEVEE_LightProbesInfo *pinfo = sldata->probes;
- EEVEE_LightGrid *egrid = &pinfo->grid_data[probe_idx];
- Object *ob = pinfo->probes_grid_ref[probe_idx];
- LightProbe *prb = (Li
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list