Code Monkey home page Code Monkey logo

Comments (5)

Eldemarkki avatar Eldemarkki commented on May 17, 2024 1

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")

from marching-cubes-terrain.

Eldemarkki avatar Eldemarkki commented on May 17, 2024

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.

from marching-cubes-terrain.

ThisUserIsNobody avatar ThisUserIsNobody commented on May 17, 2024

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?

from marching-cubes-terrain.

ThisUserIsNobody avatar ThisUserIsNobody commented on May 17, 2024

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.

from marching-cubes-terrain.

Eldemarkki avatar Eldemarkki commented on May 17, 2024

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

from marching-cubes-terrain.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.