Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2019-03-05 16:54:54 +0300
committerStefan Werner <stefan.werner@tangent-animation.com>2019-03-05 16:55:21 +0300
commitdb7f9a70b0addd17a2f8a8d87c0b4d77d78b536e (patch)
tree46a8b0a62f146a17a2e764159b58a6f0c66e01f6 /intern/cycles/render/mesh.cpp
parenta325bc6bf3e6dace5d1e15330650ea532052c9fc (diff)
Cycles: Added Float2 attribute type.
Float2 are now a new type for attributes in Cycles. Before, the choices for attribute storage were float and float3, the latter padded to float4. This meant that UV maps were inflated to twice the size necessary. Reviewers: brecht, sergey Reviewed By: brecht Subscribers: #cycles Tags: #cycles Differential Revision: https://developer.blender.org/D4409
Diffstat (limited to 'intern/cycles/render/mesh.cpp')
-rw-r--r--intern/cycles/render/mesh.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp
index 5f884a3f871..753224de1aa 100644
--- a/intern/cycles/render/mesh.cpp
+++ b/intern/cycles/render/mesh.cpp
@@ -1233,6 +1233,8 @@ void MeshManager::update_osl_attributes(Device *device, Scene *scene, vector<Att
osl_attr.type = TypeDesc::TypeFloat;
else if(req.triangle_type == TypeDesc::TypeMatrix)
osl_attr.type = TypeDesc::TypeMatrix;
+ else if(req.triangle_type == TypeFloat2)
+ osl_attr.type = TypeFloat2;
else
osl_attr.type = TypeDesc::TypeColor;
@@ -1342,6 +1344,8 @@ void MeshManager::update_svm_attributes(Device *, DeviceScene *dscene, Scene *sc
attr_map[index].w = NODE_ATTR_FLOAT;
else if(req.triangle_type == TypeDesc::TypeMatrix)
attr_map[index].w = NODE_ATTR_MATRIX;
+ else if(req.triangle_type == TypeFloat2)
+ attr_map[index].w = NODE_ATTR_FLOAT2;
else
attr_map[index].w = NODE_ATTR_FLOAT3;
@@ -1359,6 +1363,8 @@ void MeshManager::update_svm_attributes(Device *, DeviceScene *dscene, Scene *sc
attr_map[index].w = NODE_ATTR_FLOAT;
else if(req.curve_type == TypeDesc::TypeMatrix)
attr_map[index].w = NODE_ATTR_MATRIX;
+ else if(req.curve_type == TypeFloat2)
+ attr_map[index].w = NODE_ATTR_FLOAT2;
else
attr_map[index].w = NODE_ATTR_FLOAT3;
@@ -1376,6 +1382,8 @@ void MeshManager::update_svm_attributes(Device *, DeviceScene *dscene, Scene *sc
attr_map[index].w = NODE_ATTR_FLOAT;
else if(req.subd_type == TypeDesc::TypeMatrix)
attr_map[index].w = NODE_ATTR_MATRIX;
+ else if(req.subd_type == TypeFloat2)
+ attr_map[index].w = NODE_ATTR_FLOAT2;
else
attr_map[index].w = NODE_ATTR_FLOAT3;
@@ -1404,6 +1412,7 @@ static void update_attribute_element_size(Mesh *mesh,
Attribute *mattr,
AttributePrimitive prim,
size_t *attr_float_size,
+ size_t *attr_float2_size,
size_t *attr_float3_size,
size_t *attr_uchar4_size)
{
@@ -1419,6 +1428,9 @@ static void update_attribute_element_size(Mesh *mesh,
else if(mattr->type == TypeDesc::TypeFloat) {
*attr_float_size += size;
}
+ else if(mattr->type == TypeFloat2) {
+ *attr_float2_size += size;
+ }
else if(mattr->type == TypeDesc::TypeMatrix) {
*attr_float3_size += size * 4;
}
@@ -1431,6 +1443,8 @@ static void update_attribute_element_size(Mesh *mesh,
static void update_attribute_element_offset(Mesh *mesh,
device_vector<float>& attr_float,
size_t& attr_float_offset,
+ device_vector<float2>& attr_float2,
+ size_t& attr_float2_offset,
device_vector<float4>& attr_float3,
size_t& attr_float3_offset,
device_vector<uchar4>& attr_uchar4,
@@ -1477,6 +1491,16 @@ static void update_attribute_element_offset(Mesh *mesh,
}
attr_float_offset += size;
}
+ else if(mattr->type == TypeFloat2) {
+ float2 *data = mattr->data_float2();
+ offset = attr_float2_offset;
+
+ assert(attr_float2.size() >= offset + size);
+ for(size_t k = 0; k < size; k++) {
+ attr_float2[offset+k] = data[k];
+ }
+ attr_float2_offset += size;
+ }
else if(mattr->type == TypeDesc::TypeMatrix) {
Transform *tfm = mattr->data_transform();
offset = attr_float3_offset;
@@ -1561,6 +1585,7 @@ void MeshManager::device_update_attributes(Device *device, DeviceScene *dscene,
* take 2x of overall attribute memory usage.
*/
size_t attr_float_size = 0;
+ size_t attr_float2_size = 0;
size_t attr_float3_size = 0;
size_t attr_uchar4_size = 0;
for(size_t i = 0; i < scene->meshes.size(); i++) {
@@ -1575,28 +1600,33 @@ void MeshManager::device_update_attributes(Device *device, DeviceScene *dscene,
triangle_mattr,
ATTR_PRIM_TRIANGLE,
&attr_float_size,
+ &attr_float2_size,
&attr_float3_size,
&attr_uchar4_size);
update_attribute_element_size(mesh,
curve_mattr,
ATTR_PRIM_CURVE,
&attr_float_size,
+ &attr_float2_size,
&attr_float3_size,
&attr_uchar4_size);
update_attribute_element_size(mesh,
subd_mattr,
ATTR_PRIM_SUBD,
&attr_float_size,
+ &attr_float2_size,
&attr_float3_size,
&attr_uchar4_size);
}
}
dscene->attributes_float.alloc(attr_float_size);
+ dscene->attributes_float2.alloc(attr_float2_size);
dscene->attributes_float3.alloc(attr_float3_size);
dscene->attributes_uchar4.alloc(attr_uchar4_size);
size_t attr_float_offset = 0;
+ size_t attr_float2_offset = 0;
size_t attr_float3_offset = 0;
size_t attr_uchar4_offset = 0;
@@ -1614,6 +1644,7 @@ void MeshManager::device_update_attributes(Device *device, DeviceScene *dscene,
update_attribute_element_offset(mesh,
dscene->attributes_float, attr_float_offset,
+ dscene->attributes_float2, attr_float2_offset,
dscene->attributes_float3, attr_float3_offset,
dscene->attributes_uchar4, attr_uchar4_offset,
triangle_mattr,
@@ -1623,6 +1654,7 @@ void MeshManager::device_update_attributes(Device *device, DeviceScene *dscene,
update_attribute_element_offset(mesh,
dscene->attributes_float, attr_float_offset,
+ dscene->attributes_float2, attr_float2_offset,
dscene->attributes_float3, attr_float3_offset,
dscene->attributes_uchar4, attr_uchar4_offset,
curve_mattr,
@@ -1632,6 +1664,7 @@ void MeshManager::device_update_attributes(Device *device, DeviceScene *dscene,
update_attribute_element_offset(mesh,
dscene->attributes_float, attr_float_offset,
+ dscene->attributes_float2, attr_float2_offset,
dscene->attributes_float3, attr_float3_offset,
dscene->attributes_uchar4, attr_uchar4_offset,
subd_mattr,
@@ -1657,6 +1690,9 @@ void MeshManager::device_update_attributes(Device *device, DeviceScene *dscene,
if(dscene->attributes_float.size()) {
dscene->attributes_float.copy_to_device();
}
+ if(dscene->attributes_float2.size()) {
+ dscene->attributes_float2.copy_to_device();
+ }
if(dscene->attributes_float3.size()) {
dscene->attributes_float3.copy_to_device();
}
@@ -2289,6 +2325,7 @@ void MeshManager::device_free(Device *device, DeviceScene *dscene)
dscene->patches.free();
dscene->attributes_map.free();
dscene->attributes_float.free();
+ dscene->attributes_float2.free();
dscene->attributes_float3.free();
dscene->attributes_uchar4.free();