feat: include the voxel material in generated mesh#11
Draft
terrence2 wants to merge 1 commit into
Draft
Conversation
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


This third patch I'm not entirely sure how to get over the finish line and am looking for some feedback. While it works well enough for my own uses, it is currently a pretty significant performance regression to meshing in the general case.
What
In order to render a textured surface, we need to know what the voxel material is in the renderer somehow. There are two approaches one can take (at least that I've though of so far).
This works well with Bevy because you can slap a Material3d onto each of those Mesh3d and you're good to go. you can probably even do some tex-coord tricks to allow each face to have a different texture, at the cost of some flexibility. The downside is that you might be generating dozens of meshes per chunk and you'll need to either turn each of them into physics objects independently, or also generate a unified mesh for physics.
This takes quite a bit more effort with Bevy because you need either a custom material to deal with dense texture arrays, or lots of extra complexity to juggle texture atlases (assuming that would even work with 4k textures). The positive side is that you have a 1:1 relationship between chunks, meshes, and physics data that makes managing the ECS lifecycle much easier.
How
This adds a
materialfield to MeshData and populates it during meshing.Performance
This takes about a 10% performance hit (highly variable) on long tests and a random amount (up to 100%) for trivial tests. I suspect this is because we're allocating for a third vector, but haven't yet dug into the specifics.
Questions
Did I miss some subtle way to get textured voxels that already exists? Like, I figured out that you can use the position as an implicit texture coordinate for a voxel grid. Is there something similar I should be doing for the voxel data itself?
Is being able to render a textured voxelis chunk even a project goal at all? It seems like something that's going to be pretty commonly necessary, given that there are already two separate implementations, but I don't want to presume.
If you do want to support one of the strategies above, how big a performance hit is acceptable on the non-material-returning path? I'm pretty sure we should be able to put some traits in place to specialize both new with-material and unchanged without-material instruction streams from the same Rust code, but I haven't put in the work yet.
Have a great holiday! I'm not in a rush; we can discuss in more depth whenever you have some time to give it a think.