diff options
Diffstat (limited to 'intern/cycles/kernel/geom/geom_attribute.h')
-rw-r--r-- | intern/cycles/kernel/geom/geom_attribute.h | 110 |
1 files changed, 56 insertions, 54 deletions
diff --git a/intern/cycles/kernel/geom/geom_attribute.h b/intern/cycles/kernel/geom/geom_attribute.h index e991f3d685a..456608bfa22 100644 --- a/intern/cycles/kernel/geom/geom_attribute.h +++ b/intern/cycles/kernel/geom/geom_attribute.h @@ -30,81 +30,83 @@ ccl_device_inline uint subd_triangle_patch(KernelGlobals *kg, const ShaderData * ccl_device_inline uint attribute_primitive_type(KernelGlobals *kg, const ShaderData *sd) { #ifdef __HAIR__ - if(sd->type & PRIMITIVE_ALL_CURVE) { - return ATTR_PRIM_CURVE; - } - else + if (sd->type & PRIMITIVE_ALL_CURVE) { + return ATTR_PRIM_CURVE; + } + else #endif - if(subd_triangle_patch(kg, sd) != ~0) { - return ATTR_PRIM_SUBD; - } - else { - return ATTR_PRIM_TRIANGLE; - } + if (subd_triangle_patch(kg, sd) != ~0) { + return ATTR_PRIM_SUBD; + } + else { + return ATTR_PRIM_TRIANGLE; + } } ccl_device_inline AttributeDescriptor attribute_not_found() { - const AttributeDescriptor desc = {ATTR_ELEMENT_NONE, (NodeAttributeType)0, 0, ATTR_STD_NOT_FOUND}; - return desc; + const AttributeDescriptor desc = { + ATTR_ELEMENT_NONE, (NodeAttributeType)0, 0, ATTR_STD_NOT_FOUND}; + return desc; } /* Find attribute based on ID */ ccl_device_inline uint object_attribute_map_offset(KernelGlobals *kg, int object) { - return kernel_tex_fetch(__objects, object).attribute_map_offset; + return kernel_tex_fetch(__objects, object).attribute_map_offset; } -ccl_device_inline AttributeDescriptor find_attribute(KernelGlobals *kg, const ShaderData *sd, uint id) +ccl_device_inline AttributeDescriptor find_attribute(KernelGlobals *kg, + const ShaderData *sd, + uint id) { - if(sd->object == OBJECT_NONE) { - return attribute_not_found(); - } - - /* for SVM, find attribute by unique id */ - uint attr_offset = object_attribute_map_offset(kg, sd->object); - attr_offset += attribute_primitive_type(kg, sd); - uint4 attr_map = kernel_tex_fetch(__attributes_map, attr_offset); - - while(attr_map.x != id) { - if(UNLIKELY(attr_map.x == ATTR_STD_NONE)) { - return attribute_not_found(); - } - attr_offset += ATTR_PRIM_TYPES; - attr_map = kernel_tex_fetch(__attributes_map, attr_offset); - } - - AttributeDescriptor desc; - desc.element = (AttributeElement)attr_map.y; - - if(sd->prim == PRIM_NONE && - desc.element != ATTR_ELEMENT_MESH && - desc.element != ATTR_ELEMENT_VOXEL && - desc.element != ATTR_ELEMENT_OBJECT) - { - return attribute_not_found(); - } - - /* return result */ - desc.offset = (attr_map.y == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : (int)attr_map.z; - desc.type = (NodeAttributeType)(attr_map.w & 0xff); - desc.flags = (AttributeFlag)(attr_map.w >> 8); - - return desc; + if (sd->object == OBJECT_NONE) { + return attribute_not_found(); + } + + /* for SVM, find attribute by unique id */ + uint attr_offset = object_attribute_map_offset(kg, sd->object); + attr_offset += attribute_primitive_type(kg, sd); + uint4 attr_map = kernel_tex_fetch(__attributes_map, attr_offset); + + while (attr_map.x != id) { + if (UNLIKELY(attr_map.x == ATTR_STD_NONE)) { + return attribute_not_found(); + } + attr_offset += ATTR_PRIM_TYPES; + attr_map = kernel_tex_fetch(__attributes_map, attr_offset); + } + + AttributeDescriptor desc; + desc.element = (AttributeElement)attr_map.y; + + if (sd->prim == PRIM_NONE && desc.element != ATTR_ELEMENT_MESH && + desc.element != ATTR_ELEMENT_VOXEL && desc.element != ATTR_ELEMENT_OBJECT) { + return attribute_not_found(); + } + + /* return result */ + desc.offset = (attr_map.y == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : (int)attr_map.z; + desc.type = (NodeAttributeType)(attr_map.w & 0xff); + desc.flags = (AttributeFlag)(attr_map.w >> 8); + + return desc; } /* Transform matrix attribute on meshes */ -ccl_device Transform primitive_attribute_matrix(KernelGlobals *kg, const ShaderData *sd, const AttributeDescriptor desc) +ccl_device Transform primitive_attribute_matrix(KernelGlobals *kg, + const ShaderData *sd, + const AttributeDescriptor desc) { - Transform tfm; + Transform tfm; - tfm.x = kernel_tex_fetch(__attributes_float3, desc.offset + 0); - tfm.y = kernel_tex_fetch(__attributes_float3, desc.offset + 1); - tfm.z = kernel_tex_fetch(__attributes_float3, desc.offset + 2); + tfm.x = kernel_tex_fetch(__attributes_float3, desc.offset + 0); + tfm.y = kernel_tex_fetch(__attributes_float3, desc.offset + 1); + tfm.z = kernel_tex_fetch(__attributes_float3, desc.offset + 2); - return tfm; + return tfm; } CCL_NAMESPACE_END |