Back again on the Block Game..
Last time I left off wanting to replace the basic UV test shader with a proper texture. Thankfully this was pretty easy:
The usual scene, but with the UV test shader replaced with a simple, stoney texture.
That's looking better...but maybe it was too easy. So let's go to the next step: multiple block types!
Before we add that, we need to address something first. A mesh can only have one (albedo) texture, but our chunk meshes need to represent multiple textures. I'm sure there's many solutions to this but the one I (and minecrap) went with is to cram all the textures into a single atlas. We can then have a mesh display the correct texture by using the appropriate UV coordinates.
To generate the atlas, I'm using this algorithm by lisyarus. Before moving forward, I set the Chunk material to use the generated atlas as a texture to test it out:
The scene now has each voxel use the entire atlas as a texture.
Yup, that sure is an atlas!
To get the UVs, I'm giving each texture in the atlas an ID, then creating an ID-to-UV map. I'm storing the atlases (and other related things) in a singleton called AtlasManager.
To start the structure for different voxel types, I also made a VoxelManager singleton. It's currently creating its voxel types in code, but I'd like to make them actual saved Resources at some point.
Finally, I updated the temporary "worldgen" code to randomly pick from the registered blocks. I also added some logic for the player to cycle between which voxels they can place:
The scene, now randomly made up of two types of blocks. Two size-2 cubes made of a different material each are build in front of the archway.
Nice, now the game is starting to vaguely look somewhat kind of like a real game, maybe!
And I think I'm gonna call it on that note. In fact, I'll be pausing this project for now. I've been working on this for a few days now and there's a lot of other projects (SFTA included) that I need to get back to, but I'll be coming back to this eventually!
Until next time..











