forked from blender/blender
Implement Viewport render with material preview #56
@ -205,8 +205,8 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
|
|||||||
check_updates();
|
check_updates();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
set_light_shading_settings(view3d);
|
set_light_shading_settings();
|
||||||
set_world_shading_settings(view3d);
|
set_world_shading_settings();
|
||||||
add_new_objects();
|
add_new_objects();
|
||||||
update_world();
|
update_world();
|
||||||
}
|
}
|
||||||
@ -340,7 +340,7 @@ void BlenderSceneDelegate::update_objects(Object *object)
|
|||||||
if (!ObjectData::is_supported(object)) {
|
if (!ObjectData::is_supported(object)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (view3d && !V3D_USES_SCENE_LIGHTS(view3d) && object->type == OB_LAMP) {
|
if (!shading_settings.use_scene_lights && object->type == OB_LAMP) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pxr::SdfPath id = object_prim_id(object);
|
pxr::SdfPath id = object_prim_id(object);
|
||||||
@ -426,11 +426,11 @@ void BlenderSceneDelegate::check_updates()
|
|||||||
bool do_update_visibility = false;
|
bool do_update_visibility = false;
|
||||||
bool do_update_world = false;
|
bool do_update_world = false;
|
||||||
|
|
||||||
if (set_world_shading_settings(view3d)) {
|
if (set_world_shading_settings()) {
|
||||||
do_update_world = true;
|
do_update_world = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (set_light_shading_settings(view3d)) {
|
if (set_light_shading_settings()) {
|
||||||
if (shading_settings.use_scene_lights) {
|
if (shading_settings.use_scene_lights) {
|
||||||
add_new_objects(true);
|
add_new_objects(true);
|
||||||
}
|
}
|
||||||
@ -472,7 +472,7 @@ void BlenderSceneDelegate::check_updates()
|
|||||||
} break;
|
} break;
|
||||||
|
|
||||||
case ID_WO: {
|
case ID_WO: {
|
||||||
if (id->recalc & ID_RECALC_SHADING) {
|
if (shading_settings.use_scene_world && id->recalc & ID_RECALC_SHADING) {
|
||||||
do_update_world = true;
|
do_update_world = true;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
@ -591,7 +591,9 @@ 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 (!V3D_USES_SCENE_LIGHTS(view3d) && ((Object *)item.value->id)->type == OB_LAMP) {
|
if (!shading_settings.use_scene_lights &&
|
||||||
BogdanNagirniak marked this conversation as resolved
Outdated
|
|||||||
|
((Object *)item.value->id)->type == OB_LAMP)
|
||||||
|
{
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
if (ret) {
|
if (ret) {
|
||||||
@ -667,7 +669,7 @@ void BlenderSceneDelegate::update_visibility()
|
|||||||
ITER_END;
|
ITER_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BlenderSceneDelegate::set_light_shading_settings(View3D const *view3d)
|
bool BlenderSceneDelegate::set_light_shading_settings()
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
if (view3d) {
|
if (view3d) {
|
||||||
@ -679,21 +681,16 @@ bool BlenderSceneDelegate::set_light_shading_settings(View3D const *view3d)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BlenderSceneDelegate::set_world_shading_settings(View3D const *view3d)
|
bool BlenderSceneDelegate::set_world_shading_settings()
|
||||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
```
if (!view3d) {
return false;
}
.....
return !(shading_settings == prev_settings);
```
|
|||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
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;
```
|
|||||||
if (view3d) {
|
if (view3d) {
|
||||||
if (shading_settings.shading_flag != view3d->shading.flag ||
|
ShadingSettings prev_settings(shading_settings);
|
||||||
shading_settings.lookdev_light != view3d->shading.lookdev_light ||
|
shading_settings.use_scene_world = V3D_USES_SCENE_WORLD(view3d);
|
||||||
shading_settings.rotation != view3d->shading.studiolight_rot_z ||
|
shading_settings.studiolight_name = view3d->shading.lookdev_light;
|
||||||
shading_settings.intensity != view3d->shading.studiolight_intensity)
|
shading_settings.studiolight_rotation = view3d->shading.studiolight_rot_z;
|
||||||
{
|
shading_settings.studiolight_intensity = view3d->shading.studiolight_intensity;
|
||||||
shading_settings.shading_flag = view3d->shading.flag;
|
ret = shading_settings != prev_settings;
|
||||||
shading_settings.lookdev_light = view3d->shading.lookdev_light;
|
|
||||||
shading_settings.rotation = view3d->shading.studiolight_rot_z;
|
|
||||||
shading_settings.intensity = view3d->shading.studiolight_intensity;
|
|
||||||
ret = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -38,11 +38,27 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ShadingSettings {
|
struct ShadingSettings {
|
||||||
bool use_scene_lights = false;
|
bool use_scene_lights = true;
|
||||||
short shading_flag;
|
bool use_scene_world = true;
|
||||||
std::string lookdev_light;
|
std::string studiolight_name;
|
||||||
float rotation;
|
float studiolight_rotation;
|
||||||
float 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) {
|
||||||
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,
|
||||||
@ -102,8 +118,8 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
|||||||
void add_new_objects(bool only_lights = false);
|
void add_new_objects(bool only_lights = false);
|
||||||
void remove_unused_objects();
|
void remove_unused_objects();
|
||||||
void update_visibility();
|
void update_visibility();
|
||||||
bool set_light_shading_settings(View3D const *view3d);
|
bool set_light_shading_settings();
|
||||||
bool set_world_shading_settings(View3D const *view3d);
|
bool set_world_shading_settings();
|
||||||
|
|
||||||
ObjectDataMap objects_;
|
ObjectDataMap objects_;
|
||||||
MaterialDataMap materials_;
|
MaterialDataMap materials_;
|
||||||
@ -111,10 +127,4 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
|||||||
std::unique_ptr<WorldData> world_data_;
|
std::unique_ptr<WorldData> world_data_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#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
|
} // namespace blender::render::hydra
|
||||||
|
@ -272,7 +272,7 @@ 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 (!V3D_USES_SCENE_LIGHTS(scene_delegate_->view3d) &&
|
if (!scene_delegate_->shading_settings.use_scene_lights &&
|
||||||
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
|
|||||||
((Object *)item.value.data->id)->type == OB_LAMP)
|
((Object *)item.value.data->id)->type == OB_LAMP)
|
||||||
{
|
{
|
||||||
res = true;
|
res = true;
|
||||||
@ -358,10 +358,10 @@ void InstancerData::write_instances()
|
|||||||
scene_delegate_->depsgraph, scene_delegate_->scene, (Object *)id);
|
scene_delegate_->depsgraph, scene_delegate_->scene, (Object *)id);
|
||||||
LISTBASE_FOREACH (DupliObject *, dupli, lb) {
|
LISTBASE_FOREACH (DupliObject *, dupli, lb) {
|
||||||
Object *ob = dupli->ob;
|
Object *ob = dupli->ob;
|
||||||
if (scene_delegate_->view3d && !V3D_USES_SCENE_LIGHTS(scene_delegate_->view3d) &&
|
if (!scene_delegate_->shading_settings.use_scene_lights &&
|
||||||
ob->type == OB_LAMP)
|
ob->type == OB_LAMP)
|
||||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
`if (ob->type == OB_LAMP && !scene_delegate_->shading_settings.use_scene_lights)`
|
|||||||
{
|
{
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
if (!is_supported(ob) || !is_instance_visible(ob)) {
|
if (!is_supported(ob) || !is_instance_visible(ob)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
#include <pxr/usd/usdLux/tokens.h>
|
#include <pxr/usd/usdLux/tokens.h>
|
||||||
|
|
||||||
#include "BKE_context.h"
|
#include "BKE_context.h"
|
||||||
#include "DEG_depsgraph_query.h"
|
|
||||||
#include "DNA_node_types.h"
|
#include "DNA_node_types.h"
|
||||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
shouldn't be needed shouldn't be needed
|
|||||||
|
|
||||||
#include "BKE_node.h"
|
#include "BKE_node.h"
|
||||||
@ -50,11 +49,14 @@ void WorldData::init()
|
|||||||
data_.clear();
|
data_.clear();
|
||||||
|
|
||||||
data_[pxr::UsdLuxTokens->orientToStageUpAxis] = true;
|
data_[pxr::UsdLuxTokens->orientToStageUpAxis] = true;
|
||||||
eEvaluationMode deg_mode = DEG_get_mode(scene_delegate_->depsgraph);
|
|
||||||
if (world->use_nodes && ((deg_mode == DAG_EVAL_VIEWPORT && scene_delegate_->view3d &&
|
float intensity = 1.0f;
|
||||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
```
if (scene_delegate_.shading_settings.use_scene_world) {
<previous code>
}
else {
<new code>
}
```
|
|||||||
V3D_USES_SCENE_WORLD(scene_delegate_->view3d)) ||
|
float exposure = world->exposure;
|
||||||
deg_mode == DAG_EVAL_RENDER))
|
pxr::GfVec3f color(1.0f, 1.0f, 1.0f);
|
||||||
{
|
pxr::SdfAssetPath texture_file;
|
||||||
|
|
||||||
|
if (scene_delegate_->shading_settings.use_scene_world) {
|
||||||
|
if (world->use_nodes) {
|
||||||
/* TODO: Create nodes parsing system */
|
/* TODO: Create nodes parsing system */
|
||||||
|
|
||||||
bNode *output_node = ntreeShaderOutputNode(world->nodetree, SHD_OUTPUT_ALL);
|
bNode *output_node = ntreeShaderOutputNode(world->nodetree, SHD_OUTPUT_ALL);
|
||||||
@ -84,10 +86,9 @@ void WorldData::init()
|
|||||||
bNodeSocket strength_input = input_node->input_by_identifier("Strength");
|
bNodeSocket strength_input = input_node->input_by_identifier("Strength");
|
||||||
|
|
||||||
float const *strength = strength_input.default_value_typed<float>();
|
float const *strength = strength_input.default_value_typed<float>();
|
||||||
float const *color = color_input.default_value_typed<float>();
|
float const *input_color = color_input.default_value_typed<float>();
|
||||||
data_[pxr::HdLightTokens->intensity] = strength[1];
|
intensity = strength[1];
|
||||||
data_[pxr::HdLightTokens->exposure] = 1.0f;
|
color = pxr::GfVec3f(input_color[0], input_color[1], input_color[2]);
|
||||||
data_[pxr::HdLightTokens->color] = pxr::GfVec3f(color[0], color[1], color[2]);
|
|
||||||
|
|
||||||
if (!color_input.directly_linked_links().is_empty()) {
|
if (!color_input.directly_linked_links().is_empty()) {
|
||||||
bNode *color_input_node = color_input.directly_linked_links()[0]->fromnode;
|
bNode *color_input_node = color_input.directly_linked_links()[0]->fromnode;
|
||||||
@ -98,19 +99,29 @@ void WorldData::init()
|
|||||||
std::string image_path = cache_or_get_image_file(
|
std::string image_path = cache_or_get_image_file(
|
||||||
image, scene_delegate_->context, &tex->iuser);
|
image, scene_delegate_->context, &tex->iuser);
|
||||||
if (!image_path.empty()) {
|
if (!image_path.empty()) {
|
||||||
data_[pxr::HdLightTokens->textureFile] = pxr::SdfAssetPath(image_path, image_path);
|
texture_file = pxr::SdfAssetPath(image_path, image_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
float intensity = 1.0f;
|
intensity = 1.0f;
|
||||||
if (LOOK_DEV_STUDIO_LIGHT_ENABLED(scene_delegate_->view3d)) {
|
color = pxr::GfVec3f(world->horr, world->horg, world->horb);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (texture_file.GetAssetPath().empty()) {
|
||||||
|
float fill_color[4] = {color[0], color[1], color[2], 1.0f};
|
||||||
|
std::string image_path = cache_image_color(fill_color);
|
||||||
|
texture_file = pxr::SdfAssetPath(image_path, image_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (scene_delegate_->view3d && !scene_delegate_->shading_settings.use_scene_world) {
|
||||||
BogdanNagirniak marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
thif thif `if` can be removed
|
|||||||
StudioLight *sl = BKE_studiolight_find(scene_delegate_->view3d->shading.lookdev_light,
|
StudioLight *sl = BKE_studiolight_find(scene_delegate_->view3d->shading.lookdev_light,
|
||||||
STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE);
|
STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE);
|
||||||
if (sl != NULL && sl->flag & STUDIOLIGHT_TYPE_WORLD) {
|
if (sl != NULL && sl->flag & STUDIOLIGHT_TYPE_WORLD) {
|
||||||
data_[pxr::HdLightTokens->textureFile] = 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_->view3d->shading.studiolight_rot_z)),
|
RAD2DEGF(scene_delegate_->view3d->shading.studiolight_rot_z)),
|
||||||
@ -119,17 +130,12 @@ void WorldData::init()
|
|||||||
intensity = scene_delegate_->view3d->shading.studiolight_intensity / 2;
|
intensity = scene_delegate_->view3d->shading.studiolight_intensity / 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data_[pxr::HdLightTokens->intensity] = intensity;
|
|
||||||
data_[pxr::HdLightTokens->exposure] = world->exposure;
|
|
||||||
data_[pxr::HdLightTokens->color] = pxr::GfVec3f(world->horr, world->horg, world->horb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data_.find(pxr::HdLightTokens->textureFile) == data_.end()) {
|
data_[pxr::HdLightTokens->intensity] = intensity;
|
||||||
pxr::GfVec3f c = data_[pxr::HdLightTokens->color].Get<pxr::GfVec3f>();
|
data_[pxr::HdLightTokens->exposure] = exposure;
|
||||||
float color[4] = {c[0], c[1], c[2], 1.0f};
|
data_[pxr::HdLightTokens->color] = color;
|
||||||
std::string image_path = cache_image_color(color);
|
data_[pxr::HdLightTokens->textureFile] = texture_file;
|
||||||
data_[pxr::HdLightTokens->textureFile] = pxr::SdfAssetPath(image_path, image_path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldData::insert()
|
void WorldData::insert()
|
||||||
|
Loading…
Reference in New Issue
Block a user
move this check to L573