From 430ced76d559d828b6f47c5fbb22530dcc70c257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dietrich?= Date: Tue, 15 Feb 2022 17:48:49 +0100 Subject: GPU subdiv: fix custom data interpolation for N-gons Not all coarse vertices were used to compute the center value (off by one), and the interpolation for the current would always start at the base corner for the base face instead of the base corner for the current patch. --- .../draw/intern/shaders/common_subdiv_custom_data_interp_comp.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source/blender/draw/intern/shaders') diff --git a/source/blender/draw/intern/shaders/common_subdiv_custom_data_interp_comp.glsl b/source/blender/draw/intern/shaders/common_subdiv_custom_data_interp_comp.glsl index 36c3970d9a0..df0016761e2 100644 --- a/source/blender/draw/intern/shaders/common_subdiv_custom_data_interp_comp.glsl +++ b/source/blender/draw/intern/shaders/common_subdiv_custom_data_interp_comp.glsl @@ -185,7 +185,7 @@ void main() } else { /* Interpolate the src data for the center. */ - uint loop_end = loop_start + number_of_vertices - 1; + uint loop_end = loop_start + number_of_vertices; Vertex center_value; clear(center_value); @@ -202,7 +202,7 @@ void main() uint prev_coarse_corner = (current_coarse_corner + number_of_vertices - 1) % number_of_vertices; - v0 = read_vertex(loop_start); + v0 = read_vertex(loop_start + current_coarse_corner); v1 = average(v0, read_vertex(loop_start + next_coarse_corner)); v3 = average(v0, read_vertex(loop_start + prev_coarse_corner)); -- cgit v1.2.3 From 48b26d9c2e0f4f4b6b5b7279c5bfc40c3ec77a6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dietrich?= Date: Tue, 15 Feb 2022 17:51:19 +0100 Subject: Fix T95697: GPU subdivision ignores custom normals Similarly to the CPU subdivision, we interpolate custom loop normals from the coarse mesh, and this for the final normals. --- .../common_subdiv_normals_finalize_comp.glsl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'source/blender/draw/intern/shaders') diff --git a/source/blender/draw/intern/shaders/common_subdiv_normals_finalize_comp.glsl b/source/blender/draw/intern/shaders/common_subdiv_normals_finalize_comp.glsl index 84cd65d4161..c2e0e752783 100644 --- a/source/blender/draw/intern/shaders/common_subdiv_normals_finalize_comp.glsl +++ b/source/blender/draw/intern/shaders/common_subdiv_normals_finalize_comp.glsl @@ -1,6 +1,18 @@ /* To be compile with common_subdiv_lib.glsl */ +#ifdef CUSTOM_NORMALS +struct CustomNormal { + float x; + float y; + float z; +}; + +layout(std430, binding = 0) readonly buffer inputNormals +{ + CustomNormal custom_normals[]; +}; +#else layout(std430, binding = 0) readonly buffer inputNormals { vec3 vertex_normals[]; @@ -10,6 +22,7 @@ layout(std430, binding = 1) readonly buffer inputSubdivVertLoopMap { uint vert_loop_map[]; }; +#endif layout(std430, binding = 2) buffer outputPosNor { @@ -26,9 +39,17 @@ void main() uint start_loop_index = quad_index * 4; +#ifdef CUSTOM_NORMALS + for (int i = 0; i < 4; i++) { + CustomNormal custom_normal = custom_normals[start_loop_index + i]; + vec3 nor = vec3(custom_normal.x, custom_normal.y, custom_normal.z); + set_vertex_nor(pos_nor[start_loop_index + i], normalize(nor)); + } +#else for (int i = 0; i < 4; i++) { uint subdiv_vert_index = vert_loop_map[start_loop_index + i]; vec3 nor = vertex_normals[subdiv_vert_index]; set_vertex_nor(pos_nor[start_loop_index + i], nor); } +#endif } -- cgit v1.2.3