Implement Viewport render with material preview #56

Merged
Bogdan Nagirniak merged 22 commits from BLEN-421 into hydra-render 2023-06-30 09:03:28 +02:00
4 changed files with 51 additions and 32 deletions
Showing only changes of commit 4362efe5bc - Show all commits

View File

@ -205,11 +205,8 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
check_updates(); check_updates();
} }
else { else {
if (view3d) { set_light_shading_settings(view3d);
use_scene_lights_ = V3D_USES_SCENE_LIGHTS(view3d); set_world_shading_settings(view3d);
shading_flag_ = view3d->shading.flag;
lookdev_light_ = view3d->shading.lookdev_light;
}
add_new_objects(); add_new_objects();
update_world(); update_world();
} }
@ -429,32 +426,19 @@ void BlenderSceneDelegate::check_updates()
bool do_update_visibility = false; bool do_update_visibility = false;
bool do_update_world = false; bool do_update_world = false;
if (shading_flag_ != view3d->shading.flag || lookdev_light_ != view3d->shading.lookdev_light) { if (set_world_shading_settings(view3d))
shading_flag_ = view3d->shading.flag; {
lookdev_light_ = view3d->shading.lookdev_light;
do_update_world = true; do_update_world = true;
} }
bool use_scene_lights_changed = false; if (set_light_shading_settings(view3d)) {
if (shading_settings.use_scene_lights) {
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_) {
add_new_objects(true); add_new_objects(true);
} }
else { else {
do_update_collection = true; 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}; DEGIDIterData data = {0};
data.graph = depsgraph; data.graph = depsgraph;
@ -684,4 +668,38 @@ void BlenderSceneDelegate::update_visibility()
ITER_END; 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 } // namespace blender::render::hydra

View File

@ -37,6 +37,14 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
Map<pxr::TfToken, pxr::VtValue> render_tokens; Map<pxr::TfToken, pxr::VtValue> 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, BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
pxr::SdfPath const &delegate_id, pxr::SdfPath const &delegate_id,
Engine *engine); Engine *engine);
@ -71,6 +79,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
Scene *scene = nullptr; Scene *scene = nullptr;
Engine *engine; Engine *engine;
Settings settings; Settings settings;
ShadingSettings shading_settings;
private: private:
pxr::SdfPath prim_id(ID *id, const char *prefix) const; 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 add_new_objects(bool only_lights = false);
void remove_unused_objects(); void remove_unused_objects();
void update_visibility(); void update_visibility();
bool set_light_shading_settings(View3D const *view3d);
bool set_world_shading_settings(View3D const *view3d);
ObjectDataMap objects_; ObjectDataMap objects_;
MaterialDataMap materials_; MaterialDataMap materials_;
InstancerDataMap instancers_; InstancerDataMap instancers_;
std::unique_ptr<WorldData> world_data_; std::unique_ptr<WorldData> world_data_;
short shading_flag_;
std::string lookdev_light_;
bool use_scene_lights_ = false;
}; };
#define LOOK_DEV_STUDIO_LIGHT_ENABLED(v3d) \ #define LOOK_DEV_STUDIO_LIGHT_ENABLED(v3d) \

View File

@ -44,10 +44,6 @@ void WorldData::init()
{ {
ID_LOG(1, ""); ID_LOG(1, "");
if (scene_delegate_->view3d) {
rotation = scene_delegate_->view3d->shading.studiolight_rot_z;
intensity = scene_delegate_->view3d->shading.studiolight_intensity;
}
write_transform(); write_transform();
World *world = (World *)id; World *world = (World *)id;

View File

@ -31,8 +31,6 @@ class WorldData : public IdData {
pxr::VtValue get_data(pxr::TfToken const &key) const override; pxr::VtValue get_data(pxr::TfToken const &key) const override;
pxr::GfMatrix4d transform; pxr::GfMatrix4d transform;
float rotation;
float intensity;
private: private:
void write_transform(); void write_transform();