Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee/eevee_volumes.c
| Show First 20 Lines • Show All 388 Lines • ▼ Show 20 Lines | LISTBASE_FOREACH (GPUMaterialVolumeGrid *, gpu_grid, gpu_grids) { | ||||
| DRWVolumeGrid *drw_grid = (volume_grid) ? | DRWVolumeGrid *drw_grid = (volume_grid) ? | ||||
| DRW_volume_batch_cache_get_grid(volume, volume_grid) : | DRW_volume_batch_cache_get_grid(volume, volume_grid) : | ||||
| NULL; | NULL; | ||||
| /* Handle 3 cases here: | /* Handle 3 cases here: | ||||
| * - Grid exists and texture was loaded -> use texture. | * - Grid exists and texture was loaded -> use texture. | ||||
| * - Grid exists but has zero size or failed to load -> use zero. | * - Grid exists but has zero size or failed to load -> use zero. | ||||
| * - Grid does not exist -> use default value. */ | * - Grid does not exist -> use default value. */ | ||||
| GPUTexture *grid_tex = (drw_grid) ? drw_grid->texture : | GPUTexture *grid_tex = (drw_grid) ? drw_grid->texture : | ||||
| (volume_grid) ? | (volume_grid) ? e_data.dummy_zero : | ||||
| e_data.dummy_zero : | |||||
| eevee_volume_default_texture(gpu_grid->default_value); | eevee_volume_default_texture(gpu_grid->default_value); | ||||
| DRW_shgroup_uniform_texture(grp, gpu_grid->sampler_name, grid_tex); | DRW_shgroup_uniform_texture(grp, gpu_grid->sampler_name, grid_tex); | ||||
| if (drw_grid && multiple_transforms) { | if (drw_grid && multiple_transforms) { | ||||
| /* Specify per-volume transform matrix that is applied after the | /* Specify per-volume transform matrix that is applied after the | ||||
| * transform from object to bounds. */ | * transform from object to bounds. */ | ||||
| mul_m4_m4m4(drw_grid->bounds_to_texture, drw_grid->object_to_texture, bounds_to_object); | mul_m4_m4m4(drw_grid->bounds_to_texture, drw_grid->object_to_texture, bounds_to_object); | ||||
| DRW_shgroup_uniform_mat4(grp, gpu_grid->transform_name, drw_grid->bounds_to_texture); | DRW_shgroup_uniform_mat4(grp, gpu_grid->transform_name, drw_grid->bounds_to_texture); | ||||
| ▲ Show 20 Lines • Show All 386 Lines • ▼ Show 20 Lines | |||||
| void EEVEE_volumes_output_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, uint tot_samples) | void EEVEE_volumes_output_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, uint tot_samples) | ||||
| { | { | ||||
| EEVEE_FramebufferList *fbl = vedata->fbl; | EEVEE_FramebufferList *fbl = vedata->fbl; | ||||
| EEVEE_TextureList *txl = vedata->txl; | EEVEE_TextureList *txl = vedata->txl; | ||||
| EEVEE_StorageList *stl = vedata->stl; | EEVEE_StorageList *stl = vedata->stl; | ||||
| EEVEE_PassList *psl = vedata->psl; | EEVEE_PassList *psl = vedata->psl; | ||||
| EEVEE_EffectsInfo *effects = stl->effects; | EEVEE_EffectsInfo *effects = stl->effects; | ||||
| const float clear[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | |||||
| /* Create FrameBuffer. */ | /* Create FrameBuffer. */ | ||||
| /* Should be enough precision for many samples. */ | /* Should be enough precision for many samples. */ | ||||
| const eGPUTextureFormat texture_format_accum = (tot_samples > 128) ? GPU_RGBA32F : GPU_RGBA16F; | const eGPUTextureFormat texture_format_accum = (tot_samples > 128) ? GPU_RGBA32F : GPU_RGBA16F; | ||||
| DRW_texture_ensure_fullscreen_2d(&txl->volume_scatter_accum, texture_format_accum, 0); | DRW_texture_ensure_fullscreen_2d(&txl->volume_scatter_accum, texture_format_accum, 0); | ||||
| DRW_texture_ensure_fullscreen_2d(&txl->volume_transmittance_accum, texture_format_accum, 0); | DRW_texture_ensure_fullscreen_2d(&txl->volume_transmittance_accum, texture_format_accum, 0); | ||||
| GPU_framebuffer_ensure_config(&fbl->volumetric_accum_fb, | GPU_framebuffer_ensure_config(&fbl->volumetric_accum_fb, | ||||
| {GPU_ATTACHMENT_NONE, | {GPU_ATTACHMENT_NONE, | ||||
| GPU_ATTACHMENT_TEXTURE(txl->volume_scatter_accum), | GPU_ATTACHMENT_TEXTURE(txl->volume_scatter_accum), | ||||
| GPU_ATTACHMENT_TEXTURE(txl->volume_transmittance_accum)}); | GPU_ATTACHMENT_TEXTURE(txl->volume_transmittance_accum)}); | ||||
| /* Clear texture. */ | |||||
| if (effects->taa_current_sample == 1) { | |||||
| GPU_framebuffer_bind(fbl->volumetric_accum_fb); | |||||
| GPU_framebuffer_clear_color(fbl->volumetric_accum_fb, clear); | |||||
| } | |||||
| /* Create Pass and shgroup. */ | /* Create Pass and shgroup. */ | ||||
| DRW_PASS_CREATE(psl->volumetric_accum_ps, DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ADD_FULL); | DRW_PASS_CREATE(psl->volumetric_accum_ps, DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ADD_FULL); | ||||
| DRWShadingGroup *grp = NULL; | DRWShadingGroup *grp = NULL; | ||||
| if ((effects->enabled_effects & EFFECT_VOLUMETRIC) != 0) { | if ((effects->enabled_effects & EFFECT_VOLUMETRIC) != 0) { | ||||
| grp = DRW_shgroup_create(EEVEE_shaders_volumes_resolve_sh_get(true), psl->volumetric_accum_ps); | grp = DRW_shgroup_create(EEVEE_shaders_volumes_resolve_sh_get(true), psl->volumetric_accum_ps); | ||||
| DRW_shgroup_uniform_texture_ref(grp, "inScattering", &txl->volume_scatter); | DRW_shgroup_uniform_texture_ref(grp, "inScattering", &txl->volume_scatter); | ||||
| DRW_shgroup_uniform_texture_ref(grp, "inTransmittance", &txl->volume_transmit); | DRW_shgroup_uniform_texture_ref(grp, "inTransmittance", &txl->volume_transmit); | ||||
| DRW_shgroup_uniform_texture_ref(grp, "inSceneDepth", &e_data.depth_src); | DRW_shgroup_uniform_texture_ref(grp, "inSceneDepth", &e_data.depth_src); | ||||
| DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo); | DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo); | ||||
| DRW_shgroup_uniform_block(grp, "renderpass_block", sldata->renderpass_ubo.combined); | DRW_shgroup_uniform_block(grp, "renderpass_block", sldata->renderpass_ubo.combined); | ||||
| } | } | ||||
| else { | else { | ||||
| /* There is no volumetrics in the scene. Use a shader to fill the accum textures with a default | /* There is no volumetrics in the scene. Use a shader to fill the accum textures with a default | ||||
| * value. */ | * value. */ | ||||
| grp = DRW_shgroup_create(EEVEE_shaders_volumes_accum_sh_get(), psl->volumetric_accum_ps); | grp = DRW_shgroup_create(EEVEE_shaders_volumes_accum_sh_get(), psl->volumetric_accum_ps); | ||||
| } | } | ||||
| DRW_shgroup_call(grp, DRW_cache_fullscreen_quad_get(), NULL); | DRW_shgroup_call(grp, DRW_cache_fullscreen_quad_get(), NULL); | ||||
| } | } | ||||
| void EEVEE_volumes_output_accumulate(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata) | void EEVEE_volumes_output_accumulate(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata) | ||||
| { | { | ||||
| EEVEE_FramebufferList *fbl = vedata->fbl; | EEVEE_FramebufferList *fbl = vedata->fbl; | ||||
| EEVEE_PassList *psl = vedata->psl; | EEVEE_PassList *psl = vedata->psl; | ||||
| EEVEE_EffectsInfo *effects = vedata->stl->effects; | |||||
| if (fbl->volumetric_accum_fb != NULL) { | if (fbl->volumetric_accum_fb != NULL) { | ||||
| /* Accum pass */ | /* Accum pass */ | ||||
| GPU_framebuffer_bind(fbl->volumetric_accum_fb); | GPU_framebuffer_bind(fbl->volumetric_accum_fb); | ||||
| /* Clear texture. */ | |||||
| if (effects->taa_current_sample == 1) { | |||||
| const float clear[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | |||||
| GPU_framebuffer_clear_color(fbl->volumetric_accum_fb, clear); | |||||
| } | |||||
| DRW_draw_pass(psl->volumetric_accum_ps); | DRW_draw_pass(psl->volumetric_accum_ps); | ||||
| /* Restore */ | /* Restore */ | ||||
| GPU_framebuffer_bind(fbl->main_fb); | GPU_framebuffer_bind(fbl->main_fb); | ||||
| } | } | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||