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

Improve worldgen #79

Closed
2 of 3 tasks
Unarelith opened this issue Mar 7, 2020 · 9 comments
Closed
2 of 3 tasks

Improve worldgen #79

Unarelith opened this issue Mar 7, 2020 · 9 comments

Comments

@Unarelith
Copy link
Owner

Unarelith commented Mar 7, 2020

@RobertZenz
Copy link

Ideally, the worldgen would actually be implemented in Lua, as part of the mod. That way mods can not only create their own terrain, but also you can stack mods to modify the world.

Of course, that comes at a certain speed cost and creating an API for that is non-trivial in my opinion, especially when considering the placement of decorations and structures like trees, which might overlap into neighboring, not yet created, chunks. Also noise functions should be wired to the Lua API, if not already done so. I have to say that I always struggled with finding a good solution for all that, and didn't come that far either. My approach was to simply hand the newly created chunk to the mods and let them modify it, but as I said, that comes with a few drawbacks.

Regarding caves, I'm not sure whether you've done research in that area already, but Minecraft uses Perlin Worms for their cave generation. Another interesting approach, for which I can't find the source anymore, is to combine two 3D noises and only use their overlaps. Something I've implemented here...which, might be hard to read, to be honest. The basic idea is to have noise A and B, and if the value of A falls into a certain range and the value of B falls into a certain range, it's a cave. With perlin noise this does produce tunnels which might or might not connect if you use middle values, like -0.5 to 0.5 (on a -1/1 scale).

@Unarelith
Copy link
Owner Author

Unarelith commented Apr 4, 2020

I completely agree that worldgen should be implemented in Lua.
However, I don't know how the API for that part will be implemented yet.

About caves, Minecraft doesn't use Perlin Worms for cave generation but instead a whole bunch of randomness and sin/cos shenanigans. I tried to read the code to understand and noticed that they're basically carving tunnels with a random direction. Unfortunately, I don't understand the whole thing enough to be able to make my own implementation yet.

I'd be interested to know more about your way tho if it is able to carve tunnels.

@RobertZenz
Copy link

RobertZenz commented Apr 23, 2020

Oh sorry, I missed your reply.

Oh dear I've finally found the article I was talking about! Was driving me crazy...anyway, as I've already typed it, here is a short explanation from my end anyway (in pseudo-Lua-code):

local noiseA = PerlinNoise(someParams)
local noiseB = PerlinNoise(similarParams)

-- Values have the range of -1/+1.
local valueA = noiseA.get(x, y, z)
local valueB = noiseB.get(x, y, z)

if (isBetween(valueA, -0.1, 0.1)) and isBetween(valueB, -0.1, 0.1)) {
    -- Air
else
    -- Rock
end

What we're basically doing is that we are using ridged perlin noise for the caves. By combining two noises we receive a more winding and interrupted cave system, but can still control its properties very well. For example one could stretch it to receive higher or less high caves. Additional noises can be added and so forth.

@Unarelith
Copy link
Owner Author

I already tried using ridged perlin noise for the caves here but the results were not so great.

Carved tunnels have the advantage of having coherent elevation and direction. Take this screenshot for example, they're not coherent:

screenshot-20200127215345

@RobertZenz
Copy link

What do you mean with "coherent" here? You mean that they should not branch like this?

@Unarelith
Copy link
Owner Author

On this picture you can see the problem:
Inked80282809-c22bcc00-8713-11ea-8947-ea70fe0b11b1_LI

The red arrows represent the direction of the tunnel, and the black arrows represent the direction of the elevation. When tunnels go from west to east, elevation goes from north to south: it's not coherent. Elevation should follow the direction of the tunnels.

@RobertZenz
Copy link

Do you mean the elevation of the tunnels themselves or the elevation of the terrain?

Regarding the terrain, I can very well imagine that one could offset the used noises based on the heightmap in that area. That way the tunnels would always mimic the overworld elevation.

@Unarelith
Copy link
Owner Author

Of the tunnels themselves, they shouldn't care about overworld elevation.

@RobertZenz
Copy link

Oh, now I think I get what you mean. You mean that the tunnels are going up and down with no direction in either. I never thought about that. I'm not sure whether that can be solved with my suggestion. I mean, my suggestion makes this a little bit better as it combines two ridged noises, creating less of a network and more of single tunnels, but still they will move in any direction in space.

If you want tunnels that primarily lead downward as they progress, I'm not sure how to hammer the noise in such a shape.

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

No branches or pull requests

2 participants