Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by beastsOnly · May 04, 2020 at 02:25 PM · perlin noiseshapemountains

How to use Perlin Noise to create only ONE mountain?

Hi, I am working on a project that uses perlin noise to generate some terrain. The thing is, perlin noise is great to when it comes to smooth shapes, but I need only one. In other words, this is a normal output from perlin noise, but I need only ONE simple "Mountain/Hill", like this . I need my shapes to be random with the smooth transitions of perlin noise but also pretty simple. I need to be sure that I won't get any height along the borders of the image and so on. This is a very important project and I would immensly appreciate any amount of help I can get. Thank you and have a Great Day!

Here is the code I took from an online tutorial:

 using System.Collections;
 using UnityEngine;
 
 public class PerlinNoise : MonoBehaviour
 {
     private static int width = 256;
     private static int height = 128;
     public float scale = 20f;
 
     public float offsetX = 100f;
     public float offsetY = 100f;
     private int xcont = 0, ycont = 0;
     public float[,] array = new float[width,height];
 
     private void Start()
     {
         offsetX = Random.Range(0f, 99999f);
         offsetY = Random.Range(0f, 99999f);
     }
     void Update()
     {
         Renderer renderer = GetComponent<Renderer>();
         renderer.material.mainTexture = GenerateTexture();
     }
 
     
 
     Texture2D GenerateTexture()
     {
         Texture2D texture = new Texture2D(width, height);
 
         //GENERATE A PERLIN NOISE MAP FOR THE TEXTURE
 
         for(int x=0;x<width;x++)
         {
             for(int y=0;y<height;y++)
             {
                 Color color = CalculateColor(x,y);
                 texture.SetPixel(x, y, color);
             }
         }
 
         texture.Apply();
 
         return texture;
     }
 
     Color CalculateColor(int x, int y)
     {
         float xCoord = (float)x / width * scale + offsetX;
         float yCoord = (float)y / height * scale + offsetY;
         float sample = Mathf.PerlinNoise(xCoord,yCoord);
         if (xcont == width - 1)
         {
             xcont = 0;
             ycont++;
         } 
         else xcont++;
 
         if (ycont == height - 1 ) ycont = 0;
 
         array[xcont,ycont] = sample;
         return new Color(sample, sample, sample);
     }
 }
 


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by streeetwalker · May 04, 2020 at 03:30 PM

@beastsOnly, there are several ways you can approach this, and this is off the top of my head having created a mountain generator in the past based on Sebastian Lague's work (see his excellent Land Mass Generation YouTube series.)

The overall idea for both suggestions here is to use the Perlin output as modifiers for base values that you generate or read from other sources.

  1. One is to just set some function that generates zero at the edges and increases the further away you are (the closer to the center of your map). For example, half of the Sine function will do that, so Sin(0) - Sin(180) will give you a hump in both x and y and then use that to multiply by your Perlin values by (or some factor of your Perlin value depending on how much you want to perturb the base Sine values returned). You just need to map your Map size min and max to 0 through 180 for both x and y. The Sine function will give you a noticeable hump, so you might want to stretch it out, or look at some other functions ( see #4 below).

  2. Probably the easiest is you could create an base shape for your mountains as a grayscale texture, in say, photoshop, and then read through that and use the Perlin output as a multiplier for each pixel in the texture to produce the final texture2D color. If you make sure the edge values are zero (black) and grow smoothly to white (the highest points) the edges would be at the base level. However using this start with the same overall shape.

  3. Instead of working with a second bitmap you use an animation curve, or multiple animation curves, to provide the base values, and then apply Perlin as in step 1. This approach would again produce more predictable shapes.

  4. You could write your own LERP to interpolate between several values or use a Bezier or Spline functions - essentially create a curve dynamically - that you could use with randomly generated values and you apply to x and y to get the base heights that you then apply your Perlin to. Again you just need to make sure that the start and end values are zero. Bezier and Spline functions would be maybe nicer looking because they would provide smooth curves, whereas LERP is going to create more sharp edged base slope values.

For any of the suggestions above there is nothing that says you can't use different functions for each dimension - so the base values don't have to be symmetrical.

None of that should not be too difficult to implement.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image beastsOnly · May 04, 2020 at 03:59 PM 0
Share

The more I learn the more I realize how little I know. Based on your answer there are lots of ways I can solve this. I am going to try my best to test all of your suggestions to see which is the easiest /efficient on the long term. $$anonymous$$aybe I am going to follow up with some updates if needed...I really appreciate your help, Thank You!

avatar image streeetwalker beastsOnly · May 04, 2020 at 04:19 PM 0
Share

Hey thanks - any time. I'm always learning and because Unity is so broad and deep, relearning!

All of that was pretty hasty and maybe a little crudely explained. I'm sure you can find quite a few YouTube and other tutorials that use those ideas.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

200 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Best way to change the shape of an object at runtime 1 Answer

Find height of mountain in terain? 2 Answers

Perlin noise causing Unity to Freeze; am I doing something wrong? 1 Answer

How to make a pyramid-ish shape from a cube in unity (for making a muzzle flash) 1 Answer

Creating ridged perlin noise 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges