Regression: Shading artefacts in sculpt mode #96810

Closed
opened 2022-03-27 00:05:24 +01:00 by CHET · 40 comments

System Information
Operating system: Windows-10-10.0.19044-SP0 64 Bits
Graphics card: NVIDIA GeForce GTX 950M/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 496.13

Blender Version
Broken: version: 3.1.1 Release Candidate, branch: master, commit date: 2022-03-24 13:38, hash: fb2cb0324a
Worked: (newest version of Blender that worked as expected)

Short description of error
Shading artefacts in sculpt mode when use grab brush
blender_E1iUEGStqR.mp4

Exact steps for others to reproduce the error

  • Open attached file
  • Select the "Grab" brush
  • Click on random mesh positions
    untitled.blend
**System Information** Operating system: Windows-10-10.0.19044-SP0 64 Bits Graphics card: NVIDIA GeForce GTX 950M/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 496.13 **Blender Version** Broken: version: 3.1.1 Release Candidate, branch: master, commit date: 2022-03-24 13:38, hash: `fb2cb0324a` Worked: (newest version of Blender that worked as expected) **Short description of error** Shading artefacts in sculpt mode when use grab brush [blender_E1iUEGStqR.mp4](https://archive.blender.org/developer/F12948645/blender_E1iUEGStqR.mp4) **Exact steps for others to reproduce the error** - Open attached file - Select the "Grab" brush - Click on random mesh positions [untitled.blend](https://archive.blender.org/developer/F12948649/untitled.blend)
Author

Added subscriber: @cheteron

Added subscriber: @cheteron
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Changed status from 'Needs Triage' to: 'Needs User Info'

Changed status from 'Needs Triage' to: 'Needs User Info'
Member

Cannot repro here

**System Information**
Operating system: Linux-5.13.0-0.rc6.45.fc35.x86_64-x86_64-with-glibc2.34.9000 64 Bits
Graphics card: NVIDIA GeForce GTX 970M/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 495.44
version: 3.1.1, branch: master, commit date: 2022-03-29 17:50, hash: `rBd91843f3b6c6`

Is this also an issue in previous version? https://download.blender.org/release/
Have you tried other GPU driver versions?

Cannot repro here ``` **System Information** Operating system: Linux-5.13.0-0.rc6.45.fc35.x86_64-x86_64-with-glibc2.34.9000 64 Bits Graphics card: NVIDIA GeForce GTX 970M/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 495.44 version: 3.1.1, branch: master, commit date: 2022-03-29 17:50, hash: `rBd91843f3b6c6` ``` Is this also an issue in previous version? https://download.blender.org/release/ Have you tried other GPU driver versions?
Author

This comment was removed by @cheteron

*This comment was removed by @cheteron*
Author

The problem is not only visual. Where artifacts appear, vertices seem to offset, or split, and when trying to smooth, the geometry is distorted. It's wire problem, and I don't know how to identify the problem, it appears randomly, sometimes when using dyntopo, and sometimes during the sculpting process or during the undo operation, in the same way, for unknown reasons, the problem itself disappears.
Sometimes I had to remesh the geometry to remove the artifact - it helped, but sometimes

The problem is not only visual. Where artifacts appear, vertices seem to offset, or split, and when trying to smooth, the geometry is distorted. It's wire problem, and I don't know how to identify the problem, it appears randomly, sometimes when using dyntopo, and sometimes during the sculpting process or during the undo operation, in the same way, for unknown reasons, the problem itself disappears. Sometimes I had to remesh the geometry to remove the artifact - it helped, but sometimes
Author

Artifact appears after using mask and then draw brush
P.S. new nvidia drivers
blender_oPMoJ32PHQ.mp4

Artifact appears after using mask and then draw brush P.S. new nvidia drivers [blender_oPMoJ32PHQ.mp4](https://archive.blender.org/developer/F12962818/blender_oPMoJ32PHQ.mp4)
Author

Blender 3.1.2 - same problem!

Blender 3.1.2 - same problem!
Member

Have you checked 2.93 LTS? Is it the same problem there?

Have you checked 2.93 LTS? Is it the same problem there?
Author

This problem appear only in 3.1+

This problem appear only in 3.1+
Member

Changed status from 'Needs User Info' to: 'Needs Triage'

Changed status from 'Needs User Info' to: 'Needs Triage'

Added subscriber: @mano-wii

Added subscriber: @mano-wii

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'

I can reproduce the problem. But it's nothing as serious as what's shown in the video.
GIF.gif

Is it only seen on Windows?
Anyway, I believe it deserves an investigation.


Operating system: Windows-10-10.0.22000-SP0 64 Bits
Graphics card: Radeon (TM) RX 480 Graphics ATI Technologies Inc. 4.5.14802 Core Profile/Debug Context 22.2.3 30.0.14029.5006

I can reproduce the problem. But it's nothing as serious as what's shown in the video. ![GIF.gif](https://archive.blender.org/developer/F12979295/GIF.gif) Is it only seen on Windows? Anyway, I believe it deserves an investigation. --- Operating system: Windows-10-10.0.22000-SP0 64 Bits Graphics card: Radeon (TM) RX 480 Graphics ATI Technologies Inc. 4.5.14802 Core Profile/Debug Context 22.2.3 30.0.14029.5006

It is difficult to find when the problem was introduced, but I noticed that in some versions the problem was as bad as the one shown in the video. So there has been an improvement in recent versions.

@cheteron, please try the latest daily build: https://builder.blender.org/download/

Go to File → Defaults → Load Factory Settings and then load your file to see if you still can reproduce this issue.

It is difficult to find when the problem was introduced, but I noticed that in some versions the problem was as bad as the one shown in the video. So there has been an improvement in recent versions. @cheteron, please try the latest daily build: https://builder.blender.org/download/ Go to File → Defaults → Load Factory Settings and then load your file to see if you still can reproduce this issue.
Author

This is a problem because the mesh is not only visually distorted, it physically creates artifacts. And it need of a fix

This is a problem because the mesh is not only visually distorted, it physically creates artifacts. And it need of a fix
Member

In #96810#1336836, @cheteron wrote:
This problem appear only in 3.1+

@mano-wii : can you bisect this? Seems like it could be high prio if you ask me...

> In #96810#1336836, @cheteron wrote: > This problem appear only in 3.1+ @mano-wii : can you bisect this? Seems like it could be high prio if you ask me...
Philipp Oeser changed title from Shading artefacts in sculpt mode to Regression: Shading artefacts in sculpt mode 2022-04-27 14:21:40 +02:00

Added subscriber: @HooglyBoogly

Added subscriber: @HooglyBoogly

A bit difficult to bisect as the problem is random, subtle and behaves differently in different versions.
But I tried again and was more careful this time.
Apparently the problem was introduced in {7682d7de046185382985999f8f6b6e7dcf860582}
So @HooglyBoogly, any ideas what could be causing it?
GIF.gif

A bit difficult to bisect as the problem is random, subtle and behaves differently in different versions. But I tried again and was more careful this time. Apparently the problem was introduced in {7682d7de046185382985999f8f6b6e7dcf860582} So @HooglyBoogly, any ideas what could be causing it? ![GIF.gif](https://archive.blender.org/developer/F12979295/GIF.gif)
Member

No ideas at the moment. But I'll look through that commit in more depth when I get a chance, maybe there's some incorrect part.

No ideas at the moment. But I'll look through that commit in more depth when I get a chance, maybe there's some incorrect part.
Member

Added subscriber: @JulienKaspar

Added subscriber: @JulienKaspar
Member

@HooglyBoogly Are there any updates on this issue?

@HooglyBoogly Are there any updates on this issue?
Member

Added subscriber: @Jeroen-Bakker

Added subscriber: @Jeroen-Bakker
Member

Seems like they occur at pbvhnode edges...

Seems like they occur at pbvhnode edges...
Member

Sorry, I don't have any updates at the moment. The last time I looked into this I didn't get anywhere. Errors at node edges makes sense to me.

Sorry, I don't have any updates at the moment. The last time I looked into this I didn't get anywhere. Errors at node edges makes sense to me.

Added subscriber: @brecht

Added subscriber: @brecht

pbvh_update_normals_store_task_cb does not look thread safe. Two threads calling BLI_BITMAP_DISABLE to write bits in the same integer will not get synchronized correctly.

`pbvh_update_normals_store_task_cb` does not look thread safe. Two threads calling `BLI_BITMAP_DISABLE` to write bits in the same integer will not get synchronized correctly.
Member

Ah, that makes sense to me. I wonder if it's better to use atomics for this or to just switch from a bitmap to a boolean array.

Ah, that makes sense to me. I wonder if it's better to use atomics for this or to just switch from a bitmap to a boolean array.

Or just zero the entire bitmap afterwards. It's not ideal in that it involves all vertices when ideally we only work on affected nodes, but this being a bitmap array it's relatively small.

Or just zero the entire bitmap afterwards. It's not ideal in that it involves all vertices when ideally we only work on affected nodes, but this being a bitmap array it's relatively small.
Hans Goudey self-assigned this 2022-05-19 23:33:48 +02:00

Added subscriber: @Wesley-Rossi

Added subscriber: @Wesley-Rossi

This issue was referenced by b8bd20d7e0

This issue was referenced by b8bd20d7e0238df9a7f558892377f6b304d5ca75
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Author

Why was the topic closed without closing the bug?
image.png
blender_7ekQc4IQeY.jpg

Why was the topic closed without closing the bug? ![image.png](https://archive.blender.org/developer/F13263613/image.png) ![blender_7ekQc4IQeY.jpg](https://archive.blender.org/developer/F13263609/blender_7ekQc4IQeY.jpg)
Author
[blender_FoqZoWEGst.mp4](https://archive.blender.org/developer/F13263627/blender_FoqZoWEGst.mp4)
Author

Guys, open topic! Problem not resolved!

Guys, open topic! Problem not resolved!
Member

Changed status from 'Resolved' to: 'Confirmed'

Changed status from 'Resolved' to: 'Confirmed'
Member

I can still reproduce this. Both with the included example file and with factory settings. On linux.
@HooglyBoogly Can you investigate?

I can still reproduce this. Both with the included example file and with factory settings. On linux. @HooglyBoogly Can you investigate?
Member

I've looked into this for a while and found that a PBVH node calculating its vertices' normals can write into the normals of another node. I think ideally each node would affect the normals of its own unique vertices (vertices that are not part of any other node).

This change that checks if a vertex is in the node before writing to the normal fixes the problem for me, but adds exponential complexity within each node. I'll work on optimizing it next.

diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 6cebcdfea4e..6ff20ad30c1 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1017,71 +1017,84 @@ static void pbvh_update_normals_clear_task_cb(void *__restrict userdata,
 {
   PBVHUpdateData *data = userdata;
   PBVH *pbvh = data->pbvh;
   PBVHNode *node = data->nodes[n];
   float(*vnors)[3] = data->vnors;
 
   if (node->flag & PBVH_UpdateNormals) {
     const int *verts = node->vert_indices;
     const int totvert = node->uniq_verts;
     for (int i = 0; i < totvert; i++) {
       const int v = verts[i];
       if (pbvh->vert_bitmap[v]) {
         zero_v3(vnors[v]);
       }
     }
   }
 }
 
+static bool span_contains(const int *data, const int data_num, const int value)
+{
+  for (int i = 0; i < data_num; i++) {
+    if (data[i] == value) {
+      return true;
+    }
+  }
+  return false;
+}
+
 static void pbvh_update_normals_accum_task_cb(void *__restrict userdata,
                                               const int n,
                                               const TaskParallelTLS *__restrict UNUSED(tls))
 {
   PBVHUpdateData *data = userdata;
 
   PBVH *pbvh = data->pbvh;
   PBVHNode *node = data->nodes[n];
   float(*vnors)[3] = data->vnors;
 
   if (node->flag & PBVH_UpdateNormals) {
     unsigned int mpoly_prev = UINT_MAX;
     float fn[3];
 
     const int *faces = node->prim_indices;
     const int totface = node->totprim;
 
     for (int i = 0; i < totface; i++) {
       const MLoopTri *lt = &pbvh->looptri[faces[i]];
       const unsigned int vtri[3] = {
           pbvh->mloop[lt->tri[0]].v,
           pbvh->mloop[lt->tri[1]].v,
           pbvh->mloop[lt->tri[2]].v,
       };
       const int sides = 3;
 
       /* Face normal and mask */
       if (lt->poly != mpoly_prev) {
         const MPoly *mp = &pbvh->mpoly[lt->poly];
         BKE_mesh_calc_poly_normal(mp, &pbvh->mloop[mp->loopstart], pbvh->verts, fn);
         mpoly_prev = lt->poly;
       }
 
       for (int j = sides; j--;) {
         const int v = vtri[j];
+        if (!span_contains(node->vert_indices, node->uniq_verts, v)) {
+          continue;
+        }
 
         if (pbvh->vert_bitmap[v]) {
           /* NOTE: This avoids `lock, add_v3_v3, unlock`
            * and is five to ten times quicker than a spin-lock.
            * Not exact equivalent though, since atomicity is only ensured for one component
            * of the vector at a time, but here it shall not make any sensible difference. */
           for (int k = 3; k--;) {
             atomic_add_and_fetch_fl(&vnors[v][k], fn[k]);
           }
         }
       }
     }
   }
 }
 
 static void pbvh_update_normals_store_task_cb(void *__restrict userdata,
                                               const int n,
                                               const TaskParallelTLS *__restrict UNUSED(tls))

I'm not sure why this wasn't observed before, which makes me a bit skeptical. Another possible explanation is that not all necessary PBVH nodes are tagged for an update, but situation described above sounds a bit more intuitive, so I'll go with that for now.

~~I've looked into this for a while and found that a PBVH node calculating its vertices' normals can write into the normals of another node. I think ideally each node would affect the normals of its own unique vertices (vertices that are not part of any other node).~~ ~~This change that checks if a vertex is in the node before writing to the normal fixes the problem for me, but adds exponential complexity within each node. I'll work on optimizing it next.~~ ```lines=5 diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index 6cebcdfea4e..6ff20ad30c1 100644 --- a/source/blender/blenkernel/intern/pbvh.c +++ b/source/blender/blenkernel/intern/pbvh.c @@ -1017,71 +1017,84 @@ static void pbvh_update_normals_clear_task_cb(void *__restrict userdata, { PBVHUpdateData *data = userdata; PBVH *pbvh = data->pbvh; PBVHNode *node = data->nodes[n]; float(*vnors)[3] = data->vnors; if (node->flag & PBVH_UpdateNormals) { const int *verts = node->vert_indices; const int totvert = node->uniq_verts; for (int i = 0; i < totvert; i++) { const int v = verts[i]; if (pbvh->vert_bitmap[v]) { zero_v3(vnors[v]); } } } } +static bool span_contains(const int *data, const int data_num, const int value) +{ + for (int i = 0; i < data_num; i++) { + if (data[i] == value) { + return true; + } + } + return false; +} + static void pbvh_update_normals_accum_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls)) { PBVHUpdateData *data = userdata; PBVH *pbvh = data->pbvh; PBVHNode *node = data->nodes[n]; float(*vnors)[3] = data->vnors; if (node->flag & PBVH_UpdateNormals) { unsigned int mpoly_prev = UINT_MAX; float fn[3]; const int *faces = node->prim_indices; const int totface = node->totprim; for (int i = 0; i < totface; i++) { const MLoopTri *lt = &pbvh->looptri[faces[i]]; const unsigned int vtri[3] = { pbvh->mloop[lt->tri[0]].v, pbvh->mloop[lt->tri[1]].v, pbvh->mloop[lt->tri[2]].v, }; const int sides = 3; /* Face normal and mask */ if (lt->poly != mpoly_prev) { const MPoly *mp = &pbvh->mpoly[lt->poly]; BKE_mesh_calc_poly_normal(mp, &pbvh->mloop[mp->loopstart], pbvh->verts, fn); mpoly_prev = lt->poly; } for (int j = sides; j--;) { const int v = vtri[j]; + if (!span_contains(node->vert_indices, node->uniq_verts, v)) { + continue; + } if (pbvh->vert_bitmap[v]) { /* NOTE: This avoids `lock, add_v3_v3, unlock` * and is five to ten times quicker than a spin-lock. * Not exact equivalent though, since atomicity is only ensured for one component * of the vector at a time, but here it shall not make any sensible difference. */ for (int k = 3; k--;) { atomic_add_and_fetch_fl(&vnors[v][k], fn[k]); } } } } } } static void pbvh_update_normals_store_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls)) ``` ~~I'm not sure why this wasn't observed before, which makes me a bit skeptical. Another possible explanation is that not all necessary PBVH nodes are tagged for an update, but situation described above sounds a bit more intuitive, so I'll go with that for now.~~

This issue was referenced by efe0e2b183

This issue was referenced by efe0e2b18370972c14383e809719c2b606abc414
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Thomas Dinges added this to the 3.3 LTS milestone 2023-02-08 15:37:46 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
9 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#96810
No description provided.