From 4d2fcc57165ef5a223227a4fcded65679d559fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Wed, 3 Jul 2024 14:40:48 +0200 Subject: [PATCH] Fix: EEVEE: Avoid assert from empty volume object material Also avoid drawing them at all if the material has no volume shader. --- .../blender/draw/engines/eevee_next/eevee_pipeline.cc | 8 +++++--- source/blender/draw/engines/eevee_next/eevee_sync.cc | 11 +++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/source/blender/draw/engines/eevee_next/eevee_pipeline.cc b/source/blender/draw/engines/eevee_next/eevee_pipeline.cc index 871ece23dd7..8436ed6fa23 100644 --- a/source/blender/draw/engines/eevee_next/eevee_pipeline.cc +++ b/source/blender/draw/engines/eevee_next/eevee_pipeline.cc @@ -1018,7 +1018,7 @@ PassMain::Sub *VolumeLayer::occupancy_add(const Object *ob, const ::Material *blender_mat, GPUMaterial *gpumat) { - BLI_assert_msg(GPU_material_has_volume_output(gpumat) == true, + BLI_assert_msg((ob->type == OB_VOLUME) || GPU_material_has_volume_output(gpumat), "Only volume material should be added here"); bool use_fast_occupancy = (ob->type == OB_VOLUME) || (blender_mat->volume_intersection_method == MA_VOLUME_ISECT_FAST); @@ -1031,12 +1031,14 @@ PassMain::Sub *VolumeLayer::occupancy_add(const Object *ob, return pass; } -PassMain::Sub *VolumeLayer::material_add(const Object * /*ob*/, +PassMain::Sub *VolumeLayer::material_add(const Object *ob, const ::Material * /*blender_mat*/, GPUMaterial *gpumat) { - BLI_assert_msg(GPU_material_has_volume_output(gpumat) == true, + BLI_assert_msg((ob->type == OB_VOLUME) || GPU_material_has_volume_output(gpumat), "Only volume material should be added here"); + UNUSED_VARS_NDEBUG(ob); + PassMain::Sub *pass = &material_ps_->sub(GPU_material_get_name(gpumat)); pass->material_set(*inst_.manager, gpumat); if (GPU_material_flag_get(gpumat, GPU_MATFLAG_VOLUME_SCATTER)) { diff --git a/source/blender/draw/engines/eevee_next/eevee_sync.cc b/source/blender/draw/engines/eevee_next/eevee_sync.cc index c5b52dfda43..4362315fa58 100644 --- a/source/blender/draw/engines/eevee_next/eevee_sync.cc +++ b/source/blender/draw/engines/eevee_next/eevee_sync.cc @@ -367,8 +367,9 @@ void SyncModule::sync_volume(Object *ob, Material &material = inst_.materials.material_get( ob, has_motion, material_slot - 1, MAT_GEOM_VOLUME); - /* Use bounding box tag empty spaces. */ - gpu::Batch *geom = DRW_cache_cube_get(); + if (!GPU_material_has_volume_output(material.volume_material.gpumat)) { + return; + } auto drawcall_add = [&](MaterialPass &matpass, gpu::Batch *geom, ResourceHandle res_handle) { if (matpass.sub_pass == nullptr) { @@ -381,11 +382,13 @@ void SyncModule::sync_volume(Object *ob, } }; - inst_.manager->extract_object_attributes(res_handle, ob_ref, material.volume_material.gpumat); - + /* Use bounding box tag empty spaces. */ + gpu::Batch *geom = DRW_cache_cube_get(); drawcall_add(material.volume_occupancy, geom, res_handle); drawcall_add(material.volume_material, geom, res_handle); + inst_.manager->extract_object_attributes(res_handle, ob_ref, material.volume_material.gpumat); + inst_.volume.object_sync(ob_handle); }