public void CreateSphericalPerlinTexture(ref byte[] height, ref byte[] normal) { /* * Generate a spherical mapping of a height and normal map */ int mapX = 512; int mapY = 256; float south = -90.0f; float north = 90.0f; float west = -180.0f; float east = 180.0f; Perlin myPerlin = new Perlin(); Texture2D heightTexture, normalTexture; ModuleBase myModule = myPerlin; Noise2D heightMap; heightMap = new Noise2D(mapX, mapY, myModule); heightMap.GenerateSpherical(south, north, west, east); /* Get the heightMap, which is just a grayscale of the texture */ heightTexture = heightMap.GetTexture(LibNoise.Unity.Gradient.Grayscale); height = heightTexture.EncodeToPNG(); /* Get the normal map. */ normalTexture = heightMap.GetNormalMap(0); normal = normalTexture.EncodeToPNG(); //SAVE THE PICTURE SaveTexture(heightTexture); }
void GeneratePreview() { var volumeColors = new Color[_res * _res]; if (_previewTexture != null) { DestroyImmediate(_previewTexture); } _previewTexture = new Texture2D(_res, _res); _previewTexture.wrapMode = TextureWrapMode.Clamp; _previewTexture.filterMode = FilterMode.Point; _previewTexture.hideFlags = HideFlags.DontSave; if (_previewTextureNM != null) { DestroyImmediate(_previewTextureNM); } var noise = new Noise2D(_res, _res, CreateNoiseModule()); noise.GeneratePlanar(0, _size, 0, _size, _seamless); for (int x = 0; x < _res; x++) { for (int y = 0; y < _res; y++) { var idx = x + (y * _res); volumeColors[idx] = noise[x, y] * Color.white; } } _previewTexture.SetPixels(volumeColors); _previewTexture.Apply(); if (_normalMap) { _previewTextureNM = noise.GetNormalMap(2.0f); _previewTextureNM.wrapMode = TextureWrapMode.Clamp; _previewTextureNM.filterMode = FilterMode.Point; _previewTextureNM.hideFlags = HideFlags.DontSave; } }
public override bool Calculate() { _input = inputKnob.GetValue <ModuleBase>(); var noiseRenderer = new Noise2D(_previewSize, _input); ConfigureRenderer(noiseRenderer); if (outputKnob.connected()) { var output = noiseRenderer.GetTexture(); outputKnob.SetValue <Texture>(output); } if (normalMapOutputKnob.connected()) { var output = noiseRenderer.GetNormalMap(1); normalMapOutputKnob.SetValue <Texture>(output); } return(true); }
public override void Initialise(GraphicsDevice device, ContentManager content) { m_graphics = device; m_spriteBatch = new SpriteBatch(device); m_content = content; // Create the module network add = new Add(perlin, rigged); // Initialize the noise map m_noiseMap = new Noise2D(256, 256, add); m_noiseMap.GeneratePlanar(-1, 1, -1, 1); // Generate the textures m_textures[0] = m_noiseMap.GetTexture(m_graphics, Gradient.Grayscale); m_textures[1] = m_noiseMap.GetTexture(m_graphics, Gradient.Terrain); m_textures[2] = m_noiseMap.GetNormalMap(m_graphics, 3.0f); // Zoom in or out do something like this. m_noiseMap.GeneratePlanar(-1 * zoom, 1 * zoom, -1 * zoom, 1 * zoom); m_textures[3] = m_noiseMap.GetTexture(m_graphics, Gradient.Terrain); }
void GenerateTexture() { var volumeTex = new Texture3D(_res, _res, _res, TextureFormat.ARGB32, false); var volumeColors = new Color[_res * _res * _res]; var volumeTexNM = new Texture3D(_res, _res, _res, TextureFormat.ARGB32, false); var volumeColorsNM = new Color[_res * _res * _res]; EditorUtility.ClearProgressBar(); var noise = new Noise2D(_res, _res, CreateNoiseModule()); for (int z = 0; z < _res; z++) { noise.zValue = _zCurve.Evaluate(((float)z / _res)) * _size; noise.GeneratePlanar(0, _size, 0, _size, _seamless); for (int x = 0; x < _res; x++) { for (int y = 0; y < _res; y++) { var idx = x + (y * _res) + (z * (_res * _res)); volumeColors[idx] = noise[x, y] * Color.white; } } if (EditorUtility.DisplayCancelableProgressBar("3D Noise", "Generating 3D Noise", (float)z / _res)) { DestroyImmediate(volumeTex); EditorUtility.ClearProgressBar(); return; } var nm = noise.GetNormalMap(1.0f); var pixels = nm.GetPixels(); for (int x = 0; x < _res; x++) { for (int y = 0; y < _res; y++) { var idx = x + (y * _res) + (z * (_res * _res)); volumeColorsNM[idx] = pixels[x + (y * _res)]; } } DestroyImmediate(nm); } EditorUtility.ClearProgressBar(); var path = EditorUtility.SaveFilePanelInProject("Save 3D noise texture.", string.Format("{0}_noise.asset", _noiseType), "asset", "Please enter a file name to save the volume texture"); if (path.Length != 0) { volumeTex.SetPixels(volumeColors); volumeTex.Apply(); AssetDatabase.CreateAsset(volumeTex, path); AssetDatabase.Refresh(); } if (_normalMap) { volumeTexNM.SetPixels(volumeColorsNM); volumeTexNM.Apply(); path = EditorUtility.SaveFilePanelInProject("Save 3D normalmap texture.", string.Format("{0}_normalmap.asset", _noiseType), "asset", "Please enter a file name to save the volume normalmap"); if (path.Length != 0) { AssetDatabase.CreateAsset(volumeTexNM, path); AssetDatabase.Refresh(); } } }