Thursday, July 20, 2023

3D Landscapes


I has been a couple days, but it wasn't for working. After my day job tasks (senior programmer for a web marketing and development company started in 2003) were completed I kept working on Scavenge. Working on the landscape generation to be exact.

For now the Biome Generator is separated from the Landscape Generator for two reasons. 1) Easy to track bugs, and 2) I haven't implemented SQLite3 into the project yet. I didn't want to add another layer of difficulty right now. They are two separate systems (set of algorithms) anyways, and should be as self-contained as possible (ready for multithreading as well).

Soon, once I'm happy with the Landscape Generator I will bring in the biome results which will influence how each chunk would be formed. For now it's not needed to get started because I'm starting with a 16x16x384 chunk. 16x16x320 starts as "Air" and the remaining 16x16x64 starts as "Land" with 16x16x64 exactly marked as "visible/exposed." This is to help performance, but the future holds more of the performance optimization work. I mostly need to test and not have an FPS of 1.

Once I had that I wanted to be able to perform calculations and algorithms on the "chunk grid." I wanted to start with "cutting" land whenever I want to, in a "radius" (I have to use quotes because the world is made up of cubes, so there isn't much of a sphere or round shape), and at whatever level I want in the "world" that is, currently just a chunk.


Yep, it's a cube. Why is it a cube? I had "cut" a hole into the land, and everything outside of the hole is marked as "exposed." Here is inside the cube, or land.


As you can see, it's a "hole" and it's just part of the entire grid now. This hole in this example was set to a radius of 6, starting at layer/level 8. This is great, but I want to start generating interesting landscape, and ultimately caves and caverns. We will see how far I can get before I might have to seek help or advice from others willing.

Here is a simple noise (library provided by "SpiderPig" at Leadwerks/UltraEngine) algorithm thrown into the mix without much instruction.


You're like "whaaaat," and I'm like "right?" It does work. The top and bottom floor is the result of "exposure" or otherwise I wouldn't see that the top and bottom are working. This is a simple noise, added at layer 1, with a max layer of 6. I thought it was weird, but it's actually pretty cool once you go inside. It's kind of like a maze with no ending and a bunch of dead-ends.


Of course, you will have to mind the constant white block colors. I will eventually add textures. This would be a stone cave dead-maze anyways.

I added basic algorithms to be able to mix noise maps, and try to do something interesting.

The noise results are in range from -0.5 to 0.5. I have helper functions (currently stored in each layer to perform operations on its own layer and/or with a passed in grid or layer) to average point by point between layers or grids, smoothing and interpolation calculations point by point on itself, and in combination with a passed in grid or layer, and so forth.

A single smoothing operation gives me this result.


It looks the same, but now there seems to be more "room" compared to the other result. I need a 2D texture of the resulting blend to figure out what is going on exactly.

No operations. Original Noise Results.


After smoothing operations.


That explains why it seemed like there was more "room" inside the ceiling and ground. This is exactly what I wanted these operations to do, and now I can keep going.

Here is how the smoothing blended layers look as a new function I made that let's me directly insert chunks and grids (I should have mentioned earlier; a chunk is 16x16x384 and a grid is 16x16, a chunk is 3D and a grid is 2D) into the main chunk.


As we can see, this can represent as the ground. If we combine multiple layers they could be caves. I think? Can I get away with that?

However, this looks just... noisey. There doesn't seem to be any rhyme or reason to the blocks.

Time to try out a few more of the algorithm functions I made earlier, and I'm going to blend an averaging algorithm.


It might be hard to tell but each pixel is one "step" either higher or lower than it's neighbor. It tries it's best to anyway. Here is the 3D version.


As you may be able to see, again colors would help in the future, but each block has a neighbor that is only a block higher or lower. This looks way less chaotic.

How do I make this a cave?

For now, a simple: cut_ceiling()


Nice! It looks like a cave to me. Except that it's small. There is also a problem.


These are uniform, and we don't want that. We need to fix that by shifting along the noise map, perform our operations, and then insert it into the landscape.



No longer uniform. That's one chunk though. I will fill the rest of the layers up to Sea Level and call it a day.




Until next time!

Thanks for reading!


No comments:

Post a Comment

3D Landscape Basic Textures

 I thought I would add a couple textures so it wasn't just white. This is by no means a representation of what the landscape will look l...