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 39 additions and 59 deletions
Showing only changes of commit 10bc06fd87 - Show all commits

View File

@ -14,6 +14,14 @@ namespace blender::render::hydra {
CLG_LOGREF_DECLARE_GLOBAL(LOG_RENDER_HYDRA_SCENE, "render.hydra.scene"); 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, BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
pxr::SdfPath const &delegate_id, pxr::SdfPath const &delegate_id,
Engine *engine) Engine *engine)
@ -432,7 +440,7 @@ void BlenderSceneDelegate::check_updates()
if (set_light_shading_settings()) { if (set_light_shading_settings()) {
if (shading_settings.use_scene_lights) { if (shading_settings.use_scene_lights) {
add_new_objects(true); add_new_objects();
} }
else { else {
do_update_collection = true; 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}; DEGObjectIterSettings settings = {0};
settings.depsgraph = depsgraph; settings.depsgraph = depsgraph;
@ -535,16 +543,11 @@ void BlenderSceneDelegate::add_new_objects(bool only_lights)
"Visibility: %s [%s]", "Visibility: %s [%s]",
object->id.name, object->id.name,
std::bitset<3>(BKE_object_visibility(object, deg_mode)).to_string().c_str()); std::bitset<3>(BKE_object_visibility(object, deg_mode)).to_string().c_str());
if (only_lights) { if (object_data(object_prim_id(object))) {
if (object->type == OB_LAMP) { continue;
update_objects(object);
update_instancers(object);
}
}
else {
update_objects(object);
update_instancers(object);
} }
update_objects(object);
update_instancers(object);
} }
ITER_END; ITER_END;
} }
@ -569,10 +572,13 @@ void BlenderSceneDelegate::remove_unused_objects()
Object *, Object *,
object) object)
{ {
available_objects.add(instancer_prim_id(object).GetName());
if (ObjectData::is_supported(object)) { 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(object_prim_id(object).GetName());
} }
available_objects.add(instancer_prim_id(object).GetName());
} }
ITER_END; ITER_END;
@ -591,9 +597,6 @@ void BlenderSceneDelegate::remove_unused_objects()
/* Remove unused objects */ /* Remove unused objects */
objects_.remove_if([&](auto item) { objects_.remove_if([&](auto item) {
bool ret = !available_objects.contains(item.key.GetName()); 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) { if (ret) {
item.value->remove(); item.value->remove();
} }
@ -681,16 +684,15 @@ bool BlenderSceneDelegate::set_light_shading_settings()
bool BlenderSceneDelegate::set_world_shading_settings() bool BlenderSceneDelegate::set_world_shading_settings()
{ {
bool ret = false; if (!view3d) {
if (view3d) { return false;
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; 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 } // namespace blender::render::hydra

View File

@ -44,22 +44,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
float studiolight_rotation; float studiolight_rotation;
float studiolight_intensity; 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 &&
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, BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
@ -116,7 +101,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
void update_instancers(Object *object); void update_instancers(Object *object);
void update_world(); void update_world();
void check_updates(); void check_updates();
void add_new_objects(bool only_lights = false); void add_new_objects();
void remove_unused_objects(); void remove_unused_objects();
void update_visibility(); void update_visibility();
bool set_light_shading_settings(); bool set_light_shading_settings();

View File

@ -272,11 +272,6 @@ void InstancerData::check_remove(Set<std::string> &available_objects)
light_instances_.remove_if([&](auto item) { light_instances_.remove_if([&](auto item) {
bool res = !available_objects.contains(item.key.GetName()); 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) { if (res) {
item.value.transforms.clear(); item.value.transforms.clear();
update_light_instance(item.value); update_light_instance(item.value);

View File

@ -117,19 +117,17 @@ void WorldData::init()
} }
} }
else { else {
if (scene_delegate_->view3d && !scene_delegate_->shading_settings.use_scene_world) { StudioLight *sl = BKE_studiolight_find(
StudioLight *sl = BKE_studiolight_find( scene_delegate_->shading_settings.studiolight_name.c_str(),
scene_delegate_->shading_settings.studiolight_name.c_str(), STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE);
STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE); if (sl != NULL && sl->flag & STUDIOLIGHT_TYPE_WORLD) {
if (sl != NULL && sl->flag & STUDIOLIGHT_TYPE_WORLD) { texture_file = pxr::SdfAssetPath(sl->filepath, sl->filepath);
texture_file = pxr::SdfAssetPath(sl->filepath, sl->filepath); transform *= pxr::GfMatrix4d(
transform *= pxr::GfMatrix4d( pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, -1.0),
pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, -1.0), RAD2DEGF(scene_delegate_->shading_settings.studiolight_rotation)),
RAD2DEGF(scene_delegate_->shading_settings.studiolight_rotation)), pxr::GfVec3d());
pxr::GfVec3d()); /* coefficient to follow Cycles result */
/* coefficient to follow Cycles result */ intensity = scene_delegate_->shading_settings.studiolight_intensity / 2;
intensity = scene_delegate_->shading_settings.studiolight_intensity / 2;
}
} }
} }