diff --git a/source/blender/draw/engines/eevee_next/eevee_sync.cc b/source/blender/draw/engines/eevee_next/eevee_sync.cc index c392d6df3d1..60993607935 100644 --- a/source/blender/draw/engines/eevee_next/eevee_sync.cc +++ b/source/blender/draw/engines/eevee_next/eevee_sync.cc @@ -363,6 +363,13 @@ void SyncModule::sync_volume(Object *ob, return; } + /* Do not render the object if there is no attribute used in the volume. + * This mimic Cycles behavior (see #124061). */ + ListBase attr_list = GPU_material_attributes(material.volume_material.gpumat); + if (BLI_listbase_is_empty(&attr_list)) { + return; + } + auto drawcall_add = [&](MaterialPass &matpass, gpu::Batch *geom, ResourceHandle res_handle) { if (matpass.sub_pass == nullptr) { return; diff --git a/source/blender/io/usd/hydra/image.cc b/source/blender/io/usd/hydra/image.cc index e43aead7711..b29d9af69bd 100644 --- a/source/blender/io/usd/hydra/image.cc +++ b/source/blender/io/usd/hydra/image.cc @@ -3,6 +3,7 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ #include "image.hh" +#include "usd_private.hh" #include @@ -24,25 +25,6 @@ namespace blender::io::hydra { -std::string image_cache_file_path() -{ - char dir_path[FILE_MAX]; - BLI_path_join(dir_path, sizeof(dir_path), BKE_tempdir_session(), "hydra", "image_cache"); - return dir_path; -} - -static std::string get_cache_file(const std::string &file_name, bool mkdir = true) -{ - std::string dir_path = image_cache_file_path(); - if (mkdir) { - BLI_dir_create_recursive(dir_path.c_str()); - } - - char file_path[FILE_MAX]; - BLI_path_join(file_path, sizeof(file_path), dir_path.c_str(), file_name.c_str()); - return file_path; -} - static std::string cache_image_file( Main *bmain, Scene *scene, Image *image, ImageUser *iuser, bool check_exist) { @@ -58,7 +40,7 @@ static std::string cache_image_file( SNPRINTF(file_name, "img_%p%s", image, r_ext); - file_path = get_cache_file(file_name); + file_path = blender::io::usd::get_image_cache_file(file_name); if (check_exist && BLI_exists(file_path.c_str())) { return file_path; } @@ -87,7 +69,7 @@ std::string cache_or_get_image_file(Main *bmain, Scene *scene, Image *image, Ima } else if (BKE_image_has_packedfile(image)) { do_check_extension = true; - std::string dir_path = image_cache_file_path(); + std::string dir_path = blender::io::usd::image_cache_file_path(); char *cached_path; char subfolder[FILE_MAXDIR]; SNPRINTF(subfolder, "unpack_%p", image); @@ -126,33 +108,4 @@ std::string cache_or_get_image_file(Main *bmain, Scene *scene, Image *image, Ima return file_path; } -std::string cache_image_color(float color[4]) -{ - char name[128]; - SNPRINTF(name, - "color_%02d%02d%02d.hdr", - int(color[0] * 255), - int(color[1] * 255), - int(color[2] * 255)); - std::string file_path = get_cache_file(name); - if (BLI_exists(file_path.c_str())) { - return file_path; - } - - ImBuf *ibuf = IMB_allocImBuf(4, 4, 32, IB_rectfloat); - IMB_rectfill(ibuf, color); - ibuf->ftype = IMB_FTYPE_RADHDR; - - if (IMB_saveiff(ibuf, file_path.c_str(), IB_rectfloat)) { - CLOG_INFO(LOG_HYDRA_SCENE, 1, "%s", file_path.c_str()); - } - else { - CLOG_ERROR(LOG_HYDRA_SCENE, "Can't save %s", file_path.c_str()); - file_path = ""; - } - IMB_freeImBuf(ibuf); - - return file_path; -} - } // namespace blender::io::hydra diff --git a/source/blender/io/usd/hydra/image.hh b/source/blender/io/usd/hydra/image.hh index 73c7cc8d08b..dd64d8eef44 100644 --- a/source/blender/io/usd/hydra/image.hh +++ b/source/blender/io/usd/hydra/image.hh @@ -13,9 +13,6 @@ struct ImageUser; namespace blender::io::hydra { -std::string image_cache_file_path(); - std::string cache_or_get_image_file(Main *bmain, Scene *Scene, Image *image, ImageUser *iuser); -std::string cache_image_color(float color[4]); } // namespace blender::io::hydra diff --git a/source/blender/io/usd/hydra/material.cc b/source/blender/io/usd/hydra/material.cc index 2f331965df8..730dd2fb078 100644 --- a/source/blender/io/usd/hydra/material.cc +++ b/source/blender/io/usd/hydra/material.cc @@ -3,6 +3,7 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ #include "material.hh" +#include "usd_private.hh" #include #include @@ -80,7 +81,7 @@ void MaterialData::init() material_library_path, get_time_code, export_params, - image_cache_file_path(), + blender::io::usd::image_cache_file_path(), cache_or_get_image_file}; /* Create USD material. */ pxr::UsdShadeMaterial usd_material; diff --git a/source/blender/io/usd/hydra/world.cc b/source/blender/io/usd/hydra/world.cc index 926435fe27f..d05a4c4c9af 100644 --- a/source/blender/io/usd/hydra/world.cc +++ b/source/blender/io/usd/hydra/world.cc @@ -3,6 +3,7 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ #include "world.hh" +#include "usd_private.hh" #include #include @@ -112,7 +113,7 @@ void WorldData::init() if (texture_file.GetAssetPath().empty()) { float fill_color[4] = {color[0], color[1], color[2], 1.0f}; - std::string image_path = cache_image_color(fill_color); + std::string image_path = blender::io::usd::cache_image_color(fill_color); texture_file = pxr::SdfAssetPath(image_path, image_path); } } diff --git a/source/blender/io/usd/intern/usd_capi_export.cc b/source/blender/io/usd/intern/usd_capi_export.cc index 53120ee86c3..05166733656 100644 --- a/source/blender/io/usd/intern/usd_capi_export.cc +++ b/source/blender/io/usd/intern/usd_capi_export.cc @@ -48,6 +48,9 @@ #include "BLI_string.h" #include "BLI_timeit.hh" +#include +#include + #include "WM_api.hh" #include "WM_types.hh" @@ -329,6 +332,54 @@ static bool perform_usdz_conversion(const ExportJobData *data) return true; } +std::string image_cache_file_path() +{ + char dir_path[FILE_MAX]; + BLI_path_join(dir_path, sizeof(dir_path), BKE_tempdir_session(), "usd", "image_cache"); + return dir_path; +} + +std::string get_image_cache_file(const std::string &file_name, bool mkdir) +{ + std::string dir_path = image_cache_file_path(); + if (mkdir) { + BLI_dir_create_recursive(dir_path.c_str()); + } + + char file_path[FILE_MAX]; + BLI_path_join(file_path, sizeof(file_path), dir_path.c_str(), file_name.c_str()); + return file_path; +} + +std::string cache_image_color(float color[4]) +{ + char name[128]; + SNPRINTF(name, + "color_%02d%02d%02d.hdr", + int(color[0] * 255), + int(color[1] * 255), + int(color[2] * 255)); + std::string file_path = get_image_cache_file(name); + if (BLI_exists(file_path.c_str())) { + return file_path; + } + + ImBuf *ibuf = IMB_allocImBuf(4, 4, 32, IB_rectfloat); + IMB_rectfill(ibuf, color); + ibuf->ftype = IMB_FTYPE_RADHDR; + + if (IMB_saveiff(ibuf, file_path.c_str(), IB_rectfloat)) { + CLOG_INFO(&LOG, 1, "%s", file_path.c_str()); + } + else { + CLOG_ERROR(&LOG, "Can't save %s", file_path.c_str()); + file_path = ""; + } + IMB_freeImBuf(ibuf); + + return file_path; +} + pxr::UsdStageRefPtr export_to_stage(const USDExportParams ¶ms, Depsgraph *depsgraph, const char *filepath) diff --git a/source/blender/io/usd/intern/usd_light_convert.cc b/source/blender/io/usd/intern/usd_light_convert.cc index 29dcda43fe6..fac53d07eef 100644 --- a/source/blender/io/usd/intern/usd_light_convert.cc +++ b/source/blender/io/usd/intern/usd_light_convert.cc @@ -6,6 +6,7 @@ #include "usd.hh" #include "usd_asset_utils.hh" +#include "usd_private.hh" #include "usd_reader_prim.hh" #include "usd_writer_material.hh" @@ -32,8 +33,6 @@ #include "DNA_scene_types.h" #include "DNA_world_types.h" -#include "../hydra/image.hh" - #include #include "CLG_log.h" @@ -308,7 +307,7 @@ void world_material_to_dome_light(const USDExportParams ¶ms, float fill_color[4] = {res.world_color[0], res.world_color[1], res.world_color[2], 1.0f}; - std::string source_path = blender::io::hydra::cache_image_color(fill_color); + std::string source_path = cache_image_color(fill_color); const std::string base_path = stage->GetRootLayer()->GetRealPath(); /* It'll be short, coming from cache_image_color. */ diff --git a/source/blender/io/usd/usd_private.hh b/source/blender/io/usd/usd_private.hh index b72f91fd065..0898dd799d2 100644 --- a/source/blender/io/usd/usd_private.hh +++ b/source/blender/io/usd/usd_private.hh @@ -6,6 +6,8 @@ #include +#include + #include "usd.hh" struct Depsgraph; @@ -16,4 +18,8 @@ pxr::UsdStageRefPtr export_to_stage(const USDExportParams ¶ms, Depsgraph *depsgraph, const char *filepath); -}; +std::string image_cache_file_path(); +std::string get_image_cache_file(const std::string &file_name, bool mkdir = true); +std::string cache_image_color(float color[4]); + +}; // namespace blender::io::usd