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

Ability to procedurally generate terrain using 3D noise #39

Open
ThisUserIsNobody opened this issue Jul 14, 2020 · 5 comments
Open

Ability to procedurally generate terrain using 3D noise #39

ThisUserIsNobody opened this issue Jul 14, 2020 · 5 comments
Labels
feature New feature

Comments

@ThisUserIsNobody
Copy link

I've been experimenting on this project for a bit now and the feature that I feel like could make a difference is adding the ability to generate a terrain using 3D noise.
This would give much more interesting results, with the things like overhangs, arches and etc..

@Eldemarkki
Copy link
Owner

A while ago I was playing around with 3d noise but didn't really bother polishing it. Could be a nice addition. If you want to try 3d noise yourself, you could tweak this line to use noise.snoise(int3), taking inspiration from the OctaveNoise() function below that line.

@Eldemarkki Eldemarkki added the feature New feature label Jul 14, 2020
@ThisUserIsNobody
Copy link
Author

Hey, I have tried changing this line to use float3 but I cannot get it to work or at least get any actual results. What I did is changed the OctaveNoise() function to accept additional float z parameter and have sent the x, y and z world position values when calling this method.

return worldPositionY - this.OctaveNoise(worldPositionX, worldPositionY, worldPositionZ, proceduralTerrainSettings.NoiseFrequency * 0.001f, proceduralTerrainSettings.NoiseOctaveCount) * proceduralTerrainSettings.Amplitude - proceduralTerrainSettings.HeightOffset;

When calling noise function I simply added z parameter and that's it

float pureNoise = (noise.snoise(new float3(octaveModifier * x * frequency, octaveModifier * y * frequency, octaveModifier * z * frequency)) + 1) / 2f;

But all I get is pretty much the same type of terrain. Seems like it's just a heightmap based terrain. Do I need to change something else?

@Eldemarkki
Copy link
Owner

Eldemarkki commented Jul 15, 2020

I got some kind of 3D noise working, here's how I did it:

public float CalculateVoxelData(int worldPositionX, int worldPositionY, int worldPositionZ)
{
    float voxelData = worldPositionY;
        
    // Create 3D noise in range [-1, 1]
    float overhang = noise.snoise(new float3(worldPositionX, worldPositionY, worldPositionZ) * ProceduralTerrainSettings.NoiseFrequency * 0.01f);

    // Remap the 3D noise to be in range [0, 1]
    overhang = (overhang + 1) * 0.5f;

    // Multiply it by some constant
    overhang *= 100;

    voxelData -= overhang;
    voxelData -= OctaveNoise(worldPositionX, worldPositionZ, ProceduralTerrainSettings.NoiseFrequency * 0.001f, ProceduralTerrainSettings.NoiseOctaveCount) * ProceduralTerrainSettings.Amplitude;
    voxelData -= ProceduralTerrainSettings.HeightOffset;
    voxelData *= 0.5f;
    return voxelData;
}

You can change the intensity of the 3D noise by changing the multiplier, which in this example is 100
It works, but sometimes the physics are questionable, to say the least:

picture of overhang floating in the air, not attached to the ground

There's also some artifacts, but I'm pretty sure thats coming from the noise.snoise function itself. The fix would be to use a different noise library, but I'm not sure how well that would go with the Burst compiler.
artifacts in the noise

Also, you said it just looks the same: If this doesn't fix it, make sure you are in the correct scene ("Procedural World Example")

@ThisUserIsNobody
Copy link
Author

Thanks! After playing around with some settings like frequency and amplitude I got some pretty interesting results!

Result

Although, there are a lot of floating parts. You think it's because of the noise function? I was thinking trying to check the size of the floating piece and if the element is big enough make the thing separate with its own collider and rigidbody and if it's small just remove it.
Although, I'm not sure how to detect these parts.

FloatingParts

I also tried to blend two noises together, to have like a flat land with occasional mountains, I managed to make something to the extent, but I got really hard edges when the mountain starts. I suppose I need to blend the heights? Not really sure how to tho.

@Eldemarkki
Copy link
Owner

Eldemarkki commented Jul 15, 2020

Although, there are a lot of floating parts. You think it's because of the noise function?

Yep.

I'm not sure how to detect these parts.

This could be done using the flood fill algorithm to detect different areas. One problem though would be the edges of the visible world, where the terrain has not yet been generated so you don't know if a part is either floating or attached to something that has not been loaded yet.

And about the biomes, see #40

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

No branches or pull requests

2 participants