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();
}
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

View File

@ -37,6 +37,14 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
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,
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<WorldData> world_data_;
short shading_flag_;
std::string lookdev_light_;
bool use_scene_lights_ = false;
};
#define LOOK_DEV_STUDIO_LIGHT_ENABLED(v3d) \

View File

@ -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;

View File

@ -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();