Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displacement mapping a.k.a. bump mapping at the slicing stage (reusing Fuzzy Skin backend code). #8649

Open
10 of 11 tasks
Poikilos opened this issue Aug 7, 2022 · 11 comments
Open
10 of 11 tasks

Comments

@Poikilos
Copy link

Poikilos commented Aug 7, 2022

Is your feature request related to a problem? Please describe.
Lol "I'm always frustrated when" the model I download is dozens of megabytes and runs at 1 frame per 2 seconds because the author had to apply a displacement map to the mesh with automatic subdivision, yet when I decimate it to 1/20 of its original file size the model isn't visibly different but navigation is smooth.

Describe the solution you'd like
I would like to help PrusaSlicer start an industry trend of allowing a displacement map to be applied during the slicing stage similar to the vb_fuzzy_skin branch. It is good for many simple tasks like brick walls, which are popularly uploaded to model sites with displacement maps applied. For example, https://www.thingiverse.com/thing:5190970 makes Blender run at 1 frame per 30+ sec on an old i7 while doing any editing causing 10% more sadness per frame.

Describe how it would work
For each island on a layer, the distance from the center of that island would be used to determine an arc length to map back to the texture using a pixels_per_mm value (that the user could set). For the vertical mapping, the z coordinate of the bottom of the layer + 1/2 of the layer height would be used instead, against the same pixels_per_mm value.

  • Using the arc length of a virtual circle it for consistency: It will ensure that the texture mapping doesn't result in moire-like patterns where the model has bumps (where the path has turns that differ on each layer).
  • An optional bump-degrees-as-mm mode can prevent texture skewing on models that taper, where keeping pixels aligned vertically is preferred over stretch prevention.

Describe alternatives you've considered

  • Adding a displacement map to the model may be more of a standard process and have shared code and respect original UV maps. However, this would only work for models designed with mapping in mind (properly UV mapped models). I know how to add a UV map myself and redo it to be tidy and even, but most people do not. Therefore, doing the process using math is more useful to more people. Doing it at the time of slicing will also save RAM (even in the slicing preview, only more segments not more triangles would be stored, so it would use geometrically less RAM). For use cases requiring accuracy, applying the displacement map in a modeling application is better and fits the use case of a modeling application better than a slicer.
    • If UV mapping could be applied at slice time (optionally), that would be ideal but may be very difficult to implement.
  • Decimating models isn't reliable. Though I said "when I decimate it to 1/20 of its original file size the model isn't visibly different," many 3D printable models are made by beginners, so in many cases decimation makes model errors (those identified by Blender's included 3D-Print Toolbox add-on, such as non-manifold edges) more difficult to fix or adds more self-intersecting geometry or visible glitches.

Additional context

Tasks:

  • fork the master branch using the web interface.
git clone https://github.com/Poikilos/PrusaSlicer.git
cd PrusaSlicer
git fetch -a
git switch displacement_map
  • Get PrusaSlicer to compile (and ensure that the Fuzzy Skin feature works).
  • Add settings (Simple category except maybe bump-degrees-as-mm in Advanced):
    • fuzzy_skin_displacement_map bump-map-path
    • (use existing fuzzy_skin_point_dist as pixels per mm if map path is not blank) bump-pixels-per-mm
    • (use existing) fuzzy_skin_thickness (default .3) bump-mm (default around 1) and bump-offset (around -.5 so gray means unchanged)
    • cube mapping (on 4/6 sides) to fix tapered objects without skewing (choose "face" based on angle from center of island then use distance from "left" of that face plus all faces from starting face's left to current face's left--this allows textures with something different on each side to work)
      • cube mapping based on normal
    • fuzzy_degrees_as_mm bump-degrees-as-mm to enable cylindrical mapping (0 for square mapping).
  • (implemented GetLuma) Load the map and read a pixel's brightness Luma from it, showing test output on the console to that effect.
  • Map the texture to the outer wall path of each island separately.
  • Ensure fuzz still works with the displacement mapping feature turned off (Implement fuzz on top of the new code if necessary).

Forum topic:

@Poikilos Poikilos changed the title Displacement mapping a.k.a. bump mapping at the slicing stage could be leveraged to provide paint-on fuzzy and fuzzy features and more. Displacement mapping a.k.a. bump mapping at the slicing stage (reusing Fuzzy Skin backend code). Aug 7, 2022
@Poikilos
Copy link
Author

Progress!
image

Poikilos added a commit to Poikilos/PrusaSlicer that referenced this issue Dec 24, 2022
@Poikilos
Copy link
Author

Poikilos commented Dec 24, 2022

Tasks:

  • Fix alignment
    image

Poikilos added a commit to Poikilos/PrusaSlicer that referenced this issue Dec 25, 2022
…rusa3d#8649). Flip y to fix image orientation. FIXME: "double free or corruption (!prev)" etc. thrown by libpng on changing images.
Poikilos added a commit to Poikilos/PrusaSlicer that referenced this issue Dec 28, 2022
…rusa3d#8649). Move image loading to the main thread for reliability.
Poikilos added a commit to Poikilos/PrusaSlicer that referenced this issue Dec 28, 2022
@Poikilos
Copy link
Author

It calculates normals! Cube mapping is complete!
2022-12-27b calculated-normals

@Poikilos
Copy link
Author

Poikilos commented Dec 28, 2022

With this 1024x1024 texture and large model (The 111x107.87x196 mm model shown), it seems to hang at 90% though the Export option is available (on i7-12000F and 16GB RAM, Fedora 37). After a few minutes it says Exporting.

:edit: It eventually saved correctly, after several minutes.

@adenta
Copy link

adenta commented Feb 6, 2024

So what ever came of this?

@Poikilos
Copy link
Author

Poikilos commented Mar 21, 2024

So what ever came of this?

You tell me...It works fine but no one noticed. Recently there was more discussion of this feature not existing here: 3D Print Any Texture You Want! on YouTube (he uses dense meshes, and both the description and comments say it is unfortunate the feature doesn't exist...)

@adenta
Copy link

adenta commented Mar 21, 2024

@Poikilos what do you mean noone noticed? Can we bundle this with Orca/Bambu perhaps?

@Poikilos
Copy link
Author

Well, I mean I thought more people might find, react, and discuss this issue, and maybe maintainers would put it up for discussion, since people talk about the feature a lot just not on GitHub :)

@adenta
Copy link

adenta commented Mar 22, 2024 via email

@Chocolateandmilkwin
Copy link

Sad that there isn't a star feature for issues, this would be such a huge addition for micro detailing.

@Poikilos
Copy link
Author

Poikilos commented Sep 9, 2024

Sad that there isn't a star feature for issues, this would be such a huge addition for micro detailing.

Well, you could react to the original post by clicking emoji then thumbs up, or in this case, click the thumbs up that is already there. Typically people add "thumbs up" on issues on GitHub, so maybe if enough people do, it will get traction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants