Blender V5.3
scene/volume.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include "graph/node.h"
8
9#include "scene/mesh.h"
10
11#ifdef WITH_OPENVDB
12# include <openvdb/openvdb.h>
13#endif
14
16
17class Object;
18class Octree;
19
20class Volume : public Mesh {
21 public:
23
24 Volume();
25
26 NODE_SOCKET_API(float, step_size)
27 NODE_SOCKET_API(bool, object_space)
28 NODE_SOCKET_API(float, velocity_scale)
29
30 /* Merge attributes for efficiency, call right after creating them. */
31 void merge_grids(const Scene *scene);
32
33 void clear(bool preserve_shaders = false) override;
34};
35
37 public:
40
41 void device_update(Device *, DeviceScene *, const Scene *, Progress &);
43
44 /* Tag volume octree for update when scene changes. */
45 void tag_update();
46 void tag_update(const Shader *shader);
47 void tag_update(const set<Object *> &objects, const uint32_t flag);
48 void tag_update(const set<Geometry *> &geometry);
49 void tag_update_indices();
51
52 /* Check whether the shader is a homogeneous volume. */
53 static bool is_homogeneous_volume(const Object *, const Shader *);
54
56
57 private:
58 /* Initialize octrees from the volumes in the scene. */
59 void initialize_octree(const Scene *, Progress &);
60
61 /* Build octrees based on the volume density. */
62 void build_octree(Device *, Progress &);
63
64 /* Update the object and shader index of octree root nodes. */
65 void update_root_indices(DeviceScene *, const Scene *) const;
66
67 /* Converting the octrees into an array for uploading to the kernel. */
68 void flatten_octree(DeviceScene *, const Scene *) const;
69
70 /* Count all the nodes of the octrees. */
71 void update_num_octree_nodes();
72 int num_octree_nodes() const;
73 int num_octree_roots() const;
74
75 /* When running Blender with environment variable `CYCLES_VOLUME_OCTREE_DUMP`, an octree
76 * visualization is written to `filename`, which is a Python script that can be run inside
77 * Blender. */
78 std::string visualize_octree(const char *filename) const;
79
80 /* Step size for ray marching. */
81 void update_step_size(const Scene *, DeviceScene *, Progress &progress);
82
83 /* One octree per object per shader. */
84 std::map<std::pair<const Object *, const Shader *>, std::shared_ptr<Octree>> object_octrees_;
85
86 /* TODO(weizhen): replace booleans with enum `update_flags`? */
87 bool update_root_indices_ = false;
88 bool need_rebuild_;
89 bool update_visualization_ = false;
90 bool algorithm_modified_ = true;
91
92 int num_octree_nodes_;
93 int num_octree_roots_;
94
95#ifdef WITH_OPENVDB
96 /* Create SDF grid for mesh volumes, to determine whether a certain point is in the
97 * interior of the mesh. This reduces evaluation time needed for heterogeneous volume. */
98 openvdb::BoolGrid::ConstPtr mesh_to_sdf_grid(const Mesh *mesh,
99 const Shader *shader,
100 const float half_width);
101 openvdb::BoolGrid::ConstPtr get_vdb(const Geometry *, const Shader *) const;
102 std::map<std::pair<const Geometry *, const Shader *>, openvdb::BoolGrid::ConstPtr> vdb_map_;
103#endif
104};
105
Mesh(const NodeType *node_type_, Type geom_type_)
Definition scene.h:133
void tag_update_algorithm()
void device_update(Device *, DeviceScene *, const Scene *, Progress &)
void device_free(DeviceScene *)
bool need_update_step_size
static bool is_homogeneous_volume(const Object *, const Shader *)
void tag_update_indices()
NODE_DECLARE Volume()
void merge_grids(const Scene *scene)
void clear(bool preserve_shaders=false) override
#define CCL_NAMESPACE_END
#define NODE_SOCKET_API(type_, name)
Definition graph/node.h:56
#define NODE_DECLARE
Definition node_type.h:150