From 29ba521604ab1d502fa361d76e6e9b335c129eae Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Wed, 14 Jun 2023 13:11:36 +0300 Subject: [PATCH 01/20] initial --- .../scene_delegate/blender_scene_delegate.cc | 12 ++++++++++ .../scene_delegate/blender_scene_delegate.h | 8 +++++++ .../render/hydra/scene_delegate/world.cc | 22 ++++++++++++++++++- .../render/hydra/scene_delegate/world.h | 2 ++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 4326fc6bf008..9460e7a18973 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -422,6 +422,18 @@ void BlenderSceneDelegate::check_updates() bool do_update_visibility = false; bool do_update_world = false; + if (shading_flag_ != view3d->shading.flag) { + shading_flag_ = view3d->shading.flag; + do_update_world = true; + } + + if (LOOK_DEV_STUDIO_LIGHT_ENABLED(view3d) && + (world_data_->rotation != view3d->shading.studiolight_rot_z || + world_data_->intensity != view3d->shading.studiolight_intensity)) + { + do_update_world = true; + } + DEGIDIterData data = {0}; data.graph = depsgraph; data.only_updated = true; diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index c7b1468408e4..81938a7a0e7c 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -98,6 +98,14 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { MaterialDataMap materials_; InstancerDataMap instancers_; std::unique_ptr world_data_; + + short shading_flag_; }; +#define LOOK_DEV_STUDIO_LIGHT_ENABLED(v3d) \ + ((v3d) && (((v3d->shading.type == OB_MATERIAL) && \ + ((v3d->shading.flag & V3D_SHADING_SCENE_WORLD) == 0)) || \ + ((v3d->shading.type == OB_RENDER) && \ + ((v3d->shading.flag & V3D_SHADING_SCENE_WORLD_RENDER) == 0)))) + } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index 8df6dbb04a27..5c975dfe0015 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -15,7 +15,9 @@ #include "DNA_node_types.h" #include "BKE_node.h" +#include "BKE_studiolight.h" #include "BKE_node_runtime.hh" +#include "BLI_math_rotation.h" #include "BLI_path_util.h" #include "NOD_shader.h" @@ -26,6 +28,8 @@ /* TODO : add custom tftoken "transparency"? */ +/* NOTE: opacity and blur aren't supported by USD */ + namespace blender::render::hydra { WorldData::WorldData(BlenderSceneDelegate *scene_delegate, @@ -39,6 +43,8 @@ void WorldData::init() { ID_LOG(1, ""); + rotation = scene_delegate_->view3d->shading.studiolight_rot_z; + intensity = scene_delegate_->view3d->shading.studiolight_intensity; write_transform(); World *world = (World *)id; @@ -46,7 +52,7 @@ void WorldData::init() data_[pxr::UsdLuxTokens->orientToStageUpAxis] = true; - if (world->use_nodes) { + if (world->use_nodes && V3D_USES_SCENE_WORLD(scene_delegate_->view3d)) { /* TODO: Create nodes parsing system */ bNode *output_node = ntreeShaderOutputNode(world->nodetree, SHD_OUTPUT_ALL); @@ -95,6 +101,20 @@ void WorldData::init() } } } + else if (LOOK_DEV_STUDIO_LIGHT_ENABLED(scene_delegate_->view3d)) { + StudioLight *sl = BKE_studiolight_find(scene_delegate_->view3d->shading.lookdev_light, + STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE); + if (sl == NULL || (sl->flag & STUDIOLIGHT_TYPE_WORLD) == 0) { + return; + } + data_[pxr::HdLightTokens->textureFile] = pxr::SdfAssetPath(sl->filepath, sl->filepath); + data_[pxr::HdLightTokens->intensity] = scene_delegate_->view3d->shading.studiolight_intensity / 2; + + transform *= pxr::GfMatrix4d( + pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, -1.0), + RAD2DEGF(scene_delegate_->view3d->shading.studiolight_rot_z)), + pxr::GfVec3d()); + } else { data_[pxr::HdLightTokens->intensity] = 1.0f; data_[pxr::HdLightTokens->exposure] = world->exposure; diff --git a/source/blender/render/hydra/scene_delegate/world.h b/source/blender/render/hydra/scene_delegate/world.h index 2eb62555c555..902e635bcb8e 100644 --- a/source/blender/render/hydra/scene_delegate/world.h +++ b/source/blender/render/hydra/scene_delegate/world.h @@ -31,6 +31,8 @@ class WorldData : public IdData { pxr::VtValue get_data(pxr::TfToken const &key) const override; pxr::GfMatrix4d transform; + float rotation; + float intensity; private: void write_transform(); -- 2.30.2 From 5176f868d048d8e918fcca218afebde0c8e18b6d Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 15 Jun 2023 11:41:26 +0300 Subject: [PATCH 02/20] implemented checkbox "scene lights" --- .../scene_delegate/blender_scene_delegate.cc | 52 ++++++++++++++++++- .../scene_delegate/blender_scene_delegate.h | 2 + .../render/hydra/scene_delegate/image.cc | 13 +++-- 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 9460e7a18973..e43850d712d9 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -338,7 +338,9 @@ void BlenderSceneDelegate::update_objects(Object *object) if (!ObjectData::is_supported(object)) { return; } - + if (!V3D_USES_SCENE_LIGHTS(view3d) && object->type == OB_LAMP) { + return; + } pxr::SdfPath id = object_prim_id(object); ObjectData *obj_data = object_data(id); if (obj_data) { @@ -416,6 +418,36 @@ void BlenderSceneDelegate::update_world() } } +void BlenderSceneDelegate::update_scene_lights() { + DEGObjectIterSettings settings = {0}; + settings.depsgraph = depsgraph; + settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET; + DEGObjectIterData data = {0}; + data.settings = &settings; + data.graph = settings.depsgraph; + data.flag = settings.flags; + eEvaluationMode deg_mode = DEG_get_mode(depsgraph); + + ITER_BEGIN (DEG_iterator_objects_begin, + DEG_iterator_objects_next, + DEG_iterator_objects_end, + &data, + Object *, + object) + { + if (object->type == OB_LAMP) { + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, + 2, + "Visibility: %s [%s]", + object->id.name, + std::bitset<3>(BKE_object_visibility(object, deg_mode)).to_string().c_str()); + update_objects(object); + update_instancers(object); + } + } + ITER_END; +} + void BlenderSceneDelegate::check_updates() { bool do_update_collection = false; @@ -426,7 +458,20 @@ void BlenderSceneDelegate::check_updates() shading_flag_ = view3d->shading.flag; do_update_world = true; } - + bool use_scene_lights_changed = false; + auto a = V3D_USES_SCENE_LIGHTS(view3d); + if (use_scene_lights != V3D_USES_SCENE_LIGHTS(view3d)) { + use_scene_lights = V3D_USES_SCENE_LIGHTS(view3d); + use_scene_lights_changed = true; + } + if (use_scene_lights_changed) { + if (use_scene_lights) { + update_scene_lights(); + } + else { + remove_unused_objects(); + } + } if (LOOK_DEV_STUDIO_LIGHT_ENABLED(view3d) && (world_data_->rotation != view3d->shading.studiolight_rot_z || world_data_->intensity != view3d->shading.studiolight_intensity)) @@ -578,6 +623,9 @@ void BlenderSceneDelegate::remove_unused_objects() /* Remove unused objects */ objects_.remove_if([&](auto item) { bool ret = !available_objects.contains(item.key.GetName()); + if (!V3D_USES_SCENE_LIGHTS(view3d) && ((Object *)item.value->id)->type == OB_LAMP) { + ret = true; + } if (ret) { item.value->remove(); } diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index 81938a7a0e7c..3f98608b4722 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -89,6 +89,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { void update_objects(Object *object); void update_instancers(Object *object); void update_world(); + void update_scene_lights(); void check_updates(); void add_new_objects(); void remove_unused_objects(); @@ -100,6 +101,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { std::unique_ptr world_data_; short shading_flag_; + bool use_scene_lights = true; }; #define LOOK_DEV_STUDIO_LIGHT_ENABLED(v3d) \ diff --git a/source/blender/render/hydra/scene_delegate/image.cc b/source/blender/render/hydra/scene_delegate/image.cc index c82731eb788f..1354e57ada99 100644 --- a/source/blender/render/hydra/scene_delegate/image.cc +++ b/source/blender/render/hydra/scene_delegate/image.cc @@ -67,24 +67,23 @@ static std::string cache_image_file(Image *image, std::string cache_or_get_image_file(Image *image, bContext *context, ImageUser *iuser) { - std::string file_path; + char file_path[FILE_MAX]; if (image->source == IMA_SRC_GENERATED) { - file_path = cache_image_file(image, context, iuser, false); + strcpy(file_path, cache_image_file(image, context, iuser, false).c_str()); } else if (BKE_image_has_packedfile(image)) { - file_path = cache_image_file(image, context, iuser, true); + strcpy(file_path, cache_image_file(image, context, iuser, true).c_str()); } else { Main *main = CTX_data_main(context); - file_path.reserve(FILE_MAX); - BKE_image_user_file_path_ex(main, iuser, image, file_path.data(), false, true); + BKE_image_user_file_path_ex(main, iuser, image, file_path, false, true); if (!pxr::HioImageRegistry::GetInstance().IsSupportedImageFile(file_path)) { - file_path = cache_image_file(image, context, iuser, true); + strcpy(file_path, cache_image_file(image, context, iuser, true).c_str()); } } - CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s -> %s", image->id.name, file_path.c_str()); + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s -> %s", image->id.name, file_path); return file_path; } -- 2.30.2 From c71afbdbe71f9ad0d2d5cfa1b8cfd3a145ec0e51 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 15 Jun 2023 14:19:21 +0300 Subject: [PATCH 03/20] removed update_scene_lights --- .../scene_delegate/blender_scene_delegate.cc | 51 ++++++------------- .../scene_delegate/blender_scene_delegate.h | 5 +- 2 files changed, 18 insertions(+), 38 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index e43850d712d9..b267132ea825 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -205,6 +205,8 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) check_updates(); } else { + use_scene_lights = V3D_USES_SCENE_LIGHTS(view3d); + shading_flag_ = view3d->shading.flag; add_new_objects(); update_world(); } @@ -418,36 +420,6 @@ void BlenderSceneDelegate::update_world() } } -void BlenderSceneDelegate::update_scene_lights() { - DEGObjectIterSettings settings = {0}; - settings.depsgraph = depsgraph; - settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET; - DEGObjectIterData data = {0}; - data.settings = &settings; - data.graph = settings.depsgraph; - data.flag = settings.flags; - eEvaluationMode deg_mode = DEG_get_mode(depsgraph); - - ITER_BEGIN (DEG_iterator_objects_begin, - DEG_iterator_objects_next, - DEG_iterator_objects_end, - &data, - Object *, - object) - { - if (object->type == OB_LAMP) { - CLOG_INFO(LOG_RENDER_HYDRA_SCENE, - 2, - "Visibility: %s [%s]", - object->id.name, - std::bitset<3>(BKE_object_visibility(object, deg_mode)).to_string().c_str()); - update_objects(object); - update_instancers(object); - } - } - ITER_END; -} - void BlenderSceneDelegate::check_updates() { bool do_update_collection = false; @@ -458,15 +430,16 @@ void BlenderSceneDelegate::check_updates() shading_flag_ = view3d->shading.flag; do_update_world = true; } + bool use_scene_lights_changed = false; - auto a = V3D_USES_SCENE_LIGHTS(view3d); + if (use_scene_lights != V3D_USES_SCENE_LIGHTS(view3d)) { use_scene_lights = V3D_USES_SCENE_LIGHTS(view3d); use_scene_lights_changed = true; } if (use_scene_lights_changed) { if (use_scene_lights) { - update_scene_lights(); + add_new_objects(true); } else { remove_unused_objects(); @@ -552,7 +525,7 @@ void BlenderSceneDelegate::check_updates() } } -void BlenderSceneDelegate::add_new_objects() +void BlenderSceneDelegate::add_new_objects(bool only_lights) { DEGObjectIterSettings settings = {0}; settings.depsgraph = depsgraph; @@ -575,8 +548,16 @@ void BlenderSceneDelegate::add_new_objects() "Visibility: %s [%s]", object->id.name, std::bitset<3>(BKE_object_visibility(object, deg_mode)).to_string().c_str()); - update_objects(object); - update_instancers(object); + if (only_lights) { + if (object->type == OB_LAMP) { + update_objects(object); + update_instancers(object); + } + } + else { + update_objects(object); + update_instancers(object); + } } ITER_END; } diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index 3f98608b4722..f8f148652849 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -89,9 +89,8 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { void update_objects(Object *object); void update_instancers(Object *object); void update_world(); - void update_scene_lights(); void check_updates(); - void add_new_objects(); + void add_new_objects(bool only_lights = false); void remove_unused_objects(); void update_visibility(); @@ -101,7 +100,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { std::unique_ptr world_data_; short shading_flag_; - bool use_scene_lights = true; + bool use_scene_lights = false; }; #define LOOK_DEV_STUDIO_LIGHT_ENABLED(v3d) \ -- 2.30.2 From 3af45f013f69682fdff258ddcdf78db12d8a28bc Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 15 Jun 2023 15:28:39 +0300 Subject: [PATCH 04/20] fixed update on changing image --- .../hydra/scene_delegate/blender_scene_delegate.cc | 12 +++++++----- .../hydra/scene_delegate/blender_scene_delegate.h | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index b267132ea825..6d738ec8ed96 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -205,8 +205,9 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) check_updates(); } else { - use_scene_lights = V3D_USES_SCENE_LIGHTS(view3d); + use_scene_lights_ = V3D_USES_SCENE_LIGHTS(view3d); shading_flag_ = view3d->shading.flag; + lookdev_light_ = view3d->shading.lookdev_light; add_new_objects(); update_world(); } @@ -426,19 +427,20 @@ void BlenderSceneDelegate::check_updates() bool do_update_visibility = false; bool do_update_world = false; - if (shading_flag_ != view3d->shading.flag) { + if (shading_flag_ != view3d->shading.flag || lookdev_light_ != view3d->shading.lookdev_light) { shading_flag_ = view3d->shading.flag; + lookdev_light_ = view3d->shading.lookdev_light; do_update_world = true; } bool use_scene_lights_changed = false; - if (use_scene_lights != V3D_USES_SCENE_LIGHTS(view3d)) { - use_scene_lights = V3D_USES_SCENE_LIGHTS(view3d); + if (use_scene_lights_ != V3D_USES_SCENE_LIGHTS(view3d)) { + use_scene_lights_ = V3D_USES_SCENE_LIGHTS(view3d); use_scene_lights_changed = true; } if (use_scene_lights_changed) { - if (use_scene_lights) { + if (use_scene_lights_) { add_new_objects(true); } else { diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index f8f148652849..140a6330374e 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -100,7 +100,8 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { std::unique_ptr world_data_; short shading_flag_; - bool use_scene_lights = false; + std::string lookdev_light_; + bool use_scene_lights_ = false; }; #define LOOK_DEV_STUDIO_LIGHT_ENABLED(v3d) \ -- 2.30.2 From 4ce6d34eee3e5267cb656c4f1352a462bba3895c Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 15 Jun 2023 15:28:57 +0300 Subject: [PATCH 05/20] Added comment --- source/blender/render/hydra/scene_delegate/world.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index 573afed035f4..dd5d9da8cfaa 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -109,6 +109,7 @@ void WorldData::init() return; } data_[pxr::HdLightTokens->textureFile] = pxr::SdfAssetPath(sl->filepath, sl->filepath); + /* coefficient to follow Cycles result */ data_[pxr::HdLightTokens->intensity] = scene_delegate_->view3d->shading.studiolight_intensity / 2; transform *= pxr::GfMatrix4d( -- 2.30.2 From e2780854be77098b56da89ae353e32ee1c0dd773 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 15 Jun 2023 15:47:44 +0300 Subject: [PATCH 06/20] code improvements --- .../render/hydra/scene_delegate/world.cc | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index dd5d9da8cfaa..b533b5730c0e 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -102,23 +102,22 @@ void WorldData::init() } } } - else if (LOOK_DEV_STUDIO_LIGHT_ENABLED(scene_delegate_->view3d)) { - StudioLight *sl = BKE_studiolight_find(scene_delegate_->view3d->shading.lookdev_light, - STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE); - if (sl == NULL || (sl->flag & STUDIOLIGHT_TYPE_WORLD) == 0) { - return; - } - data_[pxr::HdLightTokens->textureFile] = pxr::SdfAssetPath(sl->filepath, sl->filepath); - /* coefficient to follow Cycles result */ - data_[pxr::HdLightTokens->intensity] = scene_delegate_->view3d->shading.studiolight_intensity / 2; - - transform *= pxr::GfMatrix4d( - pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, -1.0), - RAD2DEGF(scene_delegate_->view3d->shading.studiolight_rot_z)), - pxr::GfVec3d()); - } else { - data_[pxr::HdLightTokens->intensity] = 1.0f; + float intensity = 1.0f; + if (LOOK_DEV_STUDIO_LIGHT_ENABLED(scene_delegate_->view3d)) { + StudioLight *sl = BKE_studiolight_find(scene_delegate_->view3d->shading.lookdev_light, + STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE); + if (sl != NULL && sl->flag & STUDIOLIGHT_TYPE_WORLD) { + data_[pxr::HdLightTokens->textureFile] = pxr::SdfAssetPath(sl->filepath, sl->filepath); + transform *= pxr::GfMatrix4d( + pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, -1.0), + RAD2DEGF(scene_delegate_->view3d->shading.studiolight_rot_z)), + pxr::GfVec3d()); + /* coefficient to follow Cycles result */ + intensity = scene_delegate_->view3d->shading.studiolight_intensity / 2; + } + } + data_[pxr::HdLightTokens->intensity] = intensity; data_[pxr::HdLightTokens->exposure] = world->exposure; data_[pxr::HdLightTokens->color] = pxr::GfVec3f(world->horr, world->horg, world->horb); } -- 2.30.2 From 8ad1e29adb627235d0b67175daa8ca28265677ac Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 15 Jun 2023 17:50:33 +0300 Subject: [PATCH 07/20] make format --- source/blender/render/hydra/preview_engine.cc | 4 +++- source/blender/render/hydra/scene_delegate/world.cc | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/source/blender/render/hydra/preview_engine.cc b/source/blender/render/hydra/preview_engine.cc index 651154cbf4a2..70ee57a12a11 100644 --- a/source/blender/render/hydra/preview_engine.cc +++ b/source/blender/render/hydra/preview_engine.cc @@ -39,7 +39,9 @@ void PreviewEngine::update_render_result(std::vector &pixels) RenderLayer *layer = (RenderLayer *)result->layers.first; RenderPass *pass = (RenderPass *)layer->passes.first; - memcpy(pass->buffer.data, pixels.data(), sizeof(float) * pass->rectx * pass->recty * pass->channels); + memcpy(pass->buffer.data, + pixels.data(), + sizeof(float) * pass->rectx * pass->recty * pass->channels); RE_engine_end_result(bl_engine_, result, false, false, false); } diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index b533b5730c0e..01201e153972 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -15,8 +15,8 @@ #include "DNA_node_types.h" #include "BKE_node.h" -#include "BKE_studiolight.h" #include "BKE_node_runtime.hh" +#include "BKE_studiolight.h" #include "BLI_math_rotation.h" #include "BLI_path_util.h" #include "NOD_shader.h" -- 2.30.2 From 037bc85feba6993d1c6a86ef2a3c004fea6183cf Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 15 Jun 2023 18:52:26 +0300 Subject: [PATCH 08/20] fix add/remove instanced lights --- source/blender/render/hydra/scene_delegate/instancer.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 3db5626e89e5..cb566feb6fe9 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -272,6 +272,11 @@ void InstancerData::check_remove(Set &available_objects) light_instances_.remove_if([&](auto item) { bool res = !available_objects.contains(item.key.GetName()); + if (!V3D_USES_SCENE_LIGHTS(scene_delegate_->view3d) && + ((Object *)item.value.data->id)->type == OB_LAMP) + { + res = true; + } if (res) { item.value.transforms.clear(); update_light_instance(item.value); @@ -353,6 +358,9 @@ void InstancerData::write_instances() scene_delegate_->depsgraph, scene_delegate_->scene, (Object *)id); LISTBASE_FOREACH (DupliObject *, dupli, lb) { Object *ob = dupli->ob; + if (!V3D_USES_SCENE_LIGHTS(scene_delegate_->view3d) && ob->type == OB_LAMP) { + return; + } if (!is_supported(ob) || !is_instance_visible(ob)) { continue; } -- 2.30.2 From 77b831d247da8488f063c95a90e79ae9f7617029 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 15 Jun 2023 19:21:38 +0300 Subject: [PATCH 09/20] move include --- .../render/hydra/scene_delegate/blender_scene_delegate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index 140a6330374e..4e392f973137 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -7,11 +7,11 @@ #include #include "BKE_context.h" +#include "BLI_map.hh" #include "DEG_depsgraph.h" #include "CLG_log.h" -#include "BLI_map.hh" #include "curves.h" #include "instancer.h" #include "light.h" -- 2.30.2 From 8e875becace075da5e2e4fc5e5059141c209085b Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Mon, 19 Jun 2023 14:29:34 +0300 Subject: [PATCH 10/20] added checks for view3d --- .../hydra/scene_delegate/blender_scene_delegate.cc | 12 +++++++----- .../blender/render/hydra/scene_delegate/instancer.cc | 3 ++- source/blender/render/hydra/scene_delegate/world.cc | 12 ++++++++---- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 6d738ec8ed96..8449b9c69b30 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -205,9 +205,11 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) check_updates(); } else { - use_scene_lights_ = V3D_USES_SCENE_LIGHTS(view3d); - shading_flag_ = view3d->shading.flag; - lookdev_light_ = view3d->shading.lookdev_light; + if (view3d) { + use_scene_lights_ = V3D_USES_SCENE_LIGHTS(view3d); + shading_flag_ = view3d->shading.flag; + lookdev_light_ = view3d->shading.lookdev_light; + } add_new_objects(); update_world(); } @@ -341,7 +343,7 @@ void BlenderSceneDelegate::update_objects(Object *object) if (!ObjectData::is_supported(object)) { return; } - if (!V3D_USES_SCENE_LIGHTS(view3d) && object->type == OB_LAMP) { + if (view3d && !V3D_USES_SCENE_LIGHTS(view3d) && object->type == OB_LAMP) { return; } pxr::SdfPath id = object_prim_id(object); @@ -444,7 +446,7 @@ void BlenderSceneDelegate::check_updates() add_new_objects(true); } else { - remove_unused_objects(); + do_update_collection = true; } } if (LOOK_DEV_STUDIO_LIGHT_ENABLED(view3d) && diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index cb566feb6fe9..0cbb91b2d031 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -358,7 +358,8 @@ void InstancerData::write_instances() scene_delegate_->depsgraph, scene_delegate_->scene, (Object *)id); LISTBASE_FOREACH (DupliObject *, dupli, lb) { Object *ob = dupli->ob; - if (!V3D_USES_SCENE_LIGHTS(scene_delegate_->view3d) && ob->type == OB_LAMP) { + if (scene_delegate_->view3d && !V3D_USES_SCENE_LIGHTS(scene_delegate_->view3d) && + ob->type == OB_LAMP) { return; } if (!is_supported(ob) || !is_instance_visible(ob)) { diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index 01201e153972..635e50937af4 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -13,6 +13,7 @@ #include "BKE_context.h" #include "DNA_node_types.h" +#include "DEG_depsgraph_query.h" #include "BKE_node.h" #include "BKE_node_runtime.hh" @@ -43,16 +44,19 @@ void WorldData::init() { ID_LOG(1, ""); - rotation = scene_delegate_->view3d->shading.studiolight_rot_z; - intensity = scene_delegate_->view3d->shading.studiolight_intensity; + if (scene_delegate_->view3d) { + rotation = scene_delegate_->view3d->shading.studiolight_rot_z; + intensity = scene_delegate_->view3d->shading.studiolight_intensity; + } write_transform(); World *world = (World *)id; data_.clear(); data_[pxr::UsdLuxTokens->orientToStageUpAxis] = true; - - if (world->use_nodes && V3D_USES_SCENE_WORLD(scene_delegate_->view3d)) { + eEvaluationMode deg_mode = DEG_get_mode(scene_delegate_->depsgraph); + if (world->use_nodes && ((deg_mode == DAG_EVAL_VIEWPORT && scene_delegate_->view3d && V3D_USES_SCENE_WORLD(scene_delegate_->view3d)) || deg_mode == DAG_EVAL_RENDER)) + { /* TODO: Create nodes parsing system */ bNode *output_node = ntreeShaderOutputNode(world->nodetree, SHD_OUTPUT_ALL); -- 2.30.2 From 03af6f785da2daa3488a18c89fa63d5530e34992 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Mon, 19 Jun 2023 14:31:46 +0300 Subject: [PATCH 11/20] make format --- source/blender/render/hydra/scene_delegate/instancer.cc | 3 ++- source/blender/render/hydra/scene_delegate/world.cc | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 0cbb91b2d031..cb911fca0813 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -359,7 +359,8 @@ void InstancerData::write_instances() LISTBASE_FOREACH (DupliObject *, dupli, lb) { Object *ob = dupli->ob; if (scene_delegate_->view3d && !V3D_USES_SCENE_LIGHTS(scene_delegate_->view3d) && - ob->type == OB_LAMP) { + ob->type == OB_LAMP) + { return; } if (!is_supported(ob) || !is_instance_visible(ob)) { diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index 635e50937af4..cc2a81b212d3 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -12,8 +12,8 @@ #include #include "BKE_context.h" -#include "DNA_node_types.h" #include "DEG_depsgraph_query.h" +#include "DNA_node_types.h" #include "BKE_node.h" #include "BKE_node_runtime.hh" @@ -55,7 +55,9 @@ void WorldData::init() data_[pxr::UsdLuxTokens->orientToStageUpAxis] = true; eEvaluationMode deg_mode = DEG_get_mode(scene_delegate_->depsgraph); - if (world->use_nodes && ((deg_mode == DAG_EVAL_VIEWPORT && scene_delegate_->view3d && V3D_USES_SCENE_WORLD(scene_delegate_->view3d)) || deg_mode == DAG_EVAL_RENDER)) + if (world->use_nodes && ((deg_mode == DAG_EVAL_VIEWPORT && scene_delegate_->view3d && + V3D_USES_SCENE_WORLD(scene_delegate_->view3d)) || + deg_mode == DAG_EVAL_RENDER)) { /* TODO: Create nodes parsing system */ -- 2.30.2 From 4362efe5bc0218cda4f2da27efc333ac9058fd1a Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 20 Jun 2023 12:59:34 +0300 Subject: [PATCH 12/20] fix review comments --- .../scene_delegate/blender_scene_delegate.cc | 62 ++++++++++++------- .../scene_delegate/blender_scene_delegate.h | 15 +++-- .../render/hydra/scene_delegate/world.cc | 4 -- .../render/hydra/scene_delegate/world.h | 2 - 4 files changed, 51 insertions(+), 32 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 8449b9c69b30..9ad8eb085a28 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -205,11 +205,8 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) check_updates(); } else { - if (view3d) { - use_scene_lights_ = V3D_USES_SCENE_LIGHTS(view3d); - shading_flag_ = view3d->shading.flag; - lookdev_light_ = view3d->shading.lookdev_light; - } + set_light_shading_settings(view3d); + set_world_shading_settings(view3d); add_new_objects(); update_world(); } @@ -429,32 +426,19 @@ void BlenderSceneDelegate::check_updates() bool do_update_visibility = false; bool do_update_world = false; - if (shading_flag_ != view3d->shading.flag || lookdev_light_ != view3d->shading.lookdev_light) { - shading_flag_ = view3d->shading.flag; - lookdev_light_ = view3d->shading.lookdev_light; + if (set_world_shading_settings(view3d)) + { do_update_world = true; } - bool use_scene_lights_changed = false; - - if (use_scene_lights_ != V3D_USES_SCENE_LIGHTS(view3d)) { - use_scene_lights_ = V3D_USES_SCENE_LIGHTS(view3d); - use_scene_lights_changed = true; - } - if (use_scene_lights_changed) { - if (use_scene_lights_) { + if (set_light_shading_settings(view3d)) { + if (shading_settings.use_scene_lights) { add_new_objects(true); } else { do_update_collection = true; } } - if (LOOK_DEV_STUDIO_LIGHT_ENABLED(view3d) && - (world_data_->rotation != view3d->shading.studiolight_rot_z || - world_data_->intensity != view3d->shading.studiolight_intensity)) - { - do_update_world = true; - } DEGIDIterData data = {0}; data.graph = depsgraph; @@ -684,4 +668,38 @@ void BlenderSceneDelegate::update_visibility() ITER_END; } +bool BlenderSceneDelegate::set_light_shading_settings(View3D const *view3d) +{ + bool ret = false; + if (view3d) { + if (shading_settings.use_scene_lights != V3D_USES_SCENE_LIGHTS(view3d)) + { + shading_settings.use_scene_lights = V3D_USES_SCENE_LIGHTS(view3d); + ret = true; + } + } + return ret; +} + +bool BlenderSceneDelegate::set_world_shading_settings(View3D const *view3d) +{ + bool ret = false; + if (view3d) { + if (shading_settings.shading_flag != view3d->shading.flag || + shading_settings.lookdev_light != view3d->shading.lookdev_light || + shading_settings.rotation != view3d->shading.studiolight_rot_z || + shading_settings.intensity != view3d->shading.studiolight_intensity + ) + { + shading_settings.shading_flag = view3d->shading.flag; + shading_settings.lookdev_light = view3d->shading.lookdev_light; + shading_settings.rotation = view3d->shading.studiolight_rot_z; + shading_settings.intensity = view3d->shading.studiolight_intensity; + + ret = true; + } + } + return ret; +} + } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index 4e392f973137..0e1f9d60e104 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -37,6 +37,14 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { Map render_tokens; }; + struct ShadingSettings { + bool use_scene_lights = false; + short shading_flag; + std::string lookdev_light; + float rotation; + float intensity; + }; + BlenderSceneDelegate(pxr::HdRenderIndex *parent_index, pxr::SdfPath const &delegate_id, Engine *engine); @@ -71,6 +79,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { Scene *scene = nullptr; Engine *engine; Settings settings; + ShadingSettings shading_settings; private: pxr::SdfPath prim_id(ID *id, const char *prefix) const; @@ -93,15 +102,13 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { void add_new_objects(bool only_lights = false); void remove_unused_objects(); void update_visibility(); + bool set_light_shading_settings(View3D const *view3d); + bool set_world_shading_settings(View3D const *view3d); ObjectDataMap objects_; MaterialDataMap materials_; InstancerDataMap instancers_; std::unique_ptr world_data_; - - short shading_flag_; - std::string lookdev_light_; - bool use_scene_lights_ = false; }; #define LOOK_DEV_STUDIO_LIGHT_ENABLED(v3d) \ diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index cc2a81b212d3..5f6fe414089b 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -44,10 +44,6 @@ void WorldData::init() { ID_LOG(1, ""); - if (scene_delegate_->view3d) { - rotation = scene_delegate_->view3d->shading.studiolight_rot_z; - intensity = scene_delegate_->view3d->shading.studiolight_intensity; - } write_transform(); World *world = (World *)id; diff --git a/source/blender/render/hydra/scene_delegate/world.h b/source/blender/render/hydra/scene_delegate/world.h index 902e635bcb8e..2eb62555c555 100644 --- a/source/blender/render/hydra/scene_delegate/world.h +++ b/source/blender/render/hydra/scene_delegate/world.h @@ -31,8 +31,6 @@ class WorldData : public IdData { pxr::VtValue get_data(pxr::TfToken const &key) const override; pxr::GfMatrix4d transform; - float rotation; - float intensity; private: void write_transform(); -- 2.30.2 From 9d471339d275b96a7775269819ae4f84e8152be2 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 20 Jun 2023 13:00:17 +0300 Subject: [PATCH 13/20] make format --- .../hydra/scene_delegate/blender_scene_delegate.cc | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 9ad8eb085a28..480e204a4272 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -426,8 +426,7 @@ void BlenderSceneDelegate::check_updates() bool do_update_visibility = false; bool do_update_world = false; - if (set_world_shading_settings(view3d)) - { + if (set_world_shading_settings(view3d)) { do_update_world = true; } @@ -672,8 +671,7 @@ bool BlenderSceneDelegate::set_light_shading_settings(View3D const *view3d) { bool ret = false; if (view3d) { - if (shading_settings.use_scene_lights != V3D_USES_SCENE_LIGHTS(view3d)) - { + if (shading_settings.use_scene_lights != V3D_USES_SCENE_LIGHTS(view3d)) { shading_settings.use_scene_lights = V3D_USES_SCENE_LIGHTS(view3d); ret = true; } @@ -688,14 +686,12 @@ bool BlenderSceneDelegate::set_world_shading_settings(View3D const *view3d) if (shading_settings.shading_flag != view3d->shading.flag || shading_settings.lookdev_light != view3d->shading.lookdev_light || shading_settings.rotation != view3d->shading.studiolight_rot_z || - shading_settings.intensity != view3d->shading.studiolight_intensity - ) + shading_settings.intensity != view3d->shading.studiolight_intensity) { shading_settings.shading_flag = view3d->shading.flag; shading_settings.lookdev_light = view3d->shading.lookdev_light; shading_settings.rotation = view3d->shading.studiolight_rot_z; shading_settings.intensity = view3d->shading.studiolight_intensity; - ret = true; } } -- 2.30.2 From ffb3b4a4f63325e72318f769059186d1286910c4 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 20 Jun 2023 15:58:27 +0300 Subject: [PATCH 14/20] fix review comments --- .../scene_delegate/blender_scene_delegate.cc | 37 +++--- .../scene_delegate/blender_scene_delegate.h | 36 ++++-- .../render/hydra/scene_delegate/instancer.cc | 6 +- .../render/hydra/scene_delegate/world.cc | 116 +++++++++--------- 4 files changed, 104 insertions(+), 91 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 480e204a4272..e42b097e7d0a 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -205,8 +205,8 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) check_updates(); } else { - set_light_shading_settings(view3d); - set_world_shading_settings(view3d); + set_light_shading_settings(); + set_world_shading_settings(); add_new_objects(); update_world(); } @@ -340,7 +340,7 @@ void BlenderSceneDelegate::update_objects(Object *object) if (!ObjectData::is_supported(object)) { return; } - if (view3d && !V3D_USES_SCENE_LIGHTS(view3d) && object->type == OB_LAMP) { + if (!shading_settings.use_scene_lights && object->type == OB_LAMP) { return; } pxr::SdfPath id = object_prim_id(object); @@ -426,11 +426,11 @@ void BlenderSceneDelegate::check_updates() bool do_update_visibility = false; bool do_update_world = false; - if (set_world_shading_settings(view3d)) { + if (set_world_shading_settings()) { do_update_world = true; } - if (set_light_shading_settings(view3d)) { + if (set_light_shading_settings()) { if (shading_settings.use_scene_lights) { add_new_objects(true); } @@ -472,7 +472,7 @@ void BlenderSceneDelegate::check_updates() } break; case ID_WO: { - if (id->recalc & ID_RECALC_SHADING) { + if (shading_settings.use_scene_world && id->recalc & ID_RECALC_SHADING) { do_update_world = true; } } break; @@ -591,7 +591,9 @@ void BlenderSceneDelegate::remove_unused_objects() /* Remove unused objects */ objects_.remove_if([&](auto item) { bool ret = !available_objects.contains(item.key.GetName()); - if (!V3D_USES_SCENE_LIGHTS(view3d) && ((Object *)item.value->id)->type == OB_LAMP) { + if (!shading_settings.use_scene_lights && + ((Object *)item.value->id)->type == OB_LAMP) + { ret = true; } if (ret) { @@ -667,7 +669,7 @@ void BlenderSceneDelegate::update_visibility() ITER_END; } -bool BlenderSceneDelegate::set_light_shading_settings(View3D const *view3d) +bool BlenderSceneDelegate::set_light_shading_settings() { bool ret = false; if (view3d) { @@ -679,21 +681,16 @@ bool BlenderSceneDelegate::set_light_shading_settings(View3D const *view3d) return ret; } -bool BlenderSceneDelegate::set_world_shading_settings(View3D const *view3d) +bool BlenderSceneDelegate::set_world_shading_settings() { bool ret = false; if (view3d) { - if (shading_settings.shading_flag != view3d->shading.flag || - shading_settings.lookdev_light != view3d->shading.lookdev_light || - shading_settings.rotation != view3d->shading.studiolight_rot_z || - shading_settings.intensity != view3d->shading.studiolight_intensity) - { - shading_settings.shading_flag = view3d->shading.flag; - shading_settings.lookdev_light = view3d->shading.lookdev_light; - shading_settings.rotation = view3d->shading.studiolight_rot_z; - shading_settings.intensity = view3d->shading.studiolight_intensity; - ret = true; - } + ShadingSettings prev_settings(shading_settings); + shading_settings.use_scene_world = V3D_USES_SCENE_WORLD(view3d); + shading_settings.studiolight_name = view3d->shading.lookdev_light; + shading_settings.studiolight_rotation = view3d->shading.studiolight_rot_z; + shading_settings.studiolight_intensity = view3d->shading.studiolight_intensity; + ret = shading_settings != prev_settings; } return ret; } diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index 0e1f9d60e104..410f66818af5 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -38,11 +38,27 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { }; struct ShadingSettings { - bool use_scene_lights = false; - short shading_flag; - std::string lookdev_light; - float rotation; - float intensity; + bool use_scene_lights = true; + bool use_scene_world = true; + std::string studiolight_name; + float studiolight_rotation; + float studiolight_intensity; + + bool operator==(const ShadingSettings& other) { + return use_scene_lights == other.use_scene_lights && + use_scene_world == other.use_scene_world && + studiolight_name == other.studiolight_name && + studiolight_rotation == other.studiolight_rotation && + studiolight_intensity == other.studiolight_intensity; + } + bool operator!=(const ShadingSettings &other) + { + return use_scene_lights != other.use_scene_lights || + use_scene_world != other.use_scene_world || + studiolight_name != other.studiolight_name || + studiolight_rotation != other.studiolight_rotation || + studiolight_intensity != other.studiolight_intensity; + } }; BlenderSceneDelegate(pxr::HdRenderIndex *parent_index, @@ -102,8 +118,8 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { void add_new_objects(bool only_lights = false); void remove_unused_objects(); void update_visibility(); - bool set_light_shading_settings(View3D const *view3d); - bool set_world_shading_settings(View3D const *view3d); + bool set_light_shading_settings(); + bool set_world_shading_settings(); ObjectDataMap objects_; MaterialDataMap materials_; @@ -111,10 +127,4 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { std::unique_ptr world_data_; }; -#define LOOK_DEV_STUDIO_LIGHT_ENABLED(v3d) \ - ((v3d) && (((v3d->shading.type == OB_MATERIAL) && \ - ((v3d->shading.flag & V3D_SHADING_SCENE_WORLD) == 0)) || \ - ((v3d->shading.type == OB_RENDER) && \ - ((v3d->shading.flag & V3D_SHADING_SCENE_WORLD_RENDER) == 0)))) - } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index cb911fca0813..418988946314 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -272,7 +272,7 @@ void InstancerData::check_remove(Set &available_objects) light_instances_.remove_if([&](auto item) { bool res = !available_objects.contains(item.key.GetName()); - if (!V3D_USES_SCENE_LIGHTS(scene_delegate_->view3d) && + if (!scene_delegate_->shading_settings.use_scene_lights && ((Object *)item.value.data->id)->type == OB_LAMP) { res = true; @@ -358,10 +358,10 @@ void InstancerData::write_instances() scene_delegate_->depsgraph, scene_delegate_->scene, (Object *)id); LISTBASE_FOREACH (DupliObject *, dupli, lb) { Object *ob = dupli->ob; - if (scene_delegate_->view3d && !V3D_USES_SCENE_LIGHTS(scene_delegate_->view3d) && + if (!scene_delegate_->shading_settings.use_scene_lights && ob->type == OB_LAMP) { - return; + continue; } if (!is_supported(ob) || !is_instance_visible(ob)) { continue; diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index 5f6fe414089b..3145577e8c0e 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -12,7 +12,6 @@ #include #include "BKE_context.h" -#include "DEG_depsgraph_query.h" #include "DNA_node_types.h" #include "BKE_node.h" @@ -50,67 +49,79 @@ void WorldData::init() data_.clear(); data_[pxr::UsdLuxTokens->orientToStageUpAxis] = true; - eEvaluationMode deg_mode = DEG_get_mode(scene_delegate_->depsgraph); - if (world->use_nodes && ((deg_mode == DAG_EVAL_VIEWPORT && scene_delegate_->view3d && - V3D_USES_SCENE_WORLD(scene_delegate_->view3d)) || - deg_mode == DAG_EVAL_RENDER)) - { - /* TODO: Create nodes parsing system */ - bNode *output_node = ntreeShaderOutputNode(world->nodetree, SHD_OUTPUT_ALL); - blender::Span input_sockets = output_node->input_sockets(); - bNodeSocket *input_socket = nullptr; + float intensity = 1.0f; + float exposure = world->exposure; + pxr::GfVec3f color(1.0f, 1.0f, 1.0f); + pxr::SdfAssetPath texture_file; - for (auto socket : input_sockets) { - if (STREQ(socket->name, "Surface")) { - input_socket = socket; - break; + if (scene_delegate_->shading_settings.use_scene_world) { + if (world->use_nodes) { + /* TODO: Create nodes parsing system */ + + bNode *output_node = ntreeShaderOutputNode(world->nodetree, SHD_OUTPUT_ALL); + blender::Span input_sockets = output_node->input_sockets(); + bNodeSocket *input_socket = nullptr; + + for (auto socket : input_sockets) { + if (STREQ(socket->name, "Surface")) { + input_socket = socket; + break; + } + } + if (!input_socket) { + return; + } + bNodeLink const *link = input_socket->directly_linked_links()[0]; + if (input_socket->directly_linked_links().is_empty()) { + return; } - } - if (!input_socket) { - return; - } - bNodeLink const *link = input_socket->directly_linked_links()[0]; - if (input_socket->directly_linked_links().is_empty()) { - return; - } - bNode *input_node = link->fromnode; - if (input_node->type != SH_NODE_BACKGROUND) { - return; - } + bNode *input_node = link->fromnode; + if (input_node->type != SH_NODE_BACKGROUND) { + return; + } - bNodeSocket color_input = input_node->input_by_identifier("Color"); - bNodeSocket strength_input = input_node->input_by_identifier("Strength"); + bNodeSocket color_input = input_node->input_by_identifier("Color"); + bNodeSocket strength_input = input_node->input_by_identifier("Strength"); - float const *strength = strength_input.default_value_typed(); - float const *color = color_input.default_value_typed(); - data_[pxr::HdLightTokens->intensity] = strength[1]; - data_[pxr::HdLightTokens->exposure] = 1.0f; - data_[pxr::HdLightTokens->color] = pxr::GfVec3f(color[0], color[1], color[2]); + float const *strength = strength_input.default_value_typed(); + float const *input_color = color_input.default_value_typed(); + intensity = strength[1]; + color = pxr::GfVec3f(input_color[0], input_color[1], input_color[2]); - if (!color_input.directly_linked_links().is_empty()) { - bNode *color_input_node = color_input.directly_linked_links()[0]->fromnode; - if (color_input_node->type == SH_NODE_TEX_IMAGE) { - NodeTexImage *tex = static_cast(color_input_node->storage); - Image *image = (Image *)color_input_node->id; - if (image) { - std::string image_path = cache_or_get_image_file( - image, scene_delegate_->context, &tex->iuser); - if (!image_path.empty()) { - data_[pxr::HdLightTokens->textureFile] = pxr::SdfAssetPath(image_path, image_path); + if (!color_input.directly_linked_links().is_empty()) { + bNode *color_input_node = color_input.directly_linked_links()[0]->fromnode; + if (color_input_node->type == SH_NODE_TEX_IMAGE) { + NodeTexImage *tex = static_cast(color_input_node->storage); + Image *image = (Image *)color_input_node->id; + if (image) { + std::string image_path = cache_or_get_image_file( + image, scene_delegate_->context, &tex->iuser); + if (!image_path.empty()) { + texture_file = pxr::SdfAssetPath(image_path, image_path); + } } } } } + else { + intensity = 1.0f; + color = pxr::GfVec3f(world->horr, world->horg, world->horb); + } + + 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); + texture_file = pxr::SdfAssetPath(image_path, image_path); + } } else { - float intensity = 1.0f; - if (LOOK_DEV_STUDIO_LIGHT_ENABLED(scene_delegate_->view3d)) { + if (scene_delegate_->view3d && !scene_delegate_->shading_settings.use_scene_world) { StudioLight *sl = BKE_studiolight_find(scene_delegate_->view3d->shading.lookdev_light, STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE); if (sl != NULL && sl->flag & STUDIOLIGHT_TYPE_WORLD) { - data_[pxr::HdLightTokens->textureFile] = pxr::SdfAssetPath(sl->filepath, sl->filepath); + texture_file = pxr::SdfAssetPath(sl->filepath, sl->filepath); transform *= pxr::GfMatrix4d( pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, -1.0), RAD2DEGF(scene_delegate_->view3d->shading.studiolight_rot_z)), @@ -119,17 +130,12 @@ void WorldData::init() intensity = scene_delegate_->view3d->shading.studiolight_intensity / 2; } } - data_[pxr::HdLightTokens->intensity] = intensity; - data_[pxr::HdLightTokens->exposure] = world->exposure; - data_[pxr::HdLightTokens->color] = pxr::GfVec3f(world->horr, world->horg, world->horb); } - if (data_.find(pxr::HdLightTokens->textureFile) == data_.end()) { - pxr::GfVec3f c = data_[pxr::HdLightTokens->color].Get(); - float color[4] = {c[0], c[1], c[2], 1.0f}; - std::string image_path = cache_image_color(color); - data_[pxr::HdLightTokens->textureFile] = pxr::SdfAssetPath(image_path, image_path); - } + data_[pxr::HdLightTokens->intensity] = intensity; + data_[pxr::HdLightTokens->exposure] = exposure; + data_[pxr::HdLightTokens->color] = color; + data_[pxr::HdLightTokens->textureFile] = texture_file; } void WorldData::insert() -- 2.30.2 From 296bfa55e3584d5e2a01e788f8c6bbdcc53a0179 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 20 Jun 2023 16:08:31 +0300 Subject: [PATCH 15/20] fix review comments --- source/blender/render/hydra/scene_delegate/image.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/image.cc b/source/blender/render/hydra/scene_delegate/image.cc index 1354e57ada99..3ad5925bcfc8 100644 --- a/source/blender/render/hydra/scene_delegate/image.cc +++ b/source/blender/render/hydra/scene_delegate/image.cc @@ -67,19 +67,21 @@ static std::string cache_image_file(Image *image, std::string cache_or_get_image_file(Image *image, bContext *context, ImageUser *iuser) { - char file_path[FILE_MAX]; + std::string file_path; if (image->source == IMA_SRC_GENERATED) { - strcpy(file_path, cache_image_file(image, context, iuser, false).c_str()); + file_path = cache_image_file(image, context, iuser, false); } else if (BKE_image_has_packedfile(image)) { - strcpy(file_path, cache_image_file(image, context, iuser, true).c_str()); + file_path = cache_image_file(image, context, iuser, true); } else { + char str[FILE_MAX]; Main *main = CTX_data_main(context); - BKE_image_user_file_path_ex(main, iuser, image, file_path, false, true); + BKE_image_user_file_path_ex(main, iuser, image, str, false, true); + file_path = str; if (!pxr::HioImageRegistry::GetInstance().IsSupportedImageFile(file_path)) { - strcpy(file_path, cache_image_file(image, context, iuser, true).c_str()); + file_path = cache_image_file(image, context, iuser, true); } } -- 2.30.2 From 8291f2acc14ff9faf8e51402862675862b7f56c8 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 20 Jun 2023 16:09:07 +0300 Subject: [PATCH 16/20] make format --- .../render/hydra/scene_delegate/blender_scene_delegate.cc | 4 +--- .../render/hydra/scene_delegate/blender_scene_delegate.h | 3 ++- source/blender/render/hydra/scene_delegate/instancer.cc | 4 +--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index e42b097e7d0a..8ccedb8865a8 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -591,9 +591,7 @@ void BlenderSceneDelegate::remove_unused_objects() /* Remove unused objects */ objects_.remove_if([&](auto item) { bool ret = !available_objects.contains(item.key.GetName()); - if (!shading_settings.use_scene_lights && - ((Object *)item.value->id)->type == OB_LAMP) - { + if (!shading_settings.use_scene_lights && ((Object *)item.value->id)->type == OB_LAMP) { ret = true; } if (ret) { diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index 410f66818af5..12fd7359b456 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -44,7 +44,8 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { float studiolight_rotation; float studiolight_intensity; - bool operator==(const ShadingSettings& other) { + bool operator==(const ShadingSettings &other) + { return use_scene_lights == other.use_scene_lights && use_scene_world == other.use_scene_world && studiolight_name == other.studiolight_name && diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 418988946314..3e4540380676 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -358,9 +358,7 @@ void InstancerData::write_instances() scene_delegate_->depsgraph, scene_delegate_->scene, (Object *)id); LISTBASE_FOREACH (DupliObject *, dupli, lb) { Object *ob = dupli->ob; - if (!scene_delegate_->shading_settings.use_scene_lights && - ob->type == OB_LAMP) - { + if (!scene_delegate_->shading_settings.use_scene_lights && ob->type == OB_LAMP) { continue; } if (!is_supported(ob) || !is_instance_visible(ob)) { -- 2.30.2 From 9e0347a577dbbcd4e9cb40fc759af23517d8b6c8 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 20 Jun 2023 16:15:47 +0300 Subject: [PATCH 17/20] fix review comments --- source/blender/render/hydra/scene_delegate/world.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index 3145577e8c0e..185468bf66a7 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -118,16 +118,17 @@ void WorldData::init() } else { if (scene_delegate_->view3d && !scene_delegate_->shading_settings.use_scene_world) { - StudioLight *sl = BKE_studiolight_find(scene_delegate_->view3d->shading.lookdev_light, - STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE); + StudioLight *sl = BKE_studiolight_find( + scene_delegate_->shading_settings.studiolight_name.c_str(), + STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE); if (sl != NULL && sl->flag & STUDIOLIGHT_TYPE_WORLD) { texture_file = pxr::SdfAssetPath(sl->filepath, sl->filepath); transform *= pxr::GfMatrix4d( pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, -1.0), - RAD2DEGF(scene_delegate_->view3d->shading.studiolight_rot_z)), + RAD2DEGF(scene_delegate_->shading_settings.studiolight_rotation)), pxr::GfVec3d()); /* coefficient to follow Cycles result */ - intensity = scene_delegate_->view3d->shading.studiolight_intensity / 2; + intensity = scene_delegate_->shading_settings.studiolight_intensity / 2; } } } -- 2.30.2 From 10bc06fd87d6d5cc0945e4ee5ce3bf0c2d57ed09 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 20 Jun 2023 18:42:23 +0300 Subject: [PATCH 18/20] fix review comments --- .../scene_delegate/blender_scene_delegate.cc | 50 ++++++++++--------- .../scene_delegate/blender_scene_delegate.h | 19 +------ .../render/hydra/scene_delegate/instancer.cc | 5 -- .../render/hydra/scene_delegate/world.cc | 24 ++++----- 4 files changed, 39 insertions(+), 59 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 8ccedb8865a8..76d7618dad38 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -14,6 +14,14 @@ namespace blender::render::hydra { CLG_LOGREF_DECLARE_GLOBAL(LOG_RENDER_HYDRA_SCENE, "render.hydra.scene"); +bool BlenderSceneDelegate::ShadingSettings::operator==(const ShadingSettings &other) +{ + return use_scene_lights == other.use_scene_lights && use_scene_world == other.use_scene_world && + studiolight_name == other.studiolight_name && + studiolight_rotation == other.studiolight_rotation && + studiolight_intensity == other.studiolight_intensity; +} + BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index, pxr::SdfPath const &delegate_id, Engine *engine) @@ -432,7 +440,7 @@ void BlenderSceneDelegate::check_updates() if (set_light_shading_settings()) { if (shading_settings.use_scene_lights) { - add_new_objects(true); + add_new_objects(); } else { do_update_collection = true; @@ -512,7 +520,7 @@ void BlenderSceneDelegate::check_updates() } } -void BlenderSceneDelegate::add_new_objects(bool only_lights) +void BlenderSceneDelegate::add_new_objects() { DEGObjectIterSettings settings = {0}; settings.depsgraph = depsgraph; @@ -535,16 +543,11 @@ void BlenderSceneDelegate::add_new_objects(bool only_lights) "Visibility: %s [%s]", object->id.name, std::bitset<3>(BKE_object_visibility(object, deg_mode)).to_string().c_str()); - if (only_lights) { - if (object->type == OB_LAMP) { - update_objects(object); - update_instancers(object); - } - } - else { - update_objects(object); - update_instancers(object); + if (object_data(object_prim_id(object))) { + continue; } + update_objects(object); + update_instancers(object); } ITER_END; } @@ -569,10 +572,13 @@ void BlenderSceneDelegate::remove_unused_objects() Object *, object) { + available_objects.add(instancer_prim_id(object).GetName()); if (ObjectData::is_supported(object)) { + if (!shading_settings.use_scene_lights && object->type == OB_LAMP) { + continue; + } available_objects.add(object_prim_id(object).GetName()); } - available_objects.add(instancer_prim_id(object).GetName()); } ITER_END; @@ -591,9 +597,6 @@ void BlenderSceneDelegate::remove_unused_objects() /* Remove unused objects */ objects_.remove_if([&](auto item) { bool ret = !available_objects.contains(item.key.GetName()); - if (!shading_settings.use_scene_lights && ((Object *)item.value->id)->type == OB_LAMP) { - ret = true; - } if (ret) { item.value->remove(); } @@ -681,16 +684,15 @@ bool BlenderSceneDelegate::set_light_shading_settings() bool BlenderSceneDelegate::set_world_shading_settings() { - bool ret = false; - if (view3d) { - ShadingSettings prev_settings(shading_settings); - shading_settings.use_scene_world = V3D_USES_SCENE_WORLD(view3d); - shading_settings.studiolight_name = view3d->shading.lookdev_light; - shading_settings.studiolight_rotation = view3d->shading.studiolight_rot_z; - shading_settings.studiolight_intensity = view3d->shading.studiolight_intensity; - ret = shading_settings != prev_settings; + if (!view3d) { + return false; } - return ret; + ShadingSettings prev_settings(shading_settings); + shading_settings.use_scene_world = V3D_USES_SCENE_WORLD(view3d); + shading_settings.studiolight_name = view3d->shading.lookdev_light; + shading_settings.studiolight_rotation = view3d->shading.studiolight_rot_z; + shading_settings.studiolight_intensity = view3d->shading.studiolight_intensity; + return !(shading_settings == prev_settings); } } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index 12fd7359b456..93119206e783 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -44,22 +44,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { float studiolight_rotation; float studiolight_intensity; - bool operator==(const ShadingSettings &other) - { - return use_scene_lights == other.use_scene_lights && - use_scene_world == other.use_scene_world && - studiolight_name == other.studiolight_name && - studiolight_rotation == other.studiolight_rotation && - studiolight_intensity == other.studiolight_intensity; - } - bool operator!=(const ShadingSettings &other) - { - return use_scene_lights != other.use_scene_lights || - use_scene_world != other.use_scene_world || - studiolight_name != other.studiolight_name || - studiolight_rotation != other.studiolight_rotation || - studiolight_intensity != other.studiolight_intensity; - } + bool operator==(const ShadingSettings &other); }; BlenderSceneDelegate(pxr::HdRenderIndex *parent_index, @@ -116,7 +101,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { void update_instancers(Object *object); void update_world(); void check_updates(); - void add_new_objects(bool only_lights = false); + void add_new_objects(); void remove_unused_objects(); void update_visibility(); bool set_light_shading_settings(); diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 3e4540380676..ffbc87004dba 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -272,11 +272,6 @@ void InstancerData::check_remove(Set &available_objects) light_instances_.remove_if([&](auto item) { bool res = !available_objects.contains(item.key.GetName()); - if (!scene_delegate_->shading_settings.use_scene_lights && - ((Object *)item.value.data->id)->type == OB_LAMP) - { - res = true; - } if (res) { item.value.transforms.clear(); update_light_instance(item.value); diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index 185468bf66a7..3991e8ec3509 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -117,19 +117,17 @@ void WorldData::init() } } else { - if (scene_delegate_->view3d && !scene_delegate_->shading_settings.use_scene_world) { - StudioLight *sl = BKE_studiolight_find( - scene_delegate_->shading_settings.studiolight_name.c_str(), - STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE); - if (sl != NULL && sl->flag & STUDIOLIGHT_TYPE_WORLD) { - texture_file = pxr::SdfAssetPath(sl->filepath, sl->filepath); - transform *= pxr::GfMatrix4d( - pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, -1.0), - RAD2DEGF(scene_delegate_->shading_settings.studiolight_rotation)), - pxr::GfVec3d()); - /* coefficient to follow Cycles result */ - intensity = scene_delegate_->shading_settings.studiolight_intensity / 2; - } + StudioLight *sl = BKE_studiolight_find( + scene_delegate_->shading_settings.studiolight_name.c_str(), + STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE); + if (sl != NULL && sl->flag & STUDIOLIGHT_TYPE_WORLD) { + texture_file = pxr::SdfAssetPath(sl->filepath, sl->filepath); + transform *= pxr::GfMatrix4d( + pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, -1.0), + RAD2DEGF(scene_delegate_->shading_settings.studiolight_rotation)), + pxr::GfVec3d()); + /* coefficient to follow Cycles result */ + intensity = scene_delegate_->shading_settings.studiolight_intensity / 2; } } -- 2.30.2 From 17cad0766cacef646a70fa32d37d196f617fc537 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Wed, 21 Jun 2023 14:20:45 +0300 Subject: [PATCH 19/20] Fixed shading light usage when scene->world is null. Improved WorldData to work with studiolight and scene->world. --- .../scene_delegate/blender_scene_delegate.cc | 34 ++++++++++--------- .../render/hydra/scene_delegate/world.cc | 34 +++++++++---------- .../render/hydra/scene_delegate/world.h | 2 +- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 76d7618dad38..01754c4814a1 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -16,10 +16,15 @@ CLG_LOGREF_DECLARE_GLOBAL(LOG_RENDER_HYDRA_SCENE, "render.hydra.scene"); bool BlenderSceneDelegate::ShadingSettings::operator==(const ShadingSettings &other) { - return use_scene_lights == other.use_scene_lights && use_scene_world == other.use_scene_world && - studiolight_name == other.studiolight_name && - studiolight_rotation == other.studiolight_rotation && - studiolight_intensity == other.studiolight_intensity; + bool ret = use_scene_lights == other.use_scene_lights && + use_scene_world == other.use_scene_world; + if (ret && !use_scene_world) { + /* compare studiolight settings when studiolight is using */ + ret = studiolight_name == other.studiolight_name && + studiolight_rotation == other.studiolight_rotation && + studiolight_intensity == other.studiolight_intensity; + } + return ret; } BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index, @@ -409,17 +414,16 @@ void BlenderSceneDelegate::update_instancers(Object *object) void BlenderSceneDelegate::update_world() { - World *world = scene->world; if (!world_data_) { - if (world) { - world_data_ = std::make_unique(this, world, world_prim_id()); + if (!shading_settings.use_scene_world || (shading_settings.use_scene_world && scene->world)) { + world_data_ = std::make_unique(this, world_prim_id()); world_data_->init(); world_data_->insert(); } } else { - if (world) { - world_data_->update(world); + if (!shading_settings.use_scene_world || (shading_settings.use_scene_world && scene->world)) { + world_data_->update(); } else { world_data_->remove(); @@ -672,14 +676,12 @@ void BlenderSceneDelegate::update_visibility() bool BlenderSceneDelegate::set_light_shading_settings() { - bool ret = false; - if (view3d) { - if (shading_settings.use_scene_lights != V3D_USES_SCENE_LIGHTS(view3d)) { - shading_settings.use_scene_lights = V3D_USES_SCENE_LIGHTS(view3d); - ret = true; - } + if (!view3d) { + return false; } - return ret; + ShadingSettings prev_settings(shading_settings); + shading_settings.use_scene_lights = V3D_USES_SCENE_LIGHTS(view3d); + return !(shading_settings == prev_settings); } bool BlenderSceneDelegate::set_world_shading_settings() diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index 3991e8ec3509..d105c3da75a6 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -32,30 +32,28 @@ namespace blender::render::hydra { -WorldData::WorldData(BlenderSceneDelegate *scene_delegate, - World *world, - pxr::SdfPath const &prim_id) - : IdData(scene_delegate, (ID *)world, prim_id) +WorldData::WorldData(BlenderSceneDelegate *scene_delegate, pxr::SdfPath const &prim_id) + : IdData(scene_delegate, nullptr, prim_id) { } void WorldData::init() { - ID_LOG(1, ""); - write_transform(); - World *world = (World *)id; data_.clear(); - data_[pxr::UsdLuxTokens->orientToStageUpAxis] = true; float intensity = 1.0f; - float exposure = world->exposure; + float exposure = 0.0f; pxr::GfVec3f color(1.0f, 1.0f, 1.0f); pxr::SdfAssetPath texture_file; if (scene_delegate_->shading_settings.use_scene_world) { + World *world = scene_delegate_->scene->world; + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s: %s", prim_id.GetText(), world->id.name); + + exposure = world->exposure; if (world->use_nodes) { /* TODO: Create nodes parsing system */ @@ -117,6 +115,12 @@ void WorldData::init() } } else { + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, + 1, + "%s: studiolight: %s", + prim_id.GetText(), + scene_delegate_->shading_settings.studiolight_name.c_str()); + StudioLight *sl = BKE_studiolight_find( scene_delegate_->shading_settings.studiolight_name.c_str(), STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE); @@ -139,7 +143,7 @@ void WorldData::init() void WorldData::insert() { - ID_LOG(1, ""); + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s", prim_id.GetText()); scene_delegate_->GetRenderIndex().InsertSprim( pxr::HdPrimTypeTokens->domeLight, scene_delegate_, prim_id); } @@ -152,23 +156,17 @@ void WorldData::remove() void WorldData::update() { - ID_LOG(1, ""); + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s", prim_id.GetText()); init(); scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, pxr::HdLight::AllDirty); } -void WorldData::update(World *world) -{ - id = (ID *)world; - update(); -} - pxr::VtValue WorldData::get_data(pxr::TfToken const &key) const { auto it = data_.find(key); if (it != data_.end()) { - ID_LOG(3, "%s", key.GetText()); + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s: %s", prim_id.GetText(), key.GetText()); return pxr::VtValue(it->second); } return pxr::VtValue(); diff --git a/source/blender/render/hydra/scene_delegate/world.h b/source/blender/render/hydra/scene_delegate/world.h index 2eb62555c555..c6183ab0c1c7 100644 --- a/source/blender/render/hydra/scene_delegate/world.h +++ b/source/blender/render/hydra/scene_delegate/world.h @@ -20,7 +20,7 @@ namespace blender::render::hydra { class WorldData : public IdData { public: - WorldData(BlenderSceneDelegate *scene_delegate, World *world, pxr::SdfPath const &prim_id); + WorldData(BlenderSceneDelegate *scene_delegate, pxr::SdfPath const &prim_id); void init() override; void insert() override; -- 2.30.2 From f94cdd9e0b9bcedd876833ef8b59444cda48f831 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Wed, 21 Jun 2023 17:53:39 +0300 Subject: [PATCH 20/20] Get back exposure=1.0 by default. Fixed logging in image.cc --- source/blender/render/hydra/scene_delegate/image.cc | 4 ++-- source/blender/render/hydra/scene_delegate/world.cc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/image.cc b/source/blender/render/hydra/scene_delegate/image.cc index 3ad5925bcfc8..340fb34cf424 100644 --- a/source/blender/render/hydra/scene_delegate/image.cc +++ b/source/blender/render/hydra/scene_delegate/image.cc @@ -75,8 +75,8 @@ std::string cache_or_get_image_file(Image *image, bContext *context, ImageUser * file_path = cache_image_file(image, context, iuser, true); } else { - char str[FILE_MAX]; Main *main = CTX_data_main(context); + char str[FILE_MAX]; BKE_image_user_file_path_ex(main, iuser, image, str, false, true); file_path = str; @@ -85,7 +85,7 @@ std::string cache_or_get_image_file(Image *image, bContext *context, ImageUser * } } - CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s -> %s", image->id.name, file_path); + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s -> %s", image->id.name, file_path.c_str()); return file_path; } diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index d105c3da75a6..d9d6f0460545 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -45,7 +45,7 @@ void WorldData::init() data_[pxr::UsdLuxTokens->orientToStageUpAxis] = true; float intensity = 1.0f; - float exposure = 0.0f; + float exposure = 1.0f; pxr::GfVec3f color(1.0f, 1.0f, 1.0f); pxr::SdfAssetPath texture_file; -- 2.30.2