diff --git a/common/configs/example_cbox.json b/common/configs/example_cbox.json index 81034297..bd243768 100644 --- a/common/configs/example_cbox.json +++ b/common/configs/example_cbox.json @@ -30,7 +30,7 @@ "enable": true, "name": "ToneMappingPass", "params": { - "exposure": 1, + "exposure": 5, "operator": "aces" } } diff --git a/common/configs/example_cboxmist.json b/common/configs/volumetric/example_cboxmist.json similarity index 100% rename from common/configs/example_cboxmist.json rename to common/configs/volumetric/example_cboxmist.json diff --git a/common/configs/example_smoke.json b/common/configs/volumetric/example_smoke.json similarity index 100% rename from common/configs/example_smoke.json rename to common/configs/volumetric/example_smoke.json diff --git a/common/configs/example_teapot.json b/common/configs/volumetric/example_teapot.json similarity index 100% rename from common/configs/example_teapot.json rename to common/configs/volumetric/example_teapot.json diff --git a/src/core/device/scene.cpp b/src/core/device/scene.cpp index 7f735fa5..0df5729b 100644 --- a/src/core/device/scene.cpp +++ b/src/core/device/scene.cpp @@ -156,7 +156,10 @@ void RTScene::uploadSceneMediumData() { } else if (auto m = std::dynamic_pointer_cast(medium)) { float maxDensity{0}; mNanoVDBMedium.emplace_back(m->getNode()->getGlobalTransform(), m->sigma_a, m->sigma_s, - m->g, std::move(*m->densityGrid), KRR_DEFAULT_COLORSPACE); + m->g, std::move(*m->densityGrid), + m->temperatureGrid ? std::move(*m->temperatureGrid) + : NanoVDBGrid{}, + KRR_DEFAULT_COLORSPACE); mNanoVDBMedium.back().initializeFromHost(); } } diff --git a/src/core/scenegraph.h b/src/core/scenegraph.h index b8b93bee..5c9282bb 100644 --- a/src/core/scenegraph.h +++ b/src/core/scenegraph.h @@ -165,11 +165,6 @@ class VDBVolume : public Volume { public: using SharedPtr = std::shared_ptr; - VDBVolume(RGB sigma_a, RGB sigma_s, float g, fs::path filepath) : - sigma_a(sigma_a), sigma_s(sigma_s), g(g) { - densityGrid = loadNanoVDB(filepath); - } - VDBVolume(RGB sigma_a, RGB sigma_s, float g, NanoVDBGrid::SharedPtr density, NanoVDBGrid::SharedPtr temperature = nullptr) : sigma_a(sigma_a), sigma_s(sigma_s), g(g), densityGrid(density), temperatureGrid(temperature) {} diff --git a/src/main/kiraray.cpp b/src/main/kiraray.cpp index c52542e0..fd2872f8 100644 --- a/src/main/kiraray.cpp +++ b/src/main/kiraray.cpp @@ -14,7 +14,7 @@ extern "C" int main(int argc, char *argv[]) { "Switch to Release build for normal performance!"); #endif - string configFile = "common/configs/example_volbox.json"; + string configFile = "common/configs/example_cbox.json"; if (argc < 2){ Log(Warning, "No config file specified, using default config file: %s", configFile.c_str()); } else { diff --git a/src/render/media.cpp b/src/render/media.cpp index 7ead3f3a..60845543 100644 --- a/src/render/media.cpp +++ b/src/render/media.cpp @@ -58,14 +58,6 @@ void initializeMajorantGrid(MajorantGrid& majorantGrid, }, 0); } -NanoVDBMedium::NanoVDBMedium(const Affine3f &transform, RGB sigma_a, RGB sigma_s, float g, - NanoVDBGrid density, const RGBColorSpace *colorSpace) : - transform(transform), phase(g), sigma_a(sigma_a), sigma_s(sigma_s), densityGrid(std::move(density)), colorSpace(colorSpace) { - inverseTransform = transform.inverse(); - const Vector3f majorantGridRes{64, 64, 64}; - majorantGrid = MajorantGrid(densityGrid.getBounds(), majorantGridRes); -} - NanoVDBMedium::NanoVDBMedium(const Affine3f &transform, RGB sigma_a, RGB sigma_s, float g, NanoVDBGrid density, NanoVDBGrid temperature, const RGBColorSpace *colorSpace) : transform(transform), phase(g), sigma_a(sigma_a), sigma_s(sigma_s), densityGrid(std::move(density)), diff --git a/src/render/media.h b/src/render/media.h index f1ed40f7..4da367bc 100644 --- a/src/render/media.h +++ b/src/render/media.h @@ -136,9 +136,6 @@ class HomogeneousMedium { class NanoVDBMedium { public: - NanoVDBMedium(const Affine3f &transform, RGB sigma_a, RGB sigma_s, float g, - NanoVDBGrid density, const RGBColorSpace *colorSpace = KRR_DEFAULT_COLORSPACE); - NanoVDBMedium(const Affine3f &transform, RGB sigma_a, RGB sigma_s, float g, NanoVDBGrid density, NanoVDBGrid temperature, const RGBColorSpace *colorSpace = KRR_DEFAULT_COLORSPACE); diff --git a/src/scene/krrscene.cpp b/src/scene/krrscene.cpp index cf730523..1c7e7ad4 100644 --- a/src/scene/krrscene.cpp +++ b/src/scene/krrscene.cpp @@ -56,6 +56,7 @@ bool SceneImporter::loadMedium(Scene::SharedPtr pScene, SceneGraphNode::SharedPt pScene->addMesh(mesh); pScene->getSceneGraph()->attachLeaf(node, instance); pScene->getSceneGraph()->attachLeaf(node, volume); + return true; } else if (type == "heterogeneous") { if (params.contains("file")) { return OpenVDBImporter().import(params.at("file"), pScene, node, params); diff --git a/src/scene/openvdb.cpp b/src/scene/openvdb.cpp index 0ae823ee..82a79bee 100644 --- a/src/scene/openvdb.cpp +++ b/src/scene/openvdb.cpp @@ -16,14 +16,18 @@ bool OpenVDBImporter::import(const fs::path filepath, Scene::SharedPtr scene, scene->getSceneGraph()->setRoot(node); } - auto sigma_a = params.value("sigma_a", Array3f{1, 1, 1}); - auto sigma_s = params.value("sigma_s", Array3f{0, 0, 0}); - float g = params.value("g", 0); + auto sigma_a = params.value("sigma_a", Array3f{1, 1, 1}); + auto sigma_s = params.value("sigma_s", Array3f{0, 0, 0}); + auto key_density = params.value("key_density", "density"); + auto key_temperature = params.value("key_temperature", "temperature"); + float g = params.value("g", 0); + + NanoVDBGrid::SharedPtr densityGrid = loadNanoVDB(filepath, key_density); + NanoVDBGrid::SharedPtr temperatureGrid = loadNanoVDB(filepath, key_temperature); + auto volume = std::make_shared(sigma_a, sigma_s, g, densityGrid, temperatureGrid); auto mesh = std::make_shared(); auto instance = std::make_shared(mesh); - auto volume = std::make_shared(sigma_a, sigma_s, g, filepath); - /* initialize a intersection bounding box for this volume */ auto aabb = volume->densityGrid->getBounds(); mesh->indices = {{4, 2, 0}, {2, 7, 3}, {6, 5, 7}, {1, 7, 5}, {0, 3, 1}, {4, 1, 5}, diff --git a/src/util/volume.cpp b/src/util/volume.cpp index 8d5bcb49..06dd4029 100644 --- a/src/util/volume.cpp +++ b/src/util/volume.cpp @@ -17,7 +17,7 @@ KRR_NAMESPACE_BEGIN -NanoVDBGrid::SharedPtr loadNanoVDB(std::filesystem::path path) { +NanoVDBGrid::SharedPtr loadNanoVDB(std::filesystem::path path, std::string key) { openvdb::initialize(); Log(Info, "Loading openvdb file from %s", path.string().c_str()); openvdb::io::File file(path.generic_string()); @@ -25,19 +25,17 @@ NanoVDBGrid::SharedPtr loadNanoVDB(std::filesystem::path path) { Log(Fatal, "Failed to open vdb file %s", path.string().c_str()); openvdb::GridBase::Ptr baseGrid; - if(file.hasGrid("density")) - baseGrid = file.readGrid("density"); + if (file.hasGrid(key.c_str())) + baseGrid = file.readGrid(key.c_str()); else { - baseGrid = file.getGrids()->at(0); - Log(Warning, "VDB file do not pocess a density grid, loading the first grid [%s].", - baseGrid->getName().c_str()); + Log(Warning, "VDB file %s do not pocess a [%s] grid.", path.string().c_str(), key.c_str()); + return nullptr; } auto grid = openvdb::gridPtrCast(baseGrid); auto transform = grid->transform(); auto handle = nanovdb::openToNanoVDB(grid); const nanovdb::GridMetaData *metadata = handle.gridMetaData(); - Log(Info, "Find a vdb grid: %s", metadata->gridName()); if (metadata->gridType() != nanovdb::GridType::Float) Log(Fatal, "only support float grid!"); float minValue, maxValue; grid->evalMinMax(minValue, maxValue); diff --git a/src/util/volume.h b/src/util/volume.h index b14791be..bd022ff0 100644 --- a/src/util/volume.h +++ b/src/util/volume.h @@ -58,6 +58,6 @@ class NanoVDBGrid { float maxDensity{0}; }; -NanoVDBGrid::SharedPtr loadNanoVDB(std::filesystem::path path); +NanoVDBGrid::SharedPtr loadNanoVDB(std::filesystem::path path, std::string key); KRR_NAMESPACE_END \ No newline at end of file