Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee/eevee_lightprobes.c
| Show All 29 Lines | |||||
| #include "BLI_rand.h" | #include "BLI_rand.h" | ||||
| #include "DNA_world_types.h" | #include "DNA_world_types.h" | ||||
| #include "DNA_texture_types.h" | #include "DNA_texture_types.h" | ||||
| #include "DNA_image_types.h" | #include "DNA_image_types.h" | ||||
| #include "DNA_lightprobe_types.h" | #include "DNA_lightprobe_types.h" | ||||
| #include "DNA_view3d_types.h" | #include "DNA_view3d_types.h" | ||||
| #include "BKE_collection.h" | |||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_group.h" | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "GPU_material.h" | #include "GPU_material.h" | ||||
| #include "GPU_texture.h" | #include "GPU_texture.h" | ||||
| #include "GPU_glew.h" | #include "GPU_glew.h" | ||||
| #include "eevee_engine.h" | #include "eevee_engine.h" | ||||
| #include "eevee_private.h" | #include "eevee_private.h" | ||||
| ▲ Show 20 Lines • Show All 335 Lines • ▼ Show 20 Lines | |||||
| void EEVEE_lightprobes_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata) | void EEVEE_lightprobes_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata) | ||||
| { | { | ||||
| EEVEE_TextureList *txl = vedata->txl; | EEVEE_TextureList *txl = vedata->txl; | ||||
| EEVEE_PassList *psl = vedata->psl; | EEVEE_PassList *psl = vedata->psl; | ||||
| EEVEE_StorageList *stl = vedata->stl; | EEVEE_StorageList *stl = vedata->stl; | ||||
| EEVEE_LightProbesInfo *pinfo = sldata->probes; | EEVEE_LightProbesInfo *pinfo = sldata->probes; | ||||
| /* Make sure no aditionnal visibility check runs by default. */ | /* Make sure no aditionnal visibility check runs by default. */ | ||||
| pinfo->vis_data.group = NULL; | pinfo->vis_data.collection = NULL; | ||||
| pinfo->do_cube_update = false; | pinfo->do_cube_update = false; | ||||
| pinfo->num_cube = 1; /* at least one for the world */ | pinfo->num_cube = 1; /* at least one for the world */ | ||||
| pinfo->num_grid = 1; | pinfo->num_grid = 1; | ||||
| pinfo->num_planar = 0; | pinfo->num_planar = 0; | ||||
| pinfo->total_irradiance_samples = 1; | pinfo->total_irradiance_samples = 1; | ||||
| memset(pinfo->probes_cube_ref, 0, sizeof(pinfo->probes_cube_ref)); | memset(pinfo->probes_cube_ref, 0, sizeof(pinfo->probes_cube_ref)); | ||||
| memset(pinfo->probes_grid_ref, 0, sizeof(pinfo->probes_grid_ref)); | memset(pinfo->probes_grid_ref, 0, sizeof(pinfo->probes_grid_ref)); | ||||
| ▲ Show 20 Lines • Show All 175 Lines • ▼ Show 20 Lines | #endif | ||||
| } | } | ||||
| } | } | ||||
| bool EEVEE_lightprobes_obj_visibility_cb(bool vis_in, void *user_data) | bool EEVEE_lightprobes_obj_visibility_cb(bool vis_in, void *user_data) | ||||
| { | { | ||||
| EEVEE_ObjectEngineData *oed = (EEVEE_ObjectEngineData *)user_data; | EEVEE_ObjectEngineData *oed = (EEVEE_ObjectEngineData *)user_data; | ||||
| /* test disabled if group is NULL */ | /* test disabled if group is NULL */ | ||||
| if (oed->test_data->group == NULL) | if (oed->test_data->collection == NULL) | ||||
| return vis_in; | return vis_in; | ||||
| if (oed->test_data->cached == false) | if (oed->test_data->cached == false) | ||||
| oed->ob_vis_dirty = true; | oed->ob_vis_dirty = true; | ||||
| /* early out, don't need to compute ob_vis yet. */ | /* early out, don't need to compute ob_vis yet. */ | ||||
| if (vis_in == false) | if (vis_in == false) | ||||
| return vis_in; | return vis_in; | ||||
| if (oed->ob_vis_dirty) { | if (oed->ob_vis_dirty) { | ||||
| oed->ob_vis_dirty = false; | oed->ob_vis_dirty = false; | ||||
| oed->ob_vis = BKE_group_object_exists(oed->test_data->group, oed->ob); | oed->ob_vis = BKE_collection_has_object_recursive(oed->test_data->collection, oed->ob); | ||||
| oed->ob_vis = (oed->test_data->invert) ? !oed->ob_vis : oed->ob_vis; | oed->ob_vis = (oed->test_data->invert) ? !oed->ob_vis : oed->ob_vis; | ||||
| } | } | ||||
| return vis_in && oed->ob_vis; | return vis_in && oed->ob_vis; | ||||
| } | } | ||||
| void EEVEE_lightprobes_cache_add(EEVEE_ViewLayerData *sldata, Object *ob) | void EEVEE_lightprobes_cache_add(EEVEE_ViewLayerData *sldata, Object *ob) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 691 Lines • ▼ Show 20 Lines | for (int i = 0; i < 6; ++i) { | ||||
| DRW_draw_pass(psl->sss_pass); /* Only output standard pass */ | DRW_draw_pass(psl->sss_pass); /* Only output standard pass */ | ||||
| DRW_stats_group_end(); | DRW_stats_group_end(); | ||||
| } | } | ||||
| DRW_stats_group_end(); | DRW_stats_group_end(); | ||||
| /* Make sure no aditionnal visibility check runs after this. */ | /* Make sure no aditionnal visibility check runs after this. */ | ||||
| pinfo->vis_data.group = NULL; | pinfo->vis_data.collection = NULL; | ||||
| /* Restore */ | /* Restore */ | ||||
| txl->planar_pool = tmp_planar_pool; | txl->planar_pool = tmp_planar_pool; | ||||
| txl->maxzbuffer = tmp_maxz; | txl->maxzbuffer = tmp_maxz; | ||||
| } | } | ||||
| static void render_scene_to_planar( | static void render_scene_to_planar( | ||||
| EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, int layer, | EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, int layer, | ||||
| ▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | static void render_scene_to_planar( | ||||
| DRW_draw_pass(psl->transparent_pass); | DRW_draw_pass(psl->transparent_pass); | ||||
| DRW_state_invert_facing(); | DRW_state_invert_facing(); | ||||
| DRW_state_clip_planes_reset(); | DRW_state_clip_planes_reset(); | ||||
| DRW_stats_group_end(); | DRW_stats_group_end(); | ||||
| /* Make sure no aditionnal visibility check runs after this. */ | /* Make sure no aditionnal visibility check runs after this. */ | ||||
| pinfo->vis_data.group = NULL; | pinfo->vis_data.collection = NULL; | ||||
| /* Restore */ | /* Restore */ | ||||
| txl->planar_pool = tmp_planar_pool; | txl->planar_pool = tmp_planar_pool; | ||||
| txl->planar_depth = tmp_planar_depth; | txl->planar_depth = tmp_planar_depth; | ||||
| } | } | ||||
| static void render_world_to_probe(EEVEE_ViewLayerData *sldata, EEVEE_PassList *psl) | static void render_world_to_probe(EEVEE_ViewLayerData *sldata, EEVEE_PassList *psl) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Lines | void EEVEE_lightprobes_refresh_planar(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata) | ||||
| common_data->ssr_toggle = false; | common_data->ssr_toggle = false; | ||||
| common_data->sss_toggle = false; | common_data->sss_toggle = false; | ||||
| DRW_uniformbuffer_update(sldata->common_ubo, &sldata->common_data); | DRW_uniformbuffer_update(sldata->common_ubo, &sldata->common_data); | ||||
| for (int i = 0; (ob = pinfo->probes_planar_ref[i]) && (i < MAX_PLANAR); i++) { | for (int i = 0; (ob = pinfo->probes_planar_ref[i]) && (i < MAX_PLANAR); i++) { | ||||
| EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_ensure(ob); | EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_ensure(ob); | ||||
| LightProbe *prb = (LightProbe *)ob->data; | LightProbe *prb = (LightProbe *)ob->data; | ||||
| pinfo->vis_data.group = prb->visibility_grp; | pinfo->vis_data.collection = prb->visibility_grp; | ||||
| pinfo->vis_data.invert = prb->flag & LIGHTPROBE_FLAG_INVERT_GROUP; | pinfo->vis_data.invert = prb->flag & LIGHTPROBE_FLAG_INVERT_GROUP; | ||||
| render_scene_to_planar(sldata, vedata, i, ped); | render_scene_to_planar(sldata, vedata, i, ped); | ||||
| } | } | ||||
| /* Restore */ | /* Restore */ | ||||
| common_data->prb_num_planar = pinfo->num_planar; | common_data->prb_num_planar = pinfo->num_planar; | ||||
| common_data->ssr_toggle = true; | common_data->ssr_toggle = true; | ||||
| common_data->sss_toggle = true; | common_data->sss_toggle = true; | ||||
| Show All 32 Lines | static void lightprobes_refresh_cube(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata) | ||||
| EEVEE_LightProbesInfo *pinfo = sldata->probes; | EEVEE_LightProbesInfo *pinfo = sldata->probes; | ||||
| Object *ob; | Object *ob; | ||||
| for (int i = 1; (ob = pinfo->probes_cube_ref[i]) && (i < MAX_PROBE); i++) { | for (int i = 1; (ob = pinfo->probes_cube_ref[i]) && (i < MAX_PROBE); i++) { | ||||
| EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_ensure(ob); | EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_ensure(ob); | ||||
| if (!ped->need_update) { | if (!ped->need_update) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| LightProbe *prb = (LightProbe *)ob->data; | LightProbe *prb = (LightProbe *)ob->data; | ||||
| pinfo->vis_data.group = prb->visibility_grp; | pinfo->vis_data.collection = prb->visibility_grp; | ||||
| pinfo->vis_data.invert = prb->flag & LIGHTPROBE_FLAG_INVERT_GROUP; | pinfo->vis_data.invert = prb->flag & LIGHTPROBE_FLAG_INVERT_GROUP; | ||||
| render_scene_to_probe(sldata, vedata, ob->obmat[3], prb->clipsta, prb->clipend); | render_scene_to_probe(sldata, vedata, ob->obmat[3], prb->clipsta, prb->clipend); | ||||
| glossy_filter_probe(sldata, vedata, psl, i, prb->intensity); | glossy_filter_probe(sldata, vedata, psl, i, prb->intensity); | ||||
| ped->need_update = false; | ped->need_update = false; | ||||
| ped->probe_id = i; | ped->probe_id = i; | ||||
| if (!ped->ready_to_shade) { | if (!ped->ready_to_shade) { | ||||
| common_data->prb_num_render_cube++; | common_data->prb_num_render_cube++; | ||||
| ped->ready_to_shade = true; | ped->ready_to_shade = true; | ||||
| ▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | for (int i = 1; (ob = pinfo->probes_grid_ref[i]) && (i < MAX_GRID); i++) { | ||||
| /* But not on first bounce. */ | /* But not on first bounce. */ | ||||
| common_data->prb_num_render_grid = 0; | common_data->prb_num_render_grid = 0; | ||||
| } | } | ||||
| else { | else { | ||||
| /* Remove bias */ | /* Remove bias */ | ||||
| egrid->level_bias = (float)(1 << 0); | egrid->level_bias = (float)(1 << 0); | ||||
| DRW_uniformbuffer_update(sldata->grid_ubo, &sldata->probes->grid_data); | DRW_uniformbuffer_update(sldata->grid_ubo, &sldata->probes->grid_data); | ||||
| } | } | ||||
| pinfo->vis_data.group = prb->visibility_grp; | pinfo->vis_data.collection = prb->visibility_grp; | ||||
| pinfo->vis_data.invert = prb->flag & LIGHTPROBE_FLAG_INVERT_GROUP; | pinfo->vis_data.invert = prb->flag & LIGHTPROBE_FLAG_INVERT_GROUP; | ||||
| render_scene_to_probe(sldata, vedata, pos, prb->clipsta, prb->clipend); | render_scene_to_probe(sldata, vedata, pos, prb->clipsta, prb->clipend); | ||||
| diffuse_filter_probe(sldata, vedata, psl, egrid->offset + cell_id, | diffuse_filter_probe(sldata, vedata, psl, egrid->offset + cell_id, | ||||
| prb->clipsta, prb->clipend, egrid->visibility_range, prb->vis_blur, | prb->clipsta, prb->clipend, egrid->visibility_range, prb->vis_blur, | ||||
| prb->intensity); | prb->intensity); | ||||
| /* To see what is going on. */ | /* To see what is going on. */ | ||||
| SWAP(GPUTexture *, sldata->irradiance_pool, sldata->irradiance_rt); | SWAP(GPUTexture *, sldata->irradiance_pool, sldata->irradiance_rt); | ||||
| /* Restore */ | /* Restore */ | ||||
| ▲ Show 20 Lines • Show All 123 Lines • Show Last 20 Lines | |||||