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");
|
||||
|
||||
Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name, SettingsMap &settings)
|
||||
: bl_engine_(bl_engine), render_delegate_name_(render_delegate_name), settings_(settings)
|
||||
Engine::Engine(RenderEngine *bl_engine,
|
||||
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::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
|
||||
* 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_task_delegate_ = std::make_unique<RenderTaskDelegate>(
|
||||
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>(
|
||||
render_index_.get(),
|
||||
pxr::SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask"));
|
||||
|
@ -27,22 +27,22 @@ typedef pxr::TfHashMap<pxr::TfToken, pxr::VtValue, pxr::TfToken::HashFunctor> Se
|
||||
|
||||
class Engine {
|
||||
public:
|
||||
Engine(RenderEngine *bl_engine,
|
||||
const std::string &render_delegate_name,
|
||||
SettingsMap &settings);
|
||||
enum class EngineType { VIEWPORT = 1, FINAL, PREVIEW };
|
||||
|
||||
Engine(RenderEngine *bl_engine, const std::string &render_delegate_name, SettingsMap &settings);
|
||||
virtual ~Engine() = default;
|
||||
|
||||
virtual void sync(Depsgraph *depsgraph,
|
||||
bContext *context,
|
||||
SettingsMap &render_settings) = 0;
|
||||
virtual void sync(Depsgraph *depsgraph, bContext *context, SettingsMap &render_settings) = 0;
|
||||
virtual void render(Depsgraph *depsgraph) = 0;
|
||||
|
||||
EngineType type;
|
||||
std::string render_delegate_name;
|
||||
SettingsMap settings;
|
||||
|
||||
protected:
|
||||
float renderer_percent_done();
|
||||
|
||||
RenderEngine *bl_engine_;
|
||||
std::string render_delegate_name_;
|
||||
SettingsMap settings_;
|
||||
|
||||
/* The order is important due to deletion order */
|
||||
pxr::HgiUniquePtr hgi_;
|
||||
|
@ -13,15 +13,20 @@
|
||||
|
||||
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,
|
||||
bContext *context,
|
||||
pxr::HdRenderSettingsMap &render_settings)
|
||||
{
|
||||
scene_delegate_ = std::make_unique<BlenderSceneDelegate>(
|
||||
render_index_.get(),
|
||||
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
||||
BlenderSceneDelegate::EngineType::FINAL,
|
||||
render_delegate_name_);
|
||||
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), this);
|
||||
scene_delegate_->populate(depsgraph, context);
|
||||
|
||||
for (auto const &setting : render_settings) {
|
||||
|
@ -9,7 +9,9 @@ namespace blender::render::hydra {
|
||||
|
||||
class FinalEngine : public Engine {
|
||||
public:
|
||||
using Engine::Engine;
|
||||
FinalEngine(RenderEngine *bl_engine,
|
||||
const std::string &render_delegate_name,
|
||||
SettingsMap &settings);
|
||||
|
||||
virtual void sync(Depsgraph *depsgraph,
|
||||
bContext *context,
|
||||
|
@ -13,6 +13,14 @@ const double LIFETIME = 180.0;
|
||||
|
||||
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,
|
||||
const std::string &render_delegate_name,
|
||||
SettingsMap &settings)
|
||||
@ -43,10 +51,7 @@ void PreviewEngine::sync(Depsgraph *depsgraph,
|
||||
{
|
||||
if (!scene_delegate_) {
|
||||
scene_delegate_ = std::make_unique<BlenderSceneDelegate>(
|
||||
render_index_.get(),
|
||||
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
||||
BlenderSceneDelegate::EngineType::PREVIEW,
|
||||
render_delegate_name_);
|
||||
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), this);
|
||||
}
|
||||
scene_delegate_->clear();
|
||||
scene_delegate_->populate(depsgraph, context);
|
||||
@ -102,7 +107,7 @@ void PreviewEngine::update(RenderEngine *bl_engine,
|
||||
SettingsMap &settings)
|
||||
{
|
||||
bl_engine_ = bl_engine;
|
||||
if (render_delegate_name != render_delegate_name_) {
|
||||
if (render_delegate_name != render_delegate_name) {
|
||||
render_delegate_->Stop();
|
||||
instance_.reset(new PreviewEngine(bl_engine, render_delegate_name, settings));
|
||||
}
|
||||
|
@ -9,7 +9,9 @@ namespace blender::render::hydra {
|
||||
|
||||
class PreviewEngine : public FinalEngine {
|
||||
public:
|
||||
using FinalEngine::FinalEngine;
|
||||
PreviewEngine(RenderEngine *bl_engine,
|
||||
const std::string &render_delegate_name,
|
||||
SettingsMap &settings);
|
||||
|
||||
static PreviewEngine *get_instance(RenderEngine *bl_engine,
|
||||
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,
|
||||
pxr::SdfPath const &delegate_id,
|
||||
BlenderSceneDelegate::EngineType engine_type,
|
||||
const std::string &render_delegate_name)
|
||||
: HdSceneDelegate(parent_index, delegate_id),
|
||||
engine_type(engine_type),
|
||||
render_delegate_name(render_delegate_name)
|
||||
Engine *engine)
|
||||
: HdSceneDelegate(parent_index, delegate_id), engine(engine)
|
||||
{
|
||||
}
|
||||
|
||||
@ -376,8 +373,8 @@ void BlenderSceneDelegate::check_updates()
|
||||
DEGIDIterData data = {0};
|
||||
data.graph = depsgraph;
|
||||
data.only_updated = true;
|
||||
ITER_BEGIN (
|
||||
DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) {
|
||||
ITER_BEGIN (DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id)
|
||||
{
|
||||
|
||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE,
|
||||
2,
|
||||
@ -451,7 +448,8 @@ void BlenderSceneDelegate::add_new_objects()
|
||||
DEG_iterator_objects_end,
|
||||
&data,
|
||||
Object *,
|
||||
object) {
|
||||
object)
|
||||
{
|
||||
|
||||
update_objects(object);
|
||||
update_instancers(object);
|
||||
@ -476,7 +474,8 @@ void BlenderSceneDelegate::remove_unused_objects()
|
||||
DEG_iterator_objects_end,
|
||||
&data,
|
||||
Object *,
|
||||
object) {
|
||||
object)
|
||||
{
|
||||
if (ObjectData::is_supported(object)) {
|
||||
available_objects.insert(object_prim_id(object).GetName());
|
||||
}
|
||||
@ -554,7 +553,8 @@ void BlenderSceneDelegate::update_visibility()
|
||||
DEG_iterator_objects_end,
|
||||
&data,
|
||||
Object *,
|
||||
object) {
|
||||
object)
|
||||
{
|
||||
|
||||
if (!object_data(object_prim_id(object))) {
|
||||
update_objects(object);
|
||||
|
@ -21,18 +21,17 @@ namespace blender::render::hydra {
|
||||
|
||||
extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE;
|
||||
|
||||
class Engine;
|
||||
|
||||
class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||
friend ObjectData; /* has access to instances */
|
||||
friend MeshData; /* has access to materials */
|
||||
friend MaterialData; /* has access to objects and instancers */
|
||||
|
||||
public:
|
||||
enum class EngineType { VIEWPORT = 1, FINAL, PREVIEW };
|
||||
|
||||
BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
|
||||
pxr::SdfPath const &delegate_id,
|
||||
BlenderSceneDelegate::EngineType engine_type,
|
||||
const std::string &render_delegate_name);
|
||||
Engine *engine);
|
||||
~BlenderSceneDelegate() override = default;
|
||||
|
||||
/* Delegate methods */
|
||||
@ -56,13 +55,11 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||
void populate(Depsgraph *depsgraph, bContext *context);
|
||||
void clear();
|
||||
|
||||
EngineType engine_type;
|
||||
Depsgraph *depsgraph = nullptr;
|
||||
bContext *context = nullptr;
|
||||
View3D *view3d = nullptr;
|
||||
Scene *scene = nullptr;
|
||||
|
||||
std::string render_delegate_name;
|
||||
Engine *engine;
|
||||
|
||||
private:
|
||||
pxr::SdfPath prim_id(ID *id, const char *prefix) const;
|
||||
|
@ -66,7 +66,8 @@ void InstancerData::update()
|
||||
Object *object = (Object *)id;
|
||||
if (id->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();
|
||||
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(
|
||||
prim_id, pxr::HdChangeTracker::AllDirty);
|
||||
@ -174,7 +175,8 @@ void InstancerData::check_update(Object *object)
|
||||
if (l_it != light_instances_.end()) {
|
||||
Object *obj = (Object *)l_it->second.data->id;
|
||||
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();
|
||||
}
|
||||
return;
|
||||
|
@ -27,7 +27,8 @@ void MeshData::init()
|
||||
|
||||
Object *object = (Object *)id;
|
||||
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);
|
||||
}
|
||||
else {
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "BLI_path_util.h"
|
||||
#include "NOD_shader.h"
|
||||
|
||||
#include "../engine.h"
|
||||
#include "blender_scene_delegate.h"
|
||||
#include "image.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());
|
||||
|
||||
/* 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),
|
||||
pxr::GfVec3d());
|
||||
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, 1.0), 90.0),
|
||||
|
@ -217,16 +217,21 @@ void DrawTexture::free()
|
||||
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,
|
||||
bContext *context,
|
||||
pxr::HdRenderSettingsMap &render_settings)
|
||||
{
|
||||
if (!scene_delegate_) {
|
||||
scene_delegate_ = std::make_unique<BlenderSceneDelegate>(
|
||||
render_index_.get(),
|
||||
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
||||
BlenderSceneDelegate::EngineType::VIEWPORT,
|
||||
render_delegate_name_);
|
||||
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), this);
|
||||
}
|
||||
scene_delegate_->populate(depsgraph, context);
|
||||
|
||||
|
@ -32,7 +32,9 @@ class DrawTexture {
|
||||
|
||||
class ViewportEngine : public Engine {
|
||||
public:
|
||||
using Engine::Engine;
|
||||
ViewportEngine(RenderEngine *bl_engine,
|
||||
const std::string &render_delegate_name,
|
||||
SettingsMap &settings);
|
||||
|
||||
void sync(Depsgraph *depsgraph,
|
||||
bContext *context,
|
||||
|
Loading…
Reference in New Issue
Block a user