- Home /
3d Perlin Noise?
Hey everyone,
Been looking into procedural terrain generation for quite some time. Just looking at perlin noise now. However I want my terrain to have overhangs and caves etc (i'm going to create my own meshes instead of using unity's terrain). In researching this I've found I should use 3D Perlin noise, and use the noise value as density (= 0 = ground). Just wondering how in unity I can make 3D perlin noise? Should I still use mathf.perlinnoise in some way? Also how can I make the terrain more believable instead of just a block of holes and rocks?
Thanks in advance! Chris
Looked up perlin worms, cant find very much about how to use it?
bigmisterb has written a good description here : http://forum.unity3d.com/threads/adding-detail-to-procedurally-generated-terrain.240756/#post-1603421
edit : and similar : http://www.roguebasin.com/index.php?title=Basic_directional_dungeon_generation
Answer by maccabbe · Apr 01, 2015 at 11:22 PM
http://answers.unity3d.com/questions/357710/c-implementing-3dperlinsimplex-noise.html http://answers.unity3d.com/questions/646054/perlin-noise-for-3d-voxel-terrain.html
http://forum.unity3d.com/threads/coherentnoise-procedural-generation-library-released.91784/
http://webstaff.itn.liu.se/~stegu/TNM022-2005/perlinnoiselinks/perlin-noise-math-faq.html
Answer by FM-Productions · May 27, 2017 at 03:37 PM
Hi,
the Youtube channel Brackeys just released a video about this topic 2 days ago. Maybe you want to check it out:
https://www.youtube.com/watch?v=vFvwyu_ZKfU
Things like caves are not explained in the video, but maybe it will help.
Yeah that's not 3D mate. It's 2D noise used as a heightmap.
Answer by danrayson · Sep 27, 2019 at 09:12 PM
I was banging my head trying to get rid of the artefacts I kept seeing in the naive approach, which was found here https://www.youtube.com/watch?v=Aga0TBJkchM:
public static float PerlinNoise3D(float x, float y, float z)
{
float xy = Mathf.PerlinNoise(x, y);
float xz = Mathf.PerlinNoise(x, z);
float yz = Mathf.PerlinNoise(y, z);
float yx = Mathf.PerlinNoise(y, x);
float zx = Mathf.PerlinNoise(z, x);
float zy = Mathf.PerlinNoise(z, y);
return (xy + xz + yz + yx + zx + zy) / 6;
}
That approach may work in some cases, but for my work I kept seeing symmetrical lines throughout the data. It turns out that it was mirroring along all three axis! Terrible for a noise function to give you symmetry :)
Eventually I worked this out:
public static float PerlinNoise3D(float x, float y, float z)
{
y += 1;
z += 2;
float xy = _perlin3DFixed(x, y);
float xz = _perlin3DFixed(x, z);
float yz = _perlin3DFixed(y, z);
float yx = _perlin3DFixed(y, x);
float zx = _perlin3DFixed(z, x);
float zy = _perlin3DFixed(z, y);
return xy * xz * yz * yx * zx * zy;
}
static float _perlin3DFixed(float a, float b)
{
return Mathf.Sin(Mathf.PI * Mathf.PerlinNoise(a, b));
}
I haven't seen any artefacts in it yet.
Hope that helps you out!
EDIT: I've seen some case where there are lines again, but I'm sure someone cleverer than me an iron them out.
Perlin noise is mirrored around zero. You have to offset the xyz input. This can be done by finding the greatest negative x, y and z values and adding them as absolute values to each xyz input.
Your temporary fix was done by adding a constant offset. This is also a valid solution if your offset is high enough to map all x, y and z values positive or negative.
Your answer
Follow this Question
Related Questions
2D Procedural Terrain Generation 1 Answer
Make a high poly count plane with code 0 Answers
How to procedural generation 0 Answers
Procedural Terrain Generation on a Map the Scale of the Milky Way 2 Answers
Diamond Square Algorithm 2 Answers