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 :: .net get system environment variable 
Csharp :: enumerable.range contains 
Csharp :: make http request c# 
Csharp :: c# convert int to string 
Csharp :: contains char c# 
Csharp :: c# loop through list of objects 
Csharp :: unity change cursor texture 
Csharp :: unity exception 
Csharp :: asp.net core get root url in view 
Csharp :: get width of image unity 
Csharp :: unity call function on animation end 
Csharp :: wpf app how to get all elements 
Csharp :: operator -- c# 
Csharp :: c# set datetime to null value 
Csharp :: c# get directory name from filename 
Csharp :: get text unity 
Csharp :: c# append array 
Csharp :: c# round double 
Csharp :: Gameobject.Find in unityC# 
Csharp :: 1 line if c# 
Csharp :: Customize yup number 
Csharp :: c# create tasks and wait all 
Csharp :: c# readline char 
Csharp :: check two lists are equal c# 
Csharp :: .net core partial view with model 
Csharp :: asp.net core miniprofiler 
Csharp :: array object to datatable c# 
Csharp :: how get data from json in c# 
Csharp :: click in vue 
Csharp :: get selected item datagrid wpf 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =