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 :: C# Console multi language 
Csharp :: how to check if textbox is empty in c# 
Csharp :: c# iterate over a dictionary 
Csharp :: c# winforms textbox to int 
Csharp :: get name of project c# .net 
Csharp :: how to execute linux command from c# 
Csharp :: c# hex to console color 
Csharp :: fluentassertions force exceptions 
Csharp :: void update 
Csharp :: c# string is not null or empty 
Csharp :: c# list index 
Csharp :: c# bcrypt 
Csharp :: c# send email 
Csharp :: using serial port in c# 
Csharp :: dotnet ef database update connection string 
Csharp :: shuffle arraylist c# 
Csharp :: How to get an array of months in c# 
Csharp :: how to set up blender with unity units 
Csharp :: c# write variable in string 
Csharp :: c# dictionary loop key value 
Csharp :: unity topdown movement 
Csharp :: c# append text to file 
Csharp :: how get query from url in laravel 
Csharp :: list all files in directory and subdirectories c# 
Csharp :: run wpf application maximized 
Csharp :: C# decimal with two places store as string with two places 
Csharp :: unity quaternion 
Csharp :: unity c# check how many of an object exists 
Csharp :: c# use hashtable check if key exists 
Csharp :: c# contains 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =