Blender V5.0
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
25
26class Volume : public Mesh {
27 public:
29
30 Volume();
31
32 NODE_SOCKET_API(float, step_size)
33 NODE_SOCKET_API(bool, object_space)
35
36 /* Merge attributes for efficiency, call right after creating them. */
37 void merge_grids(const Scene *scene);
38
39 void clear(bool preserve_shaders = false) override;
40};
41
43 public:
46
47 void device_update(Device *, DeviceScene *, const Scene *, Progress &);
49
50 /* Tag volume octree for update when scene changes. */
51 void tag_update();
52 void tag_update(const Shader *shader);
53 void tag_update(const Object *object, const uint32_t flag);
54 void tag_update(const Geometry *geometry);
55 void tag_update_indices();
56
57 /* Check whether the shader is a homogeneous volume. */
58 static bool is_homogeneous_volume(const Object *, const Shader *);
59
60 private:
61 /* Initialize octrees from the volumes in the scene. */
62 void initialize_octree(const Scene *, Progress &);
63
64 /* Build octrees based on the volume density. */
65 void build_octree(Device *, Progress &);
66
67 /* Update the object and shader index of octree root nodes. */
68 void update_root_indices(DeviceScene *, const Scene *) const;
69
70 /* Converting the octrees into an array for uploading to the kernel. */
71 void flatten_octree(DeviceScene *, const Scene *) const;
72
73 /* Count all the nodes of the octrees. */
74 void update_num_octree_nodes();
75 int num_octree_nodes() const;
76 int num_octree_roots() const;
77
78 /* When running Blender with `--log-level debug`, an octree visualization is written to
79 * `filename`, which is a Python script that can be run inside Blender. */
80 std::string visualize_octree(const char *filename) const;
81
82 /* Step size for ray marching. */
83 void update_step_size(const Scene *, DeviceScene *) const;
84
85 /* One octree per object per shader. */
86 std::map<std::pair<const Object *, const Shader *>, std::shared_ptr<Octree>> object_octrees_;
87
88 bool update_root_indices_ = false;
89 bool need_rebuild_;
90 bool update_visualization_ = false;
91 int num_octree_nodes_;
92 int num_octree_roots_;
93
94 VolumeRenderingAlgorithm last_algorithm = NONE;
95
96#ifdef WITH_OPENVDB
97 /* Create SDF grid for mesh volumes, to determine whether a certain point is in the
98 * interior of the mesh. This reduces evaluation time needed for heterogeneous volume. */
99 openvdb::BoolGrid::ConstPtr mesh_to_sdf_grid(const Mesh *mesh,
100 const Shader *shader,
101 const float half_width);
102 openvdb::BoolGrid::ConstPtr get_vdb(const Geometry *, const Shader *) const;
103 std::map<std::pair<const Geometry *, const Shader *>, openvdb::BoolGrid::ConstPtr> vdb_map_;
104#endif
105};
106
struct Scene Scene
@ NONE
void device_update(Device *, DeviceScene *, const Scene *, Progress &)
void device_free(DeviceScene *)
static bool is_homogeneous_volume(const Object *, const Shader *)
void tag_update_indices()
#define CCL_NAMESPACE_END
#define NODE_SOCKET_API(type_, name)
Definition graph/node.h:55
#define NODE_DECLARE
Definition node_type.h:145
VolumeRenderingAlgorithm
@ RAY_MARCHING
@ NULL_SCATTERING
@ NONE
NODE_DECLARE Volume()
void merge_grids(const Scene *scene)
void clear(bool preserve_shaders=false) override
float velocity_scale
uint8_t flag
Definition wm_window.cc:145