Skip to content

Commit

Permalink
Merge pull request #1888 from zenustech/seperate-aov
Browse files Browse the repository at this point in the history
seperate-aov and vertex-color
  • Loading branch information
ShuliangLu authored Apr 22, 2024
2 parents a4302a3 + 726587e commit 7a6196d
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 32 deletions.
59 changes: 58 additions & 1 deletion projects/Alembic/ReadAlembic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <filesystem>
#include <zeno/utils/string.h>
#include <zeno/utils/scope_exit.h>
#include <numeric>

#ifdef ZENO_WITH_PYTHON3
#include <Python.h>
Expand Down Expand Up @@ -417,6 +418,62 @@ static void read_attributes2(std::shared_ptr<PrimitiveObject> prim, ICompoundPro
}
attr_from_data_vec(prim, samp.getScope(), p.getName(), data);
}
else if (IC4fGeomParam::matches(p)) {
IC4fGeomParam param(arbattrs, p.getName());

IC4fGeomParam::Sample samp = param.getIndexedValue(iSS);
std::vector<vec4f> data;
data.resize(samp.getVals()->size());
std::vector<vec3f> data_xyz(samp.getVals()->size());
std::vector<float> data_w(samp.getVals()->size());
for (auto i = 0; i < samp.getVals()->size(); i++) {
auto v = samp.getVals()->get()[i];
data[i] = {v[0], v[1], v[2], v[3]};
data_xyz[i] = {v[0], v[1], v[2]};
data_w[i] = v[3];
}
if (!read_done) {
log_info("[alembic] C4f attr {}, len {}.", p.getName(), data.size());
}
attr_from_data_vec(prim, samp.getScope(), p.getName(), data);
attr_from_data_vec(prim, samp.getScope(), p.getName() + "_rgb", data_xyz);
attr_from_data_vec(prim, samp.getScope(), p.getName() + "_a", data_w);
}
else {
log_info("[alembic] unknown attr {}.", p.getName());
zeno::log_info("getExtent {} ", p.getDataType().getExtent());
zeno::log_info("getNumBytes {} ", p.getDataType().getNumBytes());
zeno::log_info("getPod {} ", p.getDataType().getPod());
}
}
{
if (prim->loops.attr_keys<AttrAcceptAll>().size() == 0) {
return;
}
if (prim->loops.attr_keys<AttrAcceptAll>().size() == 1 && prim->loops.has_attr("uvs")) {
return;
}
if (!prim->loops.has_attr("uvs")) {
prim->loops.add_attr<int>("uvs");
prim->uvs.emplace_back();
}
{
std::vector<vec2f> uvs(prim->loops.size());
auto &uv_index = prim->loops.attr<int>("uvs");
for (auto i = 0; i < prim->loops.size(); i++) {
uvs[i] = prim->uvs[uv_index[i]];
}
prim->uvs.values = uvs;
std::iota(uv_index.begin(), uv_index.end(), 0);
prim->loops.foreach_attr<AttrAcceptAll>([&] (auto const &key, auto &arr) {
if (key == "uvs") {
return;
}
using T = std::decay_t<decltype(arr[0])>;
auto &attr = prim->uvs.add_attr<T>(key);
std::copy(arr.begin(), arr.end(), attr.begin());
});
}
}
}

