From 5cd56e45ed081bba423aee0b9ccd3fd5c5fda011 Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Tue, 17 Dec 2024 17:21:53 +0800 Subject: [PATCH 1/2] improve-heatmap --- zeno/src/nodes/mtl/ShaderTexture.cpp | 40 ++++++++++++++-------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/zeno/src/nodes/mtl/ShaderTexture.cpp b/zeno/src/nodes/mtl/ShaderTexture.cpp index 63b21532d5..3d8b2a9d2a 100644 --- a/zeno/src/nodes/mtl/ShaderTexture.cpp +++ b/zeno/src/nodes/mtl/ShaderTexture.cpp @@ -190,6 +190,26 @@ struct SmartTexture2D : ShaderNodeClone auto texId = em->tex2Ds.size(); auto tex = std::make_shared(); auto texture_path = get_input2("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("heatmap"); + std::vector 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("type"); @@ -242,26 +262,6 @@ struct SmartTexture2D : ShaderNodeClone } 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("heatmap"); - std::vector 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("blockCompression"); #define SET_TEX_WRAP(TEX, WRAP) \ From cadf44d32174c6a94f688376752216819a9ea3ad Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Tue, 17 Dec 2024 20:19:09 +0800 Subject: [PATCH 2/2] fix --- zenovis/xinxinoptix/OptiXStuff.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/zenovis/xinxinoptix/OptiXStuff.h b/zenovis/xinxinoptix/OptiXStuff.h index 1187c5d099..62bad9215d 100644 --- a/zenovis/xinxinoptix/OptiXStuff.h +++ b/zenovis/xinxinoptix/OptiXStuff.h @@ -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);