42 if (scene->need_global_attribute(std)) {
46 foreach (
Node *node, used_shaders) {
48 if (shader->attributes.find(std)) {
58 if (name == ustring()) {
62 foreach (
Node *node, used_shaders) {
64 if (shader->attributes.find(name)) {
76 foreach (
Node *node, used_shaders) {
78 result.add(shader->attributes);
86 foreach (
const Attribute &attr, attributes.attributes) {
102 attr_map[index].
id = id;
106 if (type == TypeDesc::TypeFloat) {
109 else if (type == TypeDesc::TypeMatrix) {
115 else if (type == TypeFloat4) {
137 attr_map[index + j].
element = chain;
138 attr_map[index + j].
offset = chain ? chain_link + j : 0;
139 attr_map[index + j].
type = 0;
140 attr_map[index + j].
flags = 0;
151 Mesh *mesh =
static_cast<Mesh *
>(geom);
152 if (mesh->get_num_subd_faces()) {
168 size_t attr_map_size = 0;
170 for (
size_t i = 0; i < scene->geometry.size(); i++) {
171 Geometry *geom = scene->geometry[i];
175 size_t attr_count = 0;
178 scene->shader_manager->get_attribute_id(req.
std) != (
uint64_t)req.
std)
184 const size_t attr_count = geom_attributes[i].size();
190 for (
size_t i = 0; i < scene->objects.size(); i++) {
191 Object *
object = scene->objects[i];
194 if (object_attributes[i].
size() == 0) {
198 object->attr_map_offset = attr_map_size;
203 if (attr_map_size == 0) {
215 for (
size_t i = 0; i < scene->geometry.size(); i++) {
216 Geometry *geom = scene->geometry[i];
225 id = scene->shader_manager->get_attribute_id(req.
name);
228 id = scene->shader_manager->get_attribute_id(req.
std);
247 for (
size_t i = 0; i < scene->objects.size(); i++) {
248 Object *
object = scene->objects[i];
252 if (attributes.size() > 0) {
253 size_t index =
object->attr_map_offset;
258 id = scene->shader_manager->get_attribute_id(req.
name);
261 id = scene->shader_manager->get_attribute_id(req.
std);
276void GeometryManager::update_attribute_element_offset(
Geometry *geom,
278 size_t &attr_float_offset,
280 size_t &attr_float2_offset,
282 size_t &attr_float3_offset,
284 size_t &attr_float4_offset,
286 size_t &attr_uchar4_offset,
302 int &offset = desc.
offset;
311 offset = attr_uchar4_offset;
313 assert(attr_uchar4.
size() >= offset + size);
315 for (
size_t k = 0; k <
size; k++) {
316 attr_uchar4[offset + k] = data[k];
320 attr_uchar4_offset +=
size;
322 else if (mattr->
type == TypeDesc::TypeFloat) {
324 offset = attr_float_offset;
326 assert(attr_float.
size() >= offset + size);
328 for (
size_t k = 0; k <
size; k++) {
329 attr_float[offset + k] = data[k];
333 attr_float_offset +=
size;
337 offset = attr_float2_offset;
339 assert(attr_float2.
size() >= offset + size);
341 for (
size_t k = 0; k <
size; k++) {
342 attr_float2[offset + k] = data[k];
346 attr_float2_offset +=
size;
348 else if (mattr->
type == TypeDesc::TypeMatrix) {
350 offset = attr_float4_offset;
352 assert(attr_float4.
size() >= offset + size * 3);
354 for (
size_t k = 0; k < size * 3; k++) {
355 attr_float4[offset + k] = (&tfm->
x)[k];
359 attr_float4_offset += size * 3;
363 offset = attr_float4_offset;
365 assert(attr_float4.
size() >= offset + size);
367 for (
size_t k = 0; k <
size; k++) {
368 attr_float4[offset + k] = data[k];
372 attr_float4_offset +=
size;
376 offset = attr_float3_offset;
378 assert(attr_float3.
size() >= offset + size);
380 for (
size_t k = 0; k <
size; k++) {
381 attr_float3[offset + k] = data[k];
385 attr_float3_offset +=
size;
391 Mesh *mesh =
static_cast<Mesh *
>(geom);
399 offset -= mesh->vert_offset;
402 offset -= mesh->vert_offset;
406 offset -= mesh->prim_offset;
409 offset -= mesh->face_offset;
414 offset -= 3 * mesh->prim_offset;
417 offset -= mesh->corner_offset;
422 Hair *hair =
static_cast<Hair *
>(geom);
427 offset -= hair->curve_key_offset;
430 offset -= hair->curve_key_offset;
452 size_t *attr_float_size,
453 size_t *attr_float2_size,
454 size_t *attr_float3_size,
455 size_t *attr_float4_size,
456 size_t *attr_uchar4_size)
465 *attr_uchar4_size +=
size;
467 else if (mattr->
type == TypeDesc::TypeFloat) {
468 *attr_float_size +=
size;
471 *attr_float2_size +=
size;
473 else if (mattr->
type == TypeDesc::TypeMatrix) {
474 *attr_float4_size += size * 4;
477 *attr_float4_size +=
size;
480 *attr_float3_size +=
size;
490 progress.
set_status(
"Updating Mesh",
"Computing attributes");
497 for (
size_t i = 0; i < scene->geometry.size(); i++) {
498 Geometry *geom = scene->geometry[i];
501 scene->need_global_attributes(geom_attributes[i]);
503 foreach (
Node *node, geom->get_used_shaders()) {
505 geom_attributes[i].add(shader->attributes);
508 if (geom->
is_hair() &&
static_cast<Hair *
>(geom)->need_shadow_transparency()) {
517 object_attribute_values.reserve(scene->objects.size());
519 for (
size_t i = 0; i < scene->objects.size(); i++) {
520 Object *
object = scene->objects[i];
522 size_t geom_idx = geom->
index;
524 assert(geom_idx < scene->geometry.size() && scene->geometry[geom_idx] == geom);
532 for (
size_t j = 0; j <
object->attributes.size(); j++) {
533 ParamValue ¶m =
object->attributes[j];
537 attributes.add(param.name());
540 assert(param.datasize() == attr->
buffer.size());
541 memcpy(attr->
buffer.data(), param.data(), param.datasize());
553 size_t attr_float_size = 0;
554 size_t attr_float2_size = 0;
555 size_t attr_float3_size = 0;
556 size_t attr_float4_size = 0;
557 size_t attr_uchar4_size = 0;
559 for (
size_t i = 0; i < scene->geometry.size(); i++) {
560 Geometry *geom = scene->geometry[i];
575 Mesh *mesh =
static_cast<Mesh *
>(geom);
576 Attribute *subd_attr = mesh->subd_attributes.find(req);
590 for (
size_t i = 0; i < scene->objects.size(); i++) {
591 Object *
object = scene->objects[i];
593 foreach (
Attribute &attr, object_attribute_values[i].attributes) {
620 size_t attr_float_offset = 0;
621 size_t attr_float2_offset = 0;
622 size_t attr_float3_offset = 0;
623 size_t attr_float4_offset = 0;
624 size_t attr_uchar4_offset = 0;
627 for (
size_t i = 0; i < scene->geometry.size(); i++) {
628 Geometry *geom = scene->geometry[i];
641 update_attribute_element_offset(geom,
658 Mesh *mesh =
static_cast<Mesh *
>(geom);
659 Attribute *subd_attr = mesh->subd_attributes.find(req);
666 update_attribute_element_offset(mesh,
689 for (
size_t i = 0; i < scene->objects.size(); i++) {
690 Object *
object = scene->objects[i];
701 update_attribute_element_offset(object->geometry,
728 if (scene->shader_manager->use_osl()) {
739 progress.
set_status(
"Updating Mesh",
"Copying Attributes to device");
753 scene->object_manager->device_update_geom_offsets(device, dscene, scene);
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
AttributeDescriptor subd_desc
Attribute * find(ustring name) const
static AttrKernelDataType kernel_type(const Attribute &attr)
size_t element_size(Geometry *geom, AttributePrimitive prim) const
ImageHandle & data_voxel()
Transform * data_transform()
device_vector< float4 > attributes_float4
device_vector< float2 > attributes_float2
device_vector< AttributeMap > attributes_map
device_vector< packed_float3 > attributes_float3
device_vector< float > attributes_float
device_vector< uchar4 > attributes_uchar4
void device_update_attributes(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
void update_osl_globals(Device *device, Scene *scene)
void update_svm_attributes(Device *device, DeviceScene *dscene, Scene *scene, vector< AttributeRequestSet > &geom_attributes, vector< AttributeRequestSet > &object_attributes)
bool has_voxel_attributes() const
bool is_pointcloud() const
AttributeRequestSet needed_attributes()
bool need_attribute(Scene *scene, AttributeStandard std)
int svm_slot(const int tile_index=0) const
void set_status(const string &status_, const string &substatus_="")
void copy_to_device_if_modified()
T * alloc(size_t width, size_t height=0, size_t depth=0)
#define CCL_NAMESPACE_END
static void emit_attribute_map_entry(AttributeMap *attr_map, size_t index, uint64_t id, TypeDesc type, const AttributeDescriptor &desc)
static void update_attribute_element_size(Geometry *geom, Attribute *mattr, AttributePrimitive prim, size_t *attr_float_size, size_t *attr_float2_size, size_t *attr_float3_size, size_t *attr_float4_size, size_t *attr_uchar4_size)
static void emit_attribute_map_terminator(AttributeMap *attr_map, size_t index, bool chain, uint chain_link)
static void emit_attribute_mapping(AttributeMap *attr_map, size_t index, uint64_t id, AttributeRequest &req, Geometry *geom)
@ ATTR_STD_SHADOW_TRANSPARENCY
@ ATTR_ELEMENT_CORNER_BYTE
@ ATTR_ELEMENT_CURVE_KEY_MOTION
@ ATTR_ELEMENT_VERTEX_MOTION
VecBase< float, 4 > float4
static constexpr TypeDesc TypeRGBA(TypeDesc::FLOAT, TypeDesc::VEC4, TypeDesc::COLOR)
CCL_NAMESPACE_BEGIN static OIIO_NAMESPACE_USING constexpr TypeDesc TypeFloat2(TypeDesc::FLOAT, TypeDesc::VEC2)
unsigned __int64 uint64_t
@ SUBDIVISION_CATMULL_CLARK
ccl_device_inline uint as_uint(int i)