Cycles: use object coordinates when generated coordinates are missing
This modifies the attribute lookup to use object coordinates if no generated coordinates are found on the geometry. This is useful to avoid creating and copying this attribute, thus saving a bit of time and memory. Reviewed By: brecht Differential Revision: https://developer.blender.org/D12238
This commit is contained in:
parent
b8ecdbcd96
commit
6b041ad3d0
@ -58,7 +58,9 @@ shader node_texture_coordinate(
|
||||
getattribute("geom:uv", UV);
|
||||
}
|
||||
else {
|
||||
getattribute("geom:generated", Generated);
|
||||
if (!getattribute("geom:generated", Generated)) {
|
||||
Generated = transform("object", P);
|
||||
}
|
||||
getattribute("geom:uv", UV);
|
||||
}
|
||||
|
||||
|
@ -72,6 +72,22 @@ ccl_device void svm_node_attr(KernelGlobals *kg, ShaderData *sd, float *stack, u
|
||||
}
|
||||
#endif
|
||||
|
||||
if (node.y == ATTR_STD_GENERATED && desc.element == ATTR_ELEMENT_NONE) {
|
||||
/* No generated attribute, fall back to object coordinates. */
|
||||
float3 f = sd->P;
|
||||
object_inverse_position_transform(kg, sd, &f);
|
||||
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
||||
stack_store_float(stack, out_offset, average(f));
|
||||
}
|
||||
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
||||
stack_store_float3(stack, out_offset, f);
|
||||
}
|
||||
else {
|
||||
stack_store_float(stack, out_offset, 1.0f);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* Surface. */
|
||||
if (desc.type == NODE_ATTR_FLOAT) {
|
||||
float f = primitive_surface_attribute_float(kg, sd, desc, NULL, NULL);
|
||||
@ -145,6 +161,22 @@ ccl_device void svm_node_attr_bump_dx(KernelGlobals *kg, ShaderData *sd, float *
|
||||
}
|
||||
#endif
|
||||
|
||||
if (node.y == ATTR_STD_GENERATED && desc.element == ATTR_ELEMENT_NONE) {
|
||||
/* No generated attribute, fall back to object coordinates. */
|
||||
float3 f = sd->P + sd->dP.dx;
|
||||
object_inverse_position_transform(kg, sd, &f);
|
||||
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
||||
stack_store_float(stack, out_offset, average(f));
|
||||
}
|
||||
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
||||
stack_store_float3(stack, out_offset, f);
|
||||
}
|
||||
else {
|
||||
stack_store_float(stack, out_offset, 1.0f);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* Surface */
|
||||
if (desc.type == NODE_ATTR_FLOAT) {
|
||||
float dx;
|
||||
@ -222,6 +254,22 @@ ccl_device void svm_node_attr_bump_dy(KernelGlobals *kg, ShaderData *sd, float *
|
||||
}
|
||||
#endif
|
||||
|
||||
if (node.y == ATTR_STD_GENERATED && desc.element == ATTR_ELEMENT_NONE) {
|
||||
/* No generated attribute, fall back to object coordinates. */
|
||||
float3 f = sd->P + sd->dP.dy;
|
||||
object_inverse_position_transform(kg, sd, &f);
|
||||
if (type == NODE_ATTR_OUTPUT_FLOAT) {
|
||||
stack_store_float(stack, out_offset, average(f));
|
||||
}
|
||||
else if (type == NODE_ATTR_OUTPUT_FLOAT3) {
|
||||
stack_store_float3(stack, out_offset, f);
|
||||
}
|
||||
else {
|
||||
stack_store_float(stack, out_offset, 1.0f);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* Surface */
|
||||
if (desc.type == NODE_ATTR_FLOAT) {
|
||||
float dy;
|
||||
|
Loading…
Reference in New Issue
Block a user