Page MenuHome

Fix T75539: Cycles. Update geometry when switching displacements
ClosedPublic

Authored by Joan Bonet Orantos (LaTerreta) on Sep 15 2020, 11:58 AM.

Details

Summary

We only updated the mesh attribute request to undisplaced position
when switching from "Displacement and Bump" to "Bump Only", but
we forgot to do it when switching from "Displacement Only" to
"Bump Only"

Diff Detail

Repository
rB Blender
Branch
T75539 (branched from master)
Build Status
Buildable 10203
Build 10203: arc lint + arc unit

Event Timeline

Joan Bonet Orantos (LaTerreta) requested review of this revision.Sep 15 2020, 11:58 AM
Joan Bonet Orantos (LaTerreta) created this revision.
Brecht Van Lommel (brecht) requested changes to this revision.Sep 15 2020, 12:43 PM

Undisplaced positions are only needed for "Displacement and Bump", and always enabling them for "Displacement" wastes memory.

Adding them here will indirectly force the geometry to be updated, but we need a more direct solution. Probably the geometry could store if it has been displaced, and then if displacement method is bump and there is displaced geometry, it can be marked for update.

This revision now requires changes to proceed.Sep 15 2020, 12:43 PM
  • track if geometry was displaced, and mark it for update if displace method is BUMP

Did you mean something like this? I am getting familiar with the code, so I hope I am not that off

Hi @Brecht Van Lommel (brecht), as adviced on the blender-coders chat, I added "Render & Cycles" as reviewers too, given that I have seen in a recent meeting minutes that you asked for other's help on reviews.

Brecht Van Lommel (brecht) requested changes to this revision.Oct 12 2020, 12:06 PM

It's individual geometry that should be marked as being displaced, not the geometry manager for all geometry.

I don't immediately have advice for how to best implement that, it may be a more complicated change.

This revision now requires changes to proceed.Oct 12 2020, 12:06 PM

What about adding a bool member to Mesh class "is_displaced", and then set it to TRUE for any mesh that is displaced in GeometryManager::displace() (in mesh_displace.cpp). I may be wrong but it looks to me that by doing that at least we would cover the first part: having individual geometry (at least meshes) marked as being displaced. If that works, what if we then set

geometry_manager->need_update = true

if we find a Mesh in the scene with "is_displaced == true"? would that make sense? Perhaps is actually "Scene" class that can have a boolean too if any of the meshes in it was displaced and then mark it for an need_update as I did.

Yes, is_displaced should be a member of Geometry.

Probably the solution involves tagging shaders as having their displacement property changed, and then in the geometry update looping over the meshes and tagging them for updated based on the shader updates.

Fix T75539: Fix simplified after D8544 landed

Brecht I know you originally mentioned that the fix should not land in Shader::tag_update but Kévin explained to me that after his change landed, the actual check of whether displacement method was modified is pretty simple. The actual fix proves that idea.

Kévin Dietrich (kevindietrich) requested changes to this revision.Nov 19 2020, 1:02 AM

This looks good, however the geometry_manager should also be tagged for an update. For now this works only because the geometry manager is tagged indirectly for an update in the Blender exporter; we don't want to depend on such behavior if it ever changes, which it might in the future with more granular updates (D9555 and beyond). The object_manager should also be tagged for a flags update (need_flags_update) since the change in displacement affects the geometries' bounds and we would then need to update the possible intersections with volumes.

intern/cycles/render/shader.cpp
329

Should be:

if (has_displacement && displacement_method_is_modified())

You should also move this check below the update of the has_displacement flag below, and perhaps merge this with the other check on displacement_method on line 354, e.g.:

if (has_displacement) {
  if (displacement_method == DISPLACE_BOTH)) {
     ...
  }
  if (displacement_method_is_modified()) {
     ...
  }
}
This revision now requires changes to proceed.Nov 19 2020, 1:02 AM

Take geometry manager and object manager required updates into consideration too.

@Kévin Dietrich (kevindietrich) I'll assume you're reviewing this patch now, unless you want me to have a look as well.

Looks good to me and it works fine.

This revision is now accepted and ready to land.Dec 14 2020, 11:42 AM