From 4d544d6ae7211f8bdf086b14415a388e44116ee5 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 9 Nov 2020 14:50:33 +0100 Subject: [PATCH 1/3] Fix T80068: skin modifier not working with motion blur The skin modifier did not output consistent results, causing failure to find corresponding vertices across frames. Remove unnecessary use of GSet, all we need is an array. --- source/blender/bmesh/operators/bmo_hull.c | 51 ++++++++++++----------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/source/blender/bmesh/operators/bmo_hull.c b/source/blender/bmesh/operators/bmo_hull.c index 84938084aec..4876a12a923 100644 --- a/source/blender/bmesh/operators/bmo_hull.c +++ b/source/blender/bmesh/operators/bmo_hull.c @@ -60,12 +60,12 @@ typedef struct HullTriangle { /*************************** Hull Triangles ***************************/ static void hull_add_triangle( - BMesh *bm, GSet *hull_triangles, BLI_mempool *pool, BMVert *v1, BMVert *v2, BMVert *v3) + BMesh *bm, BLI_mempool *hull_triangles, BMVert *v1, BMVert *v2, BMVert *v3) { HullTriangle *t; int i; - t = BLI_mempool_calloc(pool); + t = BLI_mempool_calloc(hull_triangles); t->v[0] = v1; t->v[1] = v2; t->v[2] = v3; @@ -75,7 +75,6 @@ static void hull_add_triangle( BMO_vert_flag_disable(bm, t->v[i], HULL_FLAG_INTERIOR_ELE); } - BLI_gset_insert(hull_triangles, t); normal_tri_v3(t->no, v1->co, v2->co, v3->co); } @@ -94,12 +93,13 @@ static BMFace *hull_find_example_face(BMesh *bm, BMEdge *e) return NULL; } -static void hull_output_triangles(BMesh *bm, GSet *hull_triangles) +static void hull_output_triangles(BMesh *bm, BLI_mempool *hull_triangles) { - GSetIterator iter; + BLI_mempool_iter iter; + BLI_mempool_iternew(hull_triangles, &iter); + HullTriangle *t; - GSET_ITER (iter, hull_triangles) { - HullTriangle *t = BLI_gsetIterator_getKey(&iter); + while ((t = BLI_mempool_iterstep(&iter))) { int i; if (!t->skip) { @@ -198,18 +198,20 @@ static int hull_final_edges_lookup(HullFinalEdges *final_edges, BMVert *v1, BMVe } /* Used for checking whether a pre-existing edge lies on the hull */ -static HullFinalEdges *hull_final_edges(GSet *hull_triangles) +static HullFinalEdges *hull_final_edges(BLI_mempool *hull_triangles) { HullFinalEdges *final_edges; - GSetIterator iter; final_edges = MEM_callocN(sizeof(HullFinalEdges), "HullFinalEdges"); final_edges->edges = BLI_ghash_ptr_new("final edges ghash"); final_edges->base_pool = BLI_mempool_create(sizeof(ListBase), 0, 128, BLI_MEMPOOL_NOP); final_edges->link_pool = BLI_mempool_create(sizeof(LinkData), 0, 128, BLI_MEMPOOL_NOP); - GSET_ITER (iter, hull_triangles) { - HullTriangle *t = BLI_gsetIterator_getKey(&iter); + BLI_mempool_iter iter; + BLI_mempool_iternew(hull_triangles, &iter); + HullTriangle *t; + + while ((t = BLI_mempool_iterstep(&iter))) { LinkData *link; int i; @@ -250,12 +252,15 @@ static void hull_final_edges_free(HullFinalEdges *final_edges) /**************************** Final Output ****************************/ -static void hull_remove_overlapping(BMesh *bm, GSet *hull_triangles, HullFinalEdges *final_edges) +static void hull_remove_overlapping(BMesh *bm, + BLI_mempool *hull_triangles, + HullFinalEdges *final_edges) { - GSetIterator hull_iter; + BLI_mempool_iter iter; + BLI_mempool_iternew(hull_triangles, &iter); + HullTriangle *t; - GSET_ITER (hull_iter, hull_triangles) { - HullTriangle *t = BLI_gsetIterator_getKey(&hull_iter); + while ((t = BLI_mempool_iterstep(&iter))) { BMIter bm_iter1, bm_iter2; BMFace *f; bool f_on_hull; @@ -467,7 +472,7 @@ static BMVert **hull_verts_from_bullet(plConvexHull hull, return hull_verts; } -static void hull_from_bullet(BMesh *bm, BMOperator *op, GSet *hull_triangles, BLI_mempool *pool) +static void hull_from_bullet(BMesh *bm, BMOperator *op, BLI_mempool *hull_triangles) { int *fvi = NULL; BLI_array_declare(fvi); @@ -509,7 +514,7 @@ static void hull_from_bullet(BMesh *bm, BMOperator *op, GSet *hull_triangles, BL fv[1] = hull_verts[fvi[j - 1]]; fv[2] = hull_verts[fvi[j]]; - hull_add_triangle(bm, hull_triangles, pool, fv[0], fv[1], fv[2]); + hull_add_triangle(bm, hull_triangles, fv[0], fv[1], fv[2]); } } } @@ -543,10 +548,9 @@ static bool hull_num_input_verts_is_ok(BMOperator *op) void bmo_convex_hull_exec(BMesh *bm, BMOperator *op) { HullFinalEdges *final_edges; - BLI_mempool *hull_pool; + BLI_mempool *hull_triangles; BMElemF *ele; BMOIter oiter; - GSet *hull_triangles; /* Verify that at least three verts in the input */ if (!hull_num_input_verts_is_ok(op)) { @@ -569,10 +573,9 @@ void bmo_convex_hull_exec(BMesh *bm, BMOperator *op) } } - hull_pool = BLI_mempool_create(sizeof(HullTriangle), 0, 128, BLI_MEMPOOL_NOP); - hull_triangles = BLI_gset_ptr_new("hull_triangles"); + hull_triangles = BLI_mempool_create(sizeof(HullTriangle), 0, 128, BLI_MEMPOOL_ALLOW_ITER); - hull_from_bullet(bm, op, hull_triangles, hull_pool); + hull_from_bullet(bm, op, hull_triangles); final_edges = hull_final_edges(hull_triangles); @@ -590,9 +593,7 @@ void bmo_convex_hull_exec(BMesh *bm, BMOperator *op) /* Convert hull triangles to BMesh faces */ hull_output_triangles(bm, hull_triangles); - BLI_mempool_destroy(hull_pool); - - BLI_gset_free(hull_triangles, NULL); + BLI_mempool_destroy(hull_triangles); hull_tag_unused(bm, op); From dfe50ef2d84263c3470011eaba60ca45e4684b67 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 9 Nov 2020 14:34:21 +0100 Subject: [PATCH 2/3] Fluid: Fix strict compiler warning Proper way to check for DEBUG_PRINT is to do `if defined` check rather than `if`: this is because in non-debug builds the symbol is not defined. --- source/blender/blenkernel/intern/fluid.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c index d8573b9f032..d93b635d67d 100644 --- a/source/blender/blenkernel/intern/fluid.c +++ b/source/blender/blenkernel/intern/fluid.c @@ -3201,9 +3201,12 @@ static void update_effectors_task_cb(void *__restrict userdata, data->force_y[index] = retvel[1]; data->force_z[index] = retvel[2]; -# if DEBUG_PRINT +# ifdef DEBUG_PRINT /* Debugging: Print forces. */ - printf("setting force: [%f, %f, %f]\n", data->force_x[index], data->force_y[index], data->force_z[index]); + printf("setting force: [%f, %f, %f]\n", + data->force_x[index], + data->force_y[index], + data->force_z[index]); # endif } } From ec6a9322e8723b906089f02ff76b04a7bb7d136f Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 9 Nov 2020 17:23:32 +0100 Subject: [PATCH 3/3] Fix T78956: banding artifacts of vertex colors in Cycles Byte colors must be encoded in sRGB and converted to linear on lookup, to avoid precision loss. --- intern/cycles/blender/blender_mesh.cpp | 9 +++++---- intern/cycles/kernel/geom/geom_patch.h | 3 ++- .../cycles/kernel/geom/geom_subd_triangle.h | 19 ++++++++++--------- intern/cycles/kernel/geom/geom_triangle.h | 12 ++++++++---- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp index e40e1f5f001..b78a2c30b5e 100644 --- a/intern/cycles/blender/blender_mesh.cpp +++ b/intern/cycles/blender/blender_mesh.cpp @@ -346,7 +346,7 @@ static void attr_create_vertex_color(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh, for (int i = 0; i < n; i++) { float4 color = get_float4(l->data[p->loop_start() + i].color()); /* Compress/encode vertex color using the sRGB curve. */ - *(cdata++) = color_float4_to_uchar4(color_srgb_to_linear_v4(color)); + *(cdata++) = color_float4_to_uchar4(color); } } } @@ -368,9 +368,10 @@ static void attr_create_vertex_color(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh, float4 c3 = get_float4(l->data[li[2]].color()); /* Compress/encode vertex color using the sRGB curve. */ - cdata[0] = color_float4_to_uchar4(color_srgb_to_linear_v4(c1)); - cdata[1] = color_float4_to_uchar4(color_srgb_to_linear_v4(c2)); - cdata[2] = color_float4_to_uchar4(color_srgb_to_linear_v4(c3)); + cdata[0] = color_float4_to_uchar4(c1); + cdata[1] = color_float4_to_uchar4(c2); + cdata[2] = color_float4_to_uchar4(c3); + cdata += 3; } } diff --git a/intern/cycles/kernel/geom/geom_patch.h b/intern/cycles/kernel/geom/geom_patch.h index 8b4b91b96c8..b996294c51f 100644 --- a/intern/cycles/kernel/geom/geom_patch.h +++ b/intern/cycles/kernel/geom/geom_patch.h @@ -405,7 +405,8 @@ ccl_device float4 patch_eval_uchar4(KernelGlobals *kg, *dv = make_float4(0.0f, 0.0f, 0.0f, 0.0f); for (int i = 0; i < num_control; i++) { - float4 v = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, offset + indices[i])); + float4 v = color_srgb_to_linear_v4( + color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, offset + indices[i]))); val += v * weights[i]; if (du) diff --git a/intern/cycles/kernel/geom/geom_subd_triangle.h b/intern/cycles/kernel/geom/geom_subd_triangle.h index 3eef9857ae3..317f3984a9a 100644 --- a/intern/cycles/kernel/geom/geom_subd_triangle.h +++ b/intern/cycles/kernel/geom/geom_subd_triangle.h @@ -581,14 +581,14 @@ ccl_device_noinline float4 subd_triangle_attribute_float4(KernelGlobals *kg, int corners[4]; subd_triangle_patch_corners(kg, patch, corners); - float4 f0 = color_uchar4_to_float4( - kernel_tex_fetch(__attributes_uchar4, corners[0] + desc.offset)); - float4 f1 = color_uchar4_to_float4( - kernel_tex_fetch(__attributes_uchar4, corners[1] + desc.offset)); - float4 f2 = color_uchar4_to_float4( - kernel_tex_fetch(__attributes_uchar4, corners[2] + desc.offset)); - float4 f3 = color_uchar4_to_float4( - kernel_tex_fetch(__attributes_uchar4, corners[3] + desc.offset)); + float4 f0 = color_srgb_to_linear_v4( + color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[0] + desc.offset))); + float4 f1 = color_srgb_to_linear_v4( + color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[1] + desc.offset))); + float4 f2 = color_srgb_to_linear_v4( + color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[2] + desc.offset))); + float4 f3 = color_srgb_to_linear_v4( + color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[3] + desc.offset))); if (subd_triangle_patch_num_corners(kg, patch) != 4) { f1 = (f1 + f0) * 0.5f; @@ -614,7 +614,8 @@ ccl_device_noinline float4 subd_triangle_attribute_float4(KernelGlobals *kg, if (dy) *dy = make_float4(0.0f, 0.0f, 0.0f, 0.0f); - return color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, desc.offset)); + return color_srgb_to_linear_v4( + color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, desc.offset))); } else { if (dx) diff --git a/intern/cycles/kernel/geom/geom_triangle.h b/intern/cycles/kernel/geom/geom_triangle.h index 0278f3ade8e..5ecc2566815 100644 --- a/intern/cycles/kernel/geom/geom_triangle.h +++ b/intern/cycles/kernel/geom/geom_triangle.h @@ -317,9 +317,12 @@ ccl_device float4 triangle_attribute_float4(KernelGlobals *kg, if (desc.element == ATTR_ELEMENT_CORNER_BYTE) { int tri = desc.offset + sd->prim * 3; - f0 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 0)); - f1 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 1)); - f2 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 2)); + f0 = color_srgb_to_linear_v4( + color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 0))); + f1 = color_srgb_to_linear_v4( + color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 1))); + f2 = color_srgb_to_linear_v4( + color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 2))); } else { uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim); @@ -343,7 +346,8 @@ ccl_device float4 triangle_attribute_float4(KernelGlobals *kg, if (dy) *dy = make_float4(0.0f, 0.0f, 0.0f, 0.0f); - return color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, desc.offset)); + return color_srgb_to_linear_v4( + color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, desc.offset))); } else { if (dx)