Skip to content

Commit

Permalink
Merge pull request #2073 from zenustech/improve-optix
Browse files Browse the repository at this point in the history
improve-heatmap
  • Loading branch information
zhxx1987 authored Dec 18, 2024
2 parents b518b64 + cadf44d commit fa3832a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
40 changes: 20 additions & 20 deletions zeno/src/nodes/mtl/ShaderTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,26 @@ struct SmartTexture2D : ShaderNodeClone<SmartTexture2D>
auto texId = em->tex2Ds.size();
auto tex = std::make_shared<zeno::Texture2DObject>();
auto texture_path = get_input2<std::string>("path");
if (has_input("heatmap")) {
if (texture_path.empty()) {
std::srand(std::time(0));
texture_path = std::filesystem::temp_directory_path().string() + '/' + "heatmap-" + std::to_string(std::rand()) + ".png";
}
auto heatmap = get_input<zeno::HeatmapObject>("heatmap");
std::vector<uint8_t> col;
int width = heatmap->colors.size();
int height = width;
col.reserve(width * height * 3);
for (auto i = 0; i < height; i++) {
for (auto & color : heatmap->colors) {
col.push_back(zeno::clamp(int(color[0] * 255.99), 0, 255));
col.push_back(zeno::clamp(int(color[1] * 255.99), 0, 255));
col.push_back(zeno::clamp(int(color[2] * 255.99), 0, 255));
}
}
stbi_flip_vertically_on_write(false);
stbi_write_png(texture_path.c_str(), width, height, 3, col.data(), 0);
}
if(!std::filesystem::exists(std::filesystem::u8path(texture_path))){
zeno::log_warn("texture file not found!");
auto type = get_input2<std::string>("type");
Expand Down Expand Up @@ -242,26 +262,6 @@ struct SmartTexture2D : ShaderNodeClone<SmartTexture2D>
}

tex->path = texture_path;
if (has_input("heatmap")) {
if (tex->path.empty()) {
std::srand(std::time(0));
tex->path = std::filesystem::temp_directory_path().string() + '/' + "heatmap-" + std::to_string(std::rand()) + ".png";
}
auto heatmap = get_input<zeno::HeatmapObject>("heatmap");
std::vector<uint8_t> col;
int width = heatmap->colors.size();
int height = width;
col.reserve(width * height * 3);
for (auto i = 0; i < height; i++) {
for (auto & color : heatmap->colors) {
col.push_back(zeno::clamp(int(color[0] * 255.99), 0, 255));
col.push_back(zeno::clamp(int(color[1] * 255.99), 0, 255));
col.push_back(zeno::clamp(int(color[2] * 255.99), 0, 255));
}
}
stbi_flip_vertically_on_write(false);
stbi_write_png(tex->path.c_str(), width, height, 3, col.data(), 0);
}
tex->blockCompression = get_input2<bool>("blockCompression");

#define SET_TEX_WRAP(TEX, WRAP) \
Expand Down
6 changes: 1 addition & 5 deletions zenovis/xinxinoptix/OptiXStuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -874,11 +874,7 @@ inline void addTexture(std::string path, bool blockCompression=false, TaskType*
{
std::string native_path = std::filesystem::u8path(path).string();

TexKey tex_key {path, blockCompression};

if (tex_lut.count(tex_key)) {
return; // do nothing
}
TexKey tex_key {path, blockCompression};

zeno::log_debug("loading texture :{}", path);

Expand Down

0 comments on commit fa3832a

Please sign in to comment.