Eevee: Cleanup, avoid too much nested indentation
Just do early `continue`, makes code easier to follow than fewzillion of nested checks and loops and everything.
This commit is contained in:
parent
28048f75ce
commit
e168e0f46f
|
@ -1342,96 +1342,97 @@ void EEVEE_lightprobes_refresh(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
|
|||
for (int i = 1; (ob = pinfo->probes_grid_ref[i]) && (i < MAX_GRID); i++) {
|
||||
EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_ensure(ob);
|
||||
|
||||
if (ped->need_update) {
|
||||
EEVEE_LightGrid *egrid = &pinfo->grid_data[i];
|
||||
LightProbe *prb = (LightProbe *)ob->data;
|
||||
if (!ped->need_update) {
|
||||
continue;
|
||||
}
|
||||
EEVEE_LightGrid *egrid = &pinfo->grid_data[i];
|
||||
LightProbe *prb = (LightProbe *)ob->data;
|
||||
|
||||
/* Find the next cell corresponding to the current level. */
|
||||
bool valid_cell = false;
|
||||
int cell_id = ped->updated_cells;
|
||||
float pos[3], grid_loc[3];
|
||||
/* Find the next cell corresponding to the current level. */
|
||||
bool valid_cell = false;
|
||||
int cell_id = ped->updated_cells;
|
||||
float pos[3], grid_loc[3];
|
||||
|
||||
/* Other levels */
|
||||
int current_stride = 1 << max_ii(0, ped->max_lvl - ped->updated_lvl);
|
||||
int prev_stride = current_stride << 1;
|
||||
/* Other levels */
|
||||
int current_stride = 1 << max_ii(0, ped->max_lvl - ped->updated_lvl);
|
||||
int prev_stride = current_stride << 1;
|
||||
|
||||
while (!valid_cell) {
|
||||
cell_id = ped->updated_cells;
|
||||
lightprobe_cell_grid_location_get(egrid, cell_id, grid_loc);
|
||||
while (!valid_cell) {
|
||||
cell_id = ped->updated_cells;
|
||||
lightprobe_cell_grid_location_get(egrid, cell_id, grid_loc);
|
||||
|
||||
if (ped->updated_lvl == 0 && cell_id == 0) {
|
||||
valid_cell = true;
|
||||
ped->updated_cells = ped->num_cell;
|
||||
continue;
|
||||
}
|
||||
else if (((((int)grid_loc[0] % current_stride) == 0) &&
|
||||
(((int)grid_loc[1] % current_stride) == 0) &&
|
||||
(((int)grid_loc[2] % current_stride) == 0)) &&
|
||||
!((((int)grid_loc[0] % prev_stride) == 0) &&
|
||||
(((int)grid_loc[1] % prev_stride) == 0) &&
|
||||
(((int)grid_loc[2] % prev_stride) == 0)))
|
||||
{
|
||||
valid_cell = true;
|
||||
}
|
||||
|
||||
ped->updated_cells++;
|
||||
|
||||
if (ped->updated_cells > ped->num_cell) {
|
||||
goto skip_rendering;
|
||||
}
|
||||
if (ped->updated_lvl == 0 && cell_id == 0) {
|
||||
valid_cell = true;
|
||||
ped->updated_cells = ped->num_cell;
|
||||
continue;
|
||||
}
|
||||
else if (((((int)grid_loc[0] % current_stride) == 0) &&
|
||||
(((int)grid_loc[1] % current_stride) == 0) &&
|
||||
(((int)grid_loc[2] % current_stride) == 0)) &&
|
||||
!((((int)grid_loc[0] % prev_stride) == 0) &&
|
||||
(((int)grid_loc[1] % prev_stride) == 0) &&
|
||||
(((int)grid_loc[2] % prev_stride) == 0)))
|
||||
{
|
||||
valid_cell = true;
|
||||
}
|
||||
|
||||
lightprobe_cell_world_location_get(egrid, grid_loc, pos);
|
||||
ped->updated_cells++;
|
||||
|
||||
SWAP(GPUTexture *, sldata->irradiance_pool, sldata->irradiance_rt);
|
||||
|
||||
/* Temporary Remove all probes. */
|
||||
int tmp_num_render_grid = pinfo->num_render_grid;
|
||||
int tmp_num_render_cube = pinfo->num_render_cube;
|
||||
int tmp_num_planar = pinfo->num_planar;
|
||||
pinfo->num_render_cube = 0;
|
||||
pinfo->num_planar = 0;
|
||||
|
||||
/* Use light from previous bounce when capturing radiance. */
|
||||
if (pinfo->updated_bounce == 0) {
|
||||
pinfo->num_render_grid = 0;
|
||||
if (ped->updated_cells > ped->num_cell) {
|
||||
goto skip_rendering;
|
||||
}
|
||||
}
|
||||
|
||||
render_scene_to_probe(sldata, vedata, pos, prb->clipsta, prb->clipend);
|
||||
diffuse_filter_probe(sldata, vedata, psl, egrid->offset + cell_id);
|
||||
lightprobe_cell_world_location_get(egrid, grid_loc, pos);
|
||||
|
||||
/* To see what is going on. */
|
||||
SWAP(GPUTexture *, sldata->irradiance_pool, sldata->irradiance_rt);
|
||||
SWAP(GPUTexture *, sldata->irradiance_pool, sldata->irradiance_rt);
|
||||
|
||||
/* Restore */
|
||||
pinfo->num_render_grid = tmp_num_render_grid;
|
||||
pinfo->num_render_cube = tmp_num_render_cube;
|
||||
pinfo->num_planar = tmp_num_planar;
|
||||
/* Temporary Remove all probes. */
|
||||
int tmp_num_render_grid = pinfo->num_render_grid;
|
||||
int tmp_num_render_cube = pinfo->num_render_cube;
|
||||
int tmp_num_planar = pinfo->num_planar;
|
||||
pinfo->num_render_cube = 0;
|
||||
pinfo->num_planar = 0;
|
||||
|
||||
/* Use light from previous bounce when capturing radiance. */
|
||||
if (pinfo->updated_bounce == 0) {
|
||||
pinfo->num_render_grid = 0;
|
||||
}
|
||||
|
||||
render_scene_to_probe(sldata, vedata, pos, prb->clipsta, prb->clipend);
|
||||
diffuse_filter_probe(sldata, vedata, psl, egrid->offset + cell_id);
|
||||
|
||||
/* To see what is going on. */
|
||||
SWAP(GPUTexture *, sldata->irradiance_pool, sldata->irradiance_rt);
|
||||
|
||||
/* Restore */
|
||||
pinfo->num_render_grid = tmp_num_render_grid;
|
||||
pinfo->num_render_cube = tmp_num_render_cube;
|
||||
pinfo->num_planar = tmp_num_planar;
|
||||
|
||||
skip_rendering:
|
||||
|
||||
if (ped->updated_cells >= ped->num_cell) {
|
||||
ped->updated_lvl++;
|
||||
ped->updated_cells = 0;
|
||||
if (ped->updated_cells >= ped->num_cell) {
|
||||
ped->updated_lvl++;
|
||||
ped->updated_cells = 0;
|
||||
|
||||
if (ped->updated_lvl > ped->max_lvl) {
|
||||
ped->need_update = false;
|
||||
}
|
||||
|
||||
egrid->level_bias = (float)(1 << max_ii(0, ped->max_lvl - ped->updated_lvl + 1));
|
||||
DRW_uniformbuffer_update(sldata->grid_ubo, &sldata->probes->grid_data);
|
||||
if (ped->updated_lvl > ped->max_lvl) {
|
||||
ped->need_update = false;
|
||||
}
|
||||
#if 0
|
||||
printf("Updated Grid %d : cell %d / %d, bounce %d / %d\n",
|
||||
i, ped->updated_cells, ped->num_cell, pinfo->updated_bounce + 1, pinfo->num_bounce);
|
||||
#endif
|
||||
/* Only do one probe per frame */
|
||||
DRW_viewport_request_redraw();
|
||||
/* Do not let this frame accumulate. */
|
||||
stl->effects->taa_current_sample = 1;
|
||||
|
||||
goto update_planar;
|
||||
egrid->level_bias = (float)(1 << max_ii(0, ped->max_lvl - ped->updated_lvl + 1));
|
||||
DRW_uniformbuffer_update(sldata->grid_ubo, &sldata->probes->grid_data);
|
||||
}
|
||||
#if 0
|
||||
printf("Updated Grid %d : cell %d / %d, bounce %d / %d\n",
|
||||
i, ped->updated_cells, ped->num_cell, pinfo->updated_bounce + 1, pinfo->num_bounce);
|
||||
#endif
|
||||
/* Only do one probe per frame */
|
||||
DRW_viewport_request_redraw();
|
||||
/* Do not let this frame accumulate. */
|
||||
stl->effects->taa_current_sample = 1;
|
||||
|
||||
goto update_planar;
|
||||
}
|
||||
|
||||
pinfo->updated_bounce++;
|
||||
|
@ -1462,29 +1463,30 @@ skip_rendering:
|
|||
for (int i = 1; (ob = pinfo->probes_cube_ref[i]) && (i < MAX_PROBE); i++) {
|
||||
EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_ensure(ob);
|
||||
|
||||
if (ped->need_update) {
|
||||
LightProbe *prb = (LightProbe *)ob->data;
|
||||
|
||||
render_scene_to_probe(sldata, vedata, ob->obmat[3], prb->clipsta, prb->clipend);
|
||||
glossy_filter_probe(sldata, vedata, psl, i);
|
||||
|
||||
ped->need_update = false;
|
||||
ped->probe_id = i;
|
||||
|
||||
if (!ped->ready_to_shade) {
|
||||
pinfo->num_render_cube++;
|
||||
ped->ready_to_shade = true;
|
||||
}
|
||||
#if 0
|
||||
printf("Update Cubemap %d\n", i);
|
||||
#endif
|
||||
DRW_viewport_request_redraw();
|
||||
/* Do not let this frame accumulate. */
|
||||
stl->effects->taa_current_sample = 1;
|
||||
|
||||
/* Only do one probe per frame */
|
||||
goto update_planar;
|
||||
if (!ped->need_update) {
|
||||
continue;
|
||||
}
|
||||
LightProbe *prb = (LightProbe *)ob->data;
|
||||
|
||||
render_scene_to_probe(sldata, vedata, ob->obmat[3], prb->clipsta, prb->clipend);
|
||||
glossy_filter_probe(sldata, vedata, psl, i);
|
||||
|
||||
ped->need_update = false;
|
||||
ped->probe_id = i;
|
||||
|
||||
if (!ped->ready_to_shade) {
|
||||
pinfo->num_render_cube++;
|
||||
ped->ready_to_shade = true;
|
||||
}
|
||||
#if 0
|
||||
printf("Update Cubemap %d\n", i);
|
||||
#endif
|
||||
DRW_viewport_request_redraw();
|
||||
/* Do not let this frame accumulate. */
|
||||
stl->effects->taa_current_sample = 1;
|
||||
|
||||
/* Only do one probe per frame */
|
||||
goto update_planar;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1493,19 +1495,21 @@ update_planar:
|
|||
for (int i = 0; (ob = pinfo->probes_planar_ref[i]) && (i < MAX_PLANAR); i++) {
|
||||
EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_ensure(ob);
|
||||
|
||||
if (ped->need_update) {
|
||||
/* Temporary Remove all planar reflections (avoid lag effect). */
|
||||
int tmp_num_planar = pinfo->num_planar;
|
||||
pinfo->num_planar = 0;
|
||||
|
||||
render_scene_to_planar(sldata, vedata, i, ped->viewmat, ped->persmat, ped->planer_eq_offset);
|
||||
|
||||
/* Restore */
|
||||
pinfo->num_planar = tmp_num_planar;
|
||||
|
||||
ped->need_update = false;
|
||||
ped->probe_id = i;
|
||||
if (!ped->need_update) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Temporary Remove all planar reflections (avoid lag effect). */
|
||||
int tmp_num_planar = pinfo->num_planar;
|
||||
pinfo->num_planar = 0;
|
||||
|
||||
render_scene_to_planar(sldata, vedata, i, ped->viewmat, ped->persmat, ped->planer_eq_offset);
|
||||
|
||||
/* Restore */
|
||||
pinfo->num_planar = tmp_num_planar;
|
||||
|
||||
ped->need_update = false;
|
||||
ped->probe_id = i;
|
||||
}
|
||||
|
||||
/* If there is at least one planar probe */
|
||||
|
|
|
@ -927,74 +927,76 @@ void EEVEE_draw_shadows(EEVEE_ViewLayerData *sldata, EEVEE_PassList *psl)
|
|||
float cube_projmat[4][4];
|
||||
perspective_m4(cube_projmat, -la->clipsta, la->clipsta, -la->clipsta, la->clipsta, la->clipsta, la->clipend);
|
||||
|
||||
if (led->need_update) {
|
||||
EEVEE_ShadowRender *srd = &linfo->shadow_render_data;
|
||||
EEVEE_ShadowCubeData *evscd = (EEVEE_ShadowCubeData *)led->storage;
|
||||
|
||||
srd->clip_near = la->clipsta;
|
||||
srd->clip_far = la->clipend;
|
||||
copy_v3_v3(srd->position, ob->obmat[3]);
|
||||
for (int j = 0; j < 6; j++) {
|
||||
float tmp[4][4];
|
||||
|
||||
unit_m4(tmp);
|
||||
negate_v3_v3(tmp[3], ob->obmat[3]);
|
||||
mul_m4_m4m4(srd->viewmat[j], cubefacemat[j], tmp);
|
||||
|
||||
mul_m4_m4m4(srd->shadowmat[j], cube_projmat, srd->viewmat[j]);
|
||||
}
|
||||
DRW_uniformbuffer_update(sldata->shadow_render_ubo, srd);
|
||||
|
||||
DRW_framebuffer_bind(sldata->shadow_target_fb);
|
||||
DRW_framebuffer_clear(true, true, false, clear_col, 1.0f);
|
||||
|
||||
/* Render shadow cube */
|
||||
DRW_draw_pass(psl->shadow_cube_pass);
|
||||
|
||||
/* 0.001f is arbitrary, but it should be relatively small so that filter size is not too big. */
|
||||
float filter_texture_size = la->soft * 0.001f;
|
||||
float filter_pixel_size = ceil(filter_texture_size / linfo->shadow_render_data.cube_texel_size);
|
||||
linfo->filter_size = linfo->shadow_render_data.cube_texel_size * ((filter_pixel_size > 1.0f) ? 1.5f : 0.0f);
|
||||
|
||||
/* TODO: OPTI: Filter all faces in one/two draw call */
|
||||
for (linfo->current_shadow_face = 0;
|
||||
linfo->current_shadow_face < 6;
|
||||
linfo->current_shadow_face++)
|
||||
{
|
||||
/* Copy using a small 3x3 box filter */
|
||||
DRW_framebuffer_cubeface_attach(sldata->shadow_store_fb, sldata->shadow_cube_blur, 0, linfo->current_shadow_face, 0);
|
||||
DRW_framebuffer_bind(sldata->shadow_store_fb);
|
||||
DRW_draw_pass(psl->shadow_cube_copy_pass);
|
||||
DRW_framebuffer_texture_detach(sldata->shadow_cube_blur);
|
||||
}
|
||||
|
||||
/* Push it to shadowmap array */
|
||||
|
||||
/* Adjust constants if concentric samples change. */
|
||||
const float max_filter_size = 7.5f;
|
||||
const float previous_box_filter_size = 9.0f; /* Dunno why but that works. */
|
||||
const int max_sample = 256;
|
||||
|
||||
if (filter_pixel_size > 2.0f) {
|
||||
linfo->filter_size = linfo->shadow_render_data.cube_texel_size * max_filter_size * previous_box_filter_size;
|
||||
filter_pixel_size = max_ff(0.0f, filter_pixel_size - 3.0f);
|
||||
/* Compute number of concentric samples. Depends directly on filter size. */
|
||||
float pix_size_sqr = filter_pixel_size * filter_pixel_size;
|
||||
srd->shadow_samples_ct = min_ii(max_sample, 4 + 8 * (int)filter_pixel_size + 4 * (int)(pix_size_sqr));
|
||||
}
|
||||
else {
|
||||
linfo->filter_size = 0.0f;
|
||||
srd->shadow_samples_ct = 4;
|
||||
}
|
||||
srd->shadow_inv_samples_ct = 1.0f / (float)srd->shadow_samples_ct;
|
||||
DRW_uniformbuffer_update(sldata->shadow_render_ubo, srd);
|
||||
|
||||
DRW_framebuffer_texture_layer_attach(sldata->shadow_store_fb, sldata->shadow_pool, 0, evscd->layer_id, 0);
|
||||
DRW_framebuffer_bind(sldata->shadow_store_fb);
|
||||
DRW_draw_pass(psl->shadow_cube_store_pass);
|
||||
|
||||
led->need_update = false;
|
||||
if (!led->need_update) {
|
||||
continue;
|
||||
}
|
||||
|
||||
EEVEE_ShadowRender *srd = &linfo->shadow_render_data;
|
||||
EEVEE_ShadowCubeData *evscd = (EEVEE_ShadowCubeData *)led->storage;
|
||||
|
||||
srd->clip_near = la->clipsta;
|
||||
srd->clip_far = la->clipend;
|
||||
copy_v3_v3(srd->position, ob->obmat[3]);
|
||||
for (int j = 0; j < 6; j++) {
|
||||
float tmp[4][4];
|
||||
|
||||
unit_m4(tmp);
|
||||
negate_v3_v3(tmp[3], ob->obmat[3]);
|
||||
mul_m4_m4m4(srd->viewmat[j], cubefacemat[j], tmp);
|
||||
|
||||
mul_m4_m4m4(srd->shadowmat[j], cube_projmat, srd->viewmat[j]);
|
||||
}
|
||||
DRW_uniformbuffer_update(sldata->shadow_render_ubo, srd);
|
||||
|
||||
DRW_framebuffer_bind(sldata->shadow_target_fb);
|
||||
DRW_framebuffer_clear(true, true, false, clear_col, 1.0f);
|
||||
|
||||
/* Render shadow cube */
|
||||
DRW_draw_pass(psl->shadow_cube_pass);
|
||||
|
||||
/* 0.001f is arbitrary, but it should be relatively small so that filter size is not too big. */
|
||||
float filter_texture_size = la->soft * 0.001f;
|
||||
float filter_pixel_size = ceil(filter_texture_size / linfo->shadow_render_data.cube_texel_size);
|
||||
linfo->filter_size = linfo->shadow_render_data.cube_texel_size * ((filter_pixel_size > 1.0f) ? 1.5f : 0.0f);
|
||||
|
||||
/* TODO: OPTI: Filter all faces in one/two draw call */
|
||||
for (linfo->current_shadow_face = 0;
|
||||
linfo->current_shadow_face < 6;
|
||||
linfo->current_shadow_face++)
|
||||
{
|
||||
/* Copy using a small 3x3 box filter */
|
||||
DRW_framebuffer_cubeface_attach(sldata->shadow_store_fb, sldata->shadow_cube_blur, 0, linfo->current_shadow_face, 0);
|
||||
DRW_framebuffer_bind(sldata->shadow_store_fb);
|
||||
DRW_draw_pass(psl->shadow_cube_copy_pass);
|
||||
DRW_framebuffer_texture_detach(sldata->shadow_cube_blur);
|
||||
}
|
||||
|
||||
/* Push it to shadowmap array */
|
||||
|
||||
/* Adjust constants if concentric samples change. */
|
||||
const float max_filter_size = 7.5f;
|
||||
const float previous_box_filter_size = 9.0f; /* Dunno why but that works. */
|
||||
const int max_sample = 256;
|
||||
|
||||
if (filter_pixel_size > 2.0f) {
|
||||
linfo->filter_size = linfo->shadow_render_data.cube_texel_size * max_filter_size * previous_box_filter_size;
|
||||
filter_pixel_size = max_ff(0.0f, filter_pixel_size - 3.0f);
|
||||
/* Compute number of concentric samples. Depends directly on filter size. */
|
||||
float pix_size_sqr = filter_pixel_size * filter_pixel_size;
|
||||
srd->shadow_samples_ct = min_ii(max_sample, 4 + 8 * (int)filter_pixel_size + 4 * (int)(pix_size_sqr));
|
||||
}
|
||||
else {
|
||||
linfo->filter_size = 0.0f;
|
||||
srd->shadow_samples_ct = 4;
|
||||
}
|
||||
srd->shadow_inv_samples_ct = 1.0f / (float)srd->shadow_samples_ct;
|
||||
DRW_uniformbuffer_update(sldata->shadow_render_ubo, srd);
|
||||
|
||||
DRW_framebuffer_texture_layer_attach(sldata->shadow_store_fb, sldata->shadow_pool, 0, evscd->layer_id, 0);
|
||||
DRW_framebuffer_bind(sldata->shadow_store_fb);
|
||||
DRW_draw_pass(psl->shadow_cube_store_pass);
|
||||
|
||||
led->need_update = false;
|
||||
}
|
||||
linfo->update_flag &= ~LIGHT_UPDATE_SHADOW_CUBE;
|
||||
|
||||
|
|
Loading…
Reference in New Issue