Expand Down Expand Up @@ -1358,7 +1415,7 @@ ZENDEFNODE(PrimsFilterInUserdata, {
{"bool", "fuzzy", "0"},
},
{
{"out"},
{"list", "out"},
},
{},
{"alembic"},
Expand Down
3 changes: 3 additions & 0 deletions ui/zenoedit/launch/optixcmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ int optixcmd(const QCoreApplication& app, int port)
{"video", "video", "export video"},
{"aov", "aov", "aov"},
{"exr", "exr", "exr"},
{"mask", "mask", "mask"},
{"needDenoise", "needDenoise", "needDenoise"},
{"videoname", "videoname", "export video's name"},
{"subzsg", "subgraphzsg", "subgraph zsg file path"},
Expand Down Expand Up @@ -116,6 +117,8 @@ int optixcmd(const QCoreApplication& app, int port)
ud.set2("output_aov", enableAOV != 0);
ud.set2("output_exr", exportExr != 0);
ud.set2("optix_show_background", optixShowBackground);
int enableMask = cmdParser.isSet("mask") ? cmdParser.value("mask").toInt() : 0;
ud.set2("output_mask", enableMask != 0);
param.videoName = cmdParser.isSet("videoname") ? cmdParser.value("videoname") : "output.mp4";
param.subZsg = cmdParser.isSet("subzsg") ? cmdParser.value("subzsg") : "";
#else
Expand Down
86 changes: 55 additions & 31 deletions zenovis/xinxinoptix/optixPathTracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3809,6 +3809,26 @@ static void save_exr(float3* ptr, int w, int h, std::string path) {
}
}
}
static void save_png_data(std::string path, int w, int h, float* ptr) {
std::vector<uint8_t> data;
data.reserve(w * h * 3);
for (auto i = 0; i < w * h * 3; i++) {
data.push_back(std::lround(ptr[i] * 255.0f));
}
std::string native_path = zeno::create_directories_when_write_file(path);
stbi_flip_vertically_on_write(1);
stbi_write_png(native_path.c_str(), w, h, 3, data.data(),0);
}
static void save_png_color(std::string path, int w, int h, float* ptr) {
std::vector<uint8_t> data;
data.reserve(w * h * 3);
for (auto i = 0; i < w * h * 3; i++) {
data.push_back(std::lround(pow(ptr[i], 1.0f/2.2f) * 255.0f));
}
std::string native_path = zeno::create_directories_when_write_file(path);
stbi_flip_vertically_on_write(1);
stbi_write_png(native_path.c_str(), w, h, 3, data.data(),0);
}
void optixrender(int fbo, int samples, bool denoise, bool simpleRender) {

bool imageRendered = false;
Expand Down Expand Up @@ -3849,40 +3869,44 @@ void optixrender(int fbo, int samples, bool denoise, bool simpleRender) {
bool enable_output_mask = zeno::getSession().userData().get2<bool>("output_mask", false);
auto exr_path = path.substr(0, path.size() - 4) + ".exr";
if (enable_output_mask) {
std::vector<uint8_t> data;
data.reserve(w * h * 3);
float* ptr = (float *)optixgetimg_extra("mask");
for (auto i = 0; i < w * h * 3; i++) {
data.push_back(int(ptr[i]));
}
std::string native_path = zeno::create_directories_when_write_file(path + "_mask.png");
stbi_flip_vertically_on_write(1);
stbi_write_png(native_path.c_str(), w, h, 3, data.data(),0);
path = path.substr(0, path.size() - 4);
save_png_data(path + "_mask.png", w, h, (float*)optixgetimg_extra("mask"));
}
// AOV
if (enable_output_aov) {
zeno::create_directories_when_write_file(exr_path);
SaveMultiLayerEXR(
{
(float*)optixgetimg_extra("color"),
(float*)optixgetimg_extra("diffuse"),
(float*)optixgetimg_extra("specular"),
(float*)optixgetimg_extra("transmit"),
(float*)optixgetimg_extra("background"),
(float*)optixgetimg_extra("mask"),
},
w,
h,
{
"",
"diffuse.",
"specular.",
"transmit.",
"background.",
"mask.",
},
exr_path.c_str()
);
if (enable_output_exr) {
zeno::create_directories_when_write_file(exr_path);
SaveMultiLayerEXR(
{
(float*)optixgetimg_extra("color"),
(float*)optixgetimg_extra("diffuse"),
(float*)optixgetimg_extra("specular"),
(float*)optixgetimg_extra("transmit"),
(float*)optixgetimg_extra("background"),
(float*)optixgetimg_extra("mask"),
},
w,
h,
{
"",
"diffuse.",
"specular.",
"transmit.",
"background.",
"mask.",
},
exr_path.c_str()
);

}
else {
path = path.substr(0, path.size() - 4);
save_png_color(path + ".aov.diffuse.png", w, h, (float*)optixgetimg_extra("diffuse"));
save_png_color(path + ".aov.specular.png", w, h, (float*)optixgetimg_extra("specular"));
save_png_color(path + ".aov.transmit.png", w, h, (float*)optixgetimg_extra("transmit"));
save_png_data(path + ".aov.background.png", w, h, (float*)optixgetimg_extra("background"));
save_png_data(path + ".aov.mask.png", w, h, (float*)optixgetimg_extra("mask"));
}
}
else {
if (enable_output_exr) {
Expand Down

0 comments on commit 7a6196d

Please sign in to comment.