forked from blender/blender
Create possibility to provide render settings via BlenderSceneDelegate #41
@ -17,13 +17,15 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
CLG_LOGREF_DECLARE_GLOBAL(LOG_RENDER_HYDRA, "render.hydra");
|
CLG_LOGREF_DECLARE_GLOBAL(LOG_RENDER_HYDRA, "render.hydra");
|
||||||
|
|
||||||
Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name, SettingsMap &settings)
|
Engine::Engine(RenderEngine *bl_engine,
|
||||||
: bl_engine_(bl_engine), render_delegate_name_(render_delegate_name), settings_(settings)
|
const std::string &render_delegate_name,
|
||||||
|
SettingsMap &settings)
|
||||||
|
: render_delegate_name(render_delegate_name), settings(settings), bl_engine_(bl_engine)
|
||||||
{
|
{
|
||||||
pxr::HdRendererPluginRegistry ®istry = pxr::HdRendererPluginRegistry::GetInstance();
|
pxr::HdRendererPluginRegistry ®istry = pxr::HdRendererPluginRegistry::GetInstance();
|
||||||
|
|
||||||
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
|
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
|
||||||
render_delegate_ = registry.CreateRenderDelegate(pxr::TfToken(render_delegate_name_));
|
render_delegate_ = registry.CreateRenderDelegate(pxr::TfToken(render_delegate_name));
|
||||||
|
|
||||||
/* USD has limited support for Vulkan. To make it works USD should be built
|
/* USD has limited support for Vulkan. To make it works USD should be built
|
||||||
* with PXR_ENABLE_VULKAN_SUPPORT=TRUE which is not possible now */
|
* with PXR_ENABLE_VULKAN_SUPPORT=TRUE which is not possible now */
|
||||||
@ -45,7 +47,7 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name,
|
|||||||
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("freeCamera"));
|
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("freeCamera"));
|
||||||
render_task_delegate_ = std::make_unique<RenderTaskDelegate>(
|
render_task_delegate_ = std::make_unique<RenderTaskDelegate>(
|
||||||
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask"));
|
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask"));
|
||||||
if (render_delegate_name_ == "HdStormRendererPlugin") {
|
if (render_delegate_name == "HdStormRendererPlugin") {
|
||||||
simple_light_task_delegate_ = std::make_unique<SimpleLightTaskDelegate>(
|
simple_light_task_delegate_ = std::make_unique<SimpleLightTaskDelegate>(
|
||||||
render_index_.get(),
|
render_index_.get(),
|
||||||
pxr::SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask"));
|
pxr::SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask"));
|
||||||
|
@ -27,22 +27,22 @@ typedef pxr::TfHashMap<pxr::TfToken, pxr::VtValue, pxr::TfToken::HashFunctor> Se
|
|||||||
|
|
||||||
class Engine {
|
class Engine {
|
||||||
public:
|
public:
|
||||||
Engine(RenderEngine *bl_engine,
|
enum class EngineType { VIEWPORT = 1, FINAL, PREVIEW };
|
||||||
const std::string &render_delegate_name,
|
|
||||||
SettingsMap &settings);
|
Engine(RenderEngine *bl_engine, const std::string &render_delegate_name, SettingsMap &settings);
|
||||||
virtual ~Engine() = default;
|
virtual ~Engine() = default;
|
||||||
|
|
||||||
virtual void sync(Depsgraph *depsgraph,
|
virtual void sync(Depsgraph *depsgraph, bContext *context, SettingsMap &render_settings) = 0;
|
||||||
bContext *context,
|
|
||||||
SettingsMap &render_settings) = 0;
|
|
||||||
virtual void render(Depsgraph *depsgraph) = 0;
|
virtual void render(Depsgraph *depsgraph) = 0;
|
||||||
|
|
||||||
|
EngineType type;
|
||||||
|
std::string render_delegate_name;
|
||||||
|
SettingsMap settings;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float renderer_percent_done();
|
float renderer_percent_done();
|
||||||
|
|
||||||
RenderEngine *bl_engine_;
|
RenderEngine *bl_engine_;
|
||||||
std::string render_delegate_name_;
|
|
||||||
SettingsMap settings_;
|
|
||||||
|
|
||||||
/* The order is important due to deletion order */
|
/* The order is important due to deletion order */
|
||||||
pxr::HgiUniquePtr hgi_;
|
pxr::HgiUniquePtr hgi_;
|
||||||
|
@ -13,15 +13,20 @@
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
|
FinalEngine::FinalEngine(RenderEngine *bl_engine,
|
||||||
|
const std::string &render_delegate_name,
|
||||||
|
SettingsMap &settings)
|
||||||
|
: Engine(bl_engine, render_delegate_name, settings)
|
||||||
|
{
|
||||||
|
type = EngineType::FINAL;
|
||||||
|
}
|
||||||
|
|
||||||
void FinalEngine::sync(Depsgraph *depsgraph,
|
void FinalEngine::sync(Depsgraph *depsgraph,
|
||||||
bContext *context,
|
bContext *context,
|
||||||
pxr::HdRenderSettingsMap &render_settings)
|
pxr::HdRenderSettingsMap &render_settings)
|
||||||
{
|
{
|
||||||
scene_delegate_ = std::make_unique<BlenderSceneDelegate>(
|
scene_delegate_ = std::make_unique<BlenderSceneDelegate>(
|
||||||
render_index_.get(),
|
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), this);
|
||||||
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
|
||||||
BlenderSceneDelegate::EngineType::FINAL,
|
|
||||||
render_delegate_name_);
|
|
||||||
scene_delegate_->populate(depsgraph, context);
|
scene_delegate_->populate(depsgraph, context);
|
||||||
|
|
||||||
for (auto const &setting : render_settings) {
|
for (auto const &setting : render_settings) {
|
||||||
|
@ -9,7 +9,9 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
class FinalEngine : public Engine {
|
class FinalEngine : public Engine {
|
||||||
public:
|
public:
|
||||||
using Engine::Engine;
|
FinalEngine(RenderEngine *bl_engine,
|
||||||
|
const std::string &render_delegate_name,
|
||||||
|
SettingsMap &settings);
|
||||||
|
|
||||||
virtual void sync(Depsgraph *depsgraph,
|
virtual void sync(Depsgraph *depsgraph,
|
||||||
bContext *context,
|
bContext *context,
|
||||||
|
@ -13,6 +13,14 @@ const double LIFETIME = 180.0;
|
|||||||
|
|
||||||
std::unique_ptr<PreviewEngine> PreviewEngine::instance_;
|
std::unique_ptr<PreviewEngine> PreviewEngine::instance_;
|
||||||
|
|
||||||
|
PreviewEngine::PreviewEngine(RenderEngine *bl_engine,
|
||||||
|
const std::string &render_delegate_name,
|
||||||
|
SettingsMap &settings)
|
||||||
|
: FinalEngine(bl_engine, render_delegate_name, settings)
|
||||||
|
{
|
||||||
|
type = EngineType::PREVIEW;
|
||||||
|
}
|
||||||
|
|
||||||
PreviewEngine *PreviewEngine::get_instance(RenderEngine *bl_engine,
|
PreviewEngine *PreviewEngine::get_instance(RenderEngine *bl_engine,
|
||||||
const std::string &render_delegate_name,
|
const std::string &render_delegate_name,
|
||||||
SettingsMap &settings)
|
SettingsMap &settings)
|
||||||
@ -43,10 +51,7 @@ void PreviewEngine::sync(Depsgraph *depsgraph,
|
|||||||
{
|
{
|
||||||
if (!scene_delegate_) {
|
if (!scene_delegate_) {
|
||||||
scene_delegate_ = std::make_unique<BlenderSceneDelegate>(
|
scene_delegate_ = std::make_unique<BlenderSceneDelegate>(
|
||||||
render_index_.get(),
|
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), this);
|
||||||
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
|
||||||
BlenderSceneDelegate::EngineType::PREVIEW,
|
|
||||||
render_delegate_name_);
|
|
||||||
}
|
}
|
||||||
scene_delegate_->clear();
|
scene_delegate_->clear();
|
||||||
scene_delegate_->populate(depsgraph, context);
|
scene_delegate_->populate(depsgraph, context);
|
||||||
@ -102,7 +107,7 @@ void PreviewEngine::update(RenderEngine *bl_engine,
|
|||||||
SettingsMap &settings)
|
SettingsMap &settings)
|
||||||
{
|
{
|
||||||
bl_engine_ = bl_engine;
|
bl_engine_ = bl_engine;
|
||||||
if (render_delegate_name != render_delegate_name_) {
|
if (render_delegate_name != render_delegate_name) {
|
||||||
render_delegate_->Stop();
|
render_delegate_->Stop();
|
||||||
instance_.reset(new PreviewEngine(bl_engine, render_delegate_name, settings));
|
instance_.reset(new PreviewEngine(bl_engine, render_delegate_name, settings));
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,9 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
class PreviewEngine : public FinalEngine {
|
class PreviewEngine : public FinalEngine {
|
||||||
public:
|
public:
|
||||||
using FinalEngine::FinalEngine;
|
PreviewEngine(RenderEngine *bl_engine,
|
||||||
|
const std::string &render_delegate_name,
|
||||||
|
SettingsMap &settings);
|
||||||
|
|
||||||
static PreviewEngine *get_instance(RenderEngine *bl_engine,
|
static PreviewEngine *get_instance(RenderEngine *bl_engine,
|
||||||
const std::string &render_delegate_name,
|
const std::string &render_delegate_name,
|
||||||
|
@ -14,11 +14,8 @@ CLG_LOGREF_DECLARE_GLOBAL(LOG_RENDER_HYDRA_SCENE, "render.hydra.scene");
|
|||||||
|
|
||||||
BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
|
BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
|
||||||
pxr::SdfPath const &delegate_id,
|
pxr::SdfPath const &delegate_id,
|
||||||
BlenderSceneDelegate::EngineType engine_type,
|
Engine *engine)
|
||||||
const std::string &render_delegate_name)
|
: HdSceneDelegate(parent_index, delegate_id), engine(engine)
|
||||||
: HdSceneDelegate(parent_index, delegate_id),
|
|
||||||
engine_type(engine_type),
|
|
||||||
render_delegate_name(render_delegate_name)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,8 +373,8 @@ void BlenderSceneDelegate::check_updates()
|
|||||||
DEGIDIterData data = {0};
|
DEGIDIterData data = {0};
|
||||||
data.graph = depsgraph;
|
data.graph = depsgraph;
|
||||||
data.only_updated = true;
|
data.only_updated = true;
|
||||||
ITER_BEGIN (
|
ITER_BEGIN (DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id)
|
||||||
DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) {
|
{
|
||||||
|
|
||||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE,
|
CLOG_INFO(LOG_RENDER_HYDRA_SCENE,
|
||||||
2,
|
2,
|
||||||
@ -451,7 +448,8 @@ void BlenderSceneDelegate::add_new_objects()
|
|||||||
DEG_iterator_objects_end,
|
DEG_iterator_objects_end,
|
||||||
&data,
|
&data,
|
||||||
Object *,
|
Object *,
|
||||||
object) {
|
object)
|
||||||
|
{
|
||||||
|
|
||||||
update_objects(object);
|
update_objects(object);
|
||||||
update_instancers(object);
|
update_instancers(object);
|
||||||
@ -476,7 +474,8 @@ void BlenderSceneDelegate::remove_unused_objects()
|
|||||||
DEG_iterator_objects_end,
|
DEG_iterator_objects_end,
|
||||||
&data,
|
&data,
|
||||||
Object *,
|
Object *,
|
||||||
object) {
|
object)
|
||||||
|
{
|
||||||
if (ObjectData::is_supported(object)) {
|
if (ObjectData::is_supported(object)) {
|
||||||
available_objects.insert(object_prim_id(object).GetName());
|
available_objects.insert(object_prim_id(object).GetName());
|
||||||
}
|
}
|
||||||
@ -554,7 +553,8 @@ void BlenderSceneDelegate::update_visibility()
|
|||||||
DEG_iterator_objects_end,
|
DEG_iterator_objects_end,
|
||||||
&data,
|
&data,
|
||||||
Object *,
|
Object *,
|
||||||
object) {
|
object)
|
||||||
|
{
|
||||||
|
|
||||||
if (!object_data(object_prim_id(object))) {
|
if (!object_data(object_prim_id(object))) {
|
||||||
update_objects(object);
|
update_objects(object);
|
||||||
|
@ -21,18 +21,17 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE;
|
extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE;
|
||||||
|
|
||||||
|
class Engine;
|
||||||
|
|
||||||
class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||||
friend ObjectData; /* has access to instances */
|
friend ObjectData; /* has access to instances */
|
||||||
friend MeshData; /* has access to materials */
|
friend MeshData; /* has access to materials */
|
||||||
friend MaterialData; /* has access to objects and instancers */
|
friend MaterialData; /* has access to objects and instancers */
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum class EngineType { VIEWPORT = 1, FINAL, PREVIEW };
|
|
||||||
|
|
||||||
BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
|
BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
|
||||||
pxr::SdfPath const &delegate_id,
|
pxr::SdfPath const &delegate_id,
|
||||||
BlenderSceneDelegate::EngineType engine_type,
|
Engine *engine);
|
||||||
const std::string &render_delegate_name);
|
|
||||||
~BlenderSceneDelegate() override = default;
|
~BlenderSceneDelegate() override = default;
|
||||||
|
|
||||||
/* Delegate methods */
|
/* Delegate methods */
|
||||||
@ -56,13 +55,11 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
|||||||
void populate(Depsgraph *depsgraph, bContext *context);
|
void populate(Depsgraph *depsgraph, bContext *context);
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
EngineType engine_type;
|
|
||||||
Depsgraph *depsgraph = nullptr;
|
Depsgraph *depsgraph = nullptr;
|
||||||
bContext *context = nullptr;
|
bContext *context = nullptr;
|
||||||
View3D *view3d = nullptr;
|
View3D *view3d = nullptr;
|
||||||
Scene *scene = nullptr;
|
Scene *scene = nullptr;
|
||||||
|
Engine *engine;
|
||||||
std::string render_delegate_name;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pxr::SdfPath prim_id(ID *id, const char *prefix) const;
|
pxr::SdfPath prim_id(ID *id, const char *prefix) const;
|
||||||
|
@ -66,7 +66,8 @@ void InstancerData::update()
|
|||||||
Object *object = (Object *)id;
|
Object *object = (Object *)id;
|
||||||
if (id->recalc & ID_RECALC_GEOMETRY ||
|
if (id->recalc & ID_RECALC_GEOMETRY ||
|
||||||
(object->data && ((ID *)object->data)->recalc & ID_RECALC_GEOMETRY) ||
|
(object->data && ((ID *)object->data)->recalc & ID_RECALC_GEOMETRY) ||
|
||||||
id->recalc & ID_RECALC_TRANSFORM) {
|
id->recalc & ID_RECALC_TRANSFORM)
|
||||||
|
{
|
||||||
set_instances();
|
set_instances();
|
||||||
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(
|
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(
|
||||||
prim_id, pxr::HdChangeTracker::AllDirty);
|
prim_id, pxr::HdChangeTracker::AllDirty);
|
||||||
@ -174,7 +175,8 @@ void InstancerData::check_update(Object *object)
|
|||||||
if (l_it != light_instances_.end()) {
|
if (l_it != light_instances_.end()) {
|
||||||
Object *obj = (Object *)l_it->second.data->id;
|
Object *obj = (Object *)l_it->second.data->id;
|
||||||
if (obj->id.recalc & (ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY) ||
|
if (obj->id.recalc & (ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY) ||
|
||||||
((ID *)obj->data)->recalc & ID_RECALC_GEOMETRY) {
|
((ID *)obj->data)->recalc & ID_RECALC_GEOMETRY)
|
||||||
|
{
|
||||||
set_instances();
|
set_instances();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -27,7 +27,8 @@ void MeshData::init()
|
|||||||
|
|
||||||
Object *object = (Object *)id;
|
Object *object = (Object *)id;
|
||||||
if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT &&
|
if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT &&
|
||||||
BLI_listbase_is_empty(&object->modifiers)) {
|
BLI_listbase_is_empty(&object->modifiers))
|
||||||
|
{
|
||||||
write_mesh((Mesh *)object->data);
|
write_mesh((Mesh *)object->data);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "BLI_path_util.h"
|
#include "BLI_path_util.h"
|
||||||
#include "NOD_shader.h"
|
#include "NOD_shader.h"
|
||||||
|
|
||||||
|
#include "../engine.h"
|
||||||
#include "blender_scene_delegate.h"
|
#include "blender_scene_delegate.h"
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
@ -143,7 +144,7 @@ void WorldData::write_transform()
|
|||||||
transform = pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -90), pxr::GfVec3d());
|
transform = pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -90), pxr::GfVec3d());
|
||||||
|
|
||||||
/* TODO : do this check via RenderSettings*/
|
/* TODO : do this check via RenderSettings*/
|
||||||
if (scene_delegate_->render_delegate_name == "HdRprPlugin") {
|
if (scene_delegate_->engine->render_delegate_name == "HdRprPlugin") {
|
||||||
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -180),
|
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -180),
|
||||||
pxr::GfVec3d());
|
pxr::GfVec3d());
|
||||||
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, 1.0), 90.0),
|
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, 1.0), 90.0),
|
||||||
|
@ -217,16 +217,21 @@ void DrawTexture::free()
|
|||||||
texture_ = nullptr;
|
texture_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ViewportEngine::ViewportEngine(RenderEngine *bl_engine,
|
||||||
|
const std::string &render_delegate_name,
|
||||||
|
SettingsMap &settings)
|
||||||
|
: Engine(bl_engine, render_delegate_name, settings)
|
||||||
|
{
|
||||||
|
type = EngineType::VIEWPORT;
|
||||||
|
}
|
||||||
|
|
||||||
void ViewportEngine::sync(Depsgraph *depsgraph,
|
void ViewportEngine::sync(Depsgraph *depsgraph,
|
||||||
bContext *context,
|
bContext *context,
|
||||||
pxr::HdRenderSettingsMap &render_settings)
|
pxr::HdRenderSettingsMap &render_settings)
|
||||||
{
|
{
|
||||||
if (!scene_delegate_) {
|
if (!scene_delegate_) {
|
||||||
scene_delegate_ = std::make_unique<BlenderSceneDelegate>(
|
scene_delegate_ = std::make_unique<BlenderSceneDelegate>(
|
||||||
render_index_.get(),
|
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), this);
|
||||||
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
|
||||||
BlenderSceneDelegate::EngineType::VIEWPORT,
|
|
||||||
render_delegate_name_);
|
|
||||||
}
|
}
|
||||||
scene_delegate_->populate(depsgraph, context);
|
scene_delegate_->populate(depsgraph, context);
|
||||||
|
|
||||||
|
@ -32,7 +32,9 @@ class DrawTexture {
|
|||||||
|
|
||||||
class ViewportEngine : public Engine {
|
class ViewportEngine : public Engine {
|
||||||
public:
|
public:
|
||||||
using Engine::Engine;
|
ViewportEngine(RenderEngine *bl_engine,
|
||||||
|
const std::string &render_delegate_name,
|
||||||
|
SettingsMap &settings);
|
||||||
|
|
||||||
void sync(Depsgraph *depsgraph,
|
void sync(Depsgraph *depsgraph,
|
||||||
bContext *context,
|
bContext *context,
|
||||||
|
Loading…
Reference in New Issue
Block a user