Texture2D CreateTexture() { Texture2D texture = new Texture2D(width, height); Vector2 offset = new Vector2(offsetX, offsetY); float[,] noiseMap = Noise.CalculateNoise(width, height, scale, octaves, persistance, lacunarity, offset); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Vector2 position = new Vector2(x, y); TerrainType terrain = GetTerrainFromNoise(noiseMap[x, y]); terrainMap[x, y] = terrain; switch (terrain) { case TerrainType.ROCK: texture.SetPixel(x, y, Color.black); break; case TerrainType.ROCKFLOOR: texture.SetPixel(x, y, new Color(0.64f, 0.16f, 0.16f)); break; case TerrainType.GRASS: texture.SetPixel(x, y, Color.green); break; case TerrainType.TREE: texture.SetPixel(x, y, new Color(0, 0.5f, 0)); break; case TerrainType.WATER: texture.SetPixel(x, y, new Color(0, 0, 0.5f)); break; } } } CreateResources(); texture.Apply(); return(texture); }
public void Execute(int index) { var noiseMetaInfo = NoiseMetaInfos[index]; if (noiseMetaInfo.ArchetypeChunkCalculationIndicator == CalculationIndicator.Free) { return; } var chunk = noiseMetaInfo.ArchetypeChunk; var noiseCalculations = chunk.GetBufferAccessor(NoiseCalculationType); for (var i = 0; i < noiseMetaInfo.ArchetypeChunkNoiseMetaInfoSize; i++) { var archetypeChunkNoiseMetaInfo = noiseMetaInfo[i]; if (archetypeChunkNoiseMetaInfo.CalculationIndicator == CalculationIndicator.Free) { continue; } for (int j = archetypeChunkNoiseMetaInfo.StartingIndex, fraction = 0; j <= archetypeChunkNoiseMetaInfo.EndingIndex; j++, fraction++) { var noiseCalculation = (NoiseCalculation *)noiseCalculations[j].GetUnsafePtr(); var fromIndex = archetypeChunkNoiseMetaInfo.CurrentFraction(fraction) * PartSize; for (var k = 0; k < Size; k++) { var currentIndex = fromIndex + k * 4; noiseCalculation[k] = Noise.CalculateNoise( Location.NextIndexes(currentIndex), archetypeChunkNoiseMetaInfo.PositionOffset, MeshAbout ); } } } }