42 const size_t max_step = num_steps - 1;
43 const size_t step =
min((
size_t)(
time * max_step), max_step - 1);
44 const float t =
time * max_step - step;
51 r_verts[0] = (1.0f -
t) * curr_verts[0] +
t * next_verts[0];
52 r_verts[1] = (1.0f -
t) * curr_verts[1] +
t * next_verts[1];
53 r_verts[2] = (1.0f -
t) * curr_verts[2] +
t * next_verts[2];
63 const size_t center_step = ((num_steps - 1) / 2);
64 if (step == center_step) {
72 if (step > center_step) {
75 size_t offset = step * num_verts;
76 r_verts[0] = vert_steps[
offset +
v[0]];
77 r_verts[1] = vert_steps[
offset +
v[1]];
78 r_verts[2] = vert_steps[
offset +
v[2]];
88 const float normlen =
len(
norm);
89 if (normlen == 0.0f) {
92 return norm / normlen;
125 static NodeEnum subdivision_type_enum;
133 subd_vert_creases_weight,
"Subdivision Vertex Crease Weights",
array<float>());
145 SOCKET_FLOAT(subd_dicing_rate,
"Subdivision Dicing Rate", 1.0f)
146 SOCKET_INT(subd_max_level,
"Max Subdivision Level", 1);
154 if (subdivision_type == SubdivisionType::SUBDIVISION_NONE) {
171 return get_subd_params() && (verts_is_modified() || subd_dicing_rate_is_modified() ||
172 subd_objecttoworld_is_modified() || subd_max_level_is_modified());
207 verts.resize(numverts);
208 triangles.resize(numtris * 3);
209 shader.resize(numtris);
213 triangle_patch.resize(numtris);
214 vert_patch_uv.resize(numverts);
223 verts.reserve(numverts);
224 triangles.reserve(numtris * 3);
225 shader.reserve(numtris);
229 triangle_patch.reserve(numtris);
230 vert_patch_uv.reserve(numverts);
238 subd_start_corner.resize(numfaces);
239 subd_num_corners.resize(numfaces);
240 subd_shader.resize(numfaces);
241 subd_smooth.resize(numfaces);
242 subd_ptex_offset.resize(numfaces);
243 subd_face_corners.resize(numcorners);
244 num_ngons = num_ngons_;
245 num_subd_faces = numfaces;
247 subd_attributes.resize();
252 subd_start_corner.reserve(numfaces);
253 subd_num_corners.reserve(numfaces);
254 subd_shader.reserve(numfaces);
255 subd_smooth.reserve(numfaces);
256 subd_ptex_offset.reserve(numfaces);
257 subd_face_corners.reserve(numcorners);
258 num_ngons = num_ngons_;
259 num_subd_faces = numfaces;
261 subd_attributes.resize(
true);
266 subd_creases_edge.reserve(num_creases * 2);
267 subd_creases_weight.reserve(num_creases);
277 vert_to_stitching_key_map.clear();
278 vert_stitching_map.clear();
294 triangle_patch.clear();
295 vert_patch_uv.clear();
297 subd_start_corner.clear();
298 subd_num_corners.clear();
301 subd_ptex_offset.clear();
302 subd_face_corners.clear();
304 subd_creases_edge.clear();
305 subd_creases_weight.clear();
307 subd_attributes.clear();
310 subdivision_type = SubdivisionType::SUBDIVISION_NONE;
317 clear(preserve_shaders,
false);
322 verts.push_back_reserved(
P);
323 tag_verts_modified();
327 tag_vert_patch_uv_modified();
334 tag_verts_modified();
338 tag_vert_patch_uv_modified();
344 triangles.push_back_reserved(v0);
345 triangles.push_back_reserved(
v1);
346 triangles.push_back_reserved(
v2);
347 shader.push_back_reserved(shader_);
348 smooth.push_back_reserved(smooth_);
350 tag_triangles_modified();
351 tag_shader_modified();
352 tag_smooth_modified();
355 triangle_patch.push_back_reserved(-1);
356 tag_triangle_patch_modified();
362 int start_corner = subd_face_corners.size();
364 for (
int i = 0; i < num_corners; i++) {
365 subd_face_corners.push_back_reserved(corners[i]);
371 if (subd_shader.size()) {
376 subd_start_corner.push_back_reserved(start_corner);
377 subd_num_corners.push_back_reserved(num_corners);
378 subd_shader.push_back_reserved(shader_);
379 subd_smooth.push_back_reserved(smooth_);
380 subd_ptex_offset.push_back_reserved(ptex_offset);
382 tag_subd_face_corners_modified();
383 tag_subd_start_corner_modified();
384 tag_subd_num_corners_modified();
385 tag_subd_shader_modified();
386 tag_subd_smooth_modified();
387 tag_subd_ptex_offset_modified();
403 subd_creases_edge.push_back_slow(v0);
404 subd_creases_edge.push_back_slow(
v1);
405 subd_creases_weight.push_back_slow(weight);
407 tag_subd_creases_edge_modified();
408 tag_subd_creases_edge_modified();
409 tag_subd_creases_weight_modified();
414 subd_vert_creases.push_back_slow(
v);
415 subd_vert_creases_weight.push_back_slow(weight);
417 tag_subd_vert_creases_modified();
418 tag_subd_vert_creases_weight_modified();
430 size_t numverts =
verts.size();
448 subd_attr = subd_attributes.find(
map);
462 size_t verts_size =
verts.size();
464 if (verts_size > 0) {
465 for (
size_t i = 0; i < verts_size; i++)
469 if (use_motion_blur && attr) {
470 size_t steps_size =
verts.size() * (motion_steps - 1);
473 for (
size_t i = 0; i < steps_size; i++)
474 bnds.
grow(vert_steps[i]);
481 for (
size_t i = 0; i < verts_size; i++)
484 if (use_motion_blur && attr) {
485 size_t steps_size =
verts.size() * (motion_steps - 1);
488 for (
size_t i = 0; i < steps_size; i++)
507 for (
size_t i = 0; i <
verts.size(); i++)
510 tag_verts_modified();
512 if (apply_to_motion) {
516 size_t steps_size =
verts.size() * (motion_steps - 1);
519 for (
size_t i = 0; i < steps_size; i++)
527 size_t steps_size =
verts.size() * (motion_steps - 1);
530 for (
size_t i = 0; i < steps_size; i++)
549 if (triangles_size) {
552 for (
size_t i = 0; i < triangles_size; i++) {
561 for (
size_t i = 0; i < triangles_size; i++)
569 size_t verts_size =
verts.size();
584 for (
size_t i = 0; i < triangles_size; i++) {
585 for (
size_t j = 0; j < 3; j++) {
590 for (
size_t i = 0; i < verts_size; i++) {
606 for (
int step = 0; step < motion_steps - 1; step++) {
613 for (
size_t i = 0; i < triangles_size; i++) {
614 for (
size_t j = 0; j < 3; j++) {
620 for (
size_t i = 0; i < verts_size; i++) {
648 for (
size_t i = 0; i < verts_size; i++) {
689 uint last_shader = -1;
690 bool last_smooth =
false;
693 const int *shader_ptr = shader.data();
694 const bool *smooth_ptr =
smooth.data();
696 for (
size_t i = 0; i < triangles_size; i++) {
697 const int new_shader = shader_ptr ? shader_ptr[i] : INT_MAX;
698 const bool new_smooth = smooth_ptr ? smooth_ptr[i] :
false;
700 if (new_shader != last_shader || last_smooth != new_smooth) {
701 last_shader = new_shader;
702 last_smooth = new_smooth;
703 Shader *shader = (last_shader < used_shaders.size()) ?
704 static_cast<Shader *
>(used_shaders[last_shader]) :
709 tri_shader[i] = shader_id;
716 if (attr_vN ==
NULL) {
725 size_t verts_size =
verts.size();
727 for (
size_t i = 0; i < verts_size; i++) {
742 size_t verts_size =
verts.size();
745 float2 *vert_patch_uv_ptr = vert_patch_uv.data();
747 for (
size_t i = 0; i < verts_size; i++) {
748 tri_patch_uv[i] = vert_patch_uv_ptr[i];
754 for (
size_t i = 0; i < triangles_size; i++) {
757 t.v[0] + vert_offset,
t.v[1] + vert_offset,
t.v[2] + vert_offset, 3 * (
prim_offset + i));
761 tri_verts[i * 3] =
verts[
t.v[0]];
762 tri_verts[i * 3 + 1] =
verts[
t.v[1]];
763 tri_verts[i * 3 + 2] =
verts[
t.v[2]];
772 for (
size_t f = 0; f < num_faces; f++) {
777 memcpy(
c, &subd_face_corners[face.
start_corner],
sizeof(
int) * 4);
779 *(patch_data++) =
c[0] + vert_offset;
780 *(patch_data++) =
c[1] + vert_offset;
781 *(patch_data++) =
c[2] + vert_offset;
782 *(patch_data++) =
c[3] + vert_offset;
784 *(patch_data++) = f + face_offset;
794 c[2] =
verts.size() - num_subd_verts + ngons;
797 *(patch_data++) =
c[0] + vert_offset;
798 *(patch_data++) =
c[1] + vert_offset;
799 *(patch_data++) =
c[2] + vert_offset;
800 *(patch_data++) =
c[3] + vert_offset;
802 *(patch_data++) = f + face_offset;
805 *(patch_data++) = subd_face_corners.size() + ngons + corner_offset;
_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 GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
_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
ATTR_WARN_UNUSED_RESULT const BMVert * v
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
Attribute * add(ustring name, TypeDesc type, AttributeElement element)
Attribute * find(ustring name) const
void resize(bool reserve_only=false)
void clear(bool preserve_voxel_data=false)
void get_uv_tiles(Geometry *geom, AttributePrimitive prim, unordered_set< int > &tiles) const
size_t buffer_size(Geometry *geom, AttributePrimitive prim) const
size_t data_sizeof() const
Transform transform_normal
int motion_step(float time) const
bool has_motion_blur() const
bool transform_negative_scaled
virtual void clear(bool preserve_shaders=false)
int get_shader_id(Shader *shader, bool smooth=false)
#define CCL_NAMESPACE_END
ccl_gpu_kernel_postfix ccl_global KernelWorkTile * tiles
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
@ PRIMITIVE_MOTION_TRIANGLE
@ ATTR_STD_MOTION_VERTEX_NORMAL
@ ATTR_STD_POSITION_UNDISPLACED
@ ATTR_STD_MOTION_VERTEX_POSITION
ccl_device_inline float2 safe_normalize(const float2 &a)
ccl_device_inline float2 zero_float2()
ccl_device_inline float3 zero_float3()
static void vnormal(PROCESS *process, const float point[3], float r_no[3])
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRefNull prop_name, int32_t value)
Allocate a new IDProperty of type IDP_INT, set its name and value.
vec_base< T, 3 > cross(const vec_base< T, 3 > &a, const vec_base< T, 3 > &b)
vec_base< T, Size > normalize(const vec_base< T, Size > &v)
SocketIndexByIdentifierMap * map
#define SOCKET_BOOLEAN_ARRAY(name, ui_name, default_value,...)
#define SOCKET_POINT_ARRAY(name, ui_name, default_value,...)
#define SOCKET_POINT2_ARRAY(name, ui_name, default_value,...)
#define SOCKET_FLOAT(name, ui_name, default_value,...)
#define SOCKET_INT(name, ui_name, default_value,...)
#define SOCKET_FLOAT_ARRAY(name, ui_name, default_value,...)
#define SOCKET_TRANSFORM(name, ui_name, default_value,...)
#define SOCKET_INT_ARRAY(name, ui_name, default_value,...)
#define SOCKET_ENUM(name, ui_name, values, default_value,...)
smooth(Type::FLOAT, "mask_weight")
__forceinline bool valid() const
__forceinline void grow_safe(const float3 &pt)
__forceinline void grow(const float3 &pt)
int num_ptex_faces() const
float3 normal(const Mesh *mesh) const
bool valid(const float3 *verts) const
void motion_verts(const float3 *verts, const float3 *vert_steps, size_t num_verts, size_t num_steps, float time, float3 r_verts[3]) const
void verts_for_step(const float3 *verts, const float3 *vert_steps, size_t num_verts, size_t num_steps, size_t step, float3 r_verts[3]) const
void bounds_grow(const float3 *verts, BoundBox &bounds) const
float3 compute_normal(const float3 *verts) const
SubdParams * get_subd_params()
void reserve_subd_faces(int numfaces, int num_ngons, int numcorners)
void pack_verts(packed_float3 *tri_verts, uint4 *tri_vindex, uint *tri_patch, float2 *tri_patch_uv)
size_t get_num_subd_faces() const
void add_edge_crease(int v0, int v1, float weight)
void reserve_subd_creases(size_t num_creases)
void compute_bounds() override
void add_vertex_normals()
Triangle get_triangle(size_t i) const
void copy_center_to_motion_step(const int motion_step)
void clear(bool preserve_shaders=false) override
void resize_subd_faces(int numfaces, int num_ngons, int numcorners)
void pack_patches(uint *patch_data)
void reserve_mesh(int numverts, int numfaces)
void add_vertex_slow(float3 P)
@ SUBDIVISION_CATMULL_CLARK
size_t num_triangles() const
void pack_normals(packed_float3 *vnormal)
void add_vertex(float3 P)
void get_uv_tiles(ustring map, unordered_set< int > &tiles) override
void add_vertex_crease(int v, float weight)
void add_triangle(int v0, int v1, int v2, int shader, bool smooth)
SubdFace get_subd_face(size_t index) const
void pack_shaders(Scene *scene, uint *shader)
PrimitiveType primitive_type() const override
void resize_mesh(int numverts, int numfaces)
void add_subd_face(const int *corners, int num_corners, int shader_, bool smooth_)
void apply_transform(const Transform &tfm, const bool apply_to_motion) override
void insert(const char *x, int y)
static NodeType * add(const char *name, CreateFunc create, Type type=NONE, const NodeType *base=NULL)
ShaderManager * shader_manager
ccl_device_inline uint4 make_uint4(uint x, uint y, uint z, uint w)
ccl_device_inline int mod(int x, int m)
ccl_device_inline bool isfinite_safe(float f)