Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public static class Noise {
  6.  
  7. public static float Get2DPerlin (Vector2 position, float offset, float scale) {
  8.  
  9. return Mathf.PerlinNoise ((position.x + 0.1f) / VoxelData.ChunkWidth * scale + offset, (position.y + 0.1f) / VoxelData.ChunkWidth * scale + offset);
  10.  
  11. }
  12.  
  13. public static bool Get3DPerlin (Vector3 position, float offset, float scale, float threshold) {
  14.  
  15. float x = (position.x + offset + 0.lf) * scale;
  16. float y = (position.y + offset + 0.lf) * scale;
  17. float z = (position.z + offset + 0.lf) * scale;
  18.  
  19. float AB = Mathf.PerlinNoise(x, y);
  20. float BC = Mathf.PerlinNoise(y, z);
  21. float AC = Mathf.PerlinNoise(x, z);
  22. float BA = Mathf.PerlinNoise(y, x);
  23. float CB = Mathf.PerlinNoise(z, y);
  24. float CA = Mathf.PerlinNoise(z, x);
  25.  
  26. if ((AB + BC + AC + BA + CB + CA) / 6f > threshold)
  27. return true;
  28. else
  29. return false;
  30.  
  31.  
  32. }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement