Blender  V3.3
scene/geometry.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #ifndef __GEOMETRY_H__
5 #define __GEOMETRY_H__
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/transform.h"
16 #include "util/types.h"
17 #include "util/vector.h"
18 
20 
21 class BVH;
22 class Device;
23 class DeviceScene;
24 class Mesh;
25 class Progress;
26 class RenderStats;
27 class Scene;
28 class SceneParams;
29 class Shader;
30 class Volume;
31 struct PackedBVH;
32 
33 /* Geometry
34  *
35  * Base class for geometric types like Mesh and Hair. */
36 
37 class Geometry : public Node {
38  public:
40 
41  enum Type {
46  };
47 
49 
50  /* Attributes */
52 
53  /* Shaders */
55 
56  /* Transform */
61 
62  /* Motion Blur */
63  NODE_SOCKET_API(uint, motion_steps)
64  NODE_SOCKET_API(bool, use_motion_blur)
65 
66  /* Maximum number of motion steps supported (due to Embree). */
67  static const uint MAX_MOTION_STEPS = 129;
68 
69  /* BVH */
70  BVH *bvh;
72  size_t prim_offset;
73 
74  /* Shader Properties */
75  bool has_volume; /* Set in the device_update_flags(). */
76  bool has_surface_bssrdf; /* Set in the device_update_flags(). */
77 
78  /* Update Flags */
81 
82  /* Index into scene->geometry (only valid during update) */
83  size_t index;
84 
85  /* Constructor/Destructor */
86  explicit Geometry(const NodeType *node_type, const Type type);
87  virtual ~Geometry();
88 
89  /* Geometry */
90  virtual void clear(bool preserve_shaders = false);
91  virtual void compute_bounds() = 0;
92  virtual void apply_transform(const Transform &tfm, const bool apply_to_motion) = 0;
93 
94  /* Attribute Requests */
96  bool need_attribute(Scene *scene, ustring name);
97 
99 
100  /* UDIM */
101  virtual void get_uv_tiles(ustring map, unordered_set<int> &tiles) = 0;
102 
103  /* Convert between normalized -1..1 motion time and index in the
104  * VERTEX_MOTION attribute. */
105  float motion_time(int step) const;
106  int motion_step(float time) const;
107 
108  /* BVH */
109  void compute_bvh(Device *device,
110  DeviceScene *dscene,
112  Progress *progress,
113  size_t n,
114  size_t total);
115 
116  virtual PrimitiveType primitive_type() const = 0;
117 
118  /* Check whether the geometry should have own BVH built separately. Briefly,
119  * own BVH is needed for geometry, if:
120  *
121  * - It is instanced multiple times, so each instance object should share the
122  * same BVH tree.
123  * - Special ray intersection is needed, for example to limit subsurface rays
124  * to only the geometry itself.
125  * - The BVH layout requires the top level to only contain instances.
126  */
127  bool need_build_bvh(BVHLayout layout) const;
128 
129  /* Test if the geometry should be treated as instanced. */
130  bool is_instanced() const;
131 
132  bool has_true_displacement() const;
133  bool has_motion_blur() const;
134  bool has_voxel_attributes() const;
135 
136  bool is_mesh() const
137  {
138  return geometry_type == MESH;
139  }
140 
141  bool is_hair() const
142  {
143  return geometry_type == HAIR;
144  }
145 
146  bool is_pointcloud() const
147  {
148  return geometry_type == POINTCLOUD;
149  }
150 
151  bool is_volume() const
152  {
153  return geometry_type == VOLUME;
154  }
155 
156  /* Updates */
157  void tag_update(Scene *scene, bool rebuild);
158 
159  void tag_bvh_update(bool rebuild);
160 };
161 
162 /* Geometry Manager */
163 
165  uint32_t update_flags;
166 
167  public:
168  enum : uint32_t {
169  UV_PASS_NEEDED = (1 << 0),
170  MOTION_PASS_NEEDED = (1 << 1),
171  GEOMETRY_MODIFIED = (1 << 2),
172  OBJECT_MANAGER = (1 << 3),
173  MESH_ADDED = (1 << 4),
174  MESH_REMOVED = (1 << 5),
175  HAIR_ADDED = (1 << 6),
176  HAIR_REMOVED = (1 << 7),
177  POINT_ADDED = (1 << 12),
178  POINT_REMOVED = (1 << 13),
179 
182 
185 
186  TRANSFORM_MODIFIED = (1 << 10),
187 
188  VISIBILITY_MODIFIED = (1 << 11),
189 
190  /* tag everything in the manager for an update */
191  UPDATE_ALL = ~0u,
192 
194  };
195 
196  /* Update Flags */
198 
199  /* Constructor/Destructor */
200  GeometryManager();
202 
203  /* Device Updates */
204  void device_update_preprocess(Device *device, Scene *scene, Progress &progress);
205  void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
206  void device_free(Device *device, DeviceScene *dscene, bool force_free);
207 
208  /* Updates */
209  void tag_update(Scene *scene, uint32_t flag);
210 
211  bool need_update() const;
212 
213  /* Statistics */
214  void collect_statistics(const Scene *scene, RenderStats *stats);
215 
216  protected:
217  bool displace(Device *device, Scene *scene, Mesh *mesh, Progress &progress);
218 
219  void create_volume_mesh(const Scene *scene, Volume *volume, Progress &progress);
220 
221  /* Attributes */
222  void update_osl_attributes(Device *device,
223  Scene *scene,
224  vector<AttributeRequestSet> &geom_attributes);
225  void update_svm_attributes(Device *device,
226  DeviceScene *dscene,
227  Scene *scene,
228  vector<AttributeRequestSet> &geom_attributes,
229  vector<AttributeRequestSet> &object_attributes);
230 
231  /* Compute verts/triangles/curves offsets in global arrays. */
232  void geom_calc_offset(Scene *scene, BVHLayout bvh_layout);
233 
234  void device_update_object(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
235 
236  void device_update_mesh(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
237 
238  void device_update_attributes(Device *device,
239  DeviceScene *dscene,
240  Scene *scene,
241  Progress &progress);
242 
243  void device_update_bvh(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
244 
245  void device_update_displacement_images(Device *device, Scene *scene, Progress &progress);
246 
247  void device_update_volume_images(Device *device, Scene *scene, Progress &progress);
248 
249  private:
250  static void update_attribute_element_offset(Geometry *geom,
251  device_vector<float> &attr_float,
252  size_t &attr_float_offset,
253  device_vector<float2> &attr_float2,
254  size_t &attr_float2_offset,
255  device_vector<packed_float3> &attr_float3,
256  size_t &attr_float3_offset,
257  device_vector<float4> &attr_float4,
258  size_t &attr_float4_offset,
259  device_vector<uchar4> &attr_uchar4,
260  size_t &attr_uchar4_offset,
261  Attribute *mattr,
262  AttributePrimitive prim,
263  TypeDesc &type,
264  AttributeDescriptor &desc);
265 };
266 
268 
269 #endif /* __GEOMETRY_H__ */
unsigned int uint
Definition: BLI_sys_types.h:67
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Definition: bvh/bvh.h:63
void device_update_displacement_images(Device *device, Scene *scene, Progress &progress)
void update_osl_attributes(Device *device, Scene *scene, vector< AttributeRequestSet > &geom_attributes)
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 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_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)
void device_update_mesh(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
Transform transform_normal
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_volume
bool has_voxel_attributes() const
bool has_true_displacement() const
bool need_build_bvh(BVHLayout layout) const
size_t index
bool is_volume() const
bool is_pointcloud() const
int motion_step(float time) const
bool need_attribute(Scene *scene, AttributeStandard std)
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_update_rebuild
AttributeSet attributes
bool is_mesh() const
bool transform_negative_scaled
void compute_bvh(Device *device, DeviceScene *dscene, SceneParams *params, Progress *progress, size_t n, size_t total)
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
Definition: cuda/compat.h:9
double time
Scene scene
#define NODE_SOCKET_API_ARRAY(type_, name)
Definition: graph/node.h:62
#define NODE_SOCKET_API(type_, name)
Definition: graph/node.h:54
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ccl_gpu_kernel_postfix ccl_global KernelWorkTile * tiles
PrimitiveType
Definition: kernel/types.h:549
AttributeStandard
Definition: kernel/types.h:612
AttributePrimitive
Definition: kernel/types.h:590
SocketIndexByIdentifierMap * map
#define NODE_ABSTRACT_DECLARE
Definition: node_type.h:153
CCL_NAMESPACE_BEGIN typedef KernelBVHLayout BVHLayout
Definition: params.h:19
unsigned int uint32_t
Definition: stdint.h:80
const NodeType * type
Definition: graph/node.h:175
ustring name
Definition: graph/node.h:174