Shading bugs of sculpting by curve stroke on an reused mesh #122947

Closed
opened 2024-06-09 11:51:41 +02:00 by Refone · 8 comments

System Information
Operating system: Windows 10 Professional 22H2
Graphics card: NVIDIA GeForce RTX-4080

Blender Version
Broken: 4.2.0 alpha
Worked: (newest version of Blender that worked as expected)

Short description of error

image

See my video, it is the full process of reproducing from launch. Key pressing is shown at right bottom corner.

Exact steps for others to reproduce the error

Duplicate an object with Alt + D, making them sharing the same mesh.
And sculpting one of them using curve stroke sculpt brush.
Ctrl RMB draw a curve, and press Enter to apply sculpt on curve.
There will be an shading problem.
Pressing Ctrl Z, cancel the latest "Enter", it will be ok.

**System Information** Operating system: Windows 10 Professional 22H2 Graphics card: NVIDIA GeForce RTX-4080 **Blender Version** Broken: 4.2.0 alpha Worked: (newest version of Blender that worked as expected) **Short description of error** ![image](/attachments/d0e4c74a-8b2d-43d0-947d-6430dd136838) See my video, it is the full process of reproducing from launch. Key pressing is shown at right bottom corner. **Exact steps for others to reproduce the error** Duplicate an object with Alt + D, making them sharing the same mesh. And sculpting one of them using curve stroke sculpt brush. Ctrl RMB draw a curve, and press Enter to apply sculpt on curve. There will be an shading problem. Pressing Ctrl Z, cancel the latest "Enter", it will be ok.
Refone added the
Severity
Normal
Type
Report
Status
Needs Triage
labels 2024-06-09 11:51:42 +02:00
Iliya Katushenock added the
Interest
Sculpt, Paint & Texture
label 2024-06-09 11:58:37 +02:00
Member

Pretty sure this is caused by b339e3937d

Pretty sure this is caused by b339e3937d8dc580b655efe599c3b0f97f412fb1
Member

Pretty sure this is caused by b339e3937d

CC @HooglyBoogly

> Pretty sure this is caused by b339e3937d8dc580b655efe599c3b0f97f412fb1 CC @HooglyBoogly
Philipp Oeser added
Severity
High
and removed
Severity
Normal
labels 2024-06-10 10:07:01 +02:00
Hans Goudey self-assigned this 2024-06-10 16:07:09 +02:00
Member

That commit may have exposed the issue but I don't think it's the fundamental cause. Currently I'm observing that pbvh::update_bounds doesn't recalculate the node's bounds because the PBVH_UpdateNormals flag bit is lost in between the bounds update and the normals update. This is really confusing. Even with a hardware memory breakpoint, the flag's bit changes in between update_bounds and update_normals!

I'm stuck on this for now. I'll come back to it tomorrow and see if I have more ideas.

That commit may have exposed the issue but I don't think it's the fundamental cause. Currently I'm observing that `pbvh::update_bounds` doesn't recalculate the node's bounds because the `PBVH_UpdateNormals` flag bit is lost in between the bounds update and the normals update. This is really confusing. Even with a hardware memory breakpoint, the flag's bit changes in between `update_bounds` and `update_normals`! I'm stuck on this for now. I'll come back to it tomorrow and see if I have more ideas.
Hans Goudey added
Type
Bug
and removed
Type
Report
labels 2024-06-10 19:50:37 +02:00
Sean Kim added this to the 4.2 LTS milestone 2024-06-24 22:47:57 +02:00
Member

Doing a bit more testing here. I'm unable to replicate this with the Spacing stroke type, the odd shading only happens for the Curve stroke. Switching between modes (Sculpt -> Edit -> Sculpt) fixes the appearance.

Doing a bit more testing here. I'm unable to replicate this with the `Spacing` stroke type, the odd shading only happens for the `Curve` stroke. Switching between modes (Sculpt -> Edit -> Sculpt) fixes the appearance.
Member

Maybe it has to do with the fact that the Curve stroke executes multiple brush samples before flushing updates.

Switching between modes (Sculpt -> Edit -> Sculpt) fixes the appearance.

That would happen because going to edit mode destroys any caches on the mesh, including normals.

Maybe it has to do with the fact that the Curve stroke executes multiple brush samples before flushing updates. >Switching between modes (Sculpt -> Edit -> Sculpt) fixes the appearance. That would happen because going to edit mode destroys any caches on the mesh, including normals.
Member

Commenting out the following in sculpt.cc flush_update_done fixes the original mesh display

  if (need_tag) {
    DEG_id_tag_update(&ob.id, ID_RECALC_GEOMETRY);
  }
Commenting out the following in `sculpt.cc` `flush_update_done` fixes the original mesh display ```Cpp if (need_tag) { DEG_id_tag_update(&ob.id, ID_RECALC_GEOMETRY); } ```
Member

I think I've found a deeper cause of this, though I'm unsure what a fix looks like yet.

void BKE_sculpt_update_object_before_eval(Object *ob_eval)
{
  /* Update before mesh evaluation in the dependency graph. */
  SculptSession *ss = ob_eval->sculpt;

  if (ss && ss->building_vp_handle == false) {
    if (!ss->cache && !ss->filter_cache && !ss->expand_cache) {
      /* We free pbvh on changes, except in the middle of drawing a stroke
       * since it can't deal with changing PVBH node organization, we hope
       * topology does not change in the meantime .. weak. */
      sculptsession_free_pbvh(ob_eval);

      BKE_sculptsession_free_deformMats(ob_eval->sculpt);

      /* In vertex/weight paint, force maps to be rebuilt. */
      BKE_sculptsession_free_vwpaint_data(ob_eval->sculpt);
    }
    else if (ss->pbvh) {
      Vector<PBVHNode *> nodes = blender::bke::pbvh::search_gather(*ss->pbvh, {});

      for (PBVHNode *node : nodes) {
        BKE_pbvh_node_mark_update(node);
      }
    }
  }
}

When the object is linked & duplicated, we end up calling this method which blows away the PBVH. Later when we call bke::pbvh::update_normals from draw_sculpt.cc the PBVH has been recalculated but the existing node updates are gone.

Commenting out sculptsession_free_pbvh(ob_eval) fixes this particular problem, but I'm unsure why we clear this data in the first place.

I think I've found a deeper cause of this, though I'm unsure what a fix looks like yet. ```Cpp void BKE_sculpt_update_object_before_eval(Object *ob_eval) { /* Update before mesh evaluation in the dependency graph. */ SculptSession *ss = ob_eval->sculpt; if (ss && ss->building_vp_handle == false) { if (!ss->cache && !ss->filter_cache && !ss->expand_cache) { /* We free pbvh on changes, except in the middle of drawing a stroke * since it can't deal with changing PVBH node organization, we hope * topology does not change in the meantime .. weak. */ sculptsession_free_pbvh(ob_eval); BKE_sculptsession_free_deformMats(ob_eval->sculpt); /* In vertex/weight paint, force maps to be rebuilt. */ BKE_sculptsession_free_vwpaint_data(ob_eval->sculpt); } else if (ss->pbvh) { Vector<PBVHNode *> nodes = blender::bke::pbvh::search_gather(*ss->pbvh, {}); for (PBVHNode *node : nodes) { BKE_pbvh_node_mark_update(node); } } } } ``` When the object is linked & duplicated, we end up calling this method which blows away the PBVH. Later when we call `bke::pbvh::update_normals` from `draw_sculpt.cc` the PBVH has been recalculated but the existing node updates are gone. Commenting out `sculptsession_free_pbvh(ob_eval)` fixes this particular problem, but I'm unsure why we clear this data in the first place.
Member

My guess as to why this happens specifically for the curve stroke and not for the other strokes is because all calls to stroke->update_step (and subsequently the code that marks positions & normals for updating) happen simultaneously when the user presses enter, unlike other strokes which apply them over the course of multiple events.

My guess as to why this happens specifically for the curve stroke and not for the other strokes is because all calls to `stroke->update_step` (and subsequently the code that marks positions & normals for updating) happen simultaneously when the user presses enter, unlike other strokes which apply them over the course of multiple events.
Sean Kim self-assigned this 2024-07-06 03:56:31 +02:00
Hans Goudey was unassigned by Sean Kim 2024-07-06 03:56:39 +02:00
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2024-07-08 21:36:49 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
4 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#122947
No description provided.