forked from blender/blender
Implement Viewport render with material preview #56
@ -422,6 +422,18 @@ void BlenderSceneDelegate::check_updates()
|
||||
bool do_update_visibility = false;
|
||||
bool do_update_world = false;
|
||||
|
||||
if (shading_flag_ != view3d->shading.flag) {
|
||||
shading_flag_ = view3d->shading.flag;
|
||||
do_update_world = 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;
|
||||
data.only_updated = true;
|
||||
|
@ -98,6 +98,14 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||
MaterialDataMap materials_;
|
||||
InstancerDataMap instancers_;
|
||||
std::unique_ptr<WorldData> world_data_;
|
||||
|
||||
short shading_flag_;
|
||||
};
|
||||
|
||||
#define LOOK_DEV_STUDIO_LIGHT_ENABLED(v3d) \
|
||||
((v3d) && (((v3d->shading.type == OB_MATERIAL) && \
|
||||
((v3d->shading.flag & V3D_SHADING_SCENE_WORLD) == 0)) || \
|
||||
((v3d->shading.type == OB_RENDER) && \
|
||||
((v3d->shading.flag & V3D_SHADING_SCENE_WORLD_RENDER) == 0))))
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -15,7 +15,9 @@
|
||||
#include "DNA_node_types.h"
|
||||
|
||||
#include "BKE_node.h"
|
||||
#include "BKE_studiolight.h"
|
||||
#include "BKE_node_runtime.hh"
|
||||
#include "BLI_math_rotation.h"
|
||||
#include "BLI_path_util.h"
|
||||
#include "NOD_shader.h"
|
||||
|
||||
@ -26,6 +28,8 @@
|
||||
|
||||
/* TODO : add custom tftoken "transparency"? */
|
||||
|
||||
/* NOTE: opacity and blur aren't supported by USD */
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
WorldData::WorldData(BlenderSceneDelegate *scene_delegate,
|
||||
@ -39,6 +43,8 @@ void WorldData::init()
|
||||
{
|
||||
ID_LOG(1, "");
|
||||
|
||||
rotation = scene_delegate_->view3d->shading.studiolight_rot_z;
|
||||
intensity = scene_delegate_->view3d->shading.studiolight_intensity;
|
||||
write_transform();
|
||||
|
||||
World *world = (World *)id;
|
||||
@ -46,7 +52,7 @@ void WorldData::init()
|
||||
|
||||
data_[pxr::UsdLuxTokens->orientToStageUpAxis] = true;
|
||||
|
||||
if (world->use_nodes) {
|
||||
if (world->use_nodes && V3D_USES_SCENE_WORLD(scene_delegate_->view3d)) {
|
||||
/* TODO: Create nodes parsing system */
|
||||
|
||||
bNode *output_node = ntreeShaderOutputNode(world->nodetree, SHD_OUTPUT_ALL);
|
||||
@ -95,6 +101,20 @@ void WorldData::init()
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (LOOK_DEV_STUDIO_LIGHT_ENABLED(scene_delegate_->view3d)) {
|
||||
StudioLight *sl = BKE_studiolight_find(scene_delegate_->view3d->shading.lookdev_light,
|
||||
STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE);
|
||||
if (sl == NULL || (sl->flag & STUDIOLIGHT_TYPE_WORLD) == 0) {
|
||||
return;
|
||||
}
|
||||
data_[pxr::HdLightTokens->textureFile] = pxr::SdfAssetPath(sl->filepath, sl->filepath);
|
||||
data_[pxr::HdLightTokens->intensity] = scene_delegate_->view3d->shading.studiolight_intensity / 2;
|
||||
|
||||
transform *= pxr::GfMatrix4d(
|
||||
pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, -1.0),
|
||||
RAD2DEGF(scene_delegate_->view3d->shading.studiolight_rot_z)),
|
||||
pxr::GfVec3d());
|
||||
}
|
||||
else {
|
||||
data_[pxr::HdLightTokens->intensity] = 1.0f;
|
||||
data_[pxr::HdLightTokens->exposure] = world->exposure;
|
||||
|
@ -31,6 +31,8 @@ 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();
|
||||
|
Loading…
Reference in New Issue
Block a user