From b8ecdbcd964a7e78d7e077ef84a914b1374ae076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dietrich?= Date: Tue, 17 Aug 2021 23:24:46 +0200 Subject: Cycles: avoid copying vertex normals attribute twice to the devices Vertex normals are needed for normals maps and therefore are packed and send to the device alongside the other float3 attributes. However, we already pack and send vertex normals through `DeviceScene.tri_vnormal`. This removes the packing of vertex normals from the attributes buffer, and reuses `tri_vnormal` in the kernel for normals lookup for normal maps, which reduces memory usage a bit, and speeds up device updates. This also fixes potential missing normals updates following rB12a06292af86, since the need for vertex normals for normals maps was overlooked. Reviewed By: brecht Differential Revision: https://developer.blender.org/D12237 --- intern/cycles/kernel/svm/svm_tex_coord.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'intern/cycles/kernel/svm') diff --git a/intern/cycles/kernel/svm/svm_tex_coord.h b/intern/cycles/kernel/svm/svm_tex_coord.h index fc46bb584be..09ea11ee3ed 100644 --- a/intern/cycles/kernel/svm/svm_tex_coord.h +++ b/intern/cycles/kernel/svm/svm_tex_coord.h @@ -267,7 +267,7 @@ ccl_device void svm_node_normal_map(KernelGlobals *kg, ShaderData *sd, float *st if (space == NODE_NORMAL_MAP_TANGENT) { /* tangent space */ - if (sd->object == OBJECT_NONE) { + if (sd->object == OBJECT_NONE || (sd->prim & PRIMITIVE_ALL_TRIANGLE) == 0) { /* Fallback to unperturbed normal. */ stack_store_float3(stack, normal_offset, sd->N); return; @@ -276,10 +276,8 @@ ccl_device void svm_node_normal_map(KernelGlobals *kg, ShaderData *sd, float *st /* first try to get tangent attribute */ const AttributeDescriptor attr = find_attribute(kg, sd, node.z); const AttributeDescriptor attr_sign = find_attribute(kg, sd, node.w); - 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) { /* Fallback to unperturbed normal. */ stack_store_float3(stack, normal_offset, sd->N); return; @@ -291,7 +289,7 @@ ccl_device void svm_node_normal_map(KernelGlobals *kg, ShaderData *sd, float *st float3 normal; if (sd->shader & SHADER_SMOOTH_NORMAL) { - normal = primitive_surface_attribute_float3(kg, sd, attr_normal, NULL, NULL); + normal = triangle_smooth_normal_unnormalized(kg, sd->Ng, sd->prim, sd->u, sd->v); } else { normal = sd->Ng; -- cgit v1.2.3