Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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;
  }
}
Comment

3d perlin noise unity

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;
}
Comment

unity get perlin noise 3d

    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;
    }
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to move object with keyboard in unity 3D 
Csharp :: unity actions 
Csharp :: linq where 
Csharp :: c# how to call a method from another class 
Csharp :: c# check lenght 
Csharp :: c# Get all class by namespace 
Csharp :: index of item in list C# 
Csharp :: what is type unity 
Csharp :: camera follow script car unity 
Csharp :: jagged array c# 
Csharp :: divide string in chunks c# 
Csharp :: NET Framework 4.7.1 or a later update is already installed on this computer. 
Csharp :: how to stop animation unity 
Csharp :: Convert array of strings to List<string 
Csharp :: calculate distance using latitude and longitude c# 
Csharp :: unity rewarded ads 
Csharp :: .net core copy directory to output 
Csharp :: How can I return image from controller asp.net 
Csharp :: datetime check null c# 
Csharp :: dotnet automapper.extensions.microsoft.dependencyinjection 
Csharp :: timespan to integer c# 
Csharp :: how to make a character run in unity 
Csharp :: arcane 
Csharp :: exceldatareader example c# 
Csharp :: how to print statement in c# 
Csharp :: c# today without time 
Csharp :: change size of a unity object 
Csharp :: c# convert enumb to int array 
Csharp :: linq query select where c# 
Csharp :: how to make player movement in unity 2d 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =