Blender  V3.3
unaligned.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #include "bvh/unaligned.h"
5 
6 #include "scene/hair.h"
7 #include "scene/object.h"
8 
9 #include "bvh/binning.h"
10 #include "bvh/params.h"
11 
12 #include "util/boundbox.h"
13 #include "util/transform.h"
14 
16 
17 BVHUnaligned::BVHUnaligned(const vector<Object *> &objects) : objects_(objects)
18 {
19 }
20 
22  const BVHReference *references) const
23 {
24  for (int i = range.start(); i < range.end(); ++i) {
25  const BVHReference &ref = references[i];
26  Transform aligned_space;
27  /* Use first primitive which defines correct direction to define
28  * the orientation space.
29  */
30  if (compute_aligned_space(ref, &aligned_space)) {
31  return aligned_space;
32  }
33  }
34  return transform_identity();
35 }
36 
38  const BVHReference *references) const
39 {
40  for (int i = range.start(); i < range.end(); ++i) {
41  const BVHReference &ref = references[i];
42  Transform aligned_space;
43  /* Use first primitive which defines correct direction to define
44  * the orientation space.
45  */
46  if (compute_aligned_space(ref, &aligned_space)) {
47  return aligned_space;
48  }
49  }
50  return transform_identity();
51 }
52 
53 bool BVHUnaligned::compute_aligned_space(const BVHReference &ref, Transform *aligned_space) const
54 {
55  const Object *object = objects_[ref.prim_object()];
56  const int packed_type = ref.prim_type();
57  const int type = (packed_type & PRIMITIVE_ALL);
58  /* No motion blur curves here, we can't fit them to aligned boxes well. */
59  if ((type & PRIMITIVE_CURVE) && !(type & PRIMITIVE_MOTION)) {
60  const int curve_index = ref.prim_index();
61  const int segment = PRIMITIVE_UNPACK_SEGMENT(packed_type);
62  const Hair *hair = static_cast<const Hair *>(object->get_geometry());
63  const Hair::Curve &curve = hair->get_curve(curve_index);
64  const int key = curve.first_key + segment;
65  const float3 v1 = hair->get_curve_keys()[key], v2 = hair->get_curve_keys()[key + 1];
66  float length;
67  const float3 axis = normalize_len(v2 - v1, &length);
68  if (length > 1e-6f) {
69  *aligned_space = make_transform_frame(axis);
70  return true;
71  }
72  }
73  *aligned_space = transform_identity();
74  return false;
75 }
76 
78  const Transform &aligned_space) const
79 {
81  const Object *object = objects_[prim.prim_object()];
82  const int packed_type = prim.prim_type();
83  const int type = (packed_type & PRIMITIVE_ALL);
84  /* No motion blur curves here, we can't fit them to aligned boxes well. */
85  if ((type & PRIMITIVE_CURVE) && !(type & PRIMITIVE_MOTION)) {
86  const int curve_index = prim.prim_index();
87  const int segment = PRIMITIVE_UNPACK_SEGMENT(packed_type);
88  const Hair *hair = static_cast<const Hair *>(object->get_geometry());
89  const Hair::Curve &curve = hair->get_curve(curve_index);
90  curve.bounds_grow(
91  segment, &hair->get_curve_keys()[0], &hair->get_curve_radius()[0], aligned_space, bounds);
92  }
93  else {
94  bounds = prim.bounds().transformed(&aligned_space);
95  }
96  return bounds;
97 }
98 
100  const BVHReference *references,
101  const Transform &aligned_space,
102  BoundBox *cent_bounds) const
103 {
105  if (cent_bounds != NULL) {
106  *cent_bounds = BoundBox::empty;
107  }
108  for (int i = range.start(); i < range.end(); ++i) {
109  const BVHReference &ref = references[i];
110  BoundBox ref_bounds = compute_aligned_prim_boundbox(ref, aligned_space);
111  bounds.grow(ref_bounds);
112  if (cent_bounds != NULL) {
113  cent_bounds->grow(ref_bounds.center2());
114  }
115  }
116  return bounds;
117 }
118 
120  const BVHReference *references,
121  const Transform &aligned_space,
122  BoundBox *cent_bounds) const
123 {
125  if (cent_bounds != NULL) {
126  *cent_bounds = BoundBox::empty;
127  }
128  for (int i = range.start(); i < range.end(); ++i) {
129  const BVHReference &ref = references[i];
130  BoundBox ref_bounds = compute_aligned_prim_boundbox(ref, aligned_space);
131  bounds.grow(ref_bounds);
132  if (cent_bounds != NULL) {
133  cent_bounds->grow(ref_bounds.center2());
134  }
135  }
136  return bounds;
137 }
138 
140  const Transform &aligned_space)
141 {
142  Transform space = aligned_space;
143  space.x.w -= bounds.min.x;
144  space.y.w -= bounds.min.y;
145  space.z.w -= bounds.min.z;
146  float3 dim = bounds.max - bounds.min;
147  return transform_scale(
148  1.0f / max(1e-18f, dim.x), 1.0f / max(1e-18f, dim.y), 1.0f / max(1e-18f, dim.z)) *
149  space;
150 }
151 
_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
_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 GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
ATTR_WARN_UNUSED_RESULT const BMVert * v2
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
Definition: btDbvt.cpp:299
__forceinline int start() const
Definition: params.h:285
__forceinline int end() const
Definition: params.h:293
__forceinline int prim_type() const
Definition: params.h:215
__forceinline int prim_object() const
Definition: params.h:211
__forceinline const BoundBox & bounds() const
Definition: params.h:203
__forceinline int prim_index() const
Definition: params.h:207
BVHUnaligned(const vector< Object * > &objects)
Definition: unaligned.cpp:17
Transform compute_aligned_space(const BVHObjectBinning &range, const BVHReference *references) const
Definition: unaligned.cpp:21
BoundBox compute_aligned_boundbox(const BVHObjectBinning &range, const BVHReference *references, const Transform &aligned_space, BoundBox *cent_bounds=NULL) const
Definition: unaligned.cpp:99
const vector< Object * > & objects_
Definition: unaligned.h:55
BoundBox compute_aligned_prim_boundbox(const BVHReference &prim, const Transform &aligned_space) const
Definition: unaligned.cpp:77
static Transform compute_node_transform(const BoundBox &bounds, const Transform &aligned_space)
Definition: unaligned.cpp:139
Definition: hair.h:13
Curve get_curve(size_t i) const
Definition: hair.h:109
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
Curve curve
ccl_device_inline Transform make_transform_frame(float3 N)
ccl_device_inline Transform transform_identity()
ccl_device_inline Transform transform_scale(float3 s)
@ PRIMITIVE_ALL
Definition: kernel/types.h:566
@ PRIMITIVE_MOTION
Definition: kernel/types.h:558
@ PRIMITIVE_CURVE
Definition: kernel/types.h:564
#define PRIMITIVE_UNPACK_SEGMENT(type)
Definition: kernel/types.h:579
ccl_device_inline float2 normalize_len(const float2 &a, float *t)
Segment< FEdge *, Vec3r > segment
T length(const vec_base< T, Size > &a)
BoundBox transformed(const Transform *tfm) const
Definition: boundbox.h:136
@ empty
Definition: boundbox.h:35
__forceinline void grow(const float3 &pt)
Definition: boundbox.h:42
__forceinline float3 center2() const
Definition: boundbox.h:119
float z
float y
float x
float max