Blender  V3.3
bvh/split.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Adapted from code copyright 2009-2010 NVIDIA Corporation
3  * Modifications Copyright 2011-2022 Blender Foundation. */
4 
5 #ifndef __BVH_SPLIT_H__
6 #define __BVH_SPLIT_H__
7 
8 #include "bvh/build.h"
9 #include "bvh/params.h"
10 
12 
13 class BVHBuild;
14 class Hair;
15 class Mesh;
16 class PointCloud;
17 struct Transform;
18 
19 /* Object Split */
20 
22  public:
23  float sah;
24  int dim;
25  int num_left;
28 
30  {
31  }
32  BVHObjectSplit(BVHBuild *builder,
33  BVHSpatialStorage *storage,
34  const BVHRange &range,
35  vector<BVHReference> &references,
36  float nodeSAH,
37  const BVHUnaligned *unaligned_heuristic = NULL,
38  const Transform *aligned_space = NULL);
39 
40  void split(BVHRange &left, BVHRange &right, const BVHRange &range);
41 
42  protected:
47 
49  {
50  if (aligned_space_ == NULL) {
51  return prim.bounds();
52  }
53  else {
55  }
56  }
57 };
58 
59 /* Spatial Split */
60 
62  public:
63  float sah;
64  int dim;
65  float pos;
66 
67  BVHSpatialSplit() : sah(FLT_MAX), dim(0), pos(0.0f), storage_(NULL), references_(NULL)
68  {
69  }
70  BVHSpatialSplit(const BVHBuild &builder,
71  BVHSpatialStorage *storage,
72  const BVHRange &range,
73  vector<BVHReference> &references,
74  float nodeSAH,
75  const BVHUnaligned *unaligned_heuristic = NULL,
76  const Transform *aligned_space = NULL);
77 
78  void split(BVHBuild *builder, BVHRange &left, BVHRange &right, const BVHRange &range);
79 
80  void split_reference(const BVHBuild &builder,
83  const BVHReference &ref,
84  int dim,
85  float pos);
86 
87  protected:
92 
93  /* Lower-level functions which calculates boundaries of left and right nodes
94  * needed for spatial split.
95  *
96  * Operates directly with primitive specified by its index, reused by higher
97  * level splitting functions.
98  */
100  const Transform *tfm,
101  int prim_index,
102  int dim,
103  float pos,
104  BoundBox &left_bounds,
105  BoundBox &right_bounds);
106  void split_curve_primitive(const Hair *hair,
107  const Transform *tfm,
108  int prim_index,
109  int segment_index,
110  int dim,
111  float pos,
112  BoundBox &left_bounds,
113  BoundBox &right_bounds);
114  void split_point_primitive(const PointCloud *pointcloud,
115  const Transform *tfm,
116  int prim_index,
117  int dim,
118  float pos,
119  BoundBox &left_bounds,
120  BoundBox &right_bounds);
121 
122  /* Lower-level functions which calculates boundaries of left and right nodes
123  * needed for spatial split.
124  *
125  * Operates with BVHReference, internally uses lower level API functions.
126  */
127  void split_triangle_reference(const BVHReference &ref,
128  const Mesh *mesh,
129  int dim,
130  float pos,
131  BoundBox &left_bounds,
132  BoundBox &right_bounds);
133  void split_curve_reference(const BVHReference &ref,
134  const Hair *hair,
135  int dim,
136  float pos,
137  BoundBox &left_bounds,
138  BoundBox &right_bounds);
139  void split_point_reference(const BVHReference &ref,
140  const PointCloud *pointcloud,
141  int dim,
142  float pos,
143  BoundBox &left_bounds,
144  BoundBox &right_bounds);
146  const Object *object, int dim, float pos, BoundBox &left_bounds, BoundBox &right_bounds);
147 
149  {
150  if (aligned_space_ == NULL) {
151  return prim.bounds();
152  }
153  else {
155  }
156  }
157 
159  {
160  if (aligned_space_ == NULL) {
161  return point;
162  }
163  else {
165  }
166  }
167 };
168 
169 /* Mixed Object-Spatial Split */
170 
172  public:
175 
176  float leafSAH;
177  float nodeSAH;
178  float minSAH;
179 
180  bool no_split;
181 
183 
185  {
186  }
187 
189  BVHSpatialStorage *storage,
190  const BVHRange &range,
191  vector<BVHReference> &references,
192  int level,
193  const BVHUnaligned *unaligned_heuristic = NULL,
194  const Transform *aligned_space = NULL)
195  {
196  if (aligned_space == NULL) {
197  bounds = range.bounds();
198  }
199  else {
200  bounds = unaligned_heuristic->compute_aligned_boundbox(
201  range, &references.at(0), *aligned_space);
202  }
203  /* find split candidates. */
204  float area = bounds.safe_area();
205 
206  leafSAH = area * builder->params.primitive_cost(range.size());
207  nodeSAH = area * builder->params.node_cost(2);
208 
209  object = BVHObjectSplit(
210  builder, storage, range, references, nodeSAH, unaligned_heuristic, aligned_space);
211 
212  if (builder->params.use_spatial_split && level < BVHParams::MAX_SPATIAL_DEPTH) {
213  BoundBox overlap = object.left_bounds;
214  overlap.intersect(object.right_bounds);
215 
216  if (overlap.safe_area() >= builder->spatial_min_overlap) {
218  *builder, storage, range, references, nodeSAH, unaligned_heuristic, aligned_space);
219  }
220  }
221 
222  /* leaf SAH is the lowest => create leaf. */
223  minSAH = min(min(leafSAH, object.sah), spatial.sah);
224  no_split = (minSAH == leafSAH && builder->range_within_max_leaf_size(range, references));
225  }
226 
227  __forceinline void split(BVHBuild *builder,
228  BVHRange &left,
229  BVHRange &right,
230  const BVHRange &range)
231  {
232  if (builder->params.use_spatial_split && minSAH == spatial.sah)
233  spatial.split(builder, left, right, range);
234  if (!left.size() || !right.size())
235  object.split(left, right, range);
236  }
237 };
238 
240 
241 #endif /* __BVH_SPLIT_H__ */
_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 const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble right
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a point
Definition: build.h:34
bool range_within_max_leaf_size(const BVHRange &range, const vector< BVHReference > &references) const
Definition: build.cpp:626
BVHParams params
Definition: build.h:107
float spatial_min_overlap
Definition: build.h:117
BVHSpatialSplit spatial
Definition: bvh/split.h:174
__forceinline void split(BVHBuild *builder, BVHRange &left, BVHRange &right, const BVHRange &range)
Definition: bvh/split.h:227
float nodeSAH
Definition: bvh/split.h:177
__forceinline BVHMixedSplit(BVHBuild *builder, BVHSpatialStorage *storage, const BVHRange &range, vector< BVHReference > &references, int level, const BVHUnaligned *unaligned_heuristic=NULL, const Transform *aligned_space=NULL)
Definition: bvh/split.h:188
BVHObjectSplit object
Definition: bvh/split.h:173
BoundBox bounds
Definition: bvh/split.h:182
float leafSAH
Definition: bvh/split.h:176
float minSAH
Definition: bvh/split.h:178
BVHSpatialStorage * storage_
Definition: bvh/split.h:43
vector< BVHReference > * references_
Definition: bvh/split.h:44
BoundBox left_bounds
Definition: bvh/split.h:26
BoundBox right_bounds
Definition: bvh/split.h:27
__forceinline BoundBox get_prim_bounds(const BVHReference &prim) const
Definition: bvh/split.h:48
void split(BVHRange &left, BVHRange &right, const BVHRange &range)
Definition: bvh/split.cpp:84
const Transform * aligned_space_
Definition: bvh/split.h:46
const BVHUnaligned * unaligned_heuristic_
Definition: bvh/split.h:45
__forceinline float node_cost(int n) const
Definition: params.h:155
bool use_spatial_split
Definition: params.h:57
@ MAX_SPATIAL_DEPTH
Definition: params.h:108
__forceinline float primitive_cost(int n) const
Definition: params.h:150
__forceinline int size() const
Definition: params.h:289
__forceinline const BoundBox & bounds() const
Definition: params.h:277
__forceinline const BoundBox & bounds() const
Definition: params.h:203
void split_point_primitive(const PointCloud *pointcloud, const Transform *tfm, int prim_index, int dim, float pos, BoundBox &left_bounds, BoundBox &right_bounds)
Definition: bvh/split.cpp:417
void split_curve_primitive(const Hair *hair, const Transform *tfm, int prim_index, int segment_index, int dim, float pos, BoundBox &left_bounds, BoundBox &right_bounds)
Definition: bvh/split.cpp:370
const BVHUnaligned * unaligned_heuristic_
Definition: bvh/split.h:90
void split_curve_reference(const BVHReference &ref, const Hair *hair, int dim, float pos, BoundBox &left_bounds, BoundBox &right_bounds)
Definition: bvh/split.cpp:453
void split_triangle_primitive(const Mesh *mesh, const Transform *tfm, int prim_index, int dim, float pos, BoundBox &left_bounds, BoundBox &right_bounds)
Definition: bvh/split.cpp:333
__forceinline float3 get_unaligned_point(const float3 &point) const
Definition: bvh/split.h:158
__forceinline BoundBox get_prim_bounds(const BVHReference &prim) const
Definition: bvh/split.h:148
BVHSpatialStorage * storage_
Definition: bvh/split.h:88
void split_object_reference(const Object *object, int dim, float pos, BoundBox &left_bounds, BoundBox &right_bounds)
Definition: bvh/split.cpp:480
const Transform * aligned_space_
Definition: bvh/split.h:91
vector< BVHReference > * references_
Definition: bvh/split.h:89
void split_triangle_reference(const BVHReference &ref, const Mesh *mesh, int dim, float pos, BoundBox &left_bounds, BoundBox &right_bounds)
Definition: bvh/split.cpp:443
void split_point_reference(const BVHReference &ref, const PointCloud *pointcloud, int dim, float pos, BoundBox &left_bounds, BoundBox &right_bounds)
Definition: bvh/split.cpp:470
void split_reference(const BVHBuild &builder, BVHReference &left, BVHReference &right, const BVHReference &ref, int dim, float pos)
Definition: bvh/split.cpp:511
void split(BVHBuild *builder, BVHRange &left, BVHRange &right, const BVHRange &range)
Definition: bvh/split.cpp:224
BoundBox compute_aligned_prim_boundbox(const BVHReference &prim, const Transform &aligned_space) const
Definition: unaligned.cpp:77
Definition: hair.h:13
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
CCL_NAMESPACE_END CCL_NAMESPACE_BEGIN ccl_device_inline float3 transform_point(ccl_private const Transform *t, const float3 a)
static int left
static void area(int d1, int d2, int e1, int e2, float weights[2])
#define __forceinline
#define min(a, b)
Definition: sort.c:35
__forceinline void intersect(const BoundBox &bbox)
Definition: boundbox.h:88
__forceinline float safe_area() const
Definition: boundbox.h:95