Blender V5.0
scene/geometry.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include "graph/node.h"
8
9#include "bvh/params.h"
10
11#include "scene/attribute.h"
12
13#include "util/boundbox.h"
14#include "util/set.h"
15#include "util/task.h"
16#include "util/transform.h"
17#include "util/types.h"
18#include "util/vector.h"
19
21
22class BVH;
23class Device;
24class DeviceScene;
25class Mesh;
26class Progress;
27class RenderStats;
28class Scene;
29class SceneParams;
30class Shader;
31class Volume;
32struct PackedBVH;
33
34/* Set of flags used to help determining what data has been modified or needs reallocation, so we
35 * can decide which device data to free or update. */
36enum {
40
46
50
55
57
64};
65
66/* Geometry
67 *
68 * Base class for geometric types like Mesh and Hair. */
69
70class Geometry : public Node {
71 public:
73
81
83
84 /* Attributes */
86
87 /* Shaders */
89
90 /* Transform */
95
96 /* Motion Blur */
97 NODE_SOCKET_API(uint, motion_steps)
98 NODE_SOCKET_API(bool, use_motion_blur)
99
100 /* Maximum number of motion steps supported (due to Embree). */
101 static const uint MAX_MOTION_STEPS = 129;
102
103 /* BVH */
107
108 /* Shader Properties */
109 bool has_volume; /* Set in the device_update_flags(). */
110 bool has_surface_bssrdf; /* Set in the device_update_flags(). */
111
112 /* Update Flags */
115
116 /* Index into scene->geometry (only valid during update) */
117 size_t index;
118
119 /* Constructor/Destructor */
120 explicit Geometry(const NodeType *node_type, const Type type);
122
123 /* Geometry */
124 virtual void clear(bool preserve_shaders = false);
125 virtual void compute_bounds() = 0;
126 virtual void apply_transform(const Transform &tfm, const bool apply_to_motion) = 0;
127
128 /* Attribute Requests */
129 bool need_attribute(Scene *scene, AttributeStandard std);
130 bool need_attribute(Scene *scene, ustring name);
131
133
134 /* UDIM */
135 virtual void get_uv_tiles(ustring map, unordered_set<int> &tiles) = 0;
136
137 /* Convert between normalized -1..1 motion time and index in the
138 * VERTEX_MOTION attribute. */
139 float motion_time(const int step) const;
140 int motion_step(const float time) const;
141
142 /* BVH */
143 void compute_bvh(Device *device,
144 DeviceScene *dscene,
146 Progress *progress,
147 const size_t n,
148 size_t total);
149
150 virtual PrimitiveType primitive_type() const = 0;
151
152 /* Check whether the geometry should have own BVH built separately. Briefly,
153 * own BVH is needed for geometry, if:
154 *
155 * - It is instanced multiple times, so each instance object should share the
156 * same BVH tree.
157 * - Special ray intersection is needed, for example to limit subsurface rays
158 * to only the geometry itself.
159 * - The BVH layout requires the top level to only contain instances.
160 */
161 bool need_build_bvh(BVHLayout layout) const;
162
163 /* Test if the geometry should be treated as instanced. */
164 bool is_instanced() const;
165
166 bool has_true_displacement() const;
167 virtual bool has_motion_blur() const;
168 bool has_voxel_attributes() const;
169
170 bool is_mesh() const
171 {
172 return geometry_type == MESH;
173 }
174
175 bool is_hair() const
176 {
177 return geometry_type == HAIR;
178 }
179
180 bool is_pointcloud() const
181 {
182 return geometry_type == POINTCLOUD;
183 }
184
185 bool is_volume() const
186 {
187 return geometry_type == VOLUME;
188 }
189
190 bool is_light() const
191 {
192 return geometry_type == LIGHT;
193 }
194
195 /* Updates */
196 void tag_update(Scene *scene, bool rebuild);
197};
198
199/* Geometry Manager */
200
202 uint32_t update_flags;
203
204 /* Persistent task pool for BVH building, because the Embree scene creates its own
205 * task group that has a parent pointer to this one. And if we create a task pool
206 * on the stack, that becomes a dangling pointer. See #143662 for details. */
207 TaskPool bvh_task_pool_;
208
209 public:
210 enum : uint32_t {
211 UV_PASS_NEEDED = (1 << 0),
214 OBJECT_MANAGER = (1 << 3),
215 MESH_ADDED = (1 << 4),
216 MESH_REMOVED = (1 << 5),
217 HAIR_ADDED = (1 << 6),
218 HAIR_REMOVED = (1 << 7),
219 POINT_ADDED = (1 << 12),
220 POINT_REMOVED = (1 << 13),
221
224
227
229
231
232 /* tag everything in the manager for an update */
234
236 };
237
238 /* Update Flags */
240
241 /* Constructor/Destructor */
244
245 /* Device Updates */
246 void device_update_preprocess(Device *device, Scene *scene, Progress &progress);
247 void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
248 void device_free(Device *device, DeviceScene *dscene, bool force_free);
249
250 /* Updates */
251 void tag_update(Scene *scene, const uint32_t flag);
252
253 bool need_update() const;
254
255 /* Statistics */
256 void collect_statistics(const Scene *scene, RenderStats *stats);
257
258 protected:
259 bool displace(Device *device, Scene *scene, Mesh *mesh, Progress &progress);
260
261 void create_volume_mesh(const Scene *scene, Volume *volume, Progress &progress);
262
263 /* Attributes */
264 void update_osl_globals(Device *device, Scene *scene);
265 void update_svm_attributes(Device *device,
266 DeviceScene *dscene,
267 Scene *scene,
268 vector<AttributeRequestSet> &geom_attributes,
269 vector<AttributeRequestSet> &object_attributes);
270
271 /* Compute verts/triangles/curves offsets in global arrays. */
272 void geom_calc_offset(Scene *scene, BVHLayout bvh_layout);
273
274 void device_update_object(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
275
276 void device_update_mesh(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
277
278 void device_update_attributes(Device *device,
279 DeviceScene *dscene,
280 Scene *scene,
281 Progress &progress);
282
283 void device_update_bvh(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
284
285 void device_update_displacement_images(Device *device, Scene *scene, Progress &progress);
286
287 void device_update_volume_images(Device *device, Scene *scene, Progress &progress);
288};
289
unsigned int uint
Definition bvh/bvh.h:67
void device_update_displacement_images(Device *device, Scene *scene, Progress &progress)
void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
void geom_calc_offset(Scene *scene, BVHLayout bvh_layout)
void tag_update(Scene *scene, const uint32_t flag)
void device_update_attributes(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
void update_osl_globals(Device *device, Scene *scene)
void create_volume_mesh(const Scene *scene, Volume *volume, Progress &progress)
void device_free(Device *device, DeviceScene *dscene, bool force_free)
void device_update_object(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
void device_update_bvh(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
void collect_statistics(const Scene *scene, RenderStats *stats)
void device_update_mesh(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
void device_update_preprocess(Device *device, Scene *scene, Progress &progress)
void device_update_volume_images(Device *device, Scene *scene, Progress &progress)
void update_svm_attributes(Device *device, DeviceScene *dscene, Scene *scene, vector< AttributeRequestSet > &geom_attributes, vector< AttributeRequestSet > &object_attributes)
bool need_update() const
bool displace(Device *device, Scene *scene, Mesh *mesh, Progress &progress)
Transform transform_normal
Type geometry_type
virtual void compute_bounds()=0
int motion_step(const float time) const
BoundBox bounds
bool need_update_bvh_for_offset
bool transform_applied
static const uint MAX_MOTION_STEPS
bool has_voxel_attributes() const
bool has_true_displacement() const
bool is_light() const
bool need_build_bvh(BVHLayout layout) const
bool is_volume() const
bool is_pointcloud() const
bool is_hair() const
bool has_surface_bssrdf
bool is_instanced() const
void compute_bvh(Device *device, DeviceScene *dscene, SceneParams *params, Progress *progress, const size_t n, size_t total)
virtual PrimitiveType primitive_type() const =0
AttributeRequestSet needed_attributes()
size_t attr_map_offset
size_t prim_offset
virtual bool has_motion_blur() const
unique_ptr< BVH > bvh
void tag_update(Scene *scene, bool rebuild)
virtual void get_uv_tiles(ustring map, unordered_set< int > &tiles)=0
bool need_attribute(Scene *scene, AttributeStandard std)
bool need_update_rebuild
AttributeSet attributes
bool is_mesh() const
Geometry(const NodeType *node_type, const Type type)
bool transform_negative_scaled
float motion_time(const int step) const
virtual void apply_transform(const Transform &tfm, const bool apply_to_motion)=0
virtual void clear(bool preserve_shaders=false)
#define CCL_NAMESPACE_END
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
#define NODE_SOCKET_API_ARRAY(type_, name)
Definition graph/node.h:63
#define NODE_SOCKET_API(type_, name)
Definition graph/node.h:55
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ccl_gpu_kernel_postfix ccl_global KernelWorkTile * tiles
PrimitiveType
AttributeStandard
#define NODE_ABSTRACT_DECLARE
Definition node_type.h:171
KernelBVHLayout BVHLayout
Definition params.h:22
@ ATTR_FLOAT4_MODIFIED
@ ATTR_UCHAR4_MODIFIED
@ MESH_DATA_NEED_REALLOC
@ DEVICE_MESH_DATA_NEEDS_REALLOC
@ ATTR_FLOAT3_MODIFIED
@ DEVICE_POINT_DATA_MODIFIED
@ DEVICE_POINT_DATA_NEEDS_REALLOC
@ ATTR_FLOAT4_NEEDS_REALLOC
@ ATTR_UCHAR4_NEEDS_REALLOC
@ ATTR_FLOAT_MODIFIED
@ ATTR_FLOAT2_NEEDS_REALLOC
@ DEVICE_MESH_DATA_MODIFIED
@ DEVICE_CURVE_DATA_MODIFIED
@ ATTR_FLOAT2_MODIFIED
@ ATTR_FLOAT_NEEDS_REALLOC
@ CURVE_DATA_NEED_REALLOC
@ POINT_DATA_NEED_REALLOC
@ DEVICE_CURVE_DATA_NEEDS_REALLOC
@ ATTR_FLOAT3_NEEDS_REALLOC
@ ATTRS_NEED_REALLOC
const NodeType * type
Definition graph/node.h:178
ustring name
Definition graph/node.h:177
Node(const NodeType *type, ustring name=ustring())
bool override
Definition wm_files.cc:1192
uint8_t flag
Definition wm_window.cc:145