Skip to content

Commit

Permalink
load density/temp with specified keys
Browse files Browse the repository at this point in the history
  • Loading branch information
cuteday committed Nov 11, 2023
1 parent 5a66606 commit 181e4cb
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 32 deletions.
2 changes: 1 addition & 1 deletion common/configs/example_cbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"enable": true,
"name": "ToneMappingPass",
"params": {
"exposure": 1,
"exposure": 5,
"operator": "aces"
}
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion src/core/device/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ void RTScene::uploadSceneMediumData() {
} else if (auto m = std::dynamic_pointer_cast<VDBVolume>(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();
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/core/scenegraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,6 @@ class VDBVolume : public Volume {
public:
using SharedPtr = std::shared_ptr<VDBVolume>;

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) {}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kiraray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 0 additions & 8 deletions src/render/media.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
3 changes: 0 additions & 3 deletions src/render/media.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions src/scene/krrscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 9 additions & 5 deletions src/scene/openvdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ bool OpenVDBImporter::import(const fs::path filepath, Scene::SharedPtr scene,
scene->getSceneGraph()->setRoot(node);
}

auto sigma_a = params.value<Array3f>("sigma_a", Array3f{1, 1, 1});
auto sigma_s = params.value<Array3f>("sigma_s", Array3f{0, 0, 0});
float g = params.value<float>("g", 0);
auto sigma_a = params.value<Array3f>("sigma_a", Array3f{1, 1, 1});
auto sigma_s = params.value<Array3f>("sigma_s", Array3f{0, 0, 0});
auto key_density = params.value<string>("key_density", "density");
auto key_temperature = params.value<string>("key_temperature", "temperature");
float g = params.value<float>("g", 0);

NanoVDBGrid::SharedPtr densityGrid = loadNanoVDB(filepath, key_density);
NanoVDBGrid::SharedPtr temperatureGrid = loadNanoVDB(filepath, key_temperature);
auto volume = std::make_shared<VDBVolume>(sigma_a, sigma_s, g, densityGrid, temperatureGrid);

auto mesh = std::make_shared<Mesh>();
auto instance = std::make_shared<MeshInstance>(mesh);
auto volume = std::make_shared<VDBVolume>(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},
Expand Down
12 changes: 5 additions & 7 deletions src/util/volume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,25 @@

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());
if (!file.open())
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<openvdb::FloatGrid>(baseGrid);
auto transform = grid->transform();
auto handle = nanovdb::openToNanoVDB<nanovdb::CudaDeviceBuffer>(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);
Expand Down
2 changes: 1 addition & 1 deletion src/util/volume.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 181e4cb

Please sign in to comment.