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
Collaborator

Purpose

Implement Viewport render with material preview

Technical steps

  • Fixed issue with wrong std::string usage which leads to incorrect behavior;
  • Added special checks for various options of material preview;
### Purpose Implement Viewport render with material preview ### Technical steps * Fixed issue with wrong `std::string` usage which leads to incorrect behavior; * Added special checks for various options of material preview;
Georgiy Markelov self-assigned this 2023-06-15 18:26:43 +02:00
Brian Savery (AMD) was assigned by Georgiy Markelov 2023-06-15 18:26:43 +02:00
Vasyl Pidhirskyi was assigned by Georgiy Markelov 2023-06-15 18:26:43 +02:00
Bogdan Nagirniak was assigned by Georgiy Markelov 2023-06-15 18:26:43 +02:00
Georgiy Markelov added 11 commits 2023-06-15 18:27:03 +02:00
Georgiy Markelov requested review from Brian Savery (AMD) 2023-06-15 18:27:11 +02:00
Georgiy Markelov requested review from Vasyl Pidhirskyi 2023-06-15 18:27:11 +02:00
Georgiy Markelov added 2 commits 2023-06-19 13:32:22 +02:00
Bogdan Nagirniak requested changes 2023-06-20 10:43:06 +02:00
@ -99,2 +99,4 @@
InstancerDataMap instancers_;
std::unique_ptr<WorldData> world_data_;
short shading_flag_;

Move this new settings to internal struct ShadingSettings

Move this new settings to internal `struct ShadingSettings`
BogdanNagirniak marked this conversation as resolved
@ -78,3 +78,2 @@
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);

Revert changes in this function and add

char str[FILE_MAX];
BKE_image_user_file_path_ex(main, iuser, image, str, false, true);
file_path = str;
Revert changes in this function and add ``` char str[FILE_MAX]; BKE_image_user_file_path_ex(main, iuser, image, str, false, true); file_path = str; ```
BogdanNagirniak marked this conversation as resolved
@ -32,2 +32,4 @@
pxr::GfMatrix4d transform;
float rotation;
float intensity;

move this to BlenderSceneDelegate::ShadingSettings

