From 63a9f24b55d0b5d84d625bdbb44d498fb1f2ae01 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Tue, 20 Oct 2020 11:00:16 +0200 Subject: Volumes: simplify volumes in modifiers or on load This changes how the simplify volumes setting works. Before, it only affeted viewport rendering. This was an issue, because all internal computations would still have to happen on the high resolution volumes. With this patch, the simplify setting already affects file loading and procedural generation of volumes. Rendering does not have to care about the simplify option anymore, it just gets the correct simplified version from the depsgraph. Reviewers: brecht Differential Revision: https://developer.blender.org/D9176 --- source/blender/blenkernel/intern/volume_render.cc | 54 +---------------------- 1 file changed, 1 insertion(+), 53 deletions(-) (limited to 'source/blender/blenkernel/intern/volume_render.cc') diff --git a/source/blender/blenkernel/intern/volume_render.cc b/source/blender/blenkernel/intern/volume_render.cc index 8e8cfb5945a..37b397a9c6d 100644 --- a/source/blender/blenkernel/intern/volume_render.cc +++ b/source/blender/blenkernel/intern/volume_render.cc @@ -34,59 +34,12 @@ #ifdef WITH_OPENVDB # include # include -# include #endif /* Dense Voxels */ #ifdef WITH_OPENVDB -/** - * Returns a grid of the same type as the input, but with more/less resolution. If - * resolution_factor is 1/2, the resolution on each axis is halved. The transform of the returned - * grid is adjusted to match the original grid. */ -template -static typename GridType::Ptr create_grid_with_changed_resolution(const GridType &old_grid, - const float resolution_factor) -{ - BLI_assert(resolution_factor > 0.0f); - - openvdb::Mat4R xform; - xform.setToScale(openvdb::Vec3d(resolution_factor)); - openvdb::tools::GridTransformer transformer{xform}; - - typename GridType::Ptr new_grid = GridType::create(); - transformer.transformGrid(old_grid, *new_grid); - new_grid->transform() = old_grid.transform(); - new_grid->transform().preScale(1.0f / resolution_factor); - return new_grid; -} - -struct CreateGridWithChangedResolutionOp { - const openvdb::GridBase &grid; - const float resolution_factor; - - template typename openvdb::GridBase::Ptr operator()() - { - if constexpr (std::is_same_v) { - return {}; - } - else { - return create_grid_with_changed_resolution(static_cast(grid), - resolution_factor); - } - } -}; - -static openvdb::GridBase::Ptr create_grid_with_changed_resolution( - const VolumeGridType grid_type, - const openvdb::GridBase &old_grid, - const float resolution_factor) -{ - CreateGridWithChangedResolutionOp op{old_grid, resolution_factor}; - return BKE_volume_grid_type_operation(grid_type, op); -} - template static void extract_dense_voxels(const openvdb::GridBase &grid, const openvdb::CoordBBox bbox, @@ -152,16 +105,11 @@ static void create_texture_to_object_matrix(const openvdb::Mat4d &grid_transform bool BKE_volume_grid_dense_floats(const Volume *volume, VolumeGrid *volume_grid, - const float resolution_factor, DenseFloatVolumeGrid *r_dense_grid) { #ifdef WITH_OPENVDB const VolumeGridType grid_type = BKE_volume_grid_type(volume_grid); - openvdb::GridBase::ConstPtr grid = BKE_volume_grid_openvdb_for_read(volume, volume_grid); - if (resolution_factor != 1.0f) { - grid = create_grid_with_changed_resolution(grid_type, *grid, resolution_factor); - } const openvdb::CoordBBox bbox = grid->evalActiveVoxelBoundingBox(); if (bbox.empty()) { @@ -189,7 +137,7 @@ bool BKE_volume_grid_dense_floats(const Volume *volume, copy_v3_v3_int(r_dense_grid->resolution, resolution.asV()); return true; #endif - UNUSED_VARS(volume, volume_grid, resolution_factor, r_dense_grid); + UNUSED_VARS(volume, volume_grid, r_dense_grid); return false; } -- cgit v1.2.3