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
|
|
|
|
* limitations under the License
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* Attribute Node */
|
|
|
|
|
2013-11-15 23:17:10 +00:00
|
|
|
ccl_device void svm_node_attr_init(KernelGlobals *kg, ShaderData *sd,
|
2011-04-27 11:58:34 +00:00
|
|
|
uint4 node, NodeAttributeType *type,
|
2012-05-13 12:32:44 +00:00
|
|
|
NodeAttributeType *mesh_type, AttributeElement *elem, int *offset, uint *out_offset)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2014-03-29 12:03:48 +00:00
|
|
|
if(sd->object != OBJECT_NONE) {
|
2011-04-27 11:58:34 +00:00
|
|
|
/* find attribute by unique id */
|
|
|
|
uint id = node.y;
|
|
|
|
uint attr_offset = sd->object*kernel_data.bvh.attributes_map_stride;
|
2013-01-03 13:18:35 +00:00
|
|
|
#ifdef __HAIR__
|
2014-03-29 12:03:48 +00:00
|
|
|
attr_offset = (sd->type & PRIMITIVE_ALL_CURVE)? attr_offset + ATTR_PRIM_CURVE: attr_offset;
|
2013-01-03 13:18:35 +00:00
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
uint4 attr_map = kernel_tex_fetch(__attributes_map, attr_offset);
|
2013-01-03 12:08:54 +00:00
|
|
|
|
|
|
|
while(attr_map.x != id) {
|
|
|
|
attr_offset += ATTR_PRIM_TYPES;
|
|
|
|
attr_map = kernel_tex_fetch(__attributes_map, attr_offset);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* return result */
|
|
|
|
*elem = (AttributeElement)attr_map.y;
|
2012-05-13 12:32:44 +00:00
|
|
|
*offset = as_int(attr_map.z);
|
2011-04-27 11:58:34 +00:00
|
|
|
*mesh_type = (NodeAttributeType)attr_map.w;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* background */
|
|
|
|
*elem = ATTR_ELEMENT_NONE;
|
|
|
|
*offset = 0;
|
|
|
|
*mesh_type = (NodeAttributeType)node.w;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out_offset = node.z;
|
|
|
|
*type = (NodeAttributeType)node.w;
|
|
|
|
}
|
|
|
|
|
2013-11-15 23:17:10 +00:00
|
|
|
ccl_device void svm_node_attr(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
NodeAttributeType type, mesh_type;
|
|
|
|
AttributeElement elem;
|
2012-05-13 12:32:44 +00:00
|
|
|
uint out_offset;
|
|
|
|
int offset;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
svm_node_attr_init(kg, sd, node, &type, &mesh_type, &elem, &offset, &out_offset);
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
/* fetch and store attribute */
|
|
|
|
if(type == NODE_ATTR_FLOAT) {
|
|
|
|
if(mesh_type == NODE_ATTR_FLOAT) {
|
|
|
|
float f = primitive_attribute_float(kg, sd, elem, offset, NULL, NULL);
|
|
|
|
stack_store_float(stack, out_offset, f);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
else {
|
2013-01-03 12:08:54 +00:00
|
|
|
float3 f = primitive_attribute_float3(kg, sd, elem, offset, NULL, NULL);
|
|
|
|
stack_store_float(stack, out_offset, average(f));
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-03 12:08:54 +00:00
|
|
|
else {
|
|
|
|
if(mesh_type == NODE_ATTR_FLOAT3) {
|
|
|
|
float3 f = primitive_attribute_float3(kg, sd, elem, offset, NULL, NULL);
|
|
|
|
stack_store_float3(stack, out_offset, f);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-01-03 12:08:54 +00:00
|
|
|
float f = primitive_attribute_float(kg, sd, elem, offset, NULL, NULL);
|
|
|
|
stack_store_float3(stack, out_offset, make_float3(f, f, f));
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-15 23:17:10 +00:00
|
|
|
ccl_device void svm_node_attr_bump_dx(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
NodeAttributeType type, mesh_type;
|
|
|
|
AttributeElement elem;
|
2012-05-13 12:32:44 +00:00
|
|
|
uint out_offset;
|
|
|
|
int offset;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
svm_node_attr_init(kg, sd, node, &type, &mesh_type, &elem, &offset, &out_offset);
|
|
|
|
|
|
|
|
/* fetch and store attribute */
|
2013-01-03 12:08:54 +00:00
|
|
|
if(type == NODE_ATTR_FLOAT) {
|
|
|
|
if(mesh_type == NODE_ATTR_FLOAT) {
|
|
|
|
float dx;
|
|
|
|
float f = primitive_attribute_float(kg, sd, elem, offset, &dx, NULL);
|
|
|
|
stack_store_float(stack, out_offset, f+dx);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
float3 dx;
|
|
|
|
float3 f = primitive_attribute_float3(kg, sd, elem, offset, &dx, NULL);
|
|
|
|
stack_store_float(stack, out_offset, average(f+dx));
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-01-03 12:08:54 +00:00
|
|
|
if(mesh_type == NODE_ATTR_FLOAT3) {
|
|
|
|
float3 dx;
|
|
|
|
float3 f = primitive_attribute_float3(kg, sd, elem, offset, &dx, NULL);
|
|
|
|
stack_store_float3(stack, out_offset, f+dx);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-01-03 12:08:54 +00:00
|
|
|
float dx;
|
|
|
|
float f = primitive_attribute_float(kg, sd, elem, offset, &dx, NULL);
|
|
|
|
stack_store_float3(stack, out_offset, make_float3(f+dx, f+dx, f+dx));
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-15 23:17:10 +00:00
|
|
|
ccl_device void svm_node_attr_bump_dy(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
NodeAttributeType type, mesh_type;
|
|
|
|
AttributeElement elem;
|
2012-05-13 12:32:44 +00:00
|
|
|
uint out_offset;
|
|
|
|
int offset;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
svm_node_attr_init(kg, sd, node, &type, &mesh_type, &elem, &offset, &out_offset);
|
|
|
|
|
|
|
|
/* fetch and store attribute */
|
2013-01-03 12:08:54 +00:00
|
|
|
if(type == NODE_ATTR_FLOAT) {
|
|
|
|
if(mesh_type == NODE_ATTR_FLOAT) {
|
|
|
|
float dy;
|
|
|
|
float f = primitive_attribute_float(kg, sd, elem, offset, NULL, &dy);
|
|
|
|
stack_store_float(stack, out_offset, f+dy);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
float3 dy;
|
|
|
|
float3 f = primitive_attribute_float3(kg, sd, elem, offset, NULL, &dy);
|
|
|
|
stack_store_float(stack, out_offset, average(f+dy));
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-01-03 12:08:54 +00:00
|
|
|
if(mesh_type == NODE_ATTR_FLOAT3) {
|
|
|
|
float3 dy;
|
|
|
|
float3 f = primitive_attribute_float3(kg, sd, elem, offset, NULL, &dy);
|
|
|
|
stack_store_float3(stack, out_offset, f+dy);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-01-03 12:08:54 +00:00
|
|
|
float dy;
|
|
|
|
float f = primitive_attribute_float(kg, sd, elem, offset, NULL, &dy);
|
|
|
|
stack_store_float3(stack, out_offset, make_float3(f+dy, f+dy, f+dy));
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|