Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2017-11-29 13:59:15 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2017-11-29 14:00:03 +0300
commite168e0f46fc9525e9b2f118a47b4400fb9980fd8 (patch)
treec8a36bba63b75cf1575571872b61206a67037bd5 /source
parent28048f75ce42b370c76cc62a6b8b5de14586fcd6 (diff)
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.
Diffstat (limited to 'source')
-rw-r--r--source/blender/draw/engines/eevee/eevee_lightprobes.c206
-rw-r--r--source/blender/draw/engines/eevee/eevee_lights.c118
2 files changed, 165 insertions, 159 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_lightprobes.c b/source/blender/draw/engines/eevee/eevee_lightprobes.c
index b56673f18e7..d2e65cbdbe3 100644
--- a/source/blender/draw/engines/eevee/eevee_lightprobes.c
+++ b/source/blender/draw/engines/eevee/eevee_lightprobes.c
@@ -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;
-
- /* 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;
-
- 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->need_update) {
+ continue;
+ }
+ EEVEE_LightGrid *egrid = &pinfo->grid_data[i];
+ LightProbe *prb = (LightProbe *)ob->data;
- lightprobe_cell_world_location_get(egrid, grid_loc, pos);
+ /* 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];
- SWAP(GPUTexture *, sldata->irradiance_pool, sldata->irradiance_rt);
+ /* Other levels */
+ int current_stride = 1 << max_ii(0, ped->max_lvl - ped->updated_lvl);
+ int prev_stride = current_stride << 1;
- /* 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;
+ while (!valid_cell) {
+ cell_id = ped->updated_cells;
+ lightprobe_cell_grid_location_get(egrid, cell_id, grid_loc);
- /* Use light from previous bounce when capturing radiance. */
- if (pinfo->updated_bounce == 0) {
- pinfo->num_render_grid = 0;
+ 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;
}
- render_scene_to_probe(sldata, vedata, pos, prb->clipsta, prb->clipend);
- diffuse_filter_probe(sldata, vedata, psl, egrid->offset + cell_id);
+ ped->updated_cells++;
- /* To see what is going on. */
- SWAP(GPUTexture *, sldata->irradiance_pool, sldata->irradiance_rt);
+ if (ped->updated_cells > ped->num_cell) {
+ goto skip_rendering;
+ }
+ }
- /* Restore */
- pinfo->num_render_grid = tmp_num_render_grid;
- pinfo->num_render_cube = tmp_num_render_cube;
- pinfo->num_planar = tmp_num_planar;
+ lightprobe_cell_world_location_get(egrid, grid_loc, pos);
-skip_rendering:
+ SWAP(GPUTexture *, sldata->irradiance_pool, sldata->irradiance_rt);
- if (ped->updated_cells >= ped->num_cell) {
- ped->updated_lvl++;
- ped->updated_cells = 0;
+ /* 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;
- if (ped->updated_lvl > ped->max_lvl) {
- ped->need_update = false;
- }
+ /* Use light from previous bounce when capturing radiance. */
+ if (pinfo->updated_bounce == 0) {
+ pinfo->num_render_grid = 0;
+ }
- 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);
+ 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_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 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);
+ 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;
+ /* 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;
- }
+ 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;
+ 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);
+ 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;
+ ped->need_update = false;
+ ped->probe_id = i;
- if (!ped->ready_to_shade) {
- pinfo->num_render_cube++;
- ped->ready_to_shade = true;
- }
+ if (!ped->ready_to_shade) {
+ pinfo->num_render_cube++;
+ ped->ready_to_shade = true;
+ }
#if 0
- printf("Update Cubemap %d\n", i);
+ printf("Update Cubemap %d\n", i);
#endif
- DRW_viewport_request_redraw();
- /* Do not let this frame accumulate. */
- stl->effects->taa_current_sample = 1;
+ 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;
- }
+ /* 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;
+ if (!ped->need_update) {
+ continue;
+ }
- render_scene_to_planar(sldata, vedata, i, ped->viewmat, ped->persmat, ped->planer_eq_offset);
+ /* Temporary Remove all planar reflections (avoid lag effect). */
+ int tmp_num_planar = pinfo->num_planar;
+ pinfo->num_planar = 0;
- /* Restore */
- pinfo->num_planar = tmp_num_planar;
+ render_scene_to_planar(sldata, vedata, i, ped->viewmat, ped->persmat, ped->planer_eq_offset);
- ped->need_update = false;
- ped->probe_id = i;
- }
+ /* Restore */
+ pinfo->num_planar = tmp_num_planar;
+
+ ped->need_update = false;
+ ped->probe_id = i;
}
/* If there is at least one planar probe */
diff --git a/source/blender/draw/engines/eevee/eevee_lights.c b/source/blender/draw/engines/eevee/eevee_lights.c
index d6c45e55edd..22465c04cfa 100644
--- a/source/blender/draw/engines/eevee/eevee_lights.c
+++ b/source/blender/draw/engines/eevee/eevee_lights.c
@@ -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;
+ if (!led->need_update) {
+ continue;
+ }
- 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];
+ EEVEE_ShadowRender *srd = &linfo->shadow_render_data;
+ EEVEE_ShadowCubeData *evscd = (EEVEE_ShadowCubeData *)led->storage;
- unit_m4(tmp);
- negate_v3_v3(tmp[3], ob->obmat[3]);
- mul_m4_m4m4(srd->viewmat[j], cubefacemat[j], tmp);
+ 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];
- 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);
- }
+ unit_m4(tmp);
+ negate_v3_v3(tmp[3], ob->obmat[3]);
+ mul_m4_m4m4(srd->viewmat[j], cubefacemat[j], tmp);
- /* Push it to shadowmap array */
+ mul_m4_m4m4(srd->shadowmat[j], cube_projmat, srd->viewmat[j]);
+ }
+ DRW_uniformbuffer_update(sldata->shadow_render_ubo, srd);
- /* 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;
+ DRW_framebuffer_bind(sldata->shadow_target_fb);
+ DRW_framebuffer_clear(true, true, false, clear_col, 1.0f);
- 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);
+ /* Render shadow cube */
+ DRW_draw_pass(psl->shadow_cube_pass);
- DRW_framebuffer_texture_layer_attach(sldata->shadow_store_fb, sldata->shadow_pool, 0, evscd->layer_id, 0);
+ /* 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_store_pass);
+ 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;
- led->need_update = false;
+ 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;