diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-03-05 16:54:54 +0300 |
---|---|---|
committer | Stefan Werner <stefan.werner@tangent-animation.com> | 2019-03-05 16:55:21 +0300 |
commit | db7f9a70b0addd17a2f8a8d87c0b4d77d78b536e (patch) | |
tree | 46a8b0a62f146a17a2e764159b58a6f0c66e01f6 /intern/cycles/kernel/svm | |
parent | a325bc6bf3e6dace5d1e15330650ea532052c9fc (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/kernel/svm')
-rw-r--r-- | intern/cycles/kernel/svm/svm_attribute.h | 47 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_tex_coord.h | 10 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_types.h | 1 |
3 files changed, 48 insertions, 10 deletions
diff --git a/intern/cycles/kernel/svm/svm_attribute.h b/intern/cycles/kernel/svm/svm_attribute.h index ef6f7d7cbb5..c2366df71d0 100644 --- a/intern/cycles/kernel/svm/svm_attribute.h +++ b/intern/cycles/kernel/svm/svm_attribute.h @@ -52,18 +52,27 @@ ccl_device void svm_node_attr(KernelGlobals *kg, ShaderData *sd, float *stack, u AttributeDescriptor desc = svm_node_attr_init(kg, sd, node, &type, &out_offset); /* fetch and store attribute */ - if (desc.type == NODE_ATTR_FLOAT) { + if(desc.type == NODE_ATTR_FLOAT) { float f = primitive_attribute_float(kg, sd, desc, NULL, NULL); - if (type == NODE_ATTR_FLOAT) { + if(type == NODE_ATTR_FLOAT) { stack_store_float(stack, out_offset, f); } else { stack_store_float3(stack, out_offset, make_float3(f, f, f)); } } + else if(desc.type == NODE_ATTR_FLOAT2) { + float2 f = primitive_attribute_float2(kg, sd, desc, NULL, NULL); + if(type == NODE_ATTR_FLOAT) { + stack_store_float(stack, out_offset, f.x); + } + else { + stack_store_float3(stack, out_offset, make_float3(f.x, f.y, 0.0f)); + } + } else { float3 f = primitive_attribute_float3(kg, sd, desc, NULL, NULL); - if (type == NODE_ATTR_FLOAT) { + if(type == NODE_ATTR_FLOAT) { stack_store_float(stack, out_offset, average(f)); } else { @@ -84,20 +93,30 @@ void svm_node_attr_bump_dx(KernelGlobals *kg, ShaderData *sd, float *stack, uint AttributeDescriptor desc = svm_node_attr_init(kg, sd, node, &type, &out_offset); /* fetch and store attribute */ - if (desc.type == NODE_ATTR_FLOAT) { + if(desc.type == NODE_ATTR_FLOAT) { float dx; float f = primitive_surface_attribute_float(kg, sd, desc, &dx, NULL); - if (type == NODE_ATTR_FLOAT) { + if(type == NODE_ATTR_FLOAT) { stack_store_float(stack, out_offset, f+dx); } else { stack_store_float3(stack, out_offset, make_float3(f+dx, f+dx, f+dx)); } } + else if(desc.type == NODE_ATTR_FLOAT2) { + float2 dx; + float2 f = primitive_attribute_float2(kg, sd, desc, &dx, NULL); + if (type == NODE_ATTR_FLOAT) { + stack_store_float(stack, out_offset, f.x + dx.x); + } + else { + stack_store_float3(stack, out_offset, make_float3(f.x+dx.x, f.y+dx.y, 0.0f)); + } + } else { float3 dx; float3 f = primitive_surface_attribute_float3(kg, sd, desc, &dx, NULL); - if (type == NODE_ATTR_FLOAT) { + if(type == NODE_ATTR_FLOAT) { stack_store_float(stack, out_offset, average(f+dx)); } else { @@ -121,20 +140,30 @@ void svm_node_attr_bump_dy(KernelGlobals *kg, AttributeDescriptor desc = svm_node_attr_init(kg, sd, node, &type, &out_offset); /* fetch and store attribute */ - if (desc.type == NODE_ATTR_FLOAT) { + if(desc.type == NODE_ATTR_FLOAT) { float dy; float f = primitive_surface_attribute_float(kg, sd, desc, NULL, &dy); - if (type == NODE_ATTR_FLOAT) { + if(type == NODE_ATTR_FLOAT) { stack_store_float(stack, out_offset, f+dy); } else { stack_store_float3(stack, out_offset, make_float3(f+dy, f+dy, f+dy)); } } + else if(desc.type == NODE_ATTR_FLOAT2) { + float2 dy; + float2 f = primitive_attribute_float2(kg, sd, desc, NULL, &dy); + if(type == NODE_ATTR_FLOAT) { + stack_store_float(stack, out_offset, f.x + dy.x); + } + else { + stack_store_float3(stack, out_offset, make_float3(f.x+dy.x, f.y+dy.y, 0.0f)); + } + } else { float3 dy; float3 f = primitive_surface_attribute_float3(kg, sd, desc, NULL, &dy); - if (type == NODE_ATTR_FLOAT) { + if(type == NODE_ATTR_FLOAT) { stack_store_float(stack, out_offset, average(f+dy)); } else { diff --git a/intern/cycles/kernel/svm/svm_tex_coord.h b/intern/cycles/kernel/svm/svm_tex_coord.h index 72871254f0d..fe61292d0b0 100644 --- a/intern/cycles/kernel/svm/svm_tex_coord.h +++ b/intern/cycles/kernel/svm/svm_tex_coord.h @@ -363,7 +363,15 @@ ccl_device void svm_node_tangent(KernelGlobals *kg, ShaderData *sd, float *stack float3 attribute_value; const AttributeDescriptor desc = find_attribute(kg, sd, node.z); if (desc.offset != ATTR_STD_NOT_FOUND) { - attribute_value = primitive_surface_attribute_float3(kg, sd, desc, NULL, NULL); + if(desc.type == NODE_ATTR_FLOAT2) { + float2 value = primitive_surface_attribute_float2(kg, sd, desc, NULL, NULL); + attribute_value.x = value.x; + attribute_value.y = value.y; + attribute_value.z = 0.0f; + } + else { + attribute_value = primitive_surface_attribute_float3(kg, sd, desc, NULL, NULL); + } } diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h index 0f1dfa4936b..8b15d7bf9f4 100644 --- a/intern/cycles/kernel/svm/svm_types.h +++ b/intern/cycles/kernel/svm/svm_types.h @@ -141,6 +141,7 @@ typedef enum ShaderNodeType { typedef enum NodeAttributeType { NODE_ATTR_FLOAT = 0, + NODE_ATTR_FLOAT2, NODE_ATTR_FLOAT3, NODE_ATTR_MATRIX } NodeAttributeType; |