webik150

ProceduralAsteroid - Color assigner

Oct 31st, 2015
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. Color GetColorByCoordinate (float x, float y, float size, float seed)     //This code generates the colors. It's really simple, Mathf.PerlinNoise(x,y) returns float (0-1) according to the "height" of x and y.
  2.     {
  3.         if (Mathf.PerlinNoise ((seed + x) / size, (seed + y) / size) < deepOcean) {  //We take the height, and check for the apropriate layer. That's all.
  4.             return veryDeepOceanColor;            //The (seed+x) could be switched for some more complex calculation, but you can do that when assigning the seed. "/size" makes everything the right size.
  5.         }
  6.         if (Mathf.PerlinNoise ((seed + x) / size, (seed + y) / size) >= deepOcean && Mathf.PerlinNoise ((seed + x) / size, (seed + y) / size) < ocean) {
  7.             return deepOceanColor;
  8.         }
  9.         if (Mathf.PerlinNoise ((seed + x) / size, (seed + y) / size) >= ocean && Mathf.PerlinNoise ((seed + x) / size, (seed + y) / size) < shallowWater) {
  10.             return oceanColor;
  11.         }
  12.         if (Mathf.PerlinNoise ((seed + x) / size, (seed + y) / size) >= shallowWater && Mathf.PerlinNoise ((seed + x) / size, (seed + y) / size) < beach) {
  13.             return shallowWaterColor;
  14.         }
  15.         if (Mathf.PerlinNoise ((seed + x) / size, (seed + y) / size) >= beach && Mathf.PerlinNoise ((seed + x) / size, (seed + y) / size) < forest) {
  16.             return beachColor;
  17.         }
  18.         if (Mathf.PerlinNoise ((seed + x) / size, (seed + y) / size) >= forest && Mathf.PerlinNoise ((seed + x) / size, (seed + y) / size) < mountain) {
  19.             return forestColor;
  20.         }
  21.         if (Mathf.PerlinNoise ((seed + x) / size, (seed + y) / size) >= mountain && Mathf.PerlinNoise ((seed + x) / size, (seed + y) / size) < mountainHigh) {
  22.             return mountainColor;
  23.         }
  24.         if (Mathf.PerlinNoise ((seed + x) / size, (seed + y) / size) >= mountainHigh) {
  25.             return mountainHighColor;
  26.         }
  27.         return Color.magenta; //The error color. If you did something wrong, you'll see magenta.
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment