public override object GetValue(NodePort port) { var graph = (Terra2DGraph)this.graph; if (graph.isComputing) { try { currentState = GetCurrentState(); if (currentState != previousState) { noise = NoiseGenerator.FractalNoise(graph.seed.GetHashCode(), graph.size, offset, noiseType, fractalType, depth, frequency); if (normalize) { noise = noise.MapToRange(0, 1); } previousState = currentState; } return(noise); } catch (System.Exception e) { graph.isComputing = false; throw e; } } return(null); }
public static Texture2D ValueMapToTexture2D(ValueMap map) { map.MapToRange(0, 1); Texture2D texture = new Texture2D(map.Width, map.Height); Color[] colors = new Color[map.Width * map.Height]; for (int x = 0; x < map.Width; x++) { for (int y = 0; y < map.Height; y++) { colors[x + y * map.Width] = new Color(map[x, y], map[x, y], map[x, y]); } } texture.SetPixels(colors); texture.Apply(); return(texture); }