Cycles: Add support for uchar4 attributes.

* Added support for uchar4 attributes to Cycles' attribute system.
* This is used for Vertex Colors now, which saves some memory (4 unsigned characters, instead of 4 floats).
* GPU Texture Limit on sm_20 and sm_21 decreased from 95 to 94, because we need a new texture for the uchar4 attributes. This is no problem for sm_30 or newer.

Part of my GSoC 2014.
This commit is contained in:
Thomas Dinges
2014-06-13 23:40:39 +02:00
parent 7e20583688
commit 0ce3a755f8
12 changed files with 91 additions and 33 deletions

View File

@@ -745,7 +745,7 @@ void MeshManager::update_svm_attributes(Device *device, DeviceScene *dscene, Sce
device->tex_alloc("__attributes_map", dscene->attributes_map);
}
static void update_attribute_element_offset(Mesh *mesh, vector<float>& attr_float, vector<float4>& attr_float3,
static void update_attribute_element_offset(Mesh *mesh, vector<float>& attr_float, vector<float4>& attr_float3, vector<uchar4>& attr_uchar4,
Attribute *mattr, TypeDesc& type, int& offset, AttributeElement& element)
{
if(mattr) {
@@ -766,6 +766,15 @@ static void update_attribute_element_offset(Mesh *mesh, vector<float>& attr_floa
VoxelAttribute *voxel_data = mattr->data_voxel();
offset = voxel_data->slot;
}
if(mattr->element == ATTR_ELEMENT_CORNER_BYTE) {
uchar4 *data = mattr->data_uchar4();
offset = attr_uchar4.size();
attr_uchar4.resize(attr_uchar4.size() + size);
for(size_t k = 0; k < size; k++)
attr_uchar4[offset+k] = data[k];
}
else if(mattr->type == TypeDesc::TypeFloat) {
float *data = mattr->data_float();
offset = attr_float.size();
@@ -802,7 +811,7 @@ static void update_attribute_element_offset(Mesh *mesh, vector<float>& attr_floa
offset -= mesh->vert_offset;
else if(element == ATTR_ELEMENT_FACE)
offset -= mesh->tri_offset;
else if(element == ATTR_ELEMENT_CORNER)
else if(element == ATTR_ELEMENT_CORNER || element == ATTR_ELEMENT_CORNER_BYTE)
offset -= 3*mesh->tri_offset;
else if(element == ATTR_ELEMENT_CURVE)
offset -= mesh->curve_offset;
@@ -843,6 +852,7 @@ void MeshManager::device_update_attributes(Device *device, DeviceScene *dscene,
* maps next */
vector<float> attr_float;
vector<float4> attr_float3;
vector<uchar4> attr_uchar4;
for(size_t i = 0; i < scene->meshes.size(); i++) {
Mesh *mesh = scene->meshes[i];
@@ -863,10 +873,10 @@ void MeshManager::device_update_attributes(Device *device, DeviceScene *dscene,
memcpy(triangle_mattr->data_float3(), &mesh->verts[0], sizeof(float3)*mesh->verts.size());
}
update_attribute_element_offset(mesh, attr_float, attr_float3, triangle_mattr,
update_attribute_element_offset(mesh, attr_float, attr_float3, attr_uchar4, triangle_mattr,
req.triangle_type, req.triangle_offset, req.triangle_element);
update_attribute_element_offset(mesh, attr_float, attr_float3, curve_mattr,
update_attribute_element_offset(mesh, attr_float, attr_float3, attr_uchar4, curve_mattr,
req.curve_type, req.curve_offset, req.curve_element);
if(progress.get_cancel()) return;
@@ -892,6 +902,10 @@ void MeshManager::device_update_attributes(Device *device, DeviceScene *dscene,
dscene->attributes_float3.copy(&attr_float3[0], attr_float3.size());
device->tex_alloc("__attributes_float3", dscene->attributes_float3);
}
if(attr_uchar4.size()) {
dscene->attributes_uchar4.copy(&attr_uchar4[0], attr_uchar4.size());
device->tex_alloc("__attributes_uchar4", dscene->attributes_uchar4);
}
}
void MeshManager::device_update_mesh(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)