move this to `BlenderSceneDelegate::ShadingSettings`
BogdanNagirniak marked this conversation as resolved
Georgiy Markelov added 2 commits 2023-06-20 12:00:51 +02:00
Bogdan Nagirniak requested changes 2023-06-20 13:02:58 +02:00
@ -642,0 +683,4 @@
{
bool ret = false;
if (view3d) {
if (shading_settings.shading_flag != view3d->shading.flag ||

simplify by using add operator==() and copy constructor to ShadingSettings

ShadingSettings prev_settings(shading_settings);
shading_settings. ....
return shading_settings != prev_settings;
simplify by using add `operator==()` and copy constructor to ShadingSettings ``` ShadingSettings prev_settings(shading_settings); shading_settings. .... return shading_settings != prev_settings; ```
BogdanNagirniak marked this conversation as resolved
@ -40,0 +42,4 @@
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;
    floatstudiolight_intensity;
``` bool use_scene_lights = true; bool use_scene_world = true; std::string studiolight_name; float studiolight_rotation; floatstudiolight_intensity; ```
BogdanNagirniak marked this conversation as resolved
@ -94,2 +103,4 @@
void remove_unused_objects();
void update_visibility();
bool set_light_shading_settings(View3D const *view3d);
bool set_world_shading_settings(View3D const *view3d);

remove parameter view3d

remove parameter `view3d`
BogdanNagirniak marked this conversation as resolved
@ -100,4 +111,10 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
std::unique_ptr<WorldData> world_data_;
};
#define LOOK_DEV_STUDIO_LIGHT_ENABLED(v3d) \

should be removed

should be removed
BogdanNagirniak marked this conversation as resolved
@ -272,6 +272,11 @@ void InstancerData::check_remove(Set<std::string> &available_objects)
light_instances_.remove_if([&](auto item) {
bool res = !available_objects.contains(item.key.GetName());
if (!V3D_USES_SCENE_LIGHTS(scene_delegate_->view3d) &&

use scene_delegate_->shading_settings.use_scene_lights

use `scene_delegate_->shading_settings.use_scene_lights`
BogdanNagirniak marked this conversation as resolved
@ -354,2 +359,4 @@
LISTBASE_FOREACH (DupliObject *, dupli, lb) {
Object *ob = dupli->ob;
if (scene_delegate_->view3d && !V3D_USES_SCENE_LIGHTS(scene_delegate_->view3d) &&
ob->type == OB_LAMP)

if (ob->type == OB_LAMP && !scene_delegate_->shading_settings.use_scene_lights)

`if (ob->type == OB_LAMP && !scene_delegate_->shading_settings.use_scene_lights)`
BogdanNagirniak marked this conversation as resolved
@ -12,10 +12,13 @@
#include <pxr/usd/usdLux/tokens.h>
#include "BKE_context.h"
#include "DEG_depsgraph_query.h"

shouldn't be needed

shouldn't be needed
BogdanNagirniak marked this conversation as resolved
@ -47,3 +52,2 @@
data_[pxr::UsdLuxTokens->orientToStageUpAxis] = true;
if (world->use_nodes) {
eEvaluationMode deg_mode = DEG_get_mode(scene_delegate_->depsgraph);
if (scene_delegate_.shading_settings.use_scene_world) {
   <previous code>
}
else {
  <new code>
}
``` if (scene_delegate_.shading_settings.use_scene_world) { <previous code> } else { <new code> } ```
BogdanNagirniak marked this conversation as resolved
Georgiy Markelov added 3 commits 2023-06-20 15:09:36 +02:00
Georgiy Markelov added 1 commit 2023-06-20 15:16:06 +02:00
Bogdan Nagirniak requested changes 2023-06-20 16:48:40 +02:00
@ -520,3 +537,2 @@
std::bitset<3>(BKE_object_visibility(object, deg_mode)).to_string().c_str());
update_objects(object);
update_instancers(object);
if (only_lights) {

simplify:

if (object_data(object_prim_id(object)) {
  continue;
}

only_lights can be removed

simplify: ``` if (object_data(object_prim_id(object)) { continue; } ``` only_lights can be removed
BogdanNagirniak marked this conversation as resolved
@ -566,6 +591,9 @@ 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) {

move this check to L573

move this check to L573
BogdanNagirniak marked this conversation as resolved
@ -642,0 +681,4 @@
bool BlenderSceneDelegate::set_world_shading_settings()
{
bool ret = false;
if (!view3d) {
  return false;
}
.....
return !(shading_settings == prev_settings);
``` if (!view3d) { return false; } ..... return !(shading_settings == prev_settings); ```
BogdanNagirniak marked this conversation as resolved
@ -40,0 +44,4 @@
float studiolight_rotation;
float studiolight_intensity;
bool operator==(const ShadingSettings &other)

move implementation to blender_scene_delegate.cc

move implementation to blender_scene_delegate.cc
BogdanNagirniak marked this conversation as resolved
@ -272,6 +272,11 @@ void InstancerData::check_remove(Set<std::string> &available_objects)
light_instances_.remove_if([&](auto item) {
bool res = !available_objects.contains(item.key.GetName());
if (!scene_delegate_->shading_settings.use_scene_lights &&

lights shouldn't be in available_objects, this can be reverted

lights shouldn't be in available_objects, this can be reverted
BogdanNagirniak marked this conversation as resolved
@ -100,3 +120,1 @@
data_[pxr::HdLightTokens->intensity] = 1.0f;
data_[pxr::HdLightTokens->exposure] = world->exposure;
data_[pxr::HdLightTokens->color] = pxr::GfVec3f(world->horr, world->horg, world->horb);
if (scene_delegate_->view3d && !scene_delegate_->shading_settings.use_scene_world) {

thif if can be removed

thif `if` can be removed
BogdanNagirniak marked this conversation as resolved
Georgiy Markelov added 1 commit 2023-06-20 17:42:54 +02:00
Bogdan Nagirniak added 1 commit 2023-06-21 13:21:22 +02:00
Bogdan Nagirniak approved these changes 2023-06-21 13:25:10 +02:00
Bogdan Nagirniak left a comment
Owner

Added fix when scene->world is empty + improved WorldData.
Tested - works good.

Added fix when scene->world is empty + improved WorldData. Tested - works good.
Bogdan Nagirniak added 1 commit 2023-06-21 16:54:14 +02:00
Author
Collaborator

Works good.

Works good.
Brian Savery (AMD) approved these changes 2023-06-26 18:45:45 +02:00
Brian Savery (AMD) approved these changes 2023-06-26 18:45:47 +02:00
Bogdan Nagirniak merged commit a34976e949 into hydra-render 2023-06-30 09:03:28 +02:00
Sign in to join this conversation.
No Label
No Milestone
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: BogdanNagirniak/blender#56
No description provided.