forked from blender/blender
Add IBL support #29
@ -58,8 +58,6 @@ set(SRC
|
|||||||
viewport_engine.cc
|
viewport_engine.cc
|
||||||
camera.h
|
camera.h
|
||||||
camera.cc
|
camera.cc
|
||||||
utils.h
|
|
||||||
utils.cc
|
|
||||||
|
|
||||||
render_task_delegate.cc
|
render_task_delegate.cc
|
||||||
render_task_delegate.h
|
render_task_delegate.h
|
||||||
@ -84,6 +82,8 @@ set(SRC
|
|||||||
scene_delegate/world.cc
|
scene_delegate/world.cc
|
||||||
scene_delegate/instancer.h
|
scene_delegate/instancer.h
|
||||||
scene_delegate/instancer.cc
|
scene_delegate/instancer.cc
|
||||||
|
scene_delegate/image.h
|
||||||
|
scene_delegate/image.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
set(LIB
|
set(LIB
|
||||||
|
@ -3,9 +3,10 @@
|
|||||||
|
|
||||||
#include "DNA_camera_types.h"
|
#include "DNA_camera_types.h"
|
||||||
#include "DNA_screen_types.h"
|
#include "DNA_screen_types.h"
|
||||||
|
#include "DNA_view3d_types.h"
|
||||||
|
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "utils.h"
|
#include "scene_delegate/object.h"
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
|
@ -13,11 +13,8 @@
|
|||||||
|
|
||||||
#include "final_engine.h"
|
#include "final_engine.h"
|
||||||
#include "preview_engine.h"
|
#include "preview_engine.h"
|
||||||
#include "utils.h"
|
|
||||||
#include "viewport_engine.h"
|
#include "viewport_engine.h"
|
||||||
|
|
||||||
#include "BLI_timer.h"
|
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
static PyObject *init_func(PyObject * /*self*/, PyObject *args)
|
static PyObject *init_func(PyObject * /*self*/, PyObject *args)
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include "DEG_depsgraph_query.h"
|
#include "DEG_depsgraph_query.h"
|
||||||
#include "DNA_scene_types.h"
|
#include "DNA_scene_types.h"
|
||||||
|
|
||||||
#include "..\utils.h"
|
|
||||||
#include "blender_scene_delegate.h"
|
#include "blender_scene_delegate.h"
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
@ -191,7 +190,7 @@ pxr::SdfPath BlenderSceneDelegate::prim_id(ID *id, const char *prefix) const
|
|||||||
{
|
{
|
||||||
/* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */
|
/* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */
|
||||||
char str[32];
|
char str[32];
|
||||||
snprintf(str, 32, "%s_%016llx", prefix, (uint64_t)id);
|
snprintf(str, 32, "%s_%016llx", prefix, (uintptr_t)id);
|
||||||
return GetDelegateID().AppendElementString(str);
|
return GetDelegateID().AppendElementString(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
78
source/blender/render/hydra/scene_delegate/image.cc
Normal file
78
source/blender/render/hydra/scene_delegate/image.cc
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/* SPDX-License-Identifier: Apache-2.0
|
||||||
|
* Copyright 2011-2022 Blender Foundation */
|
||||||
|
|
||||||
|
#include <pxr/imaging/hio/imageRegistry.h>
|
||||||
|
|
||||||
|
#include "BKE_appdir.h"
|
||||||
|
#include "BKE_image.h"
|
||||||
|
#include "BKE_image_save.h"
|
||||||
|
#include "BLI_fileops.h"
|
||||||
|
#include "BLI_path_util.h"
|
||||||
|
|
||||||
|
#include "DNA_windowmanager_types.h"
|
||||||
|
|
||||||
|
#include "blender_scene_delegate.h"
|
||||||
|
#include "image.h"
|
||||||
|
|
||||||
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
|
static std::string cache_image_file(Image *image,
|
||||||
|
BlenderSceneDelegate *scene_delegate,
|
||||||
|
ImageUser *iuser,
|
||||||
|
bool check_exist)
|
||||||
|
{
|
||||||
|
std::string file_path(FILE_MAX, 0);
|
||||||
|
char file_name[32];
|
||||||
|
snprintf(file_name, 32, "img_%016llx.hdr", (uintptr_t)image);
|
||||||
|
BLI_path_join(file_path.data(),
|
||||||
|
file_path.capacity(),
|
||||||
|
BKE_tempdir_session(),
|
||||||
|
"hydra_image_cache",
|
||||||
|
file_name);
|
||||||
|
|
||||||
|
if (check_exist && BLI_exists(file_path.c_str())) {
|
||||||
|
return file_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
Main *main = CTX_data_main(scene_delegate->context);
|
||||||
|
ImageSaveOptions opts;
|
||||||
|
opts.im_format.imtype = R_IMF_IMTYPE_RADHDR;
|
||||||
|
|
||||||
|
if (BKE_image_save_options_init(&opts, main, scene_delegate->scene, image, iuser, true, false)) {
|
||||||
|
STRNCPY(opts.filepath, file_path.c_str());
|
||||||
|
ReportList reports;
|
||||||
|
if (!BKE_image_save(&reports, main, image, iuser, &opts)) {
|
||||||
|
file_path = "";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
BKE_image_save_options_free(&opts);
|
||||||
|
|
||||||
|
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s -> %s", image->id.name, file_path.c_str());
|
||||||
|
return file_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string cache_or_get_image_file(Image *image,
|
||||||
|
BlenderSceneDelegate *scene_delegate,
|
||||||
|
ImageUser *iuser)
|
||||||
|
{
|
||||||
|
std::string file_path(FILE_MAX, 0);
|
||||||
|
if (image->source == IMA_SRC_GENERATED) {
|
||||||
|
file_path = cache_image_file(image, scene_delegate, iuser, false);
|
||||||
|
}
|
||||||
|
else if (BKE_image_has_packedfile(image)) {
|
||||||
|
file_path = cache_image_file(image, scene_delegate, iuser, true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Main *main = CTX_data_main(scene_delegate->context);
|
||||||
|
BKE_image_user_file_path_ex(main, iuser, image, file_path.data(), false, true);
|
||||||
|
|
||||||
|
if (!pxr::HioImageRegistry::GetInstance().IsSupportedImageFile(file_path)) {
|
||||||
|
file_path = cache_image_file(image, scene_delegate, iuser, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s -> %s", image->id.name, file_path.c_str());
|
||||||
|
return file_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace blender::render::hydra
|
17
source/blender/render/hydra/scene_delegate/image.h
Normal file
17
source/blender/render/hydra/scene_delegate/image.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/* SPDX-License-Identifier: Apache-2.0
|
||||||
|
* Copyright 2011-2022 Blender Foundation */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "BKE_image.h"
|
||||||
|
#include "BKE_image_save.h"
|
||||||
|
|
||||||
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
|
class BlenderSceneDelegate;
|
||||||
|
|
||||||
|
std::string cache_or_get_image_file(Image *image,
|
||||||
|
BlenderSceneDelegate *scene_delegate,
|
||||||
|
ImageUser *iuser);
|
||||||
|
|
||||||
|
} // namespace blender::render::hydra
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include <pxr/base/gf/vec2f.h>
|
#include <pxr/base/gf/vec2f.h>
|
||||||
|
|
||||||
#include "../utils.h"
|
|
||||||
#include "blender_scene_delegate.h"
|
#include "blender_scene_delegate.h"
|
||||||
#include "instancer.h"
|
#include "instancer.h"
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#include "BKE_mesh_runtime.h"
|
#include "BKE_mesh_runtime.h"
|
||||||
#include "BKE_object.h"
|
#include "BKE_object.h"
|
||||||
|
|
||||||
#include "../utils.h"
|
|
||||||
#include "blender_scene_delegate.h"
|
#include "blender_scene_delegate.h"
|
||||||
#include "mesh.h"
|
#include "mesh.h"
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "BKE_object.h"
|
#include "BKE_object.h"
|
||||||
|
|
||||||
#include "../utils.h"
|
|
||||||
#include "blender_scene_delegate.h"
|
#include "blender_scene_delegate.h"
|
||||||
#include "light.h"
|
#include "light.h"
|
||||||
#include "mesh.h"
|
#include "mesh.h"
|
||||||
@ -84,4 +83,15 @@ void ObjectData::write_transform()
|
|||||||
transform = gf_matrix_from_transform(((Object *)id)->object_to_world);
|
transform = gf_matrix_from_transform(((Object *)id)->object_to_world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pxr::GfMatrix4d gf_matrix_from_transform(float m[4][4])
|
||||||
|
{
|
||||||
|
pxr::GfMatrix4d ret;
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
for (int j = 0; j < 4; j++) {
|
||||||
|
ret[i][j] = m[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -35,4 +35,6 @@ class ObjectData : public IdData {
|
|||||||
using ObjectDataMap =
|
using ObjectDataMap =
|
||||||
pxr::TfHashMap<pxr::SdfPath, std::unique_ptr<ObjectData>, pxr::SdfPath::Hash>;
|
pxr::TfHashMap<pxr::SdfPath, std::unique_ptr<ObjectData>, pxr::SdfPath::Hash>;
|
||||||
|
|
||||||
|
pxr::GfMatrix4d gf_matrix_from_transform(float m[4][4]);
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -13,15 +13,14 @@
|
|||||||
|
|
||||||
#include "BKE_context.h"
|
#include "BKE_context.h"
|
||||||
#include "DNA_node_types.h"
|
#include "DNA_node_types.h"
|
||||||
#include "DNA_windowmanager_types.h"
|
|
||||||
|
|
||||||
#include "BKE_image.h"
|
|
||||||
#include "BKE_node.h"
|
#include "BKE_node.h"
|
||||||
#include "BKE_node_runtime.hh"
|
#include "BKE_node_runtime.hh"
|
||||||
|
#include "BLI_path_util.h"
|
||||||
#include "NOD_shader.h"
|
#include "NOD_shader.h"
|
||||||
|
|
||||||
#include "../utils.h"
|
|
||||||
#include "blender_scene_delegate.h"
|
#include "blender_scene_delegate.h"
|
||||||
|
#include "image.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
|
|
||||||
/* TODO : add custom tftoken "transparency"? */
|
/* TODO : add custom tftoken "transparency"? */
|
||||||
@ -96,16 +95,8 @@ void WorldData::init()
|
|||||||
if (color_input_node->type == SH_NODE_TEX_IMAGE) {
|
if (color_input_node->type == SH_NODE_TEX_IMAGE) {
|
||||||
NodeTexImage *tex = static_cast<NodeTexImage *>(color_input_node->storage);
|
NodeTexImage *tex = static_cast<NodeTexImage *>(color_input_node->storage);
|
||||||
Image *image = (Image *)color_input_node->id;
|
Image *image = (Image *)color_input_node->id;
|
||||||
|
|
||||||
if (image) {
|
if (image) {
|
||||||
Main *bmain = CTX_data_main(scene_delegate_->context);
|
std::string image_path = cache_or_get_image_file(image, scene_delegate_, &tex->iuser);
|
||||||
Scene *scene = scene_delegate_->scene;
|
|
||||||
|
|
||||||
ReportList reports;
|
|
||||||
ImageSaveOptions opts;
|
|
||||||
opts.im_format.imtype = R_IMF_IMTYPE_PNG;
|
|
||||||
|
|
||||||
std::string image_path = cache_image(bmain, scene, image, &tex->iuser, &opts, &reports);
|
|
||||||
if (!image_path.empty()) {
|
if (!image_path.empty()) {
|
||||||
data_[pxr::HdLightTokens->textureFile] = pxr::SdfAssetPath(image_path, image_path);
|
data_[pxr::HdLightTokens->textureFile] = pxr::SdfAssetPath(image_path, image_path);
|
||||||
}
|
}
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
/* SPDX-License-Identifier: Apache-2.0
|
|
||||||
* Copyright 2011-2022 Blender Foundation */
|
|
||||||
|
|
||||||
#include <filesystem>
|
|
||||||
|
|
||||||
#include <pxr/base/tf/stringUtils.h>
|
|
||||||
|
|
||||||
#include "BKE_appdir.h"
|
|
||||||
#include "BKE_image_save.h"
|
|
||||||
#include "BLI_path_util.h"
|
|
||||||
#include "BLI_string.h"
|
|
||||||
|
|
||||||
#include "DNA_camera_types.h"
|
|
||||||
|
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
|
||||||
|
|
||||||
pxr::GfMatrix4d gf_matrix_from_transform(float m[4][4])
|
|
||||||
{
|
|
||||||
pxr::GfMatrix4d ret = pxr::GfMatrix4d();
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
for (int j = 0; j < 4; j++) {
|
|
||||||
ret[i][j] = m[i][j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string cache_image(Main *bmain,
|
|
||||||
Scene *scene,
|
|
||||||
Image *image,
|
|
||||||
ImageUser *iuser,
|
|
||||||
ImageSaveOptions *opts,
|
|
||||||
ReportList *reports)
|
|
||||||
{
|
|
||||||
const char *default_format = ".png";
|
|
||||||
char tempfile[FILE_MAX];
|
|
||||||
|
|
||||||
if (!BKE_image_save_options_init(opts, bmain, scene, image, iuser, true, false)) {
|
|
||||||
BKE_image_save_options_free(opts);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
char image_name[32];
|
|
||||||
snprintf(image_name, 32, "img_%016llx", (uint64_t)image);
|
|
||||||
|
|
||||||
strcat(image_name, default_format);
|
|
||||||
|
|
||||||
BLI_path_join(
|
|
||||||
tempfile, sizeof(tempfile), BKE_tempdir_session(), "hydra_image_cache", image_name);
|
|
||||||
STRNCPY(opts->filepath, tempfile);
|
|
||||||
|
|
||||||
if (!BKE_image_save(reports, bmain, image, iuser, opts)) {
|
|
||||||
BKE_image_save_options_free(opts);
|
|
||||||
return "";
|
|
||||||
};
|
|
||||||
|
|
||||||
BKE_image_save_options_free(opts);
|
|
||||||
return tempfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
|
@ -1,23 +0,0 @@
|
|||||||
/* SPDX-License-Identifier: Apache-2.0
|
|
||||||
* Copyright 2011-2022 Blender Foundation */
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <pxr/base/gf/matrix4d.h>
|
|
||||||
|
|
||||||
#include "BKE_image.h"
|
|
||||||
#include "BKE_image_save.h"
|
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
|
||||||
|
|
||||||
pxr::GfMatrix4d gf_matrix_from_transform(float m[4][4]);
|
|
||||||
std::string cache_image(Main *bmain,
|
|
||||||
Scene *scene,
|
|
||||||
Image *image,
|
|
||||||
ImageUser *iuser,
|
|
||||||
ImageSaveOptions *opts,
|
|
||||||
ReportList *reports);
|
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
|
@ -1535,6 +1535,7 @@ if((DEFINED LIBDIR) AND TARGETDIR_LIB)
|
|||||||
)
|
)
|
||||||
install(DIRECTORY
|
install(DIRECTORY
|
||||||
${LIBDIR}/usd/plugin/usd/usdShaders
|
${LIBDIR}/usd/plugin/usd/usdShaders
|
||||||
|
${LIBDIR}/usd/plugin/usd/hioOiio
|
||||||
DESTINATION "./blender.shared/usd"
|
DESTINATION "./blender.shared/usd"
|
||||||
)
|
)
|
||||||
elseif(USD_PYTHON_SUPPORT)
|
elseif(USD_PYTHON_SUPPORT)
|
||||||
|
Loading…
Reference in New Issue
Block a user