Blender V5.3
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
49
53
62
71};
72
73/* Geometry
74 *
75 * Base class for geometric types like Mesh and Hair. */
76
77class Geometry : public Node {
78 public:
80
92
94
95 /* Attributes */
97
98 /* Shaders */
100
101 /* Transform */
106
107 /* Motion Blur */
108 NODE_SOCKET_API(uint, motion_steps)
109 NODE_SOCKET_API(bool, use_motion_blur)
110
111 /* Maximum number of motion steps supported (due to Embree). */
112 static const uint MAX_MOTION_STEPS = 129;
113
114 /* BVH */
118
119 /* Shader Properties */
120 bool has_volume; /* Set in the device_update_flags(). */
121 bool has_surface_bssrdf; /* Set in the device_update_flags(). */
122
123 /* Position attribute. */
124 const packed_float3 *get_position() const;
127 bool position_is_modified() const;
128
129 /* Radius attribute. */
130 const float *get_radius() const;
131 float *get_radius_for_write();
132 void tag_radius_modified();
133 bool radius_is_modified() const;
134
135 /* Update Flags */
138
139 /* Index into scene->geometry (only valid during update) */
140 size_t index;
141
142 /* Constructor/Destructor */
143 explicit Geometry(const NodeType *node_type, const Type type);
144 ~Geometry() override;
145
146 /* Geometry */
147 virtual void clear(bool preserve_shaders = false);
148 virtual void compute_bounds() = 0;
149 virtual void apply_transform(const Transform &tfm, const bool apply_to_motion) = 0;
150
151 /* Attribute Requests */
152 bool need_attribute(const Scene *scene, AttributeStandard std);
153 bool need_attribute(Scene *scene, ustring name);
154
156
157 /* UDIM */
158 virtual void get_uv_tiles(ustring map, unordered_set<int> &tiles) = 0;
159
160 /* Convert between normalized -1..1 motion time and index in the
161 * VERTEX_MOTION attribute. */
162 float motion_time(const int step) const;
163 int motion_step(const float time) const;
164
165 /* BVH */
166 void compute_bvh(Device *device,
167 DeviceScene *dscene,
168 SceneParams *params,
169 Progress *progress,
170 const size_t n,
171 size_t total);
172
173 virtual PrimitiveType primitive_type() const = 0;
174
175 /* Check whether the geometry should have own BVH built separately. Briefly,
176 * own BVH is needed for geometry, if:
177 *
178 * - It is instanced multiple times, so each instance object should share the
179 * same BVH tree.
180 * - Special ray intersection is needed, for example to limit subsurface rays
181 * to only the geometry itself.
182 * - The BVH layout requires the top level to only contain instances.
183 */
184 bool need_build_bvh(BVHLayout layout) const;
185
186 /* Test if the geometry should be treated as instanced. */
187 bool is_instanced() const;
188
189 bool has_true_displacement() const;
190 virtual bool has_motion_blur() const;
191 bool has_voxel_attributes() const;
192
193 bool is_mesh() const
194 {
195 return geometry_type == MESH;
196 }
197
198 bool is_hair() const
199 {
200 return geometry_type == HAIR;
201 }
202
203 bool is_pointcloud() const
204 {
205 return geometry_type == POINTCLOUD;
206 }
207
208 bool is_volume() const
209 {
210 return geometry_type == VOLUME;
211 }
212
219
220 /* Updates */
221 void tag_update(Scene *scene, bool rebuild);
222};
223
224/* Geometry Manager */
225
227 uint32_t update_flags;
228
229 /* Persistent task pool for BVH building, because the Embree scene creates its own
230 * task group that has a parent pointer to this one. And if we create a task pool
231 * on the stack, that becomes a dangling pointer. See #143662 for details. */
232 TaskPool bvh_task_pool_;
233
234 public:
235 enum : uint32_t {
236 UV_PASS_NEEDED = (1 << 0),
239 OBJECT_MANAGER = (1 << 3),
240 MESH_ADDED = (1 << 4),
241 MESH_REMOVED = (1 << 5),
242 HAIR_ADDED = (1 << 6),
243 HAIR_REMOVED = (1 << 7),
244 POINT_ADDED = (1 << 12),
245 POINT_REMOVED = (1 << 13),
246
249
252
254
256
257 VOLUME_MODIFIED = (1 << 14),
258
259 /* tag everything in the manager for an update */
261
263 };
264
265 /* Update Flags */
267
268 /* Constructor/Destructor */
271
272 void update_interactive_motion(Scene *scene);
273
274 /* Device Updates */
275 void device_update_preprocess(Device *device, Scene *scene, Progress &progress);
276 void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
277 void device_free(Device *device, DeviceScene *dscene, bool force_free);
278
279 /* Updates */
280 void tag_update(Scene *scene, const uint32_t flag);
281
282 bool need_update() const;
283
284 /* Statistics */
285 void collect_statistics(const Scene *scene, RenderStats *stats);
286
287 protected:
288 bool displace(Device *device, Scene *scene, Mesh *mesh, Progress &progress);
289
290 void create_volume_mesh(const Scene *scene, Volume *volume, Progress &progress);
291
292 /* Attributes */
293 void update_osl_globals(Device *device, Scene *scene);
294 void update_svm_attributes(Device *device,
295 DeviceScene *dscene,
296 Scene *scene,
297 vector<AttributeRequestSet> &geom_attributes,
298 vector<AttributeRequestSet> &object_attributes);
299
300 /* Compute verts/triangles/curves offsets in global arrays. */
301 void geom_calc_offset(Scene *scene, BVHLayout bvh_layout);
302
303 void device_update_object(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
304
305 void device_update_mesh(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
306
307 void device_update_attributes(Device *device,
308 DeviceScene *dscene,
309 Scene *scene,
310 Progress &progress);
311
312 void device_update_bvh(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
313
314 void device_update_displacement_images(Device *device, Scene *scene, Progress &progress);
315
316 void device_update_volume_images(Device *device, Scene *scene, Progress &progress);
317};
318
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
void update_interactive_motion(Scene *scene)
bool displace(Device *device, Scene *scene, Mesh *mesh, Progress &progress)
Transform transform_normal
bool radius_is_modified() const
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
void tag_position_modified()
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
const packed_float3 * get_position() const
size_t prim_offset
virtual bool has_motion_blur() const
unique_ptr< BVH > bvh
void tag_update(Scene *scene, bool rebuild)
float * get_radius_for_write()
virtual void get_uv_tiles(ustring map, unordered_set< int > &tiles)=0
bool position_is_modified() const
bool need_update_rebuild
const float * get_radius() const
AttributeSet attributes
bool is_mesh() const
Geometry(const NodeType *node_type, const Type type)
bool transform_negative_scaled
bool need_attribute(const Scene *scene, AttributeStandard std)
float motion_time(const int step) const
virtual void apply_transform(const Transform &tfm, const bool apply_to_motion)=0
void tag_radius_modified()
virtual void clear(bool preserve_shaders=false)
packed_float3 * get_position_for_write()
Definition scene.h:133
#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:64
#define NODE_SOCKET_API(type_, name)
Definition graph/node.h:56
ccl_gpu_kernel_postfix ccl_global KernelWorkTile * tiles
PrimitiveType
AttributeStandard
#define NODE_ABSTRACT_DECLARE
Definition node_type.h:178
KernelBVHLayout BVHLayout
Definition params.h:22
@ ATTR_FLOAT4_MODIFIED
@ ATTR_UCHAR4_MODIFIED
@ ATTR_SPHERICAL_HARMONICS_REST_NEEDS_REALLOC
@ MESH_DATA_NEED_REALLOC
@ DEVICE_MESH_DATA_NEEDS_REALLOC
@ ATTR_FLOAT3_MODIFIED
@ ATTR_NORMAL_NEEDS_REALLOC
@ DEVICE_POINT_DATA_MODIFIED
@ DEVICE_POINT_DATA_NEEDS_REALLOC
@ ATTR_FLOAT4_NEEDS_REALLOC
@ ATTR_UCHAR4_NEEDS_REALLOC
@ ATTR_SPHERICAL_HARMONICS_REST_MODIFIED
@ ATTR_FLOAT_MODIFIED
@ ATTR_FLOAT2_NEEDS_REALLOC
@ DEVICE_MESH_DATA_MODIFIED
@ DEVICE_CURVE_DATA_MODIFIED
@ ATTR_QUATERNION_NEEDS_REALLOC
@ ATTR_NORMAL_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
@ ATTR_QUATERNION_MODIFIED
const NodeType * type
Definition graph/node.h:179
ustring name
Definition graph/node.h:178
Node(const NodeType *type, ustring name=ustring())