Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-10-20 12:00:16 +0300
committerJacques Lucke <jacques@blender.org>2020-10-20 12:00:16 +0300
commit63a9f24b55d0b5d84d625bdbb44d498fb1f2ae01 (patch)
tree217fa45ec9b0c66f856dd8b32d8ab3d5cbc18d3d /source/blender/modifiers
parentf3ecb4c91e159caff2e6d335adb1ccf06423c90f (diff)
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
Diffstat (limited to 'source/blender/modifiers')
-rw-r--r--source/blender/modifiers/intern/MOD_mesh_to_volume.cc21
-rw-r--r--source/blender/modifiers/intern/MOD_volume_displace.cc2
2 files changed, 16 insertions, 7 deletions
diff --git a/source/blender/modifiers/intern/MOD_mesh_to_volume.cc b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc
index 508c84c3e8f..2e45ac66cff 100644
--- a/source/blender/modifiers/intern/MOD_mesh_to_volume.cc
+++ b/source/blender/modifiers/intern/MOD_mesh_to_volume.cc
@@ -33,7 +33,7 @@
#include "DNA_screen_types.h"
#include "DNA_volume_types.h"
-#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph.h"
#include "UI_interface.h"
#include "UI_resources.h"
@@ -176,12 +176,19 @@ static void panelRegister(ARegionType *region_type)
modifier_panel_register(region_type, eModifierType_MeshToVolume, panel_draw);
}
-static float compute_voxel_size(const MeshToVolumeModifierData *mvmd,
+static float compute_voxel_size(const ModifierEvalContext *ctx,
+ const MeshToVolumeModifierData *mvmd,
const blender::float4x4 &transform)
{
using namespace blender;
+
+ float volume_simplify = BKE_volume_simplify_factor(ctx->depsgraph);
+ if (volume_simplify == 0.0f) {
+ return 0.0f;
+ }
+
if (mvmd->resolution_mode == MESH_TO_VOLUME_RESOLUTION_MODE_VOXEL_SIZE) {
- return mvmd->voxel_size;
+ return mvmd->voxel_size / volume_simplify;
}
if (mvmd->voxel_amount <= 0) {
return 0;
@@ -192,7 +199,7 @@ static float compute_voxel_size(const MeshToVolumeModifierData *mvmd,
const float diagonal = float3::distance(transform * float3(bb->vec[6]),
transform * float3(bb->vec[0]));
const float approximate_volume_side_length = diagonal + mvmd->exterior_band_width * 2.0f;
- const float voxel_size = approximate_volume_side_length / mvmd->voxel_amount;
+ const float voxel_size = approximate_volume_side_length / mvmd->voxel_amount / volume_simplify;
return voxel_size;
}
@@ -215,7 +222,7 @@ static Volume *modifyVolume(ModifierData *md, const ModifierEvalContext *ctx, Vo
const float4x4 mesh_to_own_object_space_transform = float4x4(ctx->object->imat) *
float4x4(object_to_convert->obmat);
- const float voxel_size = compute_voxel_size(mvmd, mesh_to_own_object_space_transform);
+ const float voxel_size = compute_voxel_size(ctx, mvmd, mesh_to_own_object_space_transform);
if (voxel_size == 0.0f) {
return input_volume;
}
@@ -246,8 +253,8 @@ static Volume *modifyVolume(ModifierData *md, const ModifierEvalContext *ctx, Vo
/* Create a new volume object and add the density grid. */
Volume *volume = BKE_volume_new_for_eval(input_volume);
VolumeGrid *c_density_grid = BKE_volume_grid_add(volume, "density", VOLUME_GRID_FLOAT);
- openvdb::FloatGrid::Ptr density_grid = BKE_volume_grid_openvdb_for_write<openvdb::FloatGrid>(
- volume, c_density_grid, false);
+ openvdb::FloatGrid::Ptr density_grid = openvdb::gridPtrCast<openvdb::FloatGrid>(
+ BKE_volume_grid_openvdb_for_write(volume, c_density_grid, false));
/* Merge the generated grid into the density grid. Should be cheap because density_grid has just
* been created as well. */
diff --git a/source/blender/modifiers/intern/MOD_volume_displace.cc b/source/blender/modifiers/intern/MOD_volume_displace.cc
index 18ecefda881..22bf5cd4893 100644
--- a/source/blender/modifiers/intern/MOD_volume_displace.cc
+++ b/source/blender/modifiers/intern/MOD_volume_displace.cc
@@ -33,6 +33,7 @@
#include "DNA_volume_types.h"
#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_query.h"
#include "UI_interface.h"
#include "UI_resources.h"
@@ -290,6 +291,7 @@ static Volume *modifyVolume(ModifierData *md, const ModifierEvalContext *ctx, Vo
VolumeDisplaceModifierData *vdmd = reinterpret_cast<VolumeDisplaceModifierData *>(md);
/* Iterate over all grids and displace them one by one. */
+ BKE_volume_load(volume, DEG_get_bmain(ctx->depsgraph));
const int grid_amount = BKE_volume_num_grids(volume);
for (int grid_index = 0; grid_index < grid_amount; grid_index++) {
VolumeGrid *volume_grid = BKE_volume_grid_get(volume, grid_index);