forked from blender/blender
Implement Viewport render with material preview #56
@ -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,17 +543,12 @@ 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_objects(object);
|
||||||
update_instancers(object);
|
update_instancers(object);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
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()
|
|||||||
|
|
||||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
Outdated
Review
```
if (!view3d) {
return false;
}
.....
return !(shading_settings == prev_settings);
```
|
|||||||
bool BlenderSceneDelegate::set_world_shading_settings()
|
bool BlenderSceneDelegate::set_world_shading_settings()
|
||||||
{
|
{
|
||||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
simplify by using add
simplify by using add `operator==()` and copy constructor to ShadingSettings
```
ShadingSettings prev_settings(shading_settings);
shading_settings. ....
return shading_settings != prev_settings;
```
|
|||||||
bool ret = false;
|
if (!view3d) {
|
||||||
if (view3d) {
|
return false;
|
||||||
|
}
|
||||||
ShadingSettings prev_settings(shading_settings);
|
ShadingSettings prev_settings(shading_settings);
|
||||||
shading_settings.use_scene_world = V3D_USES_SCENE_WORLD(view3d);
|
shading_settings.use_scene_world = V3D_USES_SCENE_WORLD(view3d);
|
||||||
shading_settings.studiolight_name = view3d->shading.lookdev_light;
|
shading_settings.studiolight_name = view3d->shading.lookdev_light;
|
||||||
shading_settings.studiolight_rotation = view3d->shading.studiolight_rot_z;
|
shading_settings.studiolight_rotation = view3d->shading.studiolight_rot_z;
|
||||||
shading_settings.studiolight_intensity = view3d->shading.studiolight_intensity;
|
shading_settings.studiolight_intensity = view3d->shading.studiolight_intensity;
|
||||||
ret = shading_settings != prev_settings;
|
return !(shading_settings == prev_settings);
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -44,22 +44,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
|||||||
float studiolight_rotation;
|
float studiolight_rotation;
|
||||||
float studiolight_intensity;
|
float studiolight_intensity;
|
||||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
```
bool use_scene_lights = true;
bool use_scene_world = true;
std::string studiolight_name;
float studiolight_rotation;
floatstudiolight_intensity;
```
|
|||||||
|
|
||||||
bool operator==(const ShadingSettings &other)
|
bool operator==(const ShadingSettings &other);
|
||||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
move implementation to blender_scene_delegate.cc move implementation to blender_scene_delegate.cc
|
|||||||
{
|
|
||||||
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();
|
||||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
Move this new settings to internal Move this new settings to internal `struct ShadingSettings`
|
|||||||
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();
|
||||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
remove parameter remove parameter `view3d`
|
|||||||
bool set_light_shading_settings();
|
bool set_light_shading_settings();
|
||||||
|
@ -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) {
|
||||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
use use `scene_delegate_->shading_settings.use_scene_lights`
Bogdan Nagirniak
commented
lights shouldn't be in available_objects, this can be reverted lights shouldn't be in available_objects, this can be reverted
|
|||||||
item.value.transforms.clear();
|
item.value.transforms.clear();
|
||||||
update_light_instance(item.value);
|
update_light_instance(item.value);
|
||||||
|
@ -117,7 +117,6 @@ 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(
|
||||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
thif thif `if` can be removed
|
|||||||
scene_delegate_->shading_settings.studiolight_name.c_str(),
|
scene_delegate_->shading_settings.studiolight_name.c_str(),
|
||||||
STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE);
|
STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE);
|
||||||
@ -131,7 +130,6 @@ void WorldData::init()
|
|||||||
intensity = scene_delegate_->shading_settings.studiolight_intensity / 2;
|
intensity = scene_delegate_->shading_settings.studiolight_intensity / 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
data_[pxr::HdLightTokens->intensity] = intensity;
|
data_[pxr::HdLightTokens->intensity] = intensity;
|
||||||
data_[pxr::HdLightTokens->exposure] = exposure;
|
data_[pxr::HdLightTokens->exposure] = exposure;
|
||||||
|
Loading…
Reference in New Issue
Block a user