Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/svm/svm_tex_coord.h
| Show First 20 Lines • Show All 286 Lines • ▼ Show 20 Lines | if(space == NODE_NORMAL_MAP_TANGENT) { | ||||
| const AttributeDescriptor attr_normal = find_attribute(kg, sd, ATTR_STD_VERTEX_NORMAL); | const AttributeDescriptor attr_normal = find_attribute(kg, sd, ATTR_STD_VERTEX_NORMAL); | ||||
| if(attr.offset == ATTR_STD_NOT_FOUND || attr_sign.offset == ATTR_STD_NOT_FOUND || attr_normal.offset == ATTR_STD_NOT_FOUND) { | if(attr.offset == ATTR_STD_NOT_FOUND || attr_sign.offset == ATTR_STD_NOT_FOUND || attr_normal.offset == ATTR_STD_NOT_FOUND) { | ||||
| stack_store_float3(stack, normal_offset, make_float3(0.0f, 0.0f, 0.0f)); | stack_store_float3(stack, normal_offset, make_float3(0.0f, 0.0f, 0.0f)); | ||||
| return; | return; | ||||
| } | } | ||||
| /* get _unnormalized_ interpolated normal and tangent */ | /* get _unnormalized_ interpolated normal and tangent */ | ||||
| float3 tangent = primitive_attribute_float3(kg, sd, attr, NULL, NULL); | float3 tangent = primitive_surface_attribute_float3(kg, sd, attr, NULL, NULL); | ||||
| float sign = primitive_attribute_float(kg, sd, attr_sign, NULL, NULL); | float sign = primitive_surface_attribute_float(kg, sd, attr_sign, NULL, NULL); | ||||
| float3 normal; | float3 normal; | ||||
| if(sd->shader & SHADER_SMOOTH_NORMAL) { | if(sd->shader & SHADER_SMOOTH_NORMAL) { | ||||
| normal = primitive_attribute_float3(kg, sd, attr_normal, NULL, NULL); | normal = primitive_surface_attribute_float3(kg, sd, attr_normal, NULL, NULL); | ||||
| } | } | ||||
| else { | else { | ||||
| normal = sd->Ng; | normal = sd->Ng; | ||||
| /* the normal is already inverted, which is too soon for the math here */ | /* the normal is already inverted, which is too soon for the math here */ | ||||
| if(is_backfacing) { | if(is_backfacing) { | ||||
| normal = -normal; | normal = -normal; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| ccl_device void svm_node_tangent(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node) | ccl_device void svm_node_tangent(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node) | ||||
| { | { | ||||
| uint tangent_offset, direction_type, axis; | uint tangent_offset, direction_type, axis; | ||||
| decode_node_uchar4(node.y, &tangent_offset, &direction_type, &axis, NULL); | decode_node_uchar4(node.y, &tangent_offset, &direction_type, &axis, NULL); | ||||
| float3 tangent; | float3 tangent; | ||||
| 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(direction_type == NODE_TANGENT_UVMAP) { | if(direction_type == NODE_TANGENT_UVMAP) { | ||||
| /* UV map */ | /* UV map */ | ||||
| const AttributeDescriptor desc = find_attribute(kg, sd, node.z); | |||||
| if(desc.offset == ATTR_STD_NOT_FOUND) | if(desc.offset == ATTR_STD_NOT_FOUND) | ||||
| tangent = make_float3(0.0f, 0.0f, 0.0f); | tangent = make_float3(0.0f, 0.0f, 0.0f); | ||||
| else | else | ||||
| tangent = primitive_attribute_float3(kg, sd, desc, NULL, NULL); | tangent = attribute_value; | ||||
| } | } | ||||
| else { | else { | ||||
| /* radial */ | /* radial */ | ||||
| const AttributeDescriptor desc = find_attribute(kg, sd, node.z); | |||||
| float3 generated; | float3 generated; | ||||
| if(desc.offset == ATTR_STD_NOT_FOUND) | if(desc.offset == ATTR_STD_NOT_FOUND) | ||||
| generated = sd->P; | generated = sd->P; | ||||
| else | else | ||||
| generated = primitive_attribute_float3(kg, sd, desc, NULL, NULL); | generated = attribute_value; | ||||
| if(axis == NODE_TANGENT_AXIS_X) | if(axis == NODE_TANGENT_AXIS_X) | ||||
| tangent = make_float3(0.0f, -(generated.z - 0.5f), (generated.y - 0.5f)); | tangent = make_float3(0.0f, -(generated.z - 0.5f), (generated.y - 0.5f)); | ||||
| else if(axis == NODE_TANGENT_AXIS_Y) | else if(axis == NODE_TANGENT_AXIS_Y) | ||||
| tangent = make_float3(-(generated.z - 0.5f), 0.0f, (generated.x - 0.5f)); | tangent = make_float3(-(generated.z - 0.5f), 0.0f, (generated.x - 0.5f)); | ||||
| else | else | ||||
| tangent = make_float3(-(generated.y - 0.5f), (generated.x - 0.5f), 0.0f); | tangent = make_float3(-(generated.y - 0.5f), (generated.x - 0.5f), 0.0f); | ||||
| } | } | ||||
| object_normal_transform(kg, sd, &tangent); | object_normal_transform(kg, sd, &tangent); | ||||
| tangent = cross(sd->N, normalize(cross(tangent, sd->N))); | tangent = cross(sd->N, normalize(cross(tangent, sd->N))); | ||||
| stack_store_float3(stack, tangent_offset, tangent); | stack_store_float3(stack, tangent_offset, tangent); | ||||
| } | } | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||