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

[Suggestion] Chunk Materials #14

Open
Ayliroe opened this issue Jun 26, 2022 · 3 comments
Open

[Suggestion] Chunk Materials #14

Ayliroe opened this issue Jun 26, 2022 · 3 comments

Comments

@Ayliroe
Copy link

Ayliroe commented Jun 26, 2022

Here's an implementation I found working you can add to your tutorial:

  • ChunkBase.h:
    image
    (A blueprint-accessible array for materials, plus arrays for the material struct and vertices instead of single values)

  • ChunkBase.cpp:
    image
    (On clearing, empty the arrays then refresh using the total amount of materials, not blocks)

  • NaiveChunk.cpp, in GenerateMesh():
    image
    (Get the material for the current block's face, minus 2 to skip null and air enums, clamp as a safety, then pass it to CreateFace() )

  • NaiveChunk.cpp, in CreateFace():
    image
    (Switch all mesh structs and the vertex int to the new arrays)

  • GreedyChunk.cpp, GenerateMesh():
    image
    (Same as NaiveChunk, but using CurrentMask.Block for the face's material)

  • ApplyMesh():
    image
    (First clear all previous sections, then generate a new one for each material on the chunk)

Basically the same code as before, but generates one unique section for each different block material. Straightforward to scale-up (just add materials to the array) and supports both naive/greedy meshing. Maybe you had something in mind too of the like.

@BLaZeKiLL
Copy link
Owner

I was pondering on the same issue for a while, I was thinking of having 2 Materials (One base martials with texture arrays) and one for fluids like water with some other effects, for a while I as thinking on creating 2 separate meshed that means 2 runs of meshing algorithms which won't be performant, Didn't think of mesh sections. this is a nice scalable solution. I'll be sure to include this and credit you.

Thanks

@jorgeEsat
Copy link

What is GetID on the third image?

@AnasTheDev
Copy link

@Ayliroe Hey man. I sadly cannot seem to get your code to work. mind adding me on discord so I can bother you there haha?
No seriously please add me on discord I really need the help here is my username "anasdev"

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

No branches or pull requests

4 participants