3d perlin noise unity

// HOW TO IMPLEMENT A PERLIN NOISE FONCTION TO GET A TERRAIN HEIGHT IN UNITY
using UnityEngine;

public static class NoiseCreator
{  
  /// scale : The scale of the "perlin noise" view
  /// heightMultiplier : The maximum height of the terrain
  /// octaves : Number of iterations (the more there is, the more detailed the terrain will be)
  /// persistance : The higher it is, the rougher the terrain will be (this value should be between 0 and 1 excluded)
  /// lacunarity : The higher it is, the more "feature" the terrain will have (should be strictly positive)
  public static float GetNoiseAt(int x, int z, float scale, float heightMultiplier, int octaves, float persistance, float lacunarity)
  {
      float PerlinValue = 0f;
      float amplitude = 1f;
      float frequency = 1f;

      for(int i = 0; i < octaves; i++)
      {
      	 // Get the perlin value at that octave and add it to the sum
		 PerlinValue += Mathf.PerlinNoise(x * frequency, z * frequency) * amplitude;
         
         // Decrease the amplitude and the frequency
         amplitude *= persistance;
         frequency *= lacunarity;
      }
      
      // Return the noise value
      return PerlinValue * heightMultiplier;
  }
}

4.33
3
Ottenalm 170 points

                                    public static float[] GenerateNoiseMap(int mapWidth, int mapHeight, int seed, float scale, int octaves, float persistance, float lacunarity, Vector2 offset)
{
&nbsp;&nbsp;&nbsp;&nbsp;float[] noiseMap = new float[mapWidth * mapHeight];
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;var random = new System.Random(seed);
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;// We need atleast one octave
&nbsp;&nbsp;&nbsp;&nbsp;if (octaves &lt; 1)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;octaves = 1;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;Vector2[] octaveOffsets = new Vector2[octaves];
&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 0; i &lt; octaves; i++)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float offsetX = random.Next(-100000, 100000) + offset.x;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float offsetY = random.Next(-100000, 100000) + offset.y;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;octaveOffsets[i] = new Vector2(offsetX, offsetY);
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;if (scale &lt;= 0f)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scale = 0.0001f;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;float maxNoiseHeight = float.MinValue;
&nbsp;&nbsp;&nbsp;&nbsp;float minNoiseHeight = float.MaxValue;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;// When changing noise scale, it zooms from top-right corner
&nbsp;&nbsp;&nbsp;&nbsp;// This will make it zoom from the center
&nbsp;&nbsp;&nbsp;&nbsp;float halfWidth = mapWidth / 2f;
&nbsp;&nbsp;&nbsp;&nbsp;float halfHeight = mapHeight / 2f;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;for (int x = 0, y; x &lt; mapWidth; x++)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (y = 0; y &lt; mapHeight; y++)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float amplitude = 1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float frequency = 1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float noiseHeight = 0;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 0; i &lt; octaves; i++)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float sampleX = (x - halfWidth) / scale * frequency + octaveOffsets[i].x;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float sampleY = (y - halfHeight) / scale * frequency + octaveOffsets[i].y;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Use unity's implementation of perlin noise
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float perlinValue = Mathf.PerlinNoise(sampleX, sampleY) * 2 - 1;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;noiseHeight += perlinValue * amplitude;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;amplitude *= persistance;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;frequency *= lacunarity;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (noiseHeight &gt; maxNoiseHeight)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maxNoiseHeight = noiseHeight;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else if (noiseHeight &lt; minNoiseHeight)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;minNoiseHeight = noiseHeight;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;noiseMap[y * mapWidth + x] = noiseHeight;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;for (int x = 0, y; x &lt; mapWidth; x++)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (y = 0; y &lt; mapHeight; y++)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Returns a value between 0f and 1f based on noiseMap value
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// minNoiseHeight being 0f, and maxNoiseHeight being 1f
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;noiseMap[y * mapWidth + x] = Mathf.InverseLerp(minNoiseHeight, maxNoiseHeight, noiseMap[y * mapWidth + x]);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;return noiseMap;
}

4.33 (3 Votes)
0
4.1
10

                                    public static float Perlin3D(float x, float y, float z, float density, float scale){
  float XY = Mathf.PerlinNoise(x, y);
  float YZ = Mathf.PerlinNoise(y, z);
  float ZX = Mathf.PerlinNoise(z, x);
  
  float YX = Mathf.PerlinNoise(y, z);
  float ZY = Mathf.PerlinNoise(z, y);
  float XZ = Mathf.PerlinNoise(x, z);
  
  float val = (XY + YZ + ZX + YX + ZY + XZ)/6f;
  return val * scale;
}

4.1 (10 Votes)
0
3.9
10

                                    Mathf.PerlinNoise(x, y); // Returns a value between 0.0 and 1.0

3.9 (10 Votes)
0
5
1
Insane 70 points

                                    Mathf.PerlinNoise(x, y); //Return value is between 0.0 and 1.0

