c++renderingmayaopenvdb

Cannot get two grids working in one OpenVDB file


The problem is the following:

I have two different float valued (density) grids for the same space.

I can write them both to one OpenVDB file with the code below. But when I try to do a volumetric rendering with Arnold in Maya, both grids seem to contain the same values.

I can confirm that the grids are completely different in a preview (in Mantaflow) and that the file contains the two grids.

It seems to me that the values of the first grid are somehow overwritten with the values of the second grid.

Here is the relevant part from the Mantaflow Plugin for writing the OpenVDB file:

void
write_grids_to_vdb(
  const std::vector<
    std::pair<const Grid<Real>&,
              const std::string>
  > & grids_names,
  const std::string filename)
{

  openvdb::initialize();
  openvdb::GridPtrVec grids;

  for (const auto& gn: grids_names) {

    auto vdb_grid = openvdb::FloatGrid::create(0.0);
    vdb_grid->setTransform(
      openvdb::math::Transform::createLinearTransform(1.0));
    vdb_grid->setGridClass(openvdb::GRID_FOG_VOLUME);
    vdb_grid->setName(gn.second);

    openvdb::Coord ijk;
    typename openvdb::FloatGrid::Accessor
      accessor = vdb_grid->getAccessor();
    FOR_IJK(gn.first)
    {
      ijk[0] = i; ijk[1] = j; ijk[2] = k;
      accessor.setValue(ijk, gn.first(i,j,k));
    }

    grids.push_back(vdb_grid);

  }

  openvdb::io::File file(filename);
  file.write(grids);
  file.close();
}

So I use this to write two grids 'green' and 'red', but in my rendered picture both look like red should look.

And here is a screenshot from my corresponding setup for Maya/Arnold setup...

Selecting both grids as input

I just tried out the different channels from the volumecollector and got the same picture.

Can change the channel, both look like 'red'

And for what it is worth here is also what the rendered pictures look like:

red comes from above, green missing


Solution

  • Workaround: export multiple VDB files and load them into multiple arnold volumes.