Zylann / godot_voxel

Voxel module for Godot Engine
MIT License
2.63k stars 247 forks source link

Number of materials #272

Closed Favkis closed 2 years ago

Favkis commented 3 years ago

Can I have more than 8 materials for blocks? Or at least simply textures I see that I can change color for blocks, but what about materials?

Zylann commented 3 years ago

I plan to lift the material limit for VoxelMesherBlocky. It was 8 originally because it was simpler to implement, and also this is plenty enough for Minecraft-like games (this one uses only 3 of the slots: https://github.com/Zylann/voxelgame). However keep in consideration that the more materials you use, the more draw calls it will need. So if voxel types have the same "effects" on them (opaque? transparent? animated?) then they should share their materials and use texture atlasing or texture arrays if possible.

Favkis commented 3 years ago

@Zylann ahh right, that makes sense. But here's the thing then. I was planning on having multiple 512x512 textures for blocks, however make it so that each block only draws 1/4 of texture depending on their coords (I still am not sure how to transfer voxel ID into shader), but if I'll use atlas for my 512x512 textures, that means if I want 64 textures, I'll have to have 8192x8192 textures for albedo, normal, roughness, metallic, and I'm not sure how new GPU have to be to even be able to load such large textures

Zylann commented 3 years ago

You can use large textures, or texture arrays. If you really dont want to go too high, you could split them up then.

Zylann commented 2 years ago

The material count limitation has been removed in 12862a46d046cb34b56e62bdc991eea7c6aba5d9. They are now defined in each VoxelBlockyModel (or in meshes directly). Baking automatically detects re-used materials, so atlasing is still a good idea to get fewer draw calls.

Zylann commented 2 years ago

The initial request was implemented, so this can be closed.

slakibk commented 2 years ago

Hello. I'm migrating my project (TERROVOX) to Godot 4. I don't understand how "material_override" works. I'm adding a new material, but the voxel is rendered using the base material. In shygu you wrote that the materials for each block are implemented separately, but for some reason it doesn’t work for me. image

Godot 16 alpha Voxel-tool 625e4536f12579b1c757afa275e19bded2ad9d72

P.S. Thanks for your work. Adding multiplayer and GI-Mode is something I really enjoy.

Zylann commented 2 years ago

Can you provide a minimal reproduction project showing the issue?

slakibk commented 2 years ago

I'm trying to set up an alpha channel in a separate grass material. To make it look like this: image

But for the voxel, the main material is taken in which the transparency is not turned off. image

Zylann commented 2 years ago

Grass looks like this because your VoxelTerrain has a material_override assigned. This will override any material produced by the mesher. You have to unassign the terrain material and assign materials in your library.

Also, one of your blocks (black core) has more than 2 surfaces (materials). The baking process doesn't support more than 2 per voxel.

slakibk commented 2 years ago

Thx