-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add parallax mapping to bevy PBR #5928
Conversation
Demo available at https://nicopap.github.io/bevy_mod_paramap/ |
A few limitations to take into considerations:
|
fa34925
to
e1ff56f
Compare
Godot has the height map inverted too, but solves the confusion by simply calling it a depth map.
Godot doesn't seem to have that either, they suggest just using normal maps for that.
From what the parallax mapping that I've seen in other places so far, that seems to be a general limitation of parallax mapping if used on spheres. I'd love if this gets some more attention since parallax mapping generally looks amazing if it's used correctly! |
e1ff56f
to
bf4029f
Compare
Haven't looked at the PR beyond quickly skimming the code, but I'd like more documentation from the user's perspective. I'm not familiar with parallax mapping - it's some kind of normal map like technique? The StandardMaterial fields should have some documentation explaining what parallax mapping is, briefly how it differs from normal maps, and when/why you would want to use it :) |
df6d844
to
b8e9292
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly minor changes to clean things up. One minus sign that seems out of place in bitangent calculation. And maybe making the number of Relief Mapping steps configurable.
a2f47b9
to
ac509de
Compare
ac509de
to
b7ca6ec
Compare
For those following along, this stalled a bit as I wanted to understand from where the As I dug into it, I understood that the Also, I felt it would be more intuitive for understanding the algorithm to have the tangent space view vector pointing into the surface and step along it through the depth layers. By passing And finally, because the texture we use has a value of 0 meaning no depth below the geometric surface, and 1 meaning maximum depth, I felt it appropriate to rename PR here: nicopap#1 |
b544fba
to
d1281ae
Compare
ffb9d30
to
e0f78b6
Compare
@robtfm I feel like requiring |
Not requiring a feature would be great... and worth the extra 100KB for me. Most of the size increase comes from the first one, we could make it smaller if that's still an issue for you |
Also the examples failed on windows saying something about the lip falling to complete after 1009 iterations. When testing locally I did notice a little stuttering but I was doing other stuff on my laptop so I didn’t think anything of it. Though I did wonder if it was related to tracing rays at glancing angles. |
@mockersf I have the clean base assets I can generate better pngs. Note that when I run
So in terms of user experience, this is fine IMO, as the solution is directly given to the user. And in any case, teaching them to use the proper bevy features is better in an environment where failure to do so results in the program not running rather than assets mysteriously not loading. But you are probably worrying about compilation time of examples right? How much of a worry is this? @superdump Ahah! I happen to only have a very weak Windows machine with a very not modern GPU on hand, so it's going to be hard for me to test out. It seems possible to trigger nagga compilation for Dx12 on linux though? Just for checking? How would I go about that? |
Yup it's mostly fine... but from a user point of view, it means they can't simply try one example after the other, they will have recompilation when switching between examples with different required features. From a CI point of view, it means we'll have to add special case when building examples for tests in CI, or for building the website example page. Or for https://rparrett.github.io/prototype_bevy_example_runner/ Unless really necessary, not requiring a feature for any example is simpler. |
You make a compelling case. I'll swap the assets for pngs. |
Todo when/if this gets merged: Open a tracking issue on possible parallax mapping improvements, ordered by complexity, from easiest to most complex.
|
Objective
Add a parallax mapping shader to bevy. Please note that
this is a 3d technique, NOT a 2d sidescroller feature.
Solution
StandardMaterial
A pre-existing implementation exists at:
https://github.com/nicopap/bevy_mod_paramap/
The implementation is derived from:
https://web.archive.org/web/20150419215321/http://sunandblackcat.com/tipFullView.php?l=eng&topicid=28
Further discussion on literature is found in the
bevy_mod_paramap
README.Limitations
in artifacts for depth-dependent features such as fog or SSAO
always need to work around this limitation, though an extension is in
the works
Future work
parallaxed texture. This would enable interop with depth-based
visual effects, it also allows
discard
ing pixels of materials whencomputed depth is higher than the one in depth buffer
on distant objects
implemented through a blender plugin to the GLTF exporter that
uses the
extras
field to add height map.mapping on bending surfaces and allow clean silhouetting.
preprocessing, increase depth map size, reduces sample count greatly.
2023-03-07.23-02-45.mp4
Changelog
depth_map
field to theStandardMaterial
, it is a grayscaleimage where white represents bottom and black the top. If
depth_map
is set, bevy's pbr shader will use it to do parallax mapping to
give an increased feel of depth to the material. This is similar to a
displacement map, but with infinite precision at fairly low cost.
parallax_mapping_method
,parallax_depth_scale
andmax_parallax_layer_count
allow finer grained control over thebehavior of the parallax shader.
parallax_mapping
example to show off the effect.