Page MenuHome

Fix T82586: Sculpt normals not updating with EEVEE enabled
ClosedPublic

Authored by Pablo Dobarro (pablodp606) on Nov 11 2020, 6:15 PM.

Details

Summary

The root cause of this bug is that the function that updates the PBVH
normals is drw_sculpt_generate_calls. As now both the overlays and
mesh can be drawn without using pbvh drawing, the normals were not
updating. This patch forces a normals updates also in the no PBVH
drawing code path of the overlays. This was affecting both shading and
sculpt surface sampling in both flat and smooth shading modes.

Having the sculpt normals being updated by the drawing code is a wrong
design which also causes other issues like:

  • Brushes that sample the surface and do multiple stroke steps between

redraws will sample invalid normals, creating artifacts during the
stroke clearly visible in some brushes.

  • Brushes that do not need to sample the surface update the normals on

each redraw. This affects performance a lot as in some cases, updating the
normals takes more time than doing the brush deformation. If flat shading
is being used, this is only necessary to do once after the stroke ends.

Diff Detail

Repository
rB Blender

Event Timeline

Pablo Dobarro (pablodp606) requested review of this revision.Nov 11 2020, 6:15 PM
Sergey Sharybin (sergey) requested changes to this revision.Nov 12 2020, 10:47 AM

This patch forces a normals updates also in the no PBVH drawing code path of the overlays

Yet the code mentions nothing about why is this needed.

Is also unclear to me why do we need to have two places in the drawing code where normals are ensured. If they are needed in all sculpting-related drawing, make it a single call in one of the suitable parent calls in the callstack.

Having the sculpt normals being updated by the drawing code is a wrong

If it is wrong why are we spreading the wrong code into more places of the drawing code?

This revision now requires changes to proceed.Nov 12 2020, 10:47 AM

This is not the right fix, but it is probably the safest one for 2.91. In order to fix this properly the steps would be:

  • Commit D9079, which includes a function to check if the PBVH is rendering in flat or smooth shading
  • Tag all tools and operator depending if they need normal updates, normal updates per redraw or normal updates on finish
  • Add constant normal updates to the main brush loops for tools that need high precession normals
  • Make only smooth PBVH shading update the normals on redraw.
  • Move normal updates to basic_cache_populate
  • move normal updates to DRW_mesh_batch_cache_create_requested
  • remove unused includes
Clément Foucault (fclem) requested changes to this revision.Nov 17 2020, 3:39 PM
Clément Foucault (fclem) added inline comments.
source/blender/draw/intern/draw_manager_data.c
1037 ↗(On Diff #31166)

I would leave it there for safety. If I'm not mistaken BKE_pbvh_draw_cb needs the final GPUBatches to be available but DRW_mesh_batch_cache_create_requested is always called after it.

This can make the batch use outdated normal.

This revision now requires changes to proceed.Nov 17 2020, 3:39 PM
Pablo Dobarro (pablodp606) marked an inline comment as done.
  • Leave normal updates in draw_manager_data
source/blender/draw/intern/draw_cache_impl_mesh.c
1188
1193–1194

The goal was to have a single call to BKE_pbvh_update_normals. This change adds one to a seemingly-generic place, but there is still BKE_pbvh_update_normals in drw_sculpt_generate_calls.

Clément Foucault (fclem) requested changes to this revision.Nov 18 2020, 11:08 AM

Move this update block after /* Second chance to early out */ and it avoid the per redraw update.

This revision now requires changes to proceed.Nov 18 2020, 11:08 AM

For reference, the issue is that in the main case (pbvh drawing) we have access to the object just before issuing the drawcalls (and after culling and / or visibility testing). But for regular drawing we don't. So we have to delay this to after all the drawcalls have been registered and the batches queried. And in this instance the batch can be lazily generated but not for pbvh drawing. So we need to have BKE_pbvh_update_normals in both places.

Discussed with Clement why the seemingly-easy-and-proper-fastest approach can't work sop simply.

To summarize:

  • We only want the BKE_pbvh_update_normals to happen when object changes (so that camera navigation does not trigger the update)
  • Multiple engines can require PBVH normals to be up-to-date
  • There is no parent call in the draw manager which has all access to needed data AND will know that PBVH normals WILL be needed.

I can't unraise the concern, and accepting it at the current state is also not something what should be done. So resigning and leaving the final review/greenlight to Clement.

This revision was not accepted when it landed; it landed in state Needs Revision.Nov 18 2020, 12:21 PM
This revision was automatically updated to reflect the committed changes.

Note that I've modified the comment to reflect my changes. The update does not happen on view update now.