2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 02:50:24 +01:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "render/attribute.h"
|
2020-02-02 12:04:19 +01:00
|
|
|
#include "render/hair.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "render/image.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "render/mesh.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "util/util_foreach.h"
|
|
|
|
#include "util/util_transform.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* Attribute */
|
|
|
|
|
2020-03-08 14:21:29 +01:00
|
|
|
Attribute::Attribute(
|
|
|
|
ustring name, TypeDesc type, AttributeElement element, Geometry *geom, AttributePrimitive prim)
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 15:01:26 +01:00
|
|
|
: name(name), std(ATTR_STD_NONE), type(type), element(element), flags(0), modified(true)
|
2020-03-08 14:21:29 +01:00
|
|
|
{
|
|
|
|
/* string and matrix not supported! */
|
|
|
|
assert(type == TypeDesc::TypeFloat || type == TypeDesc::TypeColor ||
|
|
|
|
type == TypeDesc::TypePoint || type == TypeDesc::TypeVector ||
|
|
|
|
type == TypeDesc::TypeNormal || type == TypeDesc::TypeMatrix || type == TypeFloat2 ||
|
2020-10-26 18:23:40 +01:00
|
|
|
type == TypeFloat4 || type == TypeRGBA);
|
2020-03-08 14:21:29 +01:00
|
|
|
|
|
|
|
if (element == ATTR_ELEMENT_VOXEL) {
|
|
|
|
buffer.resize(sizeof(ImageHandle));
|
|
|
|
new (buffer.data()) ImageHandle();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
resize(geom, prim, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
Attribute::~Attribute()
|
|
|
|
{
|
2020-03-08 10:42:11 +01:00
|
|
|
/* For voxel data, we need to free the image handle. */
|
2020-03-19 19:50:34 +01:00
|
|
|
if (element == ATTR_ELEMENT_VOXEL && buffer.size()) {
|
2020-03-08 10:42:11 +01:00
|
|
|
ImageHandle &handle = data_voxel();
|
|
|
|
handle.~ImageHandle();
|
2014-03-29 13:03:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
void Attribute::resize(Geometry *geom, AttributePrimitive prim, bool reserve_only)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-03-08 14:21:29 +01:00
|
|
|
if (element != ATTR_ELEMENT_VOXEL) {
|
|
|
|
if (reserve_only) {
|
|
|
|
buffer.reserve(buffer_size(geom, prim));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
buffer.resize(buffer_size(geom, prim), 0);
|
|
|
|
}
|
2014-03-29 13:03:46 +01:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-07-16 22:57:06 -04:00
|
|
|
void Attribute::resize(size_t num_elements)
|
|
|
|
{
|
2020-03-08 14:21:29 +01:00
|
|
|
if (element != ATTR_ELEMENT_VOXEL) {
|
|
|
|
buffer.resize(num_elements * data_sizeof(), 0);
|
|
|
|
}
|
2016-07-16 22:57:06 -04:00
|
|
|
}
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
void Attribute::add(const float &f)
|
|
|
|
{
|
2019-03-05 18:49:47 +01:00
|
|
|
assert(data_sizeof() == sizeof(float));
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
char *data = (char *)&f;
|
|
|
|
size_t size = sizeof(f);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < size; i++)
|
|
|
|
buffer.push_back(data[i]);
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 15:01:26 +01:00
|
|
|
|
|
|
|
modified = true;
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
|
|
|
|
2014-06-13 23:40:39 +02:00
|
|
|
void Attribute::add(const uchar4 &f)
|
|
|
|
{
|
2019-03-05 18:49:47 +01:00
|
|
|
assert(data_sizeof() == sizeof(uchar4));
|
|
|
|
|
|
|
|
char *data = (char *)&f;
|
|
|
|
size_t size = sizeof(f);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < size; i++)
|
|
|
|
buffer.push_back(data[i]);
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 15:01:26 +01:00
|
|
|
|
|
|
|
modified = true;
|
2019-03-05 18:49:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Attribute::add(const float2 &f)
|
|
|
|
{
|
|
|
|
assert(data_sizeof() == sizeof(float2));
|
|
|
|
|
2014-06-13 23:40:39 +02:00
|
|
|
char *data = (char *)&f;
|
|
|
|
size_t size = sizeof(f);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < size; i++)
|
|
|
|
buffer.push_back(data[i]);
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 15:01:26 +01:00
|
|
|
|
|
|
|
modified = true;
|
2014-06-13 23:40:39 +02:00
|
|
|
}
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
void Attribute::add(const float3 &f)
|
|
|
|
{
|
2019-03-05 18:49:47 +01:00
|
|
|
assert(data_sizeof() == sizeof(float3));
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
char *data = (char *)&f;
|
|
|
|
size_t size = sizeof(f);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < size; i++)
|
|
|
|
buffer.push_back(data[i]);
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 15:01:26 +01:00
|
|
|
|
|
|
|
modified = true;
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
|
|
|
|
2013-12-31 17:33:55 +01:00
|
|
|
void Attribute::add(const Transform &f)
|
|
|
|
{
|
2019-03-05 18:49:47 +01:00
|
|
|
assert(data_sizeof() == sizeof(Transform));
|
|
|
|
|
2013-12-31 17:33:55 +01:00
|
|
|
char *data = (char *)&f;
|
|
|
|
size_t size = sizeof(f);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < size; i++)
|
|
|
|
buffer.push_back(data[i]);
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 15:01:26 +01:00
|
|
|
|
|
|
|
modified = true;
|
2013-12-31 17:33:55 +01:00
|
|
|
}
|
|
|
|
|
2014-04-13 12:51:06 +02:00
|
|
|
void Attribute::add(const char *data)
|
|
|
|
{
|
|
|
|
size_t size = data_sizeof();
|
|
|
|
|
|
|
|
for (size_t i = 0; i < size; i++)
|
|
|
|
buffer.push_back(data[i]);
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 15:01:26 +01:00
|
|
|
|
|
|
|
modified = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Attribute::set_data_from(Attribute &&other)
|
|
|
|
{
|
|
|
|
assert(other.std == std);
|
|
|
|
assert(other.type == type);
|
|
|
|
assert(other.element == element);
|
|
|
|
|
|
|
|
this->flags = other.flags;
|
|
|
|
|
|
|
|
if (this->buffer.size() != other.buffer.size()) {
|
|
|
|
this->buffer = std::move(other.buffer);
|
|
|
|
modified = true;
|
|
|
|
}
|
|
|
|
else if (memcmp(this->data(), other.data(), other.buffer.size()) != 0) {
|
|
|
|
this->buffer = std::move(other.buffer);
|
|
|
|
modified = true;
|
|
|
|
}
|
2014-04-13 12:51:06 +02:00
|
|
|
}
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
size_t Attribute::data_sizeof() const
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2014-03-29 13:03:48 +01:00
|
|
|
if (element == ATTR_ELEMENT_VOXEL)
|
2020-03-08 10:42:11 +01:00
|
|
|
return sizeof(ImageHandle);
|
2016-07-16 19:42:28 -04:00
|
|
|
else if (element == ATTR_ELEMENT_CORNER_BYTE)
|
|
|
|
return sizeof(uchar4);
|
2014-03-29 13:03:48 +01:00
|
|
|
else if (type == TypeDesc::TypeFloat)
|
2011-05-31 11:31:00 +00:00
|
|
|
return sizeof(float);
|
2019-03-05 18:49:47 +01:00
|
|
|
else if (type == TypeFloat2)
|
|
|
|
return sizeof(float2);
|
2013-12-31 17:33:55 +01:00
|
|
|
else if (type == TypeDesc::TypeMatrix)
|
|
|
|
return sizeof(Transform);
|
2011-05-31 11:31:00 +00:00
|
|
|
else
|
|
|
|
return sizeof(float3);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
size_t Attribute::element_size(Geometry *geom, AttributePrimitive prim) const
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2016-07-16 22:57:06 -04:00
|
|
|
if (flags & ATTR_FINAL_SIZE) {
|
|
|
|
return buffer.size() / data_sizeof();
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
size_t size = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-05 17:03:59 +00:00
|
|
|
switch (element) {
|
2013-12-31 17:33:55 +01:00
|
|
|
case ATTR_ELEMENT_OBJECT:
|
|
|
|
case ATTR_ELEMENT_MESH:
|
2014-03-29 13:03:48 +01:00
|
|
|
case ATTR_ELEMENT_VOXEL:
|
2013-04-05 17:03:59 +00:00
|
|
|
size = 1;
|
|
|
|
break;
|
|
|
|
case ATTR_ELEMENT_VERTEX:
|
2020-11-04 11:17:38 +01:00
|
|
|
if (geom->geometry_type == Geometry::MESH || geom->geometry_type == Geometry::VOLUME) {
|
2020-02-02 12:04:19 +01:00
|
|
|
Mesh *mesh = static_cast<Mesh *>(geom);
|
2020-11-04 11:17:38 +01:00
|
|
|
size = mesh->get_verts().size() + mesh->get_num_ngons();
|
2020-02-02 12:04:19 +01:00
|
|
|
if (prim == ATTR_PRIM_SUBD) {
|
2020-11-04 11:17:38 +01:00
|
|
|
size -= mesh->get_num_subd_verts();
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
2016-07-16 19:42:28 -04:00
|
|
|
}
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
2014-03-29 13:03:46 +01:00
|
|
|
case ATTR_ELEMENT_VERTEX_MOTION:
|
2020-11-04 11:17:38 +01:00
|
|
|
if (geom->geometry_type == Geometry::MESH) {
|
2020-02-02 12:04:19 +01:00
|
|
|
Mesh *mesh = static_cast<Mesh *>(geom);
|
2020-11-04 11:17:38 +01:00
|
|
|
size = (mesh->get_verts().size() + mesh->get_num_ngons()) * (mesh->get_motion_steps() - 1);
|
2020-02-02 12:04:19 +01:00
|
|
|
if (prim == ATTR_PRIM_SUBD) {
|
2020-11-04 11:17:38 +01:00
|
|
|
size -= mesh->get_num_subd_verts() * (mesh->get_motion_steps() - 1);
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
2016-07-16 19:42:28 -04:00
|
|
|
}
|
2014-03-29 13:03:46 +01:00
|
|
|
break;
|
2013-04-05 17:03:59 +00:00
|
|
|
case ATTR_ELEMENT_FACE:
|
2020-11-04 11:17:38 +01:00
|
|
|
if (geom->geometry_type == Geometry::MESH || geom->geometry_type == Geometry::VOLUME) {
|
2020-02-02 12:04:19 +01:00
|
|
|
Mesh *mesh = static_cast<Mesh *>(geom);
|
2020-02-03 21:40:58 +01:00
|
|
|
if (prim == ATTR_PRIM_GEOMETRY) {
|
2020-02-02 12:04:19 +01:00
|
|
|
size = mesh->num_triangles();
|
|
|
|
}
|
|
|
|
else {
|
2020-11-04 11:17:38 +01:00
|
|
|
size = mesh->get_num_subd_faces() + mesh->get_num_ngons();
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
2016-07-16 19:42:28 -04:00
|
|
|
}
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
|
|
|
case ATTR_ELEMENT_CORNER:
|
2014-06-13 23:40:39 +02:00
|
|
|
case ATTR_ELEMENT_CORNER_BYTE:
|
2020-11-04 11:17:38 +01:00
|
|
|
if (geom->geometry_type == Geometry::MESH) {
|
2020-02-02 12:04:19 +01:00
|
|
|
Mesh *mesh = static_cast<Mesh *>(geom);
|
2020-02-03 21:40:58 +01:00
|
|
|
if (prim == ATTR_PRIM_GEOMETRY) {
|
2020-02-02 12:04:19 +01:00
|
|
|
size = mesh->num_triangles() * 3;
|
|
|
|
}
|
|
|
|
else {
|
2020-11-04 11:17:38 +01:00
|
|
|
size = mesh->get_subd_face_corners().size() + mesh->get_num_ngons();
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
2016-07-16 19:42:28 -04:00
|
|
|
}
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
|
|
|
case ATTR_ELEMENT_CURVE:
|
2020-11-04 11:17:38 +01:00
|
|
|
if (geom->geometry_type == Geometry::HAIR) {
|
2020-02-02 12:04:19 +01:00
|
|
|
Hair *hair = static_cast<Hair *>(geom);
|
|
|
|
size = hair->num_curves();
|
|
|
|
}
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
|
|
|
case ATTR_ELEMENT_CURVE_KEY:
|
2020-11-04 11:17:38 +01:00
|
|
|
if (geom->geometry_type == Geometry::HAIR) {
|
2020-02-02 12:04:19 +01:00
|
|
|
Hair *hair = static_cast<Hair *>(geom);
|
2020-11-04 11:17:38 +01:00
|
|
|
size = hair->get_curve_keys().size();
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
2014-03-29 13:03:46 +01:00
|
|
|
case ATTR_ELEMENT_CURVE_KEY_MOTION:
|
2020-11-04 11:17:38 +01:00
|
|
|
if (geom->geometry_type == Geometry::HAIR) {
|
2020-02-02 12:04:19 +01:00
|
|
|
Hair *hair = static_cast<Hair *>(geom);
|
2020-11-04 11:17:38 +01:00
|
|
|
size = hair->get_curve_keys().size() * (hair->get_motion_steps() - 1);
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
2014-03-29 13:03:46 +01:00
|
|
|
break;
|
2013-04-05 17:03:59 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-05 17:03:59 +00:00
|
|
|
return size;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
size_t Attribute::buffer_size(Geometry *geom, AttributePrimitive prim) const
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-02-02 12:04:19 +01:00
|
|
|
return element_size(geom, prim) * data_sizeof();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Attribute::same_storage(TypeDesc a, TypeDesc b)
|
|
|
|
{
|
|
|
|
if (a == b)
|
|
|
|
return true;
|
2018-07-06 10:17:58 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (a == TypeDesc::TypeColor || a == TypeDesc::TypePoint || a == TypeDesc::TypeVector ||
|
|
|
|
a == TypeDesc::TypeNormal) {
|
|
|
|
if (b == TypeDesc::TypeColor || b == TypeDesc::TypePoint || b == TypeDesc::TypeVector ||
|
|
|
|
b == TypeDesc::TypeNormal) {
|
|
|
|
return true;
|
2012-06-09 18:56:12 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-16 19:42:28 -04:00
|
|
|
void Attribute::zero_data(void *dst)
|
|
|
|
{
|
|
|
|
memset(dst, 0, data_sizeof());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Attribute::add_with_weight(void *dst, void *src, float weight)
|
|
|
|
{
|
|
|
|
if (element == ATTR_ELEMENT_CORNER_BYTE) {
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
((uchar *)dst)[i] += uchar(((uchar *)src)[i] * weight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (same_storage(type, TypeDesc::TypeFloat)) {
|
|
|
|
*((float *)dst) += *((float *)src) * weight;
|
|
|
|
}
|
2019-04-25 14:31:45 +02:00
|
|
|
else if (same_storage(type, TypeFloat2)) {
|
|
|
|
*((float2 *)dst) += *((float2 *)src) * weight;
|
|
|
|
}
|
2016-07-16 19:42:28 -04:00
|
|
|
else if (same_storage(type, TypeDesc::TypeVector)) {
|
|
|
|
*((float4 *)dst) += *((float4 *)src) * weight;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert(!"not implemented for this type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
const char *Attribute::standard_name(AttributeStandard std)
|
|
|
|
{
|
2014-03-29 13:03:48 +01:00
|
|
|
switch (std) {
|
|
|
|
case ATTR_STD_VERTEX_NORMAL:
|
|
|
|
return "N";
|
|
|
|
case ATTR_STD_FACE_NORMAL:
|
|
|
|
return "Ng";
|
|
|
|
case ATTR_STD_UV:
|
|
|
|
return "uv";
|
|
|
|
case ATTR_STD_GENERATED:
|
|
|
|
return "generated";
|
|
|
|
case ATTR_STD_GENERATED_TRANSFORM:
|
|
|
|
return "generated_transform";
|
|
|
|
case ATTR_STD_UV_TANGENT:
|
|
|
|
return "tangent";
|
|
|
|
case ATTR_STD_UV_TANGENT_SIGN:
|
|
|
|
return "tangent_sign";
|
2020-02-18 17:19:16 +01:00
|
|
|
case ATTR_STD_VERTEX_COLOR:
|
|
|
|
return "vertex_color";
|
2014-03-29 13:03:48 +01:00
|
|
|
case ATTR_STD_POSITION_UNDEFORMED:
|
|
|
|
return "undeformed";
|
|
|
|
case ATTR_STD_POSITION_UNDISPLACED:
|
|
|
|
return "undisplaced";
|
|
|
|
case ATTR_STD_MOTION_VERTEX_POSITION:
|
|
|
|
return "motion_P";
|
|
|
|
case ATTR_STD_MOTION_VERTEX_NORMAL:
|
|
|
|
return "motion_N";
|
|
|
|
case ATTR_STD_PARTICLE:
|
|
|
|
return "particle";
|
|
|
|
case ATTR_STD_CURVE_INTERCEPT:
|
|
|
|
return "curve_intercept";
|
2018-02-14 14:32:38 +01:00
|
|
|
case ATTR_STD_CURVE_RANDOM:
|
|
|
|
return "curve_random";
|
2014-03-29 13:03:48 +01:00
|
|
|
case ATTR_STD_PTEX_FACE_ID:
|
|
|
|
return "ptex_face_id";
|
|
|
|
case ATTR_STD_PTEX_UV:
|
|
|
|
return "ptex_uv";
|
2014-03-29 13:03:48 +01:00
|
|
|
case ATTR_STD_VOLUME_DENSITY:
|
|
|
|
return "density";
|
|
|
|
case ATTR_STD_VOLUME_COLOR:
|
|
|
|
return "color";
|
|
|
|
case ATTR_STD_VOLUME_FLAME:
|
|
|
|
return "flame";
|
|
|
|
case ATTR_STD_VOLUME_HEAT:
|
|
|
|
return "heat";
|
2018-02-18 03:13:07 +01:00
|
|
|
case ATTR_STD_VOLUME_TEMPERATURE:
|
|
|
|
return "temperature";
|
2014-03-29 13:03:48 +01:00
|
|
|
case ATTR_STD_VOLUME_VELOCITY:
|
|
|
|
return "velocity";
|
2015-02-06 12:35:46 +05:00
|
|
|
case ATTR_STD_POINTINESS:
|
|
|
|
return "pointiness";
|
2019-11-27 12:07:20 +02:00
|
|
|
case ATTR_STD_RANDOM_PER_ISLAND:
|
|
|
|
return "random_per_island";
|
2014-03-29 13:03:48 +01:00
|
|
|
case ATTR_STD_NOT_FOUND:
|
|
|
|
case ATTR_STD_NONE:
|
|
|
|
case ATTR_STD_NUM:
|
|
|
|
return "";
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
AttributeStandard Attribute::name_standard(const char *name)
|
|
|
|
{
|
2018-02-18 03:20:39 +01:00
|
|
|
if (name) {
|
|
|
|
for (int std = ATTR_STD_NONE; std < ATTR_STD_NUM; std++) {
|
|
|
|
if (strcmp(name, Attribute::standard_name((AttributeStandard)std)) == 0) {
|
|
|
|
return (AttributeStandard)std;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-29 13:03:48 +01:00
|
|
|
|
|
|
|
return ATTR_STD_NONE;
|
|
|
|
}
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
void Attribute::get_uv_tiles(Geometry *geom,
|
|
|
|
AttributePrimitive prim,
|
|
|
|
unordered_set<int> &tiles) const
|
|
|
|
{
|
|
|
|
if (type != TypeFloat2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int num = element_size(geom, prim);
|
|
|
|
const float2 *uv = data_float2();
|
|
|
|
for (int i = 0; i < num; i++, uv++) {
|
|
|
|
float u = uv->x, v = uv->y;
|
|
|
|
int x = (int)u, y = (int)v;
|
|
|
|
|
|
|
|
if (x < 0 || y < 0 || x >= 10) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Be conservative in corners - precisely touching the right or upper edge of a tile
|
|
|
|
* should not load its right/upper neighbor as well. */
|
|
|
|
if (x > 0 && (u < x + 1e-6f)) {
|
|
|
|
x--;
|
|
|
|
}
|
|
|
|
if (y > 0 && (v < y + 1e-6f)) {
|
|
|
|
y--;
|
|
|
|
}
|
|
|
|
|
|
|
|
tiles.insert(1001 + 10 * y + x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Attribute Set */
|
|
|
|
|
2020-02-03 21:40:58 +01:00
|
|
|
AttributeSet::AttributeSet(Geometry *geometry, AttributePrimitive prim)
|
|
|
|
: geometry(geometry), prim(prim)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AttributeSet::~AttributeSet()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-08 00:09:08 +02:00
|
|
|
Attribute *AttributeSet::add(ustring name, TypeDesc type, AttributeElement element)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
Attribute *attr = find(name);
|
|
|
|
|
|
|
|
if (attr) {
|
|
|
|
/* return if same already exists */
|
|
|
|
if (attr->type == type && attr->element == element)
|
|
|
|
return attr;
|
|
|
|
|
|
|
|
/* overwrite attribute with same name but different type/element */
|
|
|
|
remove(name);
|
|
|
|
}
|
|
|
|
|
2020-03-08 14:21:29 +01:00
|
|
|
Attribute new_attr(name, type, element, geometry, prim);
|
|
|
|
attributes.emplace_back(std::move(new_attr));
|
2021-02-17 12:04:45 +01:00
|
|
|
modified = true;
|
2020-03-08 14:21:29 +01:00
|
|
|
return &attributes.back();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
Attribute *AttributeSet::find(ustring name) const
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2013-01-03 12:08:54 +00:00
|
|
|
foreach (const Attribute &attr, attributes)
|
2011-04-27 11:58:34 +00:00
|
|
|
if (attr.name == name)
|
2013-01-03 12:08:54 +00:00
|
|
|
return (Attribute *)&attr;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AttributeSet::remove(ustring name)
|
|
|
|
{
|
|
|
|
Attribute *attr = find(name);
|
|
|
|
|
|
|
|
if (attr) {
|
|
|
|
list<Attribute>::iterator it;
|
|
|
|
|
|
|
|
for (it = attributes.begin(); it != attributes.end(); it++) {
|
|
|
|
if (&*it == attr) {
|
2021-02-17 12:04:45 +01:00
|
|
|
modified = true;
|
2011-04-27 11:58:34 +00:00
|
|
|
attributes.erase(it);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
Attribute *AttributeSet::add(AttributeStandard std, ustring name)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
Attribute *attr = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (name == ustring())
|
2013-01-03 12:08:54 +00:00
|
|
|
name = Attribute::standard_name(std);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-04 11:17:38 +01:00
|
|
|
if (geometry->geometry_type == Geometry::MESH) {
|
2013-04-05 17:03:59 +00:00
|
|
|
switch (std) {
|
|
|
|
case ATTR_STD_VERTEX_NORMAL:
|
|
|
|
attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_VERTEX);
|
|
|
|
break;
|
|
|
|
case ATTR_STD_FACE_NORMAL:
|
|
|
|
attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_FACE);
|
|
|
|
break;
|
|
|
|
case ATTR_STD_UV:
|
2019-03-05 14:54:54 +01:00
|
|
|
attr = add(name, TypeFloat2, ATTR_ELEMENT_CORNER);
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
|
|
|
case ATTR_STD_UV_TANGENT:
|
|
|
|
attr = add(name, TypeDesc::TypeVector, ATTR_ELEMENT_CORNER);
|
|
|
|
break;
|
|
|
|
case ATTR_STD_UV_TANGENT_SIGN:
|
|
|
|
attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_CORNER);
|
|
|
|
break;
|
2020-02-18 17:19:16 +01:00
|
|
|
case ATTR_STD_VERTEX_COLOR:
|
2020-02-19 18:44:07 +01:00
|
|
|
attr = add(name, TypeRGBA, ATTR_ELEMENT_CORNER_BYTE);
|
2020-02-18 17:19:16 +01:00
|
|
|
break;
|
2013-04-05 17:03:59 +00:00
|
|
|
case ATTR_STD_GENERATED:
|
|
|
|
case ATTR_STD_POSITION_UNDEFORMED:
|
|
|
|
case ATTR_STD_POSITION_UNDISPLACED:
|
|
|
|
attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_VERTEX);
|
|
|
|
break;
|
2014-03-29 13:03:46 +01:00
|
|
|
case ATTR_STD_MOTION_VERTEX_POSITION:
|
|
|
|
attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_VERTEX_MOTION);
|
2014-03-29 13:03:46 +01:00
|
|
|
break;
|
|
|
|
case ATTR_STD_MOTION_VERTEX_NORMAL:
|
|
|
|
attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_VERTEX_MOTION);
|
2014-03-29 13:03:46 +01:00
|
|
|
break;
|
2013-11-28 01:28:57 +01:00
|
|
|
case ATTR_STD_PTEX_FACE_ID:
|
|
|
|
attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_FACE);
|
|
|
|
break;
|
|
|
|
case ATTR_STD_PTEX_UV:
|
|
|
|
attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_VERTEX);
|
|
|
|
break;
|
2013-12-31 17:33:55 +01:00
|
|
|
case ATTR_STD_GENERATED_TRANSFORM:
|
|
|
|
attr = add(name, TypeDesc::TypeMatrix, ATTR_ELEMENT_MESH);
|
|
|
|
break;
|
2020-08-19 15:46:50 +02:00
|
|
|
case ATTR_STD_POINTINESS:
|
|
|
|
attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_VERTEX);
|
|
|
|
break;
|
|
|
|
case ATTR_STD_RANDOM_PER_ISLAND:
|
|
|
|
attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_FACE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-11-04 11:17:38 +01:00
|
|
|
else if (geometry->geometry_type == Geometry::VOLUME) {
|
2020-08-19 15:46:50 +02:00
|
|
|
switch (std) {
|
|
|
|
case ATTR_STD_VERTEX_NORMAL:
|
|
|
|
attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_VERTEX);
|
|
|
|
break;
|
|
|
|
case ATTR_STD_FACE_NORMAL:
|
|
|
|
attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_FACE);
|
|
|
|
break;
|
2014-03-29 13:03:48 +01:00
|
|
|
case ATTR_STD_VOLUME_DENSITY:
|
|
|
|
case ATTR_STD_VOLUME_FLAME:
|
|
|
|
case ATTR_STD_VOLUME_HEAT:
|
2018-02-18 03:13:07 +01:00
|
|
|
case ATTR_STD_VOLUME_TEMPERATURE:
|
2014-03-29 13:03:48 +01:00
|
|
|
attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_VOXEL);
|
|
|
|
break;
|
|
|
|
case ATTR_STD_VOLUME_COLOR:
|
|
|
|
attr = add(name, TypeDesc::TypeColor, ATTR_ELEMENT_VOXEL);
|
|
|
|
break;
|
|
|
|
case ATTR_STD_VOLUME_VELOCITY:
|
|
|
|
attr = add(name, TypeDesc::TypeVector, ATTR_ELEMENT_VOXEL);
|
|
|
|
break;
|
2013-04-05 17:03:59 +00:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
}
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
2020-11-04 11:17:38 +01:00
|
|
|
else if (geometry->geometry_type == Geometry::HAIR) {
|
2013-04-05 17:03:59 +00:00
|
|
|
switch (std) {
|
|
|
|
case ATTR_STD_UV:
|
2019-03-20 16:59:49 +01:00
|
|
|
attr = add(name, TypeFloat2, ATTR_ELEMENT_CURVE);
|
|
|
|
break;
|
2013-04-05 17:03:59 +00:00
|
|
|
case ATTR_STD_GENERATED:
|
|
|
|
attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_CURVE);
|
|
|
|
break;
|
2014-03-29 13:03:46 +01:00
|
|
|
case ATTR_STD_MOTION_VERTEX_POSITION:
|
|
|
|
attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_CURVE_KEY_MOTION);
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
|
|
|
case ATTR_STD_CURVE_INTERCEPT:
|
|
|
|
attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_CURVE_KEY);
|
|
|
|
break;
|
2018-02-14 14:32:38 +01:00
|
|
|
case ATTR_STD_CURVE_RANDOM:
|
2018-02-13 14:20:47 +01:00
|
|
|
attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_CURVE);
|
|
|
|
break;
|
2013-12-31 17:33:55 +01:00
|
|
|
case ATTR_STD_GENERATED_TRANSFORM:
|
|
|
|
attr = add(name, TypeDesc::TypeMatrix, ATTR_ELEMENT_MESH);
|
|
|
|
break;
|
2015-02-06 12:35:46 +05:00
|
|
|
case ATTR_STD_POINTINESS:
|
|
|
|
attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_VERTEX);
|
|
|
|
break;
|
2019-11-27 12:07:20 +02:00
|
|
|
case ATTR_STD_RANDOM_PER_ISLAND:
|
|
|
|
attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_FACE);
|
|
|
|
break;
|
2013-04-05 17:03:59 +00:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
}
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
attr->std = std;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return attr;
|
|
|
|
}
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
Attribute *AttributeSet::find(AttributeStandard std) const
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2013-01-03 12:08:54 +00:00
|
|
|
foreach (const Attribute &attr, attributes)
|
2011-04-27 11:58:34 +00:00
|
|
|
if (attr.std == std)
|
2013-01-03 12:08:54 +00:00
|
|
|
return (Attribute *)&attr;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
void AttributeSet::remove(AttributeStandard std)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
Attribute *attr = find(std);
|
|
|
|
|
|
|
|
if (attr) {
|
|
|
|
list<Attribute>::iterator it;
|
|
|
|
|
|
|
|
for (it = attributes.begin(); it != attributes.end(); it++) {
|
|
|
|
if (&*it == attr) {
|
2021-02-17 12:04:45 +01:00
|
|
|
modified = true;
|
2011-04-27 11:58:34 +00:00
|
|
|
attributes.erase(it);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Attribute *AttributeSet::find(AttributeRequest &req)
|
|
|
|
{
|
2012-04-30 12:49:26 +00:00
|
|
|
if (req.std == ATTR_STD_NONE)
|
2011-04-27 11:58:34 +00:00
|
|
|
return find(req.name);
|
|
|
|
else
|
|
|
|
return find(req.std);
|
|
|
|
}
|
|
|
|
|
2017-08-25 22:51:44 +02:00
|
|
|
void AttributeSet::remove(Attribute *attribute)
|
|
|
|
{
|
|
|
|
if (attribute->std == ATTR_STD_NONE) {
|
|
|
|
remove(attribute->name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
remove(attribute->std);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-08 00:09:08 +02:00
|
|
|
void AttributeSet::resize(bool reserve_only)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2013-01-03 12:08:54 +00:00
|
|
|
foreach (Attribute &attr, attributes) {
|
2020-02-03 21:40:58 +01:00
|
|
|
attr.resize(geometry, prim, reserve_only);
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2018-03-01 11:54:01 +01:00
|
|
|
void AttributeSet::clear(bool preserve_voxel_data)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2018-03-01 11:54:01 +01:00
|
|
|
if (preserve_voxel_data) {
|
|
|
|
list<Attribute>::iterator it;
|
|
|
|
|
|
|
|
for (it = attributes.begin(); it != attributes.end();) {
|
|
|
|
if (it->element == ATTR_ELEMENT_VOXEL || it->std == ATTR_STD_GENERATED_TRANSFORM) {
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
attributes.erase(it++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
attributes.clear();
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 15:01:26 +01:00
|
|
|
void AttributeSet::update(AttributeSet &&new_attributes)
|
|
|
|
{
|
|
|
|
/* add or update old_attributes based on the new_attributes */
|
|
|
|
foreach (Attribute &attr, new_attributes.attributes) {
|
2021-01-26 15:14:29 +01:00
|
|
|
Attribute *nattr = add(attr.name, attr.type, attr.element);
|
|
|
|
nattr->std = attr.std;
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 15:01:26 +01:00
|
|
|
nattr->set_data_from(std::move(attr));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove any attributes not on new_attributes */
|
|
|
|
list<Attribute>::iterator it;
|
|
|
|
for (it = attributes.begin(); it != attributes.end();) {
|
|
|
|
if (it->std != ATTR_STD_NONE) {
|
|
|
|
if (new_attributes.find(it->std) == nullptr) {
|
2021-02-17 12:04:45 +01:00
|
|
|
modified = true;
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 15:01:26 +01:00
|
|
|
attributes.erase(it++);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (it->name != "") {
|
|
|
|
if (new_attributes.find(it->name) == nullptr) {
|
2021-02-17 12:04:45 +01:00
|
|
|
modified = true;
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 15:01:26 +01:00
|
|
|
attributes.erase(it++);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
it++;
|
|
|
|
}
|
2021-04-29 15:46:06 +02:00
|
|
|
|
|
|
|
/* If all attributes were replaced, transform is no longer applied. */
|
|
|
|
geometry->transform_applied = false;
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 15:01:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AttributeSet::clear_modified()
|
|
|
|
{
|
|
|
|
foreach (Attribute &attr, attributes) {
|
|
|
|
attr.modified = false;
|
|
|
|
}
|
2021-02-17 12:04:45 +01:00
|
|
|
modified = false;
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 15:01:26 +01:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* AttributeRequest */
|
|
|
|
|
|
|
|
AttributeRequest::AttributeRequest(ustring name_)
|
|
|
|
{
|
|
|
|
name = name_;
|
2012-04-30 12:49:26 +00:00
|
|
|
std = ATTR_STD_NONE;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2020-02-03 21:40:58 +01:00
|
|
|
type = TypeDesc::TypeFloat;
|
|
|
|
desc.element = ATTR_ELEMENT_NONE;
|
|
|
|
desc.offset = 0;
|
|
|
|
desc.type = NODE_ATTR_FLOAT;
|
2016-07-16 19:42:28 -04:00
|
|
|
|
|
|
|
subd_type = TypeDesc::TypeFloat;
|
2016-07-01 17:36:27 -04:00
|
|
|
subd_desc.element = ATTR_ELEMENT_NONE;
|
|
|
|
subd_desc.offset = 0;
|
|
|
|
subd_desc.type = NODE_ATTR_FLOAT;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
AttributeRequest::AttributeRequest(AttributeStandard std_)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
name = ustring();
|
|
|
|
std = std_;
|
|
|
|
|
2020-02-03 21:40:58 +01:00
|
|
|
type = TypeDesc::TypeFloat;
|
|
|
|
desc.element = ATTR_ELEMENT_NONE;
|
|
|
|
desc.offset = 0;
|
|
|
|
desc.type = NODE_ATTR_FLOAT;
|
2016-07-16 19:42:28 -04:00
|
|
|
|
|
|
|
subd_type = TypeDesc::TypeFloat;
|
2016-07-01 17:36:27 -04:00
|
|
|
subd_desc.element = ATTR_ELEMENT_NONE;
|
|
|
|
subd_desc.offset = 0;
|
|
|
|
subd_desc.type = NODE_ATTR_FLOAT;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* AttributeRequestSet */
|
|
|
|
|
|
|
|
AttributeRequestSet::AttributeRequestSet()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AttributeRequestSet::~AttributeRequestSet()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AttributeRequestSet::modified(const AttributeRequestSet &other)
|
|
|
|
{
|
|
|
|
if (requests.size() != other.requests.size())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < requests.size(); i++) {
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for (size_t j = 0; j < requests.size() && !found; j++)
|
|
|
|
if (requests[i].name == other.requests[j].name && requests[i].std == other.requests[j].std) {
|
|
|
|
found = true;
|
2012-06-09 18:56:12 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-06-09 18:56:12 +00:00
|
|
|
if (!found) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
2012-06-09 18:56:12 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AttributeRequestSet::add(ustring name)
|
|
|
|
{
|
2018-02-18 03:20:39 +01:00
|
|
|
foreach (AttributeRequest &req, requests) {
|
|
|
|
if (req.name == name) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return;
|
2018-02-18 03:20:39 +01:00
|
|
|
}
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
requests.push_back(AttributeRequest(name));
|
|
|
|
}
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
void AttributeRequestSet::add(AttributeStandard std)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
foreach (AttributeRequest &req, requests)
|
|
|
|
if (req.std == std)
|
|
|
|
return;
|
|
|
|
|
|
|
|
requests.push_back(AttributeRequest(std));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AttributeRequestSet::add(AttributeRequestSet &reqs)
|
|
|
|
{
|
|
|
|
foreach (AttributeRequest &req, reqs.requests) {
|
2012-04-30 12:49:26 +00:00
|
|
|
if (req.std == ATTR_STD_NONE)
|
2011-04-27 11:58:34 +00:00
|
|
|
add(req.name);
|
|
|
|
else
|
|
|
|
add(req.std);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-18 03:20:39 +01:00
|
|
|
void AttributeRequestSet::add_standard(ustring name)
|
|
|
|
{
|
2018-12-11 12:17:26 +01:00
|
|
|
if (name.empty()) {
|
2018-02-18 03:20:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AttributeStandard std = Attribute::name_standard(name.c_str());
|
|
|
|
|
|
|
|
if (std) {
|
|
|
|
add(std);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
add(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
bool AttributeRequestSet::find(ustring name)
|
|
|
|
{
|
|
|
|
foreach (AttributeRequest &req, requests)
|
|
|
|
if (req.name == name)
|
|
|
|
return true;
|
2018-07-06 10:17:58 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
bool AttributeRequestSet::find(AttributeStandard std)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
foreach (AttributeRequest &req, requests)
|
|
|
|
if (req.std == std)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t AttributeRequestSet::size()
|
|
|
|
{
|
|
|
|
return requests.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AttributeRequestSet::clear()
|
|
|
|
{
|
|
|
|
requests.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|