58 return face_num * 3 + vert_num;
64 return mesh->get_triangles()[corner];
78 const int corner_index =
CornerIndex(face_num, vert_num);
79 const float2 tfuv =
uv[corner_index];
91 if (
mesh->get_smooth()[face_num]) {
105 const int corner_index =
CornerIndex(face_num, vert_num);
108 tangent_sign[corner_index] = orientation ? 1.0f : -1.0f;
114 return uv !=
nullptr;
130 const bool need_sign,
133 const char *tangent_postfix,
134 const char *tangent_sign_postfix)
141 if (attr_vN ==
nullptr && attr_cN ==
nullptr) {
150 const ustring name = ustring((attr_uv) ? attr_uv->
name.string() + tangent_postfix :
154 attr = attributes.
add(tangent_std, name);
161 float *tangent_sign =
nullptr;
163 const ustring name_sign = ustring((attr_uv) ? attr_uv->
name.string() + tangent_sign_postfix :
167 attr_sign = attributes.
add(tangent_sign_std, name_sign);
175 MikkMeshWrapper userdata(mesh, vertex_normal, corner_normal, uv, tangent, tangent_sign);
190 const size_t num_steps,
195 const size_t max_step = num_steps - 1;
196 const size_t step =
min((
size_t)(time * max_step), max_step - 1);
197 const float t = time * max_step -
step;
204 r_verts[0] = (1.0f - t) * curr_verts[0] + t * next_verts[0];
205 r_verts[1] = (1.0f - t) * curr_verts[1] + t * next_verts[1];
206 r_verts[2] = (1.0f - t) * curr_verts[2] + t * next_verts[2];
215 r_verts[0] = vert_step[
v[0]];
216 r_verts[1] = vert_step[
v[1]];
217 r_verts[2] = vert_step[
v[2]];
226 const float normlen =
len(
norm);
227 if (normlen == 0.0f) {
230 return norm / normlen;
255 return attr ? attr->
size : 0;
268 static NodeEnum subdivision_type_enum;
274 static NodeEnum subdivision_boundary_interpolation_enum;
277 subdivision_boundary_interpolation_enum.
insert(
"edge_and_corner",
280 "Subdivision Boundary Interpolation",
281 subdivision_boundary_interpolation_enum,
284 static NodeEnum subdivision_fvar_interpolation_enum;
287 subdivision_fvar_interpolation_enum.
insert(
"corners_plus1",
289 subdivision_fvar_interpolation_enum.
insert(
"corners_plus2",
294 "Subdivision Face-Varying Interpolation",
295 subdivision_fvar_interpolation_enum,
300 subd_vert_creases_weight,
"Subdivision Vertex Crease Weights",
array<float>());
311 static NodeEnum subd_adaptive_space_enum;
316 "Subdivision Adaptive Space",
317 subd_adaptive_space_enum,
319 SOCKET_FLOAT(subd_dicing_rate,
"Subdivision Dicing Rate", 1.0f)
320 SOCKET_INT(subd_max_level,
"Max Subdivision Level", 1);
330 subd_adaptive_space_is_modified() || subd_objecttoworld_is_modified() ||
331 subd_max_level_is_modified());
340 num_subd_added_verts = 0;
359 triangles.resize(numtris * 3);
360 shader.resize(numtris);
368 subd_start_corner.resize(numfaces);
369 subd_num_corners.resize(numfaces);
370 subd_shader.resize(numfaces);
371 subd_smooth.resize(numfaces);
372 subd_ptex_offset.resize(numfaces);
373 subd_face_corners.resize(numcorners);
374 num_subd_faces = numfaces;
381 subd_creases_edge.reserve(num_creases * 2);
382 subd_creases_weight.reserve(num_creases);
389 num_subd_added_verts = 0;
402 subd_start_corner.clear();
403 subd_num_corners.clear();
406 subd_ptex_offset.clear();
407 subd_face_corners.clear();
409 subd_creases_edge.clear();
410 subd_creases_weight.clear();
423 clear(preserve_shaders,
false);
439 subd_creases_edge.push_back_slow(v0);
440 subd_creases_edge.push_back_slow(v1);
441 subd_creases_weight.push_back_slow(weight);
443 tag_subd_creases_edge_modified();
444 tag_subd_creases_edge_modified();
445 tag_subd_creases_weight_modified();
450 subd_vert_creases.push_back_slow(v);
451 subd_vert_creases_weight.push_back_slow(weight);
453 tag_subd_vert_creases_modified();
454 tag_subd_vert_creases_weight_modified();
476 const size_t numcorners = triangles.size();
510 if (verts_size > 0) {
511 for (
size_t i = 0; i < verts_size; i++) {
516 if (use_motion_blur && attr_P->
has_motion()) {
517 for (
int attr_step = 1; attr_step < attr_P->
num_motion_steps(); attr_step++) {
519 for (
size_t i = 0; i < verts_size; i++) {
520 bnds.
grow(vert_step[i]);
529 for (
size_t i = 0; i < verts_size; i++) {
533 if (use_motion_blur && attr_P->
has_motion()) {
534 for (
int attr_step = 1; attr_step < attr_P->
num_motion_steps(); attr_step++) {
536 for (
size_t i = 0; i < verts_size; i++) {
558 const size_t num_verts = this->num_verts();
568 const size_t num_verts = this->num_verts();
579 const size_t num_corners = triangles.size();
582 for (
size_t i = 0; i < num_corners; i++) {
593 for (
size_t i = 0; i < size; i++) {
598 if (apply_to_motion) {
602 const size_t num_verts = this->num_verts();
615 const size_t num_verts = this->num_verts();
629 const size_t nc = triangles.size();
632 for (
size_t i = 0; i < nc; i++) {
671 for (
size_t i = 0; i < triangles_size; i++) {
673 for (
size_t j = 0; j < 3; j++) {
679 for (
size_t i = 0; i < verts_size; i++) {
684 for (
size_t i = 0; i < verts_size; i++) {
702 for (
int attr_step = 1; attr_step < attr_P->
num_motion_steps(); attr_step++) {
709 for (
size_t i = 0; i < triangles_size; i++) {
712 for (
size_t j = 0; j < 3; j++) {
713 mN_float[tri.
v[j]] += fN;
718 for (
size_t i = 0; i < verts_size; i++) {
723 for (
size_t i = 0; i < verts_size; i++) {
744 const size_t corner = subd_face_corners[face.
start_corner + j];
745 vN_float[corner] += fN;
750 for (
size_t i = 0; i < verts_size; i++) {
755 for (
size_t i = 0; i < verts_size; i++) {
808 const size_t verts_size = attr_P->
size;
812 for (
size_t i = 0; i < verts_size; ++i) {
813 generated[i] = verts[i];
827 ccl::set<ustring> uv_maps;
834 const char *tangent_postfix = (undisplaced) ?
".undisplaced_tangent" :
".tangent";
835 const char *tangent_sign_postfix = (undisplaced) ?
".undisplaced_tangent_sign" :
".tangent_sign";
847 tangent_sign_postfix);
856 const ustring tangent_name = ustring(attr.
name.string() + tangent_postfix);
857 const ustring tangent_sign_name = ustring(attr.
name.string() + tangent_sign_postfix);
868 tangent_sign_postfix);
876 uint last_shader = -1;
877 bool last_smooth =
false;
880 const int *shader_ptr = shader.data();
885 const bool *smooth_ptr = (use_corner_normals) ?
nullptr :
smooth.data();
886 const bool smooth_constant = (use_corner_normals) ?
true :
false;
888 for (
size_t i = 0; i < triangles_size; i++) {
889 const int new_shader = shader_ptr ? shader_ptr[i] :
INT_MAX;
890 const bool new_smooth = smooth_ptr ? smooth_ptr[i] : smooth_constant;
892 if (new_shader != last_shader || last_smooth != new_smooth) {
893 last_shader = new_shader;
894 last_smooth = new_smooth;
895 Shader *shader = (last_shader < used_shaders.size()) ?
896 static_cast<Shader *
>(used_shaders[last_shader]) :
898 shader_id = scene->
shader_manager->get_shader_id(shader, last_smooth);
901 tri_shader[i] = shader_id;
908 const int *p_tris = triangles.data();
910 for (
size_t i = 0; i < triangles_size; i++) {
911 tri_vindex[i] =
make_packed_uint3(p_tris[off + 0], p_tris[off + 1], p_tris[off + 2]);
920 return use_motion_blur &&
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
list< Attribute > attributes
Attribute * find(ustring name) const
Attribute * add(ustring name, const TypeDesc type, AttributeElement element)
void remove(ustring name)
void clear(bool preserve_voxel_data=false)
const T * data(const int step=0) const
void resize(Geometry *geom, AttributePrimitive prim)
T * data_for_write(const int step=0)
void add_motion(const Geometry *geom)
void get_uv_tiles(Geometry *geom, AttributePrimitive prim, unordered_set< int > &tiles) const
static const char * standard_name(AttributeStandard std)
size_t buffer_size(Geometry *geom, AttributePrimitive prim) const
int num_motion_steps() const
const T * data_at_time_step(const int step, const int num_time_steps) const
__forceinline bool valid() const
__forceinline void grow_safe(const float3 &pt)
__forceinline void grow(const float3 &pt)
Transform transform_normal
int motion_step(const float time) const
void tag_position_modified()
const packed_float3 * get_position() const
bool position_is_modified() const
Geometry(const NodeType *node_type, const Type type)
bool transform_negative_scaled
bool need_attribute(const Scene *scene, AttributeStandard std)
virtual void clear(bool preserve_shaders=false)
packed_float3 * get_position_for_write()
size_t get_num_subd_faces() const
void add_undisplaced(Scene *scene)
@ SUBDIVISION_ADAPTIVE_SPACE_OBJECT
@ SUBDIVISION_ADAPTIVE_SPACE_PIXEL
NODE_DECLARE size_t num_verts() const
void reserve_subd_creases(const size_t num_creases)
void compute_bounds() override
void add_vertex_normals()
AttributeSet subd_attributes
void copy_center_to_motion_step(const int motion_step)
Mesh(const NodeType *node_type_, Type geom_type_)
void clear(bool preserve_shaders=false) override
void add_builtin_attributes()
bool has_motion_blur() const override
@ SUBDIVISION_FVAR_LINEAR_NONE
@ SUBDIVISION_FVAR_LINEAR_CORNERS_PLUS2
@ SUBDIVISION_FVAR_LINEAR_CORNERS_ONLY
@ SUBDIVISION_FVAR_LINEAR_ALL
@ SUBDIVISION_FVAR_LINEAR_BOUNDARIES
@ SUBDIVISION_FVAR_LINEAR_CORNERS_PLUS1
void add_vertex_crease(const int v, const float weight)
SubdFace get_subd_face(const size_t index) const
void pack_triangles(packed_uint3 *tri_vindex)
@ SUBDIVISION_CATMULL_CLARK
size_t num_triangles() const
void resize_subd_faces(const int numfaces, const int numcorners)
void get_uv_tiles(ustring map, unordered_set< int > &tiles) override
void resize_mesh(const int numverts, const int numtris)
void update_generated(Scene *scene)
Triangle get_triangle(const size_t i) const
void pack_shaders(Scene *scene, uint *shader)
PrimitiveType primitive_type() const override
void add_edge_crease(const int v0, const int v1, const float weight)
void update_tangents(Scene *scene, bool undisplaced)
void apply_transform(const Transform &tfm, const bool apply_to_motion) override
@ SUBDIVISION_BOUNDARY_EDGE_ONLY
@ SUBDIVISION_BOUNDARY_EDGE_AND_CORNER
@ SUBDIVISION_BOUNDARY_NONE
unique_ptr< ShaderManager > shader_manager
#define CCL_NAMESPACE_END
#define assert(assertion)
VecBase< float, D > normalize(VecOp< float, D >) RET
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
VecT safe_normalize(VecT vector)
ccl_gpu_kernel_postfix ccl_global KernelWorkTile * tiles
@ PRIMITIVE_MOTION_TRIANGLE
@ ATTR_STD_POSITION_UNDISPLACED
@ ATTR_STD_NORMAL_UNDISPLACED
@ ATTR_STD_UV_TANGENT_SIGN
@ ATTR_STD_UV_TANGENT_SIGN_UNDISPLACED
@ ATTR_STD_UV_TANGENT_UNDISPLACED
ccl_device_inline bool isfinite_safe(const float f)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
ccl_device_inline dual2 map_to_sphere(const dual3 co)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
#define SOCKET_BOOLEAN_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 NODE_DEFINE(structname)
#define SOCKET_ENUM(name, ui_name, values, default_value,...)
static void mikk_compute_tangents(Attribute *attr_uv, Mesh *mesh, const bool need_sign, const AttributeStandard tangent_std, const AttributeStandard tangent_sign_std, const char *tangent_postfix, const char *tangent_sign_postfix)
float3 normal(const Mesh *mesh) const
float3 compute_normal(const packed_float3 *verts) const
void verts_for_step(const Attribute *attr_P, const size_t step, float3 r_verts[3]) const
void bounds_grow(const packed_float3 *verts, BoundBox &bounds) const
void motion_verts(const Attribute *attr_P, const size_t num_steps, const float time, float3 r_verts[3]) const
bool valid(const packed_float3 *verts) const
mikk::float3 GetNormal(const int face_num, const int vert_num)
int VertexIndex(const int face_num, const int vert_num)
void SetTangentSpace(const int face_num, const int vert_num, mikk::float3 T, bool orientation)
int CornerIndex(const int face_num, const int vert_num)
int GetNumVerticesOfFace(const int)
const packed_float3 * position
const packed_normal * corner_normal
MikkMeshWrapper(const Mesh *mesh, const packed_normal *vertex_normal, const packed_normal *corner_normal, const float2 *uv, packed_float3 *tangent, float *tangent_sign)
mikk::float3 GetPosition(const int face_num, const int vert_num)
mikk::float3 GetTexCoord(const int face_num, const int vert_num)
const packed_normal * vertex_normal
void insert(const char *x, const int y)
static NodeType * add(const char *name, CreateFunc create, Type type=NONE, const NodeType *base=nullptr)
ccl_device_inline packed_uint3 make_packed_uint3(const uint x, const uint y, uint z)