5 (1 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
perlin noise asset unity how to use perlin noise in 3d in unity perlin noise unity object movement unity alternative to perlin noise 3d perlin noise terrain perlin noise for 2d game Unity 2020 3d perlin noise 3d perlin noise unity 2020 Perlin noise gives same output unity unity perlin noise complete algorithm unity perlin noise algorithm is unity perlin noise open source unity build a 3d object from perlin noise perlin noise source code unity 3d perlin noise source code unity unity perlin noise script unity perlin noise vs unity perlin noise doenst work 2d perlin noise unity perlin noise plane how to use perlin noise in unity jobs perlin noise unity blocks unity perli n noise perlin noise unity script perlin noise script unity &quot;Make Some Noise&quot; perlin noise script unity unity + perlin noise generate a points using perlin noise unity unity editor using Perlin Noise homemade perlin noise unity function to create perlin noise unity 3d perlin noise for unity perlin noise 3d unity unity perlin noise 3d perlin noise plane unity perlin noise 3d terrain unity perlin noise ground unity perlin noise textures ground unity perlin noise textures unity perlin noise texture unity generate perlin noise how to make perlin noise in unity c# how to make perlin noise in unity unity perlin noise seed unity perlin noise movement unity perlin noise output perlin noise perlin noise 3d python perlin noise how to generate perlin noise perlin noise rules 3d perlin noise equation c# unity perlin noise 3d equation c# unity Simple 3d perlin noise to voxel unity unity c# 3d perlin noise using perlin noise on unity terrain unity perlin noise terrain unity terrain perlin noise perlin noise low poly unity unity advanced perlin noise unity perlin noisew create mesh with perlin noise unity how does 3d perlin noise work 3d perlin noise unity perlin noise terrain unity perlin noise algorithm in unity 3d how to use perlin noise in unity unity generate 3d perlin noise generate perlin noise unity c# unity better perlin noise unity perlin noise fall off perlin noise generator unity unity mesh perlin noise 3d perlin noise perlin noise library unity unity how to have edit perlin noise to look good perlin noise sampling at float unity + simple noise function perlin noise unity terrain perlin nosie unity perlin noise unity example unity 3d noise c# get perlin noise values perlin noise c# without unity Use time with perlin unity unity 2d all types of mathf noises unity 2d perlin noise perlin noise infinite unity level how to make a moving perlin noise generation unity unity noise script unity Mathf.perlinNoise unity mathf perlin noise generator UNITY mATHF NOISES unity how to use perlin noise to make waves applying noise map Unity how to make 2d noise terrain unity unity voronoi noise unity steps sounds are noisy perlinnoise unity read perlin noise from texture unity perlin noise mask unity perllin noise unity perlin noise c# Mathf.perlinnoise in unity making noise move unity unity add noise to value fastest noise function unity get perlin noise unity generation c# generate noise perlin c unity noise perlin a unity noise perlin n unity noise perlin unity noise perlin noise as texture unity perlin noise colour unity Mathf.PerlinNoise edge how fast is mathf perlin noise unity unity math noise plugin mathf.perlinnoise terrain change mathf.perlinnoise scale unity two perlin noise unity getnoise perlin noise function csharp unity custom perlin noise 2d perlin c# unity unity perlin noise center unity simplex noise texture generate noise unity get perlinnoise Detect perlin noise in Unity Create noise in Unity 1d perlin noise in unity add perlin noise on a line in unity generate 1d perlin noise on a line in unity 1d perlin noise unity coding 1d perlin noise in unity combine perlin noise blocks unity c# perlin noise algorithm unity perlin noise unity texture Generate perlin noise map unity c# Generate perlin noise map unity c3 set steps unity perlin noise perlin noise in unity mathf.perlinnoise time noise float unity perlin noise c# unity perlin noise unity 3d terrain unity software nise unity perlin noise generation unity noise vs random perlin noise unity y coord noise function c# mathf perlin noise unity create a noise texture unity unity random noise Perlin noise in C# get y value based off of perlin noise unity generate random perlin noise image unity perlin noise texture unity perlin noise material unity perlin noise texture in unity unity perlinnoise class unity perlinnoise noise unity unity perlin noise 2d dunity does perlin noisee require floats unity perlin noise method unity 3d noisemap generate perlin noise c# perlin noise 2d terrain generation c# unity 3d perlin noise unity plerlin noise exmaple generate perlin noise with size x and y unity perlin noise 2d unity unity noise generator how to use perlin noise unity noise function hsl unity white noise texture generator + c# generate white noise teture c# generate white noise texture Unity unity Create white noise texture noise + unity textures + unity + perlin perlin noise unity c# how to apply noisemap unity c# mathf perlinnoise uniyt material based off of perlin noise unity unity noise texture unity random noise texture uinty pixel animation pixels randomly noise how to check if x value on perlinnoise unity c# check a sertain value on perlinnoise unity c# mathf.perlinnoise unity if statement c# mathf.perlinnoise unity c# how to check where on perlin noise to place objects unity c# unity noise sprite texture perlin noise on sprite unity perlin noise Unitu unity noise map C# perlin noise unity noise unity perlin noise c sharp perlin noise mathf perlin noise unity
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source