forked from blender/blender
BLEN-367: Fix code style #14
@ -14,12 +14,12 @@
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
Engine::Engine(RenderEngine *bl_engine, const std::string &delegateId) : bl_engine(bl_engine)
|
Engine::Engine(RenderEngine *bl_engine, const std::string &delegate_id) : 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(delegateId));
|
render_delegate = registry.CreateRenderDelegate(pxr::TfToken(delegate_id));
|
||||||
|
|
||||||
pxr::HdDriverVector hd_drivers;
|
pxr::HdDriverVector hd_drivers;
|
||||||
if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) {
|
if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) {
|
||||||
|
@ -28,7 +28,7 @@ class Engine {
|
|||||||
|
|
||||||
virtual void sync(Depsgraph *depsgraph,
|
virtual void sync(Depsgraph *depsgraph,
|
||||||
bContext *context,
|
bContext *context,
|
||||||
pxr::HdRenderSettingsMap &renderSettings) = 0;
|
pxr::HdRenderSettingsMap &render_settings) = 0;
|
||||||
virtual void render(Depsgraph *depsgraph) = 0;
|
virtual void render(Depsgraph *depsgraph) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -16,15 +16,15 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
void FinalEngine::sync(Depsgraph *depsgraph,
|
void FinalEngine::sync(Depsgraph *depsgraph,
|
||||||
bContext *context,
|
bContext *context,
|
||||||
pxr::HdRenderSettingsMap &renderSettings)
|
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"),
|
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
||||||
BlenderSceneDelegate::EngineType::Final);
|
BlenderSceneDelegate::EngineType::FINAL);
|
||||||
scene_delegate->populate(depsgraph, context);
|
scene_delegate->populate(depsgraph, context);
|
||||||
|
|
||||||
for (auto const &setting : renderSettings) {
|
for (auto const &setting : render_settings) {
|
||||||
render_delegate->SetRenderSetting(setting.first, setting.second);
|
render_delegate->SetRenderSetting(setting.first, setting.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,28 +52,28 @@ void FinalEngine::render(Depsgraph *depsgraph)
|
|||||||
CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border);
|
CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border);
|
||||||
|
|
||||||
free_camera_delegate->SetCamera(camera);
|
free_camera_delegate->SetCamera(camera);
|
||||||
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
|
render_task_delegate->set_camera_and_viewport(free_camera_delegate->GetCameraId(),
|
||||||
pxr::GfVec4d(0, 0, res[0], res[1]));
|
pxr::GfVec4d(0, 0, res[0], res[1]));
|
||||||
render_task_delegate->SetRendererAov(pxr::HdAovTokens->color);
|
render_task_delegate->set_renderer_aov(pxr::HdAovTokens->color);
|
||||||
if (simple_light_task_delegate) {
|
if (simple_light_task_delegate) {
|
||||||
simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId());
|
simple_light_task_delegate->set_camera_path(free_camera_delegate->GetCameraId());
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::HdTaskSharedPtrVector tasks;
|
pxr::HdTaskSharedPtrVector tasks;
|
||||||
if (simple_light_task_delegate) {
|
if (simple_light_task_delegate) {
|
||||||
tasks.push_back(simple_light_task_delegate->GetTask());
|
tasks.push_back(simple_light_task_delegate->get_task());
|
||||||
}
|
}
|
||||||
tasks.push_back(render_task_delegate->GetTask());
|
tasks.push_back(render_task_delegate->get_task());
|
||||||
|
|
||||||
std::chrono::time_point<std::chrono::steady_clock> timeBegin = std::chrono::steady_clock::now(),
|
std::chrono::time_point<std::chrono::steady_clock> time_begin = std::chrono::steady_clock::now(),
|
||||||
timeCurrent;
|
time_current;
|
||||||
std::chrono::milliseconds elapsedTime;
|
std::chrono::milliseconds elapsed_time;
|
||||||
|
|
||||||
float percentDone = 0.0;
|
float percent_done = 0.0;
|
||||||
|
|
||||||
std::map<std::string, std::vector<float>> renderImages{
|
std::map<std::string, std::vector<float>> render_images{
|
||||||
{"Combined", std::vector<float>(res[0] * res[1] * 4)}}; // 4 - number of channels
|
{"Combined", std::vector<float>(res[0] * res[1] * 4)}}; // 4 - number of channels
|
||||||
std::vector<float> &pixels = renderImages["Combined"];
|
std::vector<float> &pixels = render_images["Combined"];
|
||||||
|
|
||||||
{
|
{
|
||||||
// Release the GIL before calling into hydra, in case any hydra plugins call into python.
|
// Release the GIL before calling into hydra, in case any hydra plugins call into python.
|
||||||
@ -86,25 +86,26 @@ void FinalEngine::render(Depsgraph *depsgraph)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
percentDone = renderer_percent_done();
|
percent_done = renderer_percent_done();
|
||||||
timeCurrent = std::chrono::steady_clock::now();
|
time_current = std::chrono::steady_clock::now();
|
||||||
elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(timeCurrent - timeBegin);
|
elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(time_current -
|
||||||
|
time_begin);
|
||||||
|
|
||||||
notify_status(percentDone / 100.0,
|
notify_status(percent_done / 100.0,
|
||||||
scene_name + ": " + layer_name,
|
scene_name + ": " + layer_name,
|
||||||
"Render Time: " + format_duration(elapsedTime) +
|
"Render Time: " + format_duration(elapsed_time) +
|
||||||
" | Done: " + std::to_string(int(percentDone)) + "%");
|
" | Done: " + std::to_string(int(percent_done)) + "%");
|
||||||
|
|
||||||
if (render_task_delegate->IsConverged()) {
|
if (render_task_delegate->is_converged()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data());
|
render_task_delegate->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
|
||||||
updateRenderResult(renderImages, layer_name, res[0], res[1]);
|
update_render_result(render_images, layer_name, res[0], res[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data());
|
render_task_delegate->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
|
||||||
updateRenderResult(renderImages, layer_name, res[0], res[1]);
|
update_render_result(render_images, layer_name, res[0], res[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::GfVec2i FinalEngine::get_resolution(Scene *scene)
|
pxr::GfVec2i FinalEngine::get_resolution(Scene *scene)
|
||||||
@ -119,19 +120,19 @@ pxr::GfVec2i FinalEngine::get_resolution(Scene *scene)
|
|||||||
int(r.ysch * border_h * r.size / 100));
|
int(r.ysch * border_h * r.size / 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FinalEngine::updateRenderResult(std::map<std::string, std::vector<float>> &renderImages,
|
void FinalEngine::update_render_result(std::map<std::string, std::vector<float>> &render_images,
|
||||||
const std::string &layerName,
|
const std::string &layer_name,
|
||||||
int width,
|
int width,
|
||||||
int height)
|
int height)
|
||||||
{
|
{
|
||||||
RenderResult *result = RE_engine_begin_result(
|
RenderResult *result = RE_engine_begin_result(
|
||||||
bl_engine, 0, 0, width, height, layerName.c_str(), nullptr);
|
bl_engine, 0, 0, width, height, layer_name.c_str(), nullptr);
|
||||||
|
|
||||||
/* TODO: only for the first render layer */
|
/* TODO: only for the first render layer */
|
||||||
RenderLayer *layer = (RenderLayer *)result->layers.first;
|
RenderLayer *layer = (RenderLayer *)result->layers.first;
|
||||||
for (RenderPass *pass = (RenderPass *)layer->passes.first; pass != nullptr; pass = pass->next) {
|
for (RenderPass *pass = (RenderPass *)layer->passes.first; pass != nullptr; pass = pass->next) {
|
||||||
auto it_image = renderImages.find(pass->name);
|
auto it_image = render_images.find(pass->name);
|
||||||
if (it_image == renderImages.end()) {
|
if (it_image == render_images.end()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
memcpy(pass->rect,
|
memcpy(pass->rect,
|
||||||
@ -171,10 +172,10 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
|
|||||||
CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border);
|
CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border);
|
||||||
|
|
||||||
free_camera_delegate->SetCamera(camera);
|
free_camera_delegate->SetCamera(camera);
|
||||||
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
|
render_task_delegate->set_camera_and_viewport(free_camera_delegate->GetCameraId(),
|
||||||
pxr::GfVec4d(0, 0, res[0], res[1]));
|
pxr::GfVec4d(0, 0, res[0], res[1]));
|
||||||
if (simple_light_task_delegate) {
|
if (simple_light_task_delegate) {
|
||||||
simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId());
|
simple_light_task_delegate->set_camera_path(free_camera_delegate->GetCameraId());
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::HdTaskSharedPtrVector tasks;
|
pxr::HdTaskSharedPtrVector tasks;
|
||||||
@ -182,30 +183,30 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
|
|||||||
/* TODO: Uncomment this and fix GL error:
|
/* TODO: Uncomment this and fix GL error:
|
||||||
invalid operation, reported from void __cdecl
|
invalid operation, reported from void __cdecl
|
||||||
pxrInternal_v0_22__pxrReserved__::HgiGLResourceBindings::BindResources(void) */
|
pxrInternal_v0_22__pxrReserved__::HgiGLResourceBindings::BindResources(void) */
|
||||||
// tasks.push_back(simple_light_task_delegate->GetTask());
|
// tasks.push_back(simple_light_task_delegate->get_task());
|
||||||
}
|
}
|
||||||
tasks.push_back(render_task_delegate->GetTask());
|
tasks.push_back(render_task_delegate->get_task());
|
||||||
|
|
||||||
std::chrono::time_point<std::chrono::steady_clock> timeBegin = std::chrono::steady_clock::now(),
|
std::chrono::time_point<std::chrono::steady_clock> time_begin = std::chrono::steady_clock::now(),
|
||||||
timeCurrent;
|
time_current;
|
||||||
std::chrono::milliseconds elapsedTime;
|
std::chrono::milliseconds elapsed_time;
|
||||||
|
|
||||||
float percentDone = 0.0;
|
float percent_done = 0.0;
|
||||||
|
|
||||||
std::map<std::string, std::vector<float>> renderImages{
|
std::map<std::string, std::vector<float>> render_images{
|
||||||
{"Combined", std::vector<float>(res[0] * res[1] * 4)}}; // 4 - number of channels
|
{"Combined", std::vector<float>(res[0] * res[1] * 4)}}; // 4 - number of channels
|
||||||
std::vector<float> &pixels = renderImages["Combined"];
|
std::vector<float> &pixels = render_images["Combined"];
|
||||||
|
|
||||||
GLuint FramebufferName = 0;
|
GLuint framebuffer_name = 0;
|
||||||
glGenFramebuffers(1, &FramebufferName);
|
glGenFramebuffers(1, &framebuffer_name);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
|
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_name);
|
||||||
|
|
||||||
// The texture we're going to render to
|
// The texture we're going to render to
|
||||||
GLuint renderedTexture;
|
GLuint rendered_texture;
|
||||||
glGenTextures(1, &renderedTexture);
|
glGenTextures(1, &rendered_texture);
|
||||||
|
|
||||||
// "Bind" the newly created texture : all future texture functions will modify this texture
|
// "Bind" the newly created texture : all future texture functions will modify this texture
|
||||||
glBindTexture(GL_TEXTURE_2D, renderedTexture);
|
glBindTexture(GL_TEXTURE_2D, rendered_texture);
|
||||||
|
|
||||||
// Give an empty image to OpenGL ( the last "0" )
|
// Give an empty image to OpenGL ( the last "0" )
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, res[0], res[1], 0, GL_RGBA, GL_FLOAT, 0);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, res[0], res[1], 0, GL_RGBA, GL_FLOAT, 0);
|
||||||
@ -214,13 +215,13 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
// Set "renderedTexture" as our colour attachement #0
|
// Set "rendered_texture" as our colour attachement #0
|
||||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexture, 0);
|
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, rendered_texture, 0);
|
||||||
|
|
||||||
// Generate vertex array
|
// Generate vertex array
|
||||||
GLuint VAO;
|
GLuint vao;
|
||||||
glGenVertexArrays(1, &VAO);
|
glGenVertexArrays(1, &vao);
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(vao);
|
||||||
|
|
||||||
{
|
{
|
||||||
// Release the GIL before calling into hydra, in case any hydra plugins call into python.
|
// Release the GIL before calling into hydra, in case any hydra plugins call into python.
|
||||||
@ -233,25 +234,26 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
percentDone = renderer_percent_done();
|
percent_done = renderer_percent_done();
|
||||||
timeCurrent = std::chrono::steady_clock::now();
|
time_current = std::chrono::steady_clock::now();
|
||||||
elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(timeCurrent - timeBegin);
|
elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(time_current -
|
||||||
|
time_begin);
|
||||||
|
|
||||||
notify_status(percentDone / 100.0,
|
notify_status(percent_done / 100.0,
|
||||||
scene_name + ": " + layer_name,
|
scene_name + ": " + layer_name,
|
||||||
"Render Time: " + format_duration(elapsedTime) +
|
"Render Time: " + format_duration(elapsed_time) +
|
||||||
" | Done: " + std::to_string(int(percentDone)) + "%");
|
" | Done: " + std::to_string(int(percent_done)) + "%");
|
||||||
|
|
||||||
if (render_task_delegate->IsConverged()) {
|
if (render_task_delegate->is_converged()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, pixels.data());
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, pixels.data());
|
||||||
updateRenderResult(renderImages, layer_name, res[0], res[1]);
|
update_render_result(render_images, layer_name, res[0], res[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, pixels.data());
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, pixels.data());
|
||||||
updateRenderResult(renderImages, layer_name, res[0], res[1]);
|
update_render_result(render_images, layer_name, res[0], res[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -14,19 +14,19 @@ class FinalEngine : public Engine {
|
|||||||
using Engine::Engine;
|
using Engine::Engine;
|
||||||
virtual void sync(Depsgraph *depsgraph,
|
virtual void sync(Depsgraph *depsgraph,
|
||||||
bContext *context,
|
bContext *context,
|
||||||
pxr::HdRenderSettingsMap &renderSettings) override;
|
pxr::HdRenderSettingsMap &render_settings) override;
|
||||||
virtual void render(Depsgraph *b_depsgraph) override;
|
virtual void render(Depsgraph *b_depsgraph) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
pxr::GfVec2i get_resolution(Scene *scene);
|
pxr::GfVec2i get_resolution(Scene *scene);
|
||||||
void updateRenderResult(std::map<std::string, std::vector<float>> &render_images,
|
void update_render_result(std::map<std::string, std::vector<float>> &render_images,
|
||||||
const std::string &layerName,
|
const std::string &layer_name,
|
||||||
int width,
|
int width,
|
||||||
int height);
|
int height);
|
||||||
void notify_status(float progress, const std::string &title, const std::string &info);
|
void notify_status(float progress, const std::string &title, const std::string &info);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
pxr::HdRenderSettingsMap renderSettings;
|
pxr::HdRenderSettingsMap render_settings;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FinalEngineGL : public FinalEngine {
|
class FinalEngineGL : public FinalEngine {
|
||||||
|
@ -10,15 +10,15 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
void PreviewEngine::sync(Depsgraph *depsgraph,
|
void PreviewEngine::sync(Depsgraph *depsgraph,
|
||||||
bContext *context,
|
bContext *context,
|
||||||
pxr::HdRenderSettingsMap &renderSettings)
|
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"),
|
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
||||||
BlenderSceneDelegate::EngineType::Preview);
|
BlenderSceneDelegate::EngineType::PREVIEW);
|
||||||
scene_delegate->populate(depsgraph, context);
|
scene_delegate->populate(depsgraph, context);
|
||||||
|
|
||||||
for (auto const &setting : renderSettings) {
|
for (auto const &setting : render_settings) {
|
||||||
render_delegate->SetRenderSetting(setting.first, setting.second);
|
render_delegate->SetRenderSetting(setting.first, setting.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -28,22 +28,22 @@ void PreviewEngine::render(Depsgraph *depsgraph)
|
|||||||
Scene *scene = DEG_get_input_scene(depsgraph);
|
Scene *scene = DEG_get_input_scene(depsgraph);
|
||||||
ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
|
ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
|
||||||
|
|
||||||
std::string layerName = view_layer->name;
|
std::string layer_name = view_layer->name;
|
||||||
pxr::GfVec2i res(scene->r.xsch, scene->r.ysch);
|
pxr::GfVec2i res(scene->r.xsch, scene->r.ysch);
|
||||||
|
|
||||||
pxr::GfCamera camera =
|
pxr::GfCamera camera =
|
||||||
CameraData(scene->camera, res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(pxr::GfVec4f(0, 0, 1, 1));
|
CameraData(scene->camera, res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(pxr::GfVec4f(0, 0, 1, 1));
|
||||||
|
|
||||||
free_camera_delegate->SetCamera(camera);
|
free_camera_delegate->SetCamera(camera);
|
||||||
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
|
render_task_delegate->set_camera_and_viewport(free_camera_delegate->GetCameraId(),
|
||||||
pxr::GfVec4d(0, 0, res[0], res[1]));
|
pxr::GfVec4d(0, 0, res[0], res[1]));
|
||||||
render_task_delegate->SetRendererAov(pxr::HdAovTokens->color);
|
render_task_delegate->set_renderer_aov(pxr::HdAovTokens->color);
|
||||||
|
|
||||||
pxr::HdTaskSharedPtrVector tasks;
|
pxr::HdTaskSharedPtrVector tasks;
|
||||||
if (simple_light_task_delegate) {
|
if (simple_light_task_delegate) {
|
||||||
tasks.push_back(simple_light_task_delegate->GetTask());
|
tasks.push_back(simple_light_task_delegate->get_task());
|
||||||
}
|
}
|
||||||
tasks.push_back(render_task_delegate->GetTask());
|
tasks.push_back(render_task_delegate->get_task());
|
||||||
|
|
||||||
std::vector<float> pixels = std::vector<float>(res[0] * res[1] * 4); // 4 - number of channels
|
std::vector<float> pixels = std::vector<float>(res[0] * res[1] * 4); // 4 - number of channels
|
||||||
|
|
||||||
@ -58,25 +58,25 @@ void PreviewEngine::render(Depsgraph *depsgraph)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (render_task_delegate->IsConverged()) {
|
if (render_task_delegate->is_converged()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data());
|
render_task_delegate->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
|
||||||
updateRenderResult(layerName, res[0], res[1], pixels);
|
update_render_result(layer_name, res[0], res[1], pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data());
|
render_task_delegate->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
|
||||||
updateRenderResult(layerName, res[0], res[1], pixels);
|
update_render_result(layer_name, res[0], res[1], pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewEngine::updateRenderResult(const std::string &layerName,
|
void PreviewEngine::update_render_result(const std::string &layer_name,
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
std::vector<float> &pixels)
|
std::vector<float> &pixels)
|
||||||
{
|
{
|
||||||
RenderResult *result = RE_engine_begin_result(
|
RenderResult *result = RE_engine_begin_result(
|
||||||
bl_engine, 0, 0, width, height, layerName.c_str(), nullptr);
|
bl_engine, 0, 0, width, height, layer_name.c_str(), nullptr);
|
||||||
|
|
||||||
RenderLayer *layer = (RenderLayer *)result->layers.first;
|
RenderLayer *layer = (RenderLayer *)result->layers.first;
|
||||||
RenderPass *pass = (RenderPass *)layer->passes.first;
|
RenderPass *pass = (RenderPass *)layer->passes.first;
|
||||||
|
@ -12,17 +12,17 @@ class PreviewEngine : public FinalEngine {
|
|||||||
using FinalEngine::FinalEngine;
|
using FinalEngine::FinalEngine;
|
||||||
void sync(Depsgraph *depsgraph,
|
void sync(Depsgraph *depsgraph,
|
||||||
bContext *context,
|
bContext *context,
|
||||||
pxr::HdRenderSettingsMap &renderSettings) override;
|
pxr::HdRenderSettingsMap &render_settings) override;
|
||||||
void render(Depsgraph *depsgraph) override;
|
void render(Depsgraph *depsgraph) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateRenderResult(const std::string &layerName,
|
void update_render_result(const std::string &layer_name,
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
std::vector<float> &pixels);
|
std::vector<float> &pixels);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
pxr::HdRenderSettingsMap renderSettings;
|
pxr::HdRenderSettingsMap render_settings;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -135,8 +135,8 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args)
|
|||||||
LOG(INFO) << "create_func";
|
LOG(INFO) << "create_func";
|
||||||
|
|
||||||
PyObject *pyengine;
|
PyObject *pyengine;
|
||||||
char *engineType, *render_delegate_id;
|
char *engine_type, *render_delegate_id;
|
||||||
if (!PyArg_ParseTuple(args, "Oss", &pyengine, &engineType, &render_delegate_id)) {
|
if (!PyArg_ParseTuple(args, "Oss", &pyengine, &engine_type, &render_delegate_id)) {
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,10 +144,10 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args)
|
|||||||
|
|
||||||
Engine *engine;
|
Engine *engine;
|
||||||
|
|
||||||
if (std::string(engineType) == "VIEWPORT") {
|
if (std::string(engine_type) == "VIEWPORT") {
|
||||||
engine = new ViewportEngine(bl_engine, render_delegate_id);
|
engine = new ViewportEngine(bl_engine, render_delegate_id);
|
||||||
}
|
}
|
||||||
else if (std::string(engineType) == "PREVIEW") {
|
else if (std::string(engine_type) == "PREVIEW") {
|
||||||
engine = new PreviewEngine(bl_engine, render_delegate_id);
|
engine = new PreviewEngine(bl_engine, render_delegate_id);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -13,27 +13,27 @@
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
RenderTaskDelegate::RenderTaskDelegate(pxr::HdRenderIndex *parentIndex,
|
RenderTaskDelegate::RenderTaskDelegate(pxr::HdRenderIndex *parent_index,
|
||||||
pxr::SdfPath const &delegateID)
|
pxr::SdfPath const &delegate_id)
|
||||||
: pxr::HdSceneDelegate(parentIndex, delegateID)
|
: pxr::HdSceneDelegate(parent_index, delegate_id)
|
||||||
{
|
{
|
||||||
pxr::SdfPath renderTaskId = GetTaskID();
|
pxr::SdfPath render_task_id = get_task_id();
|
||||||
GetRenderIndex().InsertTask<pxr::HdxRenderTask>(this, renderTaskId);
|
GetRenderIndex().InsertTask<pxr::HdxRenderTask>(this, render_task_id);
|
||||||
GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId,
|
GetRenderIndex().GetChangeTracker().MarkTaskDirty(render_task_id,
|
||||||
pxr::HdChangeTracker::DirtyCollection);
|
pxr::HdChangeTracker::DirtyCollection);
|
||||||
GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId,
|
GetRenderIndex().GetChangeTracker().MarkTaskDirty(render_task_id,
|
||||||
pxr::HdChangeTracker::DirtyRenderTags);
|
pxr::HdChangeTracker::DirtyRenderTags);
|
||||||
|
|
||||||
taskParams.enableLighting = true;
|
task_params.enableLighting = true;
|
||||||
taskParams.alphaThreshold = 0.1f;
|
task_params.alphaThreshold = 0.1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::SdfPath RenderTaskDelegate::GetTaskID() const
|
pxr::SdfPath RenderTaskDelegate::get_task_id() const
|
||||||
{
|
{
|
||||||
return GetDelegateID().AppendElementString("task");
|
return GetDelegateID().AppendElementString("task");
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::SdfPath RenderTaskDelegate::GetAovID(pxr::TfToken const &aov) const
|
pxr::SdfPath RenderTaskDelegate::get_aov_id(pxr::TfToken const &aov) const
|
||||||
{
|
{
|
||||||
return GetDelegateID().AppendElementString("aov_" + aov.GetString());
|
return GetDelegateID().AppendElementString("aov_" + aov.GetString());
|
||||||
}
|
}
|
||||||
@ -42,15 +42,15 @@ pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const
|
|||||||
{
|
{
|
||||||
LOG(INFO) << "RenderTaskDelegate::Get - " << id.GetAsString() << " " << key.GetString() << "\n";
|
LOG(INFO) << "RenderTaskDelegate::Get - " << id.GetAsString() << " " << key.GetString() << "\n";
|
||||||
if (key == pxr::HdTokens->params) {
|
if (key == pxr::HdTokens->params) {
|
||||||
return pxr::VtValue(taskParams);
|
return pxr::VtValue(task_params);
|
||||||
}
|
}
|
||||||
if (key == pxr::HdTokens->collection) {
|
if (key == pxr::HdTokens->collection) {
|
||||||
pxr::HdRprimCollection rprimCollection(pxr::HdTokens->geometry,
|
pxr::HdRprimCollection rprim_collection(pxr::HdTokens->geometry,
|
||||||
pxr::HdReprSelector(pxr::HdReprTokens->smoothHull),
|
pxr::HdReprSelector(pxr::HdReprTokens->smoothHull),
|
||||||
false,
|
false,
|
||||||
pxr::TfToken());
|
pxr::TfToken());
|
||||||
rprimCollection.SetRootPath(pxr::SdfPath::AbsoluteRootPath());
|
rprim_collection.SetRootPath(pxr::SdfPath::AbsoluteRootPath());
|
||||||
return pxr::VtValue(rprimCollection);
|
return pxr::VtValue(rprim_collection);
|
||||||
}
|
}
|
||||||
return pxr::VtValue();
|
return pxr::VtValue();
|
||||||
}
|
}
|
||||||
@ -58,81 +58,81 @@ pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const
|
|||||||
pxr::HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(pxr::SdfPath const &id)
|
pxr::HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(pxr::SdfPath const &id)
|
||||||
{
|
{
|
||||||
LOG(INFO) << "RenderTaskDelegate::GetRenderBufferDescriptor - " << id.GetAsString() << "\n";
|
LOG(INFO) << "RenderTaskDelegate::GetRenderBufferDescriptor - " << id.GetAsString() << "\n";
|
||||||
return bufferDescriptors[id];
|
return buffer_descriptors[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::TfTokenVector RenderTaskDelegate::GetTaskRenderTags(pxr::SdfPath const &taskId)
|
pxr::TfTokenVector RenderTaskDelegate::GetTaskRenderTags(pxr::SdfPath const &task_id)
|
||||||
{
|
{
|
||||||
LOG(INFO) << "RenderTaskDelegate::GetTaskRenderTags - " << taskId.GetAsString() << "\n";
|
LOG(INFO) << "RenderTaskDelegate::GetTaskRenderTags - " << task_id.GetAsString() << "\n";
|
||||||
return {pxr::HdRenderTagTokens->geometry};
|
return {pxr::HdRenderTagTokens->geometry};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderTaskDelegate::IsConverged()
|
bool RenderTaskDelegate::is_converged()
|
||||||
{
|
{
|
||||||
pxr::HdTaskSharedPtr renderTask = GetRenderIndex().GetTask(GetTaskID());
|
pxr::HdTaskSharedPtr renderTask = GetRenderIndex().GetTask(get_task_id());
|
||||||
return ((pxr::HdxRenderTask &)*renderTask).IsConverged();
|
return ((pxr::HdxRenderTask &)*renderTask).IsConverged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderTaskDelegate::SetRendererAov(pxr::TfToken const &aov)
|
void RenderTaskDelegate::set_renderer_aov(pxr::TfToken const &aov)
|
||||||
{
|
{
|
||||||
pxr::HdAovDescriptor aovDesc = GetRenderIndex().GetRenderDelegate()->GetDefaultAovDescriptor(
|
pxr::HdAovDescriptor aov_desc = GetRenderIndex().GetRenderDelegate()->GetDefaultAovDescriptor(
|
||||||
aov);
|
aov);
|
||||||
pxr::HdRenderBufferDescriptor desc(
|
pxr::HdRenderBufferDescriptor desc(
|
||||||
pxr::GfVec3i(taskParams.viewport[2], taskParams.viewport[3], 1),
|
pxr::GfVec3i(task_params.viewport[2], task_params.viewport[3], 1),
|
||||||
aovDesc.format,
|
aov_desc.format,
|
||||||
aovDesc.multiSampled);
|
aov_desc.multiSampled);
|
||||||
pxr::SdfPath bufferId = GetAovID(aov);
|
pxr::SdfPath buffer_id = get_aov_id(aov);
|
||||||
|
|
||||||
if (bufferDescriptors.find(bufferId) == bufferDescriptors.end()) {
|
if (buffer_descriptors.find(buffer_id) == buffer_descriptors.end()) {
|
||||||
GetRenderIndex().InsertBprim(pxr::HdPrimTypeTokens->renderBuffer, this, bufferId);
|
GetRenderIndex().InsertBprim(pxr::HdPrimTypeTokens->renderBuffer, this, buffer_id);
|
||||||
bufferDescriptors[bufferId] = desc;
|
buffer_descriptors[buffer_id] = desc;
|
||||||
GetRenderIndex().GetChangeTracker().MarkBprimDirty(bufferId,
|
GetRenderIndex().GetChangeTracker().MarkBprimDirty(buffer_id,
|
||||||
pxr::HdRenderBuffer::DirtyDescription);
|
pxr::HdRenderBuffer::DirtyDescription);
|
||||||
|
|
||||||
pxr::HdRenderPassAovBinding binding;
|
pxr::HdRenderPassAovBinding binding;
|
||||||
binding.aovName = aov;
|
binding.aovName = aov;
|
||||||
binding.renderBufferId = bufferId;
|
binding.renderBufferId = buffer_id;
|
||||||
binding.aovSettings = aovDesc.aovSettings;
|
binding.aovSettings = aov_desc.aovSettings;
|
||||||
taskParams.aovBindings.push_back(binding);
|
task_params.aovBindings.push_back(binding);
|
||||||
|
|
||||||
GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(),
|
GetRenderIndex().GetChangeTracker().MarkTaskDirty(get_task_id(),
|
||||||
pxr::HdChangeTracker::DirtyParams);
|
pxr::HdChangeTracker::DirtyParams);
|
||||||
}
|
}
|
||||||
else if (bufferDescriptors[bufferId] != desc) {
|
else if (buffer_descriptors[buffer_id] != desc) {
|
||||||
bufferDescriptors[bufferId] = desc;
|
buffer_descriptors[buffer_id] = desc;
|
||||||
GetRenderIndex().GetChangeTracker().MarkBprimDirty(bufferId,
|
GetRenderIndex().GetChangeTracker().MarkBprimDirty(buffer_id,
|
||||||
pxr::HdRenderBuffer::DirtyDescription);
|
pxr::HdRenderBuffer::DirtyDescription);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::HdRenderBuffer *RenderTaskDelegate::GetRendererAov(pxr::TfToken const &aov)
|
pxr::HdRenderBuffer *RenderTaskDelegate::get_renderer_aov(pxr::TfToken const &aov)
|
||||||
{
|
{
|
||||||
return (pxr::HdRenderBuffer *)(GetRenderIndex().GetBprim(pxr::HdPrimTypeTokens->renderBuffer,
|
return (pxr::HdRenderBuffer *)(GetRenderIndex().GetBprim(pxr::HdPrimTypeTokens->renderBuffer,
|
||||||
GetAovID(aov)));
|
get_aov_id(aov)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderTaskDelegate::GetRendererAovData(pxr::TfToken const &aov, void *data)
|
void RenderTaskDelegate::get_renderer_aov_data(pxr::TfToken const &aov, void *data)
|
||||||
{
|
{
|
||||||
pxr::HdRenderBuffer *buffer = GetRendererAov(aov);
|
pxr::HdRenderBuffer *buffer = get_renderer_aov(aov);
|
||||||
void *bufData = buffer->Map();
|
void *buf_data = buffer->Map();
|
||||||
memcpy(data,
|
memcpy(data,
|
||||||
bufData,
|
buf_data,
|
||||||
buffer->GetWidth() * buffer->GetHeight() * pxr::HdDataSizeOfFormat(buffer->GetFormat()));
|
buffer->GetWidth() * buffer->GetHeight() * pxr::HdDataSizeOfFormat(buffer->GetFormat()));
|
||||||
buffer->Unmap();
|
buffer->Unmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::HdTaskSharedPtr RenderTaskDelegate::GetTask()
|
pxr::HdTaskSharedPtr RenderTaskDelegate::get_task()
|
||||||
{
|
{
|
||||||
return GetRenderIndex().GetTask(GetTaskID());
|
return GetRenderIndex().GetTask(get_task_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderTaskDelegate::SetCameraAndViewport(pxr::SdfPath const &cameraId,
|
void RenderTaskDelegate::set_camera_and_viewport(pxr::SdfPath const &camera_id,
|
||||||
pxr::GfVec4d const &viewport)
|
pxr::GfVec4d const &viewport)
|
||||||
{
|
{
|
||||||
if (taskParams.viewport != viewport || taskParams.camera != cameraId) {
|
if (task_params.viewport != viewport || task_params.camera != camera_id) {
|
||||||
taskParams.viewport = viewport;
|
task_params.viewport = viewport;
|
||||||
taskParams.camera = cameraId;
|
task_params.camera = camera_id;
|
||||||
GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(),
|
GetRenderIndex().GetChangeTracker().MarkTaskDirty(get_task_id(),
|
||||||
pxr::HdChangeTracker::DirtyParams);
|
pxr::HdChangeTracker::DirtyParams);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,28 +10,28 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
class RenderTaskDelegate : public pxr::HdSceneDelegate {
|
class RenderTaskDelegate : public pxr::HdSceneDelegate {
|
||||||
public:
|
public:
|
||||||
RenderTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegateID);
|
RenderTaskDelegate(pxr::HdRenderIndex *parent_index, pxr::SdfPath const &delegate_id);
|
||||||
~RenderTaskDelegate() override = default;
|
~RenderTaskDelegate() override = default;
|
||||||
|
|
||||||
pxr::SdfPath GetTaskID() const;
|
pxr::SdfPath get_task_id() const;
|
||||||
pxr::SdfPath GetAovID(pxr::TfToken const &aov) const;
|
pxr::SdfPath get_aov_id(pxr::TfToken const &aov) const;
|
||||||
|
|
||||||
pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override;
|
pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override;
|
||||||
pxr::HdRenderBufferDescriptor GetRenderBufferDescriptor(pxr::SdfPath const &id) override;
|
pxr::HdRenderBufferDescriptor GetRenderBufferDescriptor(pxr::SdfPath const &id) override;
|
||||||
pxr::TfTokenVector GetTaskRenderTags(pxr::SdfPath const &taskId) override;
|
pxr::TfTokenVector GetTaskRenderTags(pxr::SdfPath const &taskId) override;
|
||||||
|
|
||||||
bool IsConverged();
|
bool is_converged();
|
||||||
void SetRendererAov(pxr::TfToken const &aovId);
|
void set_renderer_aov(pxr::TfToken const &aovId);
|
||||||
pxr::HdRenderBuffer *GetRendererAov(pxr::TfToken const &id);
|
pxr::HdRenderBuffer *get_renderer_aov(pxr::TfToken const &id);
|
||||||
void GetRendererAovData(pxr::TfToken const &id, void *buf);
|
void get_renderer_aov_data(pxr::TfToken const &id, void *buf);
|
||||||
|
|
||||||
pxr::HdTaskSharedPtr GetTask();
|
pxr::HdTaskSharedPtr get_task();
|
||||||
void SetCameraAndViewport(pxr::SdfPath const &cameraId, pxr::GfVec4d const &viewport);
|
void set_camera_and_viewport(pxr::SdfPath const &cameraId, pxr::GfVec4d const &viewport);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pxr::HdxRenderTaskParams taskParams;
|
pxr::HdxRenderTaskParams task_params;
|
||||||
pxr::TfHashMap<pxr::SdfPath, pxr::HdRenderBufferDescriptor, pxr::SdfPath::Hash>
|
pxr::TfHashMap<pxr::SdfPath, pxr::HdRenderBufferDescriptor, pxr::SdfPath::Hash>
|
||||||
bufferDescriptors;
|
buffer_descriptors;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -10,10 +10,10 @@
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parentIndex,
|
BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
|
||||||
pxr::SdfPath const &delegateID,
|
pxr::SdfPath const &delegate_id,
|
||||||
BlenderSceneDelegate::EngineType engine_type)
|
BlenderSceneDelegate::EngineType engine_type)
|
||||||
: HdSceneDelegate(parentIndex, delegateID),
|
: HdSceneDelegate(parent_index, delegate_id),
|
||||||
engine_type(engine_type),
|
engine_type(engine_type),
|
||||||
depsgraph(nullptr),
|
depsgraph(nullptr),
|
||||||
context(nullptr),
|
context(nullptr),
|
||||||
@ -79,67 +79,68 @@ bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id)
|
|||||||
return object_data(id)->visible;
|
return object_data(id)->visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &primId)
|
pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &prim_id)
|
||||||
{
|
{
|
||||||
LOG(INFO) << "GetInstancerId: " << primId.GetAsString();
|
LOG(INFO) << "GetInstancerId: " << prim_id.GetAsString();
|
||||||
MeshData *m_data = mesh_data(primId);
|
MeshData *m_data = mesh_data(prim_id);
|
||||||
if (m_data) {
|
if (m_data) {
|
||||||
return m_data->instancer_id;
|
return m_data->instancer_id;
|
||||||
}
|
}
|
||||||
return pxr::SdfPath();
|
return pxr::SdfPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::SdfPathVector BlenderSceneDelegate::GetInstancerPrototypes(pxr::SdfPath const &instancerId)
|
pxr::SdfPathVector BlenderSceneDelegate::GetInstancerPrototypes(pxr::SdfPath const &instancer_id)
|
||||||
{
|
{
|
||||||
LOG(INFO) << "GetInstancerPrototypes: " << instancerId.GetString();
|
LOG(INFO) << "GetInstancerPrototypes: " << instancer_id.GetString();
|
||||||
pxr::SdfPathVector paths;
|
pxr::SdfPathVector paths;
|
||||||
paths.push_back(instancerId.GetParentPath());
|
paths.push_back(instancer_id.GetParentPath());
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::VtIntArray BlenderSceneDelegate::GetInstanceIndices(pxr::SdfPath const &instancerId,
|
pxr::VtIntArray BlenderSceneDelegate::GetInstanceIndices(pxr::SdfPath const &instancer_id,
|
||||||
pxr::SdfPath const &prototypeId)
|
pxr::SdfPath const &prototype_id)
|
||||||
{
|
{
|
||||||
LOG(INFO) << "GetInstanceIndices: " << instancerId.GetString() << " " << prototypeId.GetString();
|
LOG(INFO) << "GetInstanceIndices: " << instancer_id.GetString() << " "
|
||||||
MeshData *m_data = mesh_data(prototypeId);
|
<< prototype_id.GetString();
|
||||||
|
MeshData *m_data = mesh_data(prototype_id);
|
||||||
pxr::VtIntArray ret = m_data->instance_indices();
|
pxr::VtIntArray ret = m_data->instance_indices();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(pxr::SdfPath const &instancerId)
|
pxr::GfMatrix4d BlenderSceneDelegate::get_instancer_transform(pxr::SdfPath const &instancer_id)
|
||||||
{
|
{
|
||||||
LOG(INFO) << "GetInstancerTransform: " << instancerId.GetString();
|
LOG(INFO) << "get_instancer_transform: " << instancer_id.GetString();
|
||||||
// TODO: add a separate object for instancer for cleaner handling code
|
// TODO: add a separate object for instancer for cleaner handling code
|
||||||
// Actual instancer transform is get here
|
// Actual instancer transform is get here
|
||||||
return pxr::GfMatrix4d(1.0);
|
return pxr::GfMatrix4d(1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t BlenderSceneDelegate::SampleInstancerTransform(pxr::SdfPath const &instancerId,
|
size_t BlenderSceneDelegate::SampleInstancerTransform(pxr::SdfPath const &instancer_id,
|
||||||
size_t maxSampleCount,
|
size_t max_sample_count,
|
||||||
float *sampleTimes,
|
float *sample_times,
|
||||||
pxr::GfMatrix4d *sampleValues)
|
pxr::GfMatrix4d *sample_values)
|
||||||
{
|
{
|
||||||
LOG(INFO) << "SampleInstancerTransform: " << instancerId.GetString();
|
LOG(INFO) << "SampleInstancerTransform: " << instancer_id.GetString();
|
||||||
size_t ret = 0;
|
size_t ret = 0;
|
||||||
MeshData *m_data = mesh_data(instancerId.GetParentPath());
|
MeshData *m_data = mesh_data(instancer_id.GetParentPath());
|
||||||
ret = m_data->sample_instancer_transform(maxSampleCount, sampleTimes, sampleValues);
|
ret = m_data->sample_instancer_transform(max_sample_count, sample_times, sample_values);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t BlenderSceneDelegate::SamplePrimvar(pxr::SdfPath const &id,
|
size_t BlenderSceneDelegate::SamplePrimvar(pxr::SdfPath const &id,
|
||||||
pxr::TfToken const &key,
|
pxr::TfToken const &key,
|
||||||
size_t maxSampleCount,
|
size_t max_sample_count,
|
||||||
float *sampleTimes,
|
float *sample_times,
|
||||||
pxr::VtValue *sampleValues)
|
pxr::VtValue *sample_values)
|
||||||
{
|
{
|
||||||
// TODO: add a separate object for instancer for cleaner handling code
|
// TODO: add a separate object for instancer for cleaner handling code
|
||||||
if (id.GetName() == "Instancer") {
|
if (id.GetName() == "Instancer") {
|
||||||
MeshData *m_data = mesh_data(id.GetParentPath());
|
MeshData *m_data = mesh_data(id.GetParentPath());
|
||||||
if (m_data) {
|
if (m_data) {
|
||||||
return m_data->sample_instancer_primvar(key, maxSampleCount, sampleTimes, sampleValues);
|
return m_data->sample_instancer_primvar(key, max_sample_count, sample_times, sample_values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return HdSceneDelegate::SamplePrimvar(id, key, maxSampleCount, sampleTimes, sampleValues);
|
return HdSceneDelegate::SamplePrimvar(id, key, max_sample_count, sample_times, sample_values);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
|
void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
|
||||||
@ -432,9 +433,9 @@ pxr::HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors(
|
|||||||
return primvars;
|
return primvars;
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::SdfPath BlenderSceneDelegate::GetMaterialId(pxr::SdfPath const &rprimId)
|
pxr::SdfPath BlenderSceneDelegate::GetMaterialId(pxr::SdfPath const &rprim_id)
|
||||||
{
|
{
|
||||||
return mesh_data(rprimId)->material_id;
|
return mesh_data(rprim_id)->material_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id)
|
pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id)
|
||||||
|
@ -17,10 +17,10 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||||
public:
|
public:
|
||||||
enum class EngineType { Viewport = 1, Final, Preview };
|
enum class EngineType { VIEWPORT = 1, FINAL, PREVIEW };
|
||||||
|
|
||||||
BlenderSceneDelegate(pxr::HdRenderIndex *render_index,
|
BlenderSceneDelegate(pxr::HdRenderIndex *render_index,
|
||||||
pxr::SdfPath const &delegateId,
|
pxr::SdfPath const &delegate_id,
|
||||||
BlenderSceneDelegate::EngineType engine_type);
|
BlenderSceneDelegate::EngineType engine_type);
|
||||||
~BlenderSceneDelegate() override = default;
|
~BlenderSceneDelegate() override = default;
|
||||||
|
|
||||||
@ -33,23 +33,23 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
|||||||
pxr::VtValue GetLightParamValue(pxr::SdfPath const &id, pxr::TfToken const &key) override;
|
pxr::VtValue GetLightParamValue(pxr::SdfPath const &id, pxr::TfToken const &key) override;
|
||||||
pxr::HdPrimvarDescriptorVector GetPrimvarDescriptors(
|
pxr::HdPrimvarDescriptorVector GetPrimvarDescriptors(
|
||||||
pxr::SdfPath const &id, pxr::HdInterpolation interpolation) override;
|
pxr::SdfPath const &id, pxr::HdInterpolation interpolation) override;
|
||||||
pxr::SdfPath GetMaterialId(pxr::SdfPath const &rprimId) override;
|
pxr::SdfPath GetMaterialId(pxr::SdfPath const &rprim_id) override;
|
||||||
pxr::VtValue GetMaterialResource(pxr::SdfPath const &materialId) override;
|
pxr::VtValue GetMaterialResource(pxr::SdfPath const &material_id) override;
|
||||||
bool GetVisible(pxr::SdfPath const &id) override;
|
bool GetVisible(pxr::SdfPath const &id) override;
|
||||||
pxr::SdfPath GetInstancerId(pxr::SdfPath const &primId) override;
|
pxr::SdfPath GetInstancerId(pxr::SdfPath const &prim_id) override;
|
||||||
pxr::SdfPathVector GetInstancerPrototypes(pxr::SdfPath const &instancerId) override;
|
pxr::SdfPathVector GetInstancerPrototypes(pxr::SdfPath const &instancer_id) override;
|
||||||
pxr::VtIntArray GetInstanceIndices(pxr::SdfPath const &instancerId,
|
pxr::VtIntArray GetInstanceIndices(pxr::SdfPath const &instancer_id,
|
||||||
pxr::SdfPath const &prototypeId) override;
|
pxr::SdfPath const &prototype_id) override;
|
||||||
pxr::GfMatrix4d GetInstancerTransform(pxr::SdfPath const &instancerId);
|
pxr::GfMatrix4d get_instancer_transform(pxr::SdfPath const &instancer_id);
|
||||||
size_t SampleInstancerTransform(pxr::SdfPath const &instancerId,
|
size_t SampleInstancerTransform(pxr::SdfPath const &instancer_id,
|
||||||
size_t maxSampleCount,
|
size_t max_sample_count,
|
||||||
float *sampleTimes,
|
float *sample_times,
|
||||||
pxr::GfMatrix4d *sampleValues) override;
|
pxr::GfMatrix4d *sample_values) override;
|
||||||
size_t SamplePrimvar(pxr::SdfPath const &id,
|
size_t SamplePrimvar(pxr::SdfPath const &id,
|
||||||
pxr::TfToken const &key,
|
pxr::TfToken const &key,
|
||||||
size_t maxSampleCount,
|
size_t max_sample_count,
|
||||||
float *sampleTimes,
|
float *sample_times,
|
||||||
pxr::VtValue *sampleValues) override;
|
pxr::VtValue *sample_values) override;
|
||||||
|
|
||||||
EngineType engine_type;
|
EngineType engine_type;
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object)
|
|||||||
Light *light = (Light *)((Object *)id)->data;
|
Light *light = (Light *)((Object *)id)->data;
|
||||||
|
|
||||||
data[pxr::HdLightTokens->intensity] = scene_delegate->engine_type ==
|
data[pxr::HdLightTokens->intensity] = scene_delegate->engine_type ==
|
||||||
BlenderSceneDelegate::EngineType::Preview ?
|
BlenderSceneDelegate::EngineType::PREVIEW ?
|
||||||
light->energy / 1000 :
|
light->energy / 1000 :
|
||||||
light->energy;
|
light->energy;
|
||||||
|
|
||||||
|
@ -110,24 +110,24 @@ pxr::VtIntArray MeshData::instance_indices()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t MeshData::sample_instancer_transform(size_t maxSampleCount,
|
size_t MeshData::sample_instancer_transform(size_t max_sample_count,
|
||||||
float *sampleTimes,
|
float *sample_times,
|
||||||
pxr::GfMatrix4d *sampleValues)
|
pxr::GfMatrix4d *sample_values)
|
||||||
{
|
{
|
||||||
*sampleTimes = 0.0f;
|
*sample_times = 0.0f;
|
||||||
*sampleValues = pxr::GfMatrix4d(1.0);
|
*sample_values = pxr::GfMatrix4d(1.0);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t MeshData::sample_instancer_primvar(pxr::TfToken const &key,
|
size_t MeshData::sample_instancer_primvar(pxr::TfToken const &key,
|
||||||
size_t maxSampleCount,
|
size_t max_sample_count,
|
||||||
float *sampleTimes,
|
float *sample_times,
|
||||||
pxr::VtValue *sampleValues)
|
pxr::VtValue *sample_values)
|
||||||
{
|
{
|
||||||
if (key == pxr::HdInstancerTokens->instanceTransform) {
|
if (key == pxr::HdInstancerTokens->instanceTransform) {
|
||||||
if (maxSampleCount > 0) {
|
if (max_sample_count > 0) {
|
||||||
sampleTimes[0] = 0.0f;
|
sample_times[0] = 0.0f;
|
||||||
sampleValues[0] = instances;
|
sample_values[0] = instances;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,13 +27,13 @@ class MeshData : public ObjectData {
|
|||||||
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation);
|
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation);
|
||||||
pxr::HdPrimvarDescriptorVector instancer_primvar_descriptors(pxr::HdInterpolation interpolation);
|
pxr::HdPrimvarDescriptorVector instancer_primvar_descriptors(pxr::HdInterpolation interpolation);
|
||||||
pxr::VtIntArray instance_indices();
|
pxr::VtIntArray instance_indices();
|
||||||
size_t sample_instancer_transform(size_t maxSampleCount,
|
size_t sample_instancer_transform(size_t max_sample_count,
|
||||||
float *sampleTimes,
|
float *sample_times,
|
||||||
pxr::GfMatrix4d *sampleValues);
|
pxr::GfMatrix4d *sample_values);
|
||||||
size_t sample_instancer_primvar(pxr::TfToken const &key,
|
size_t sample_instancer_primvar(pxr::TfToken const &key,
|
||||||
size_t maxSampleCount,
|
size_t max_sample_count,
|
||||||
float *sampleTimes,
|
float *sample_times,
|
||||||
pxr::VtValue *sampleValues);
|
pxr::VtValue *sample_values);
|
||||||
|
|
||||||
void add_instance(DupliObject *dupli);
|
void add_instance(DupliObject *dupli);
|
||||||
|
|
||||||
|
@ -22,29 +22,29 @@
|
|||||||
|
|
||||||
namespace mx = MaterialX;
|
namespace mx = MaterialX;
|
||||||
|
|
||||||
void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath,
|
void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlx_path,
|
||||||
pxr::TfTokenVector const &shaderSourceTypes,
|
pxr::TfTokenVector const &shader_source_types,
|
||||||
pxr::TfTokenVector const &renderContexts,
|
pxr::TfTokenVector const &render_contexts,
|
||||||
pxr::HdMaterialNetworkMap *out)
|
pxr::HdMaterialNetworkMap *out)
|
||||||
{
|
{
|
||||||
if (mtlxPath.empty()) {
|
if (mtlx_path.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string basePath = pxr::TfGetPathName(mtlxPath);
|
std::string basePath = pxr::TfGetPathName(mtlx_path);
|
||||||
|
|
||||||
pxr::ArResolver &resolver = pxr::ArGetResolver();
|
pxr::ArResolver &resolver = pxr::ArGetResolver();
|
||||||
const pxr::ArResolverContext context = resolver.CreateDefaultContextForAsset(mtlxPath);
|
const pxr::ArResolverContext context = resolver.CreateDefaultContextForAsset(mtlx_path);
|
||||||
pxr::ArResolverContextBinder binder(context);
|
pxr::ArResolverContextBinder binder(context);
|
||||||
pxr::ArResolverScopedCache resolverCache;
|
pxr::ArResolverScopedCache resolver_cache;
|
||||||
|
|
||||||
std::string mtlxName = pxr::TfGetBaseName(mtlxPath);
|
std::string mtlxName = pxr::TfGetBaseName(mtlx_path);
|
||||||
std::string stageId = pxr::TfStringPrintf(
|
std::string stage_id = pxr::TfStringPrintf(
|
||||||
"%s%s%s.usda", basePath.c_str(), ARCH_PATH_SEP, mtlxName.c_str());
|
"%s%s%s.usda", basePath.c_str(), ARCH_PATH_SEP, mtlxName.c_str());
|
||||||
pxr::UsdStageRefPtr stage = pxr::UsdStage::CreateInMemory(stageId, context);
|
pxr::UsdStageRefPtr stage = pxr::UsdStage::CreateInMemory(stage_id, context);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mx::DocumentPtr doc = pxr::UsdMtlxReadDocument(mtlxPath);
|
mx::DocumentPtr doc = pxr::UsdMtlxReadDocument(mtlx_path);
|
||||||
pxr::UsdMtlxRead(doc, stage);
|
pxr::UsdMtlxRead(doc, stage);
|
||||||
}
|
}
|
||||||
catch (mx::ExceptionFoundCycle &x) {
|
catch (mx::ExceptionFoundCycle &x) {
|
||||||
@ -65,11 +65,11 @@ void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath,
|
|||||||
if (pxr::UsdPrim materials = stage->GetPrimAtPath(pxr::SdfPath("/MaterialX/Materials"))) {
|
if (pxr::UsdPrim materials = stage->GetPrimAtPath(pxr::SdfPath("/MaterialX/Materials"))) {
|
||||||
if (pxr::UsdPrimSiblingRange children = materials.GetChildren()) {
|
if (pxr::UsdPrimSiblingRange children = materials.GetChildren()) {
|
||||||
if (auto material = pxr::UsdShadeMaterial(*children.begin())) {
|
if (auto material = pxr::UsdShadeMaterial(*children.begin())) {
|
||||||
if (pxr::UsdShadeShader mtlxSurface = material.ComputeSurfaceSource(renderContexts)) {
|
if (pxr::UsdShadeShader mtlx_surface = material.ComputeSurfaceSource(render_contexts)) {
|
||||||
UsdImagingBuildHdMaterialNetworkFromTerminal(mtlxSurface.GetPrim(),
|
UsdImagingBuildHdMaterialNetworkFromTerminal(mtlx_surface.GetPrim(),
|
||||||
pxr::HdMaterialTerminalTokens->surface,
|
pxr::HdMaterialTerminalTokens->surface,
|
||||||
shaderSourceTypes,
|
shader_source_types,
|
||||||
renderContexts,
|
render_contexts,
|
||||||
out,
|
out,
|
||||||
pxr::UsdTimeCode::Default());
|
pxr::UsdTimeCode::Default());
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
struct pxr::HdMaterialNetworkMap;
|
struct pxr::HdMaterialNetworkMap;
|
||||||
|
|
||||||
void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath,
|
void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlx_path,
|
||||||
pxr::TfTokenVector const &shaderSourceTypes,
|
pxr::TfTokenVector const &shader_source_types,
|
||||||
pxr::TfTokenVector const &renderContexts,
|
pxr::TfTokenVector const &render_contexts,
|
||||||
pxr::HdMaterialNetworkMap *out);
|
pxr::HdMaterialNetworkMap *out);
|
||||||
|
@ -7,33 +7,33 @@
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
SimpleLightTaskDelegate::SimpleLightTaskDelegate(pxr::HdRenderIndex *parentIndex,
|
SimpleLightTaskDelegate::SimpleLightTaskDelegate(pxr::HdRenderIndex *parent_index,
|
||||||
pxr::SdfPath const &delegateID)
|
pxr::SdfPath const &delegate_id)
|
||||||
: pxr::HdSceneDelegate(parentIndex, delegateID)
|
: pxr::HdSceneDelegate(parent_index, delegate_id)
|
||||||
{
|
{
|
||||||
pxr::SdfPath taskId = GetTaskID();
|
pxr::SdfPath task_id = get_task_id();
|
||||||
GetRenderIndex().InsertTask<pxr::HdxSimpleLightTask>(this, taskId);
|
GetRenderIndex().InsertTask<pxr::HdxSimpleLightTask>(this, task_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::SdfPath SimpleLightTaskDelegate::GetTaskID() const
|
pxr::SdfPath SimpleLightTaskDelegate::get_task_id() const
|
||||||
{
|
{
|
||||||
return GetDelegateID().AppendElementString("task");
|
return GetDelegateID().AppendElementString("task");
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::HdTaskSharedPtr SimpleLightTaskDelegate::GetTask()
|
pxr::HdTaskSharedPtr SimpleLightTaskDelegate::get_task()
|
||||||
{
|
{
|
||||||
return GetRenderIndex().GetTask(GetTaskID());
|
return GetRenderIndex().GetTask(get_task_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleLightTaskDelegate::SetCameraPath(pxr::SdfPath const &cameraPath)
|
void SimpleLightTaskDelegate::set_camera_path(pxr::SdfPath const &camera_path)
|
||||||
{
|
{
|
||||||
taskParams.cameraPath = cameraPath;
|
task_params.cameraPath = camera_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::VtValue SimpleLightTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key)
|
pxr::VtValue SimpleLightTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key)
|
||||||
{
|
{
|
||||||
if (key == pxr::HdTokens->params) {
|
if (key == pxr::HdTokens->params) {
|
||||||
return pxr::VtValue(taskParams);
|
return pxr::VtValue(task_params);
|
||||||
}
|
}
|
||||||
return pxr::VtValue();
|
return pxr::VtValue();
|
||||||
}
|
}
|
||||||
|
@ -10,18 +10,18 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
class SimpleLightTaskDelegate : public pxr::HdSceneDelegate {
|
class SimpleLightTaskDelegate : public pxr::HdSceneDelegate {
|
||||||
public:
|
public:
|
||||||
SimpleLightTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegateID);
|
SimpleLightTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegate_id);
|
||||||
~SimpleLightTaskDelegate() override = default;
|
~SimpleLightTaskDelegate() override = default;
|
||||||
|
|
||||||
pxr::SdfPath GetTaskID() const;
|
pxr::SdfPath get_task_id() const;
|
||||||
|
|
||||||
pxr::HdTaskSharedPtr GetTask();
|
pxr::HdTaskSharedPtr get_task();
|
||||||
void SetCameraPath(pxr::SdfPath const &);
|
void set_camera_path(pxr::SdfPath const &);
|
||||||
|
|
||||||
pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override;
|
pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pxr::HdxSimpleLightTaskParams taskParams;
|
pxr::HdxSimpleLightTaskParams task_params;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -134,20 +134,20 @@ pxr::GfCamera ViewSettings::gf_camera()
|
|||||||
(float)border[3] / screen_height));
|
(float)border[3] / screen_height));
|
||||||
}
|
}
|
||||||
|
|
||||||
GLTexture::GLTexture() : textureId(0), width(0), height(0), channels(4)
|
GLTexture::GLTexture() : texture_id(0), width(0), height(0), channels(4)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GLTexture::~GLTexture()
|
GLTexture::~GLTexture()
|
||||||
{
|
{
|
||||||
if (textureId) {
|
if (texture_id) {
|
||||||
free();
|
free();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLTexture::setBuffer(pxr::HdRenderBuffer *buffer)
|
void GLTexture::set_buffer(pxr::HdRenderBuffer *buffer)
|
||||||
{
|
{
|
||||||
if (!textureId) {
|
if (!texture_id) {
|
||||||
create(buffer);
|
create(buffer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -158,7 +158,7 @@ void GLTexture::setBuffer(pxr::HdRenderBuffer *buffer)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, textureId);
|
glBindTexture(GL_TEXTURE_2D, texture_id);
|
||||||
|
|
||||||
void *data = buffer->Map();
|
void *data = buffer->Map();
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_FLOAT, data);
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_FLOAT, data);
|
||||||
@ -171,8 +171,8 @@ void GLTexture::create(pxr::HdRenderBuffer *buffer)
|
|||||||
height = buffer->GetHeight();
|
height = buffer->GetHeight();
|
||||||
channels = pxr::HdGetComponentCount(buffer->GetFormat());
|
channels = pxr::HdGetComponentCount(buffer->GetFormat());
|
||||||
|
|
||||||
glGenTextures(1, &textureId);
|
glGenTextures(1, &texture_id);
|
||||||
glBindTexture(GL_TEXTURE_2D, textureId);
|
glBindTexture(GL_TEXTURE_2D, texture_id);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
@ -185,8 +185,8 @@ void GLTexture::create(pxr::HdRenderBuffer *buffer)
|
|||||||
|
|
||||||
void GLTexture::free()
|
void GLTexture::free()
|
||||||
{
|
{
|
||||||
glDeleteTextures(1, &textureId);
|
glDeleteTextures(1, &texture_id);
|
||||||
textureId = 0;
|
texture_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLTexture::draw(GLfloat x, GLfloat y)
|
void GLTexture::draw(GLfloat x, GLfloat y)
|
||||||
@ -218,7 +218,7 @@ void GLTexture::draw(GLfloat x, GLfloat y)
|
|||||||
|
|
||||||
// DRAWING
|
// DRAWING
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, textureId);
|
glBindTexture(GL_TEXTURE_2D, texture_id);
|
||||||
|
|
||||||
glBindVertexArray(vertex_array);
|
glBindVertexArray(vertex_array);
|
||||||
glEnableVertexAttribArray(texturecoord_location);
|
glEnableVertexAttribArray(texturecoord_location);
|
||||||
@ -242,45 +242,45 @@ void GLTexture::draw(GLfloat x, GLfloat y)
|
|||||||
|
|
||||||
void ViewportEngine::sync(Depsgraph *depsgraph,
|
void ViewportEngine::sync(Depsgraph *depsgraph,
|
||||||
bContext *context,
|
bContext *context,
|
||||||
pxr::HdRenderSettingsMap &renderSettings)
|
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"),
|
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
||||||
BlenderSceneDelegate::EngineType::Viewport);
|
BlenderSceneDelegate::EngineType::VIEWPORT);
|
||||||
}
|
}
|
||||||
scene_delegate->populate(depsgraph, context);
|
scene_delegate->populate(depsgraph, context);
|
||||||
|
|
||||||
for (auto const &setting : renderSettings) {
|
for (auto const &setting : render_settings) {
|
||||||
render_delegate->SetRenderSetting(setting.first, setting.second);
|
render_delegate->SetRenderSetting(setting.first, setting.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
|
void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
|
||||||
{
|
{
|
||||||
ViewSettings viewSettings(context);
|
ViewSettings view_settings(context);
|
||||||
if (viewSettings.width() * viewSettings.height() == 0) {
|
if (view_settings.width() * view_settings.height() == 0) {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
pxr::GfCamera gfCamera = viewSettings.gf_camera();
|
pxr::GfCamera gfCamera = view_settings.gf_camera();
|
||||||
free_camera_delegate->SetCamera(gfCamera);
|
free_camera_delegate->SetCamera(gfCamera);
|
||||||
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
|
render_task_delegate->set_camera_and_viewport(free_camera_delegate->GetCameraId(),
|
||||||
pxr::GfVec4d(viewSettings.border[0],
|
pxr::GfVec4d(view_settings.border[0],
|
||||||
viewSettings.border[1],
|
view_settings.border[1],
|
||||||
viewSettings.border[2],
|
view_settings.border[2],
|
||||||
viewSettings.border[3]));
|
view_settings.border[3]));
|
||||||
if (simple_light_task_delegate) {
|
if (simple_light_task_delegate) {
|
||||||
simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId());
|
simple_light_task_delegate->set_camera_path(free_camera_delegate->GetCameraId());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((bl_engine->type->flag & RE_USE_GPU_CONTEXT) == 0) {
|
if ((bl_engine->type->flag & RE_USE_GPU_CONTEXT) == 0) {
|
||||||
render_task_delegate->SetRendererAov(pxr::HdAovTokens->color);
|
render_task_delegate->set_renderer_aov(pxr::HdAovTokens->color);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (renderer_percent_done() == 0.0f) {
|
if (renderer_percent_done() == 0.0f) {
|
||||||
timeBegin = std::chrono::steady_clock::now();
|
time_begin = std::chrono::steady_clock::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE);
|
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE);
|
||||||
@ -288,9 +288,9 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
|
|||||||
|
|
||||||
pxr::HdTaskSharedPtrVector tasks;
|
pxr::HdTaskSharedPtrVector tasks;
|
||||||
if (simple_light_task_delegate) {
|
if (simple_light_task_delegate) {
|
||||||
tasks.push_back(simple_light_task_delegate->GetTask());
|
tasks.push_back(simple_light_task_delegate->get_task());
|
||||||
}
|
}
|
||||||
tasks.push_back(render_task_delegate->GetTask());
|
tasks.push_back(render_task_delegate->get_task());
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
|
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
|
||||||
@ -298,28 +298,28 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
|
|||||||
engine->Execute(render_index.get(), &tasks);
|
engine->Execute(render_index.get(), &tasks);
|
||||||
|
|
||||||
if ((bl_engine->type->flag & RE_USE_GPU_CONTEXT) == 0) {
|
if ((bl_engine->type->flag & RE_USE_GPU_CONTEXT) == 0) {
|
||||||
texture.setBuffer(render_task_delegate->GetRendererAov(pxr::HdAovTokens->color));
|
texture.set_buffer(render_task_delegate->get_renderer_aov(pxr::HdAovTokens->color));
|
||||||
texture.draw((GLfloat)viewSettings.border[0], (GLfloat)viewSettings.border[1]);
|
texture.draw((GLfloat)view_settings.border[0], (GLfloat)view_settings.border[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GPU_shader_unbind();
|
GPU_shader_unbind();
|
||||||
|
|
||||||
std::chrono::time_point<std::chrono::steady_clock> timeCurrent =
|
std::chrono::time_point<std::chrono::steady_clock> time_current =
|
||||||
std::chrono::steady_clock::now();
|
std::chrono::steady_clock::now();
|
||||||
std::chrono::milliseconds elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(
|
std::chrono::milliseconds elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
timeCurrent - timeBegin);
|
time_current - time_begin);
|
||||||
|
|
||||||
std::string formattedTime = format_duration(elapsedTime);
|
std::string formatted_time = format_duration(elapsed_time);
|
||||||
|
|
||||||
if (!render_task_delegate->IsConverged()) {
|
if (!render_task_delegate->is_converged()) {
|
||||||
notify_status("Time: " + formattedTime +
|
notify_status("Time: " + formatted_time +
|
||||||
" | Done: " + std::to_string(int(renderer_percent_done())) + "%",
|
" | Done: " + std::to_string(int(renderer_percent_done())) + "%",
|
||||||
"Render");
|
"Render");
|
||||||
bl_engine->flag |= RE_ENGINE_DO_DRAW;
|
bl_engine->flag |= RE_ENGINE_DO_DRAW;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
notify_status(("Time: " + formattedTime).c_str(), "Rendering Done");
|
notify_status(("Time: " + formatted_time).c_str(), "Rendering Done");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,14 +17,14 @@ class GLTexture {
|
|||||||
public:
|
public:
|
||||||
GLTexture();
|
GLTexture();
|
||||||
~GLTexture();
|
~GLTexture();
|
||||||
void setBuffer(pxr::HdRenderBuffer *buffer);
|
void set_buffer(pxr::HdRenderBuffer *buffer);
|
||||||
void draw(GLfloat x, GLfloat y);
|
void draw(GLfloat x, GLfloat y);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void create(pxr::HdRenderBuffer *buffer);
|
void create(pxr::HdRenderBuffer *buffer);
|
||||||
void free();
|
void free();
|
||||||
|
|
||||||
GLuint textureId;
|
GLuint texture_id;
|
||||||
int width, height, channels;
|
int width, height, channels;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ class ViewportEngine : public Engine {
|
|||||||
using Engine::Engine;
|
using Engine::Engine;
|
||||||
void sync(Depsgraph *depsgraph,
|
void sync(Depsgraph *depsgraph,
|
||||||
bContext *context,
|
bContext *context,
|
||||||
pxr::HdRenderSettingsMap &renderSettings) override;
|
pxr::HdRenderSettingsMap &render_settings) override;
|
||||||
void render(Depsgraph *depsgraph) override;
|
void render(Depsgraph *depsgraph) override;
|
||||||
void render(Depsgraph *depsgraph, bContext *context);
|
void render(Depsgraph *depsgraph, bContext *context);
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ class ViewportEngine : public Engine {
|
|||||||
void notify_status(const std::string &title, const std::string &info);
|
void notify_status(const std::string &title, const std::string &info);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::chrono::time_point<std::chrono::steady_clock> timeBegin;
|
std::chrono::time_point<std::chrono::steady_clock> time_begin;
|
||||||
|
|
||||||
GLTexture texture;
|
GLTexture texture;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user