diff options
author | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2021-08-18 00:24:46 +0300 |
---|---|---|
committer | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2021-08-18 22:12:39 +0300 |
commit | b8ecdbcd964a7e78d7e077ef84a914b1374ae076 (patch) | |
tree | 589d69109b3f70d219ef14a040bc717381266c85 /intern/cycles/kernel/geom | |
parent | e5f8db92b696a36e919eb6ac3125190d9e2202d9 (diff) |
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
Diffstat (limited to 'intern/cycles/kernel/geom')
-rw-r--r-- | intern/cycles/kernel/geom/geom_triangle.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/intern/cycles/kernel/geom/geom_triangle.h b/intern/cycles/kernel/geom/geom_triangle.h index 208338a934b..1e7fbd9c7fb 100644 --- a/intern/cycles/kernel/geom/geom_triangle.h +++ b/intern/cycles/kernel/geom/geom_triangle.h @@ -107,6 +107,20 @@ triangle_smooth_normal(KernelGlobals *kg, float3 Ng, int prim, float u, float v) return is_zero(N) ? Ng : N; } +ccl_device_inline float3 +triangle_smooth_normal_unnormalized(KernelGlobals *kg, float3 Ng, int prim, float u, float v) +{ + /* load triangle vertices */ + const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, prim); + float3 n0 = float4_to_float3(kernel_tex_fetch(__tri_vnormal, tri_vindex.x)); + float3 n1 = float4_to_float3(kernel_tex_fetch(__tri_vnormal, tri_vindex.y)); + float3 n2 = float4_to_float3(kernel_tex_fetch(__tri_vnormal, tri_vindex.z)); + + float3 N = (1.0f - u - v) * n2 + u * n0 + v * n1; + + return is_zero(N) ? Ng : N; +} + /* Ray differentials on triangle */ ccl_device_inline void triangle_dPdudv(KernelGlobals *kg, |