private Texture2D texture; // texture created for testing #endregion Fields #region Methods void Generate(bool addToSeed) { Perlin mySphere = new Perlin(); mySphere.Seed = seedToModify; mySphere.OctaveCount = octaves; // modify the frequency mySphere.Frequency = frequency; // modify the persistence mySphere.Persistence = persistence; ModuleBase myModule; myModule = mySphere; mySphere.Lacunarity = 2.5; // ------------------------------------------------------------------------------------------ // - Generate - // this part generates the heightmap to a texture, // and sets the renderer material texture of a sphere to the generated texture Noise2D heightMap; heightMap = new Noise2D( mapSizeX, mapSizeY, myModule ); heightMap.GenerateSpherical( south, north, west, east ); texture = heightMap.GetTexture(GradientPresets.Grayscale); sphereRenderer.material.mainTexture = texture; texture = heightMap.GetTexture(GradientPresets.planetColors); sphereRenderer.material.SetTexture("_Normals",heightMap.GetNormalMap(3)); texture = heightMap.GetTexture(GradientPresets.planetLightColors); sphereRenderer.material.SetTexture("_Lights",texture); }
private Texture2D texture; // texture created for testing #endregion Fields #region Methods // Other Functions // ---------------------------------------------------------------------------- void Generate(bool addToSeed) { Perlin mySphere = new Perlin(); mySphere.Seed = seedToModify; mySphere.OctaveCount = octaves; // modify the frequency mySphere.Frequency = frequency; // modify the persistence mySphere.Persistence = persistence; // ------------------------------------------------------------------------------------------ // - Compiled Terrain - // Debug.LogError ("Not fetching seed data for planets!"); ModuleBase myModule; myModule = mySphere; // ------------------------------------------------------------------------------------------ // - Generate - // this part generates the heightmap to a texture, // and sets the renderer material texture of a sphere to the generated texture Noise2D heightMap; heightMap = new Noise2D( mapSizeX, mapSizeY, myModule ); heightMap.GenerateSpherical( south, north, west, east ); texture = heightMap.GetTexture(GradientPresets.Grayscale); sphereRenderer.material.mainTexture = texture; //Debug.LogWarning("Removed Generate Planet Clouds to save on load times for now till I optimize it and make it run better."); }
public void UpdateTerrainPreview() { Perlin baseNoise = new Perlin() { Frequency = _noiseFreq, Lacunarity = _noiseLac, OctaveCount = _noiseOct }; if (_seed != "") { baseNoise.Seed = Convert.ToInt32(_seed); } else { baseNoise.Seed = UnityEngine.Random.Range(int.MinValue, int.MaxValue); } LibNoise.Noise2D noise2D = new LibNoise.Noise2D(_previewTex.width, baseNoise); float mOff = 0.01f; noise2D.GeneratePlanar(-1 - _mouseOffset.y * mOff, 1 - _mouseOffset.y * mOff, -1 - _mouseOffset.x * mOff, 1 - _mouseOffset.x * mOff); _previewTex = noise2D.GetTexture(); _terDrawing = new EditorTerrainDrawing(_previewTex); _terDrawing.Update(); _previewTex.Apply(); }
private Texture2D texture; // texture created for testing #endregion Fields #region Methods void Generate(bool addToSeed) { Voronoi mySphere = new Voronoi(); mySphere.Seed = seedToModify; // ------------------------------------------------------------------------------------------ // - Compiled Terrain - Debug.LogError ("Not fetching seed data for planets!"); ModuleBase myModule; myModule = mySphere; // ------------------------------------------------------------------------------------------ // - Generate - // this part generates the heightmap to a texture, // and sets the renderer material texture of a sphere to the generated texture Noise2D heightMap; heightMap = new Noise2D( mapSizeX, mapSizeY, myModule ); heightMap.GenerateSpherical( south, north, west, east ); texture = heightMap.GetTexture(GradientPresets.RGBA); sphereRenderer.material.mainTexture = texture; sphereRenderer.material.SetTexture("_Normals",texture); }
void RenderAndSetImage(ModuleBase generator) { var heightMapBuilder = new Noise2D(256, 256, generator); heightMapBuilder.GeneratePlanar(_left, _right, _top, _bottom); var image = heightMapBuilder.GetTexture(_gradient); renderer.material.mainTexture = image; }
void Start() { var perlin = new Perlin(); var heightMapBuilder = new Noise2D(512, 256, perlin); heightMapBuilder.GenerateSpherical(_north, _south, _west, _east); var image = heightMapBuilder.GetTexture(_gradient); renderer.material.mainTexture = image; }
void Start() { var perlin = new Perlin(); // Unlike on the base LibNoise tutorial, we don't have a separate heightMap target // to set - we will instead build it after. We also initialize the resulting size // on the constructor instead of passing a separate destination size. var heightMapBuilder = new Noise2D(256, 256, perlin); heightMapBuilder.GeneratePlanar(_left, _right, _top, _bottom); // Get the image var image = heightMapBuilder.GetTexture(_gradient); // Set it. It may appear inverted from the example on the LibNoise site depending // on the angle at which the object is rotated/viewed. renderer.material.mainTexture = image; // We don't do the light changes for the texture, since that's beyond the scope of // this port }
private Texture2D texture; // texture created for testing #endregion Fields #region Methods public void Generate() { Perlin mySphere = new Perlin(); mySphere.Seed = seedHandler.currentSeed; seedModifier = Random.Range(0,2048); mySphere.Seed = mySphere.Seed + seedModifier + specialSeedModifier; // modify the seed with the variable declared in the editor (default 0, or no change) mySphere.OctaveCount = octaves; // modify the frequency mySphere.Frequency = frequency; // modify the persistence mySphere.Persistence = persistence; // ------------------------------------------------------------------------------------------ // - Compiled Terrain - ModuleBase myModule; myModule = mySphere; // ------------------------------------------------------------------------------------------ // - Generate - // this part generates the heightmap to a texture, // and sets the renderer material texture of a sphere to the generated texture Noise2D heightMap; heightMap = new Noise2D( mapSizeX, mapSizeY, myModule ); heightMap.GeneratePlanar( sampleOffsetX, sampleOffsetX + sampleSizeX, sampleOffsetY, sampleOffsetY + sampleSizeY ); heightMap.GenerateSpherical( south, north, west, east ); //Somewhere this is f*****g up texture = heightMap.GetTexture(GradientPresets.nebulaColorsB); sphereRenderer.material.mainTexture = texture; }
// Other Functions // ---------------------------------------------------------------------------- void Generate() { //Perlin mySphere = new Perlin(); // ------------------------------------------------------------------------------------------ // - Compiled Terrain - ModuleBase myModule; myModule = Generator.LibnoiseModualGen.GetRTSGenerator(1); // ------------------------------------------------------------------------------------------ // - Generate - // this part generates the heightmap to a texture, // and sets the renderer material texture of a sphere to the generated texture Noise2D heightMap; heightMap = new Noise2D( mapSizeX, mapSizeY, myModule ); heightMap.GenerateSpherical( south, north, west, east ); texture = heightMap.GetTexture(GradientPresets.Grayscale); /// #if !UNITY_WEBPLAYER byte[] bytes = texture.EncodeToPNG(); File.WriteAllBytes(Application.dataPath + "/Terain/TextureGenOutput/sphere/"+TextureName+".png", bytes); #endif /// sphereRenderer.material.mainTexture = texture; }
private Texture2D texture; // texture created for testing #endregion Fields #region Methods public void Generate() { Perlin mySphere = new Perlin(); mySphere.Seed = seedHandler.currentSeed; seedModifier = Random.Range(0,2048); mySphere.Seed = mySphere.Seed + seedModifier + specialSeedModifier; // modify the seed with the variable declared in the editor (default 0, or no change) mySphere.OctaveCount = octaves; // modify the frequency mySphere.Frequency = frequency; // modify the persistence mySphere.Persistence = persistence; // ------------------------------------------------------------------------------------------ // - Compiled Terrain - Debug.LogError ("Not fetching seed data for planets!"); ModuleBase myModule; myModule = mySphere; // ------------------------------------------------------------------------------------------ // - Generate - // this part generates the heightmap to a texture, // and sets the renderer material texture of a sphere to the generated texture Noise2D heightMap; heightMap = new Noise2D( mapSizeX, mapSizeY, myModule ); heightMap.GeneratePlanar( sampleOffsetX, sampleOffsetX + sampleSizeX, sampleOffsetY, sampleOffsetY + sampleSizeY ); heightMap.GenerateSpherical( south, north, west, east ); potentialRandomGradiants = Random.Range (0,3); if(potentialRandomGradiants == 0){ texture = heightMap.GetTexture(GradientPresets.nebulaColorsD); } else if(potentialRandomGradiants == 1){ texture = heightMap.GetTexture(GradientPresets.nebulaColorsD); } else if(potentialRandomGradiants == 2){ texture = heightMap.GetTexture(GradientPresets.nebulaColorsD); } else { texture = heightMap.GetTexture(GradientPresets.nebulaColorsD); } //nebulaColorsB, C, A, D sphereRenderer.material.mainTexture = texture; }
void Start() { // defines noise type NoiseSelector(); // setup terrain data TerrainData terrain = Terrain.activeTerrain.terrainData; int hmArea = terrain.heightmapWidth; float[,] heightmapData = terrain.GetHeights(0, 0, hmArea, hmArea); // create the noise map Noise2D noiseMap = new Noise2D(maxArea, maxArea, generate); noiseMap.GeneratePlanar(0, maxArea, 0, maxArea); // send noise to texture Texture2D textMap = noiseMap.GetTexture(_gradient); // texture data to heightmap for (int y = 0; y < hmArea; y++) { for (int x = 0; x < hmArea; x++) { heightmapData[y, x] = textMap.GetPixel(x, y).grayscale; } } // set terrain heights from heightmap data terrain.SetHeights(0, 0, heightmapData); }
/// <summary> /// Gets the alphamap. /// </summary> /// <returns>The alphamap.</returns> public override Texture2D GetAlphamap() { return(heightMapBuilder.GetTexture(LibNoise.GradientPresets.RGBA)); }
void DrawSelectedNodeDetails(NodeBase node) { if (previewNeedsUpdate || lastSelected != node) { preview = new Texture2D(230, 230); if (node.Module != null && previewCalculation == null) previewCalculation = new NoiseCalculation(node.Module, 230, 230); previewNeedsUpdate = false; lastSelected = node; } if (previewCalculation != null && previewCalculation.Done) { preview = previewCalculation.Noise.GetTexture(); previewCalculation = null; } var state = mainEditorState as NoiseDesignerState; EditorGUILayout.Space(); EditorGUILayout.LabelField("Selected Node:"); GUILayout.Box(preview); EditorGUILayout.Space(); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Apply to terrain:"); terrain = EditorGUILayout.ObjectField("TerrainData", terrain, typeof(TerrainData), false) as TerrainData; if (GUILayout.Button("Apply")) { Noise2D noise = new Noise2D(terrain.heightmapWidth, terrain.heightmapHeight, node.Module); noise.GeneratePlanar(4.0f, 10.0f, 1.0f, 5.0f); terrain.SetHeights(0, 0, noise.GetNormalizedData()); } EditorGUILayout.Space(); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Export as texture:"); state.textureSize = EditorGUILayout.Vector2Field("Texture Size", state.textureSize); if (GUILayout.Button("Save as PNG")) { var path = EditorUtility.SaveFilePanelInProject("Save as PNG", "noise", "png", ""); if (!string.IsNullOrEmpty(path)) { Noise2D noise = new Noise2D((int)state.textureSize.x, (int)state.textureSize.y, node.Module); noise.GeneratePlanar(4.0f, 10.0f, 1.0f, 5.0f); var texture = noise.GetTexture(); File.WriteAllBytes(path, texture.EncodeToPNG()); AssetDatabase.Refresh(); } } }
public override void sceneEvents(SceneView sceneview){ if(teNoisePaint==false){return;} if(Event.current.type==EventType.MouseDown){ Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); RaycastHit hit = new RaycastHit(); if(Physics.Raycast(ray, out hit, 7000.0f)){ GameObject go = hit.collider.gameObject; TerrainData td = go.GetComponent<Terrain>().terrainData; Undo.RegisterUndo(td,"Paste Noise"); int x = (int)hit.point.x - (int)go.transform.position.x; int z = (int)hit.point.z - (int)go.transform.position.z; int heightres = td.heightmapResolution; float heightMult = (1.0f / td.size.x)*(float)heightres; int heiX = ((int)(heightMult*(float)x))+heightres; //x:z coords for other map resolutions int heiZ = ((int)(heightMult*(float)z))+heightres; Event.current.Use(); heights = TerrainEdge.getNeighborhoodHeights(go); float strengthmult =1.0f; int channelId = teNoiseChanIndex; Vector3 gopos = go.transform.position; float cwidth = go.GetComponent<Terrain>().terrainData.size.x; yoffset = (1f) - (gopos.x / cwidth); xoffset = (-1f) + (gopos.z / cwidth); tmpNoiseMap = new Noise2D(heightres*3, heightres*3, moduleBase[channelId]); tmpNoiseMap.GeneratePlanar(xoffset, xoffset + (1f / heightres) * (heightres*3) + 3, -yoffset, -yoffset + (1f / heightres) * (heightres*3) + 3); tmpTexture = tmpNoiseMap.GetTexture(); tmpTexture.Apply(); int pasteregionoffset = (int)((float)teNoiseBrushSize); for(int paintZ=(heiZ)-pasteregionoffset;paintZ<(heiZ)+(pasteregionoffset+1);paintZ++){ for(int paintX=(heiX)-pasteregionoffset;paintX<(heiX)+(pasteregionoffset+1);paintX++){ if(paintZ>=0&&paintZ<=(heightres*3)-2&&paintX>=0&&paintX<=(heightres*3)-2){ strengthmult = falloffMult(paintX,heiX,paintZ,heiZ,pasteregionoffset); float tmpval = (tmpNoiseMap[paintZ, paintX] + 0.5f) * noiseAmp; if(heights[paintZ,paintX]>tmpval){ heights[paintZ,paintX]-=(heights[paintZ,paintX]-tmpval) * strengthmult; } else { heights[paintZ,paintX]+=(tmpval-heights[paintZ,paintX]) * strengthmult; } } } } TerrainEdge.setNeighborhoodHeights(go,heights); } } }