Blender V4.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#ifndef __GEOMETRY_H__
6#define __GEOMETRY_H__
7
8#include "graph/node.h"
9
10#include "bvh/params.h"
11
12#include "scene/attribute.h"
13
14#include "util/boundbox.h"
15#include "util/set.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
80
82
83 /* Attributes */
85
86 /* Shaders */
88
89 /* Transform */
94
95 /* Motion Blur */
96 NODE_SOCKET_API(uint, motion_steps)
97 NODE_SOCKET_API(bool, use_motion_blur)
98
99 /* Maximum number of motion steps supported (due to Embree). */
100 static const uint MAX_MOTION_STEPS = 129;
101
102 /* BVH */
106
107 /* Shader Properties */
108 bool has_volume; /* Set in the device_update_flags(). */
109 bool has_surface_bssrdf; /* Set in the device_update_flags(). */
110
111 /* Update Flags */
114
115 /* Index into scene->geometry (only valid during update) */
116 size_t index;
117
118 /* Constructor/Destructor */
119 explicit Geometry(const NodeType *node_type, const Type type);
120 virtual ~Geometry();
121
122 /* Geometry */
123 virtual void clear(bool preserve_shaders = false);
124 virtual void compute_bounds() = 0;
125 virtual void apply_transform(const Transform &tfm, const bool apply_to_motion) = 0;
126
127 /* Attribute Requests */
128 bool need_attribute(Scene *scene, AttributeStandard std);
129 bool need_attribute(Scene *scene, ustring name);
130
132
133 /* UDIM */
134 virtual void get_uv_tiles(ustring map, unordered_set<int> &tiles) = 0;
135
136 /* Convert between normalized -1..1 motion time and index in the
137 * VERTEX_MOTION attribute. */
138 float motion_time(int step) const;
139 int motion_step(float time) const;
140
141 /* BVH */
142 void compute_bvh(Device *device,
143 DeviceScene *dscene,
145 Progress *progress,
146 size_t n,
147 size_t total);
148
149 virtual PrimitiveType primitive_type() const = 0;
150
151 /* Check whether the geometry should have own BVH built separately. Briefly,
152 * own BVH is needed for geometry, if:
153 *
154 * - It is instanced multiple times, so each instance object should share the
155 * same BVH tree.
156 * - Special ray intersection is needed, for example to limit subsurface rays
157 * to only the geometry itself.
158 * - The BVH layout requires the top level to only contain instances.
159 */
160 bool need_build_bvh(BVHLayout layout) const;
161
162 /* Test if the geometry should be treated as instanced. */
163 bool is_instanced() const;
164
165 bool has_true_displacement() const;
166 bool has_motion_blur() const;
167 bool has_voxel_attributes() const;
168
169 bool is_mesh() const
170 {
171 return geometry_type == MESH;
172 }
173
174 bool is_hair() const
175 {
176 return geometry_type == HAIR;
177 }
178
179 bool is_pointcloud() const
180 {
181 return geometry_type == POINTCLOUD;
182 }
183
184 bool is_volume() const
185 {
186 return geometry_type == VOLUME;
187 }
188
189 /* Updates */
190 void tag_update(Scene *scene, bool rebuild);
191
192 void tag_bvh_update(bool rebuild);
193};
194
195/* Geometry Manager */
196
198 uint32_t update_flags;
199
200 public:
201 enum : uint32_t {
202 UV_PASS_NEEDED = (1 << 0),
205 OBJECT_MANAGER = (1 << 3),
206 MESH_ADDED = (1 << 4),
207 MESH_REMOVED = (1 << 5),
208 HAIR_ADDED = (1 << 6),
209 HAIR_REMOVED = (1 << 7),
210 POINT_ADDED = (1 << 12),
211 POINT_REMOVED = (1 << 13),
212
215
218
220
222
223 /* tag everything in the manager for an update */
225
227 };
228
229 /* Update Flags */
231
232 /* Constructor/Destructor */
235
236 /* Device Updates */
237 void device_update_preprocess(Device *device, Scene *scene, Progress &progress);
238 void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
239 void device_free(Device *device, DeviceScene *dscene, bool force_free);
240
241 /* Updates */
242 void tag_update(Scene *scene, uint32_t flag);
243
244 bool need_update() const;
245
246 /* Statistics */
247 void collect_statistics(const Scene *scene, RenderStats *stats);
248
249 protected:
250 bool displace(Device *device, Scene *scene, Mesh *mesh, Progress &progress);
251
252 void create_volume_mesh(const Scene *scene, Volume *volume, Progress &progress);
253
254 /* Attributes */
255 void update_osl_globals(Device *device, Scene *scene);
256 void update_svm_attributes(Device *device,
257 DeviceScene *dscene,
258 Scene *scene,
259 vector<AttributeRequestSet> &geom_attributes,
260 vector<AttributeRequestSet> &object_attributes);
261
262 /* Compute verts/triangles/curves offsets in global arrays. */
263 void geom_calc_offset(Scene *scene, BVHLayout bvh_layout);
264
265 void device_update_object(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
266
267 void device_update_mesh(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
268
269 void device_update_attributes(Device *device,
270 DeviceScene *dscene,
271 Scene *scene,
272 Progress &progress);
273
274 void device_update_bvh(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
275
276 void device_update_displacement_images(Device *device, Scene *scene, Progress &progress);
277
278 void device_update_volume_images(Device *device, Scene *scene, Progress &progress);
279
280 private:
281 static void update_attribute_element_offset(Geometry *geom,
282 device_vector<float> &attr_float,
283 size_t &attr_float_offset,
284 device_vector<float2> &attr_float2,
285 size_t &attr_float2_offset,
286 device_vector<packed_float3> &attr_float3,
287 size_t &attr_float3_offset,
288 device_vector<float4> &attr_float4,
289 size_t &attr_float4_offset,
290 device_vector<uchar4> &attr_uchar4,
291 size_t &attr_uchar4_offset,
292 Attribute *mattr,
294 TypeDesc &type,
295 AttributeDescriptor &desc);
296};
297
299
300#endif /* __GEOMETRY_H__ */
unsigned int uint
Definition bvh/bvh.h:66
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 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 tag_update(Scene *scene, uint32_t flag)
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
void compute_bvh(Device *device, DeviceScene *dscene, SceneParams *params, Progress *progress, size_t n, size_t total)
float motion_time(int step) const
Type geometry_type
virtual void compute_bounds()=0
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 need_build_bvh(BVHLayout layout) const
bool is_volume() const
bool is_pointcloud() const
int motion_step(float time) const
bool is_hair() const
bool has_surface_bssrdf
bool is_instanced() const
virtual PrimitiveType primitive_type() const =0
AttributeRequestSet needed_attributes()
size_t attr_map_offset
size_t prim_offset
bool has_motion_blur() const
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
bool transform_negative_scaled
virtual void apply_transform(const Transform &tfm, const bool apply_to_motion)=0
void tag_bvh_update(bool rebuild)
virtual void clear(bool preserve_shaders=false)
#define CCL_NAMESPACE_END
#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
AttributePrimitive
#define NODE_ABSTRACT_DECLARE
Definition node_type.h:160
CCL_NAMESPACE_BEGIN typedef KernelBVHLayout BVHLayout
Definition params.h:23
@ 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
long long TypeDesc
unsigned int uint32_t
Definition stdint.h:80
uint8_t flag
Definition wm_window.cc:138