forked from blender/blender
Implement Viewport render with material preview #56
@ -16,10 +16,15 @@ 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;
|
||||
bool ret = use_scene_lights == other.use_scene_lights &&
|
||||
use_scene_world == other.use_scene_world;
|
||||
if (ret && !use_scene_world) {
|
||||
/* compare studiolight settings when studiolight is using */
|
||||
ret = studiolight_name == other.studiolight_name &&
|
||||
studiolight_rotation == other.studiolight_rotation &&
|
||||
studiolight_intensity == other.studiolight_intensity;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
|
||||
@ -409,17 +414,16 @@ void BlenderSceneDelegate::update_instancers(Object *object)
|
||||
|
||||
void BlenderSceneDelegate::update_world()
|
||||
{
|
||||
World *world = scene->world;
|
||||
if (!world_data_) {
|
||||
if (world) {
|
||||
world_data_ = std::make_unique<WorldData>(this, world, world_prim_id());
|
||||
if (!shading_settings.use_scene_world || (shading_settings.use_scene_world && scene->world)) {
|
||||
world_data_ = std::make_unique<WorldData>(this, world_prim_id());
|
||||
world_data_->init();
|
||||
world_data_->insert();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (world) {
|
||||
world_data_->update(world);
|
||||
if (!shading_settings.use_scene_world || (shading_settings.use_scene_world && scene->world)) {
|
||||
world_data_->update();
|
||||
}
|
||||
else {
|
||||
world_data_->remove();
|
||||
@ -672,14 +676,12 @@ void BlenderSceneDelegate::update_visibility()
|
||||
|
||||
bool BlenderSceneDelegate::set_light_shading_settings()
|
||||
{
|
||||
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;
|
||||
}
|
||||
if (!view3d) {
|
||||
return false;
|
||||
}
|
||||
return ret;
|
||||
ShadingSettings prev_settings(shading_settings);
|
||||
shading_settings.use_scene_lights = V3D_USES_SCENE_LIGHTS(view3d);
|
||||
return !(shading_settings == prev_settings);
|
||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
Outdated
Review
```
if (!view3d) {
return false;
}
.....
return !(shading_settings == prev_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 BlenderSceneDelegate::set_world_shading_settings()
|
||||
|
@ -32,30 +32,28 @@
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
WorldData::WorldData(BlenderSceneDelegate *scene_delegate,
|
||||
World *world,
|
||||
pxr::SdfPath const &prim_id)
|
||||
: IdData(scene_delegate, (ID *)world, prim_id)
|
||||
WorldData::WorldData(BlenderSceneDelegate *scene_delegate, pxr::SdfPath const &prim_id)
|
||||
: IdData(scene_delegate, nullptr, prim_id)
|
||||
{
|
||||
}
|
||||
|
||||
void WorldData::init()
|
||||
{
|
||||
ID_LOG(1, "");
|
||||
|
||||
write_transform();
|
||||
|
||||
World *world = (World *)id;
|
||||
data_.clear();
|
||||
|
||||
data_[pxr::UsdLuxTokens->orientToStageUpAxis] = true;
|
||||
|
||||
float intensity = 1.0f;
|
||||
float exposure = world->exposure;
|
||||
float exposure = 0.0f;
|
||||
pxr::GfVec3f color(1.0f, 1.0f, 1.0f);
|
||||
pxr::SdfAssetPath texture_file;
|
||||
|
||||
if (scene_delegate_->shading_settings.use_scene_world) {
|
||||
World *world = scene_delegate_->scene->world;
|
||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
```
if (scene_delegate_.shading_settings.use_scene_world) {
<previous code>
}
else {
<new code>
}
```
|
||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s: %s", prim_id.GetText(), world->id.name);
|
||||
|
||||
exposure = world->exposure;
|
||||
if (world->use_nodes) {
|
||||
/* TODO: Create nodes parsing system */
|
||||
|
||||
@ -117,6 +115,12 @@ void WorldData::init()
|
||||
}
|
||||
}
|
||||
else {
|
||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE,
|
||||
1,
|
||||
"%s: studiolight: %s",
|
||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
thif thif `if` can be removed
|
||||
prim_id.GetText(),
|
||||
scene_delegate_->shading_settings.studiolight_name.c_str());
|
||||
|
||||
StudioLight *sl = BKE_studiolight_find(
|
||||
scene_delegate_->shading_settings.studiolight_name.c_str(),
|
||||
STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE);
|
||||
@ -139,7 +143,7 @@ void WorldData::init()
|
||||
|
||||
void WorldData::insert()
|
||||
{
|
||||
ID_LOG(1, "");
|
||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s", prim_id.GetText());
|
||||
scene_delegate_->GetRenderIndex().InsertSprim(
|
||||
pxr::HdPrimTypeTokens->domeLight, scene_delegate_, prim_id);
|
||||
}
|
||||
@ -152,23 +156,17 @@ void WorldData::remove()
|
||||
|
||||
void WorldData::update()
|
||||
{
|
||||
ID_LOG(1, "");
|
||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 1, "%s", prim_id.GetText());
|
||||
init();
|
||||
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id,
|
||||
pxr::HdLight::AllDirty);
|
||||
}
|
||||
|
||||
void WorldData::update(World *world)
|
||||
{
|
||||
id = (ID *)world;
|
||||
update();
|
||||
}
|
||||
|
||||
pxr::VtValue WorldData::get_data(pxr::TfToken const &key) const
|
||||
{
|
||||
auto it = data_.find(key);
|
||||
if (it != data_.end()) {
|
||||
ID_LOG(3, "%s", key.GetText());
|
||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s: %s", prim_id.GetText(), key.GetText());
|
||||
return pxr::VtValue(it->second);
|
||||
}
|
||||
return pxr::VtValue();
|
||||
|
@ -20,7 +20,7 @@ namespace blender::render::hydra {
|
||||
|
||||
class WorldData : public IdData {
|
||||
public:
|
||||
WorldData(BlenderSceneDelegate *scene_delegate, World *world, pxr::SdfPath const &prim_id);
|
||||
WorldData(BlenderSceneDelegate *scene_delegate, pxr::SdfPath const &prim_id);
|
||||
|
||||
void init() override;
|
||||
void insert() override;
|
||||
|
Loading…
Reference in New Issue
Block a user