Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by SnotE101 · Nov 18, 2014 at 02:15 AM · c#mathplaneperlinwtf

Perlin Noise applied to plane, except endpoints

Here goes,

I have created a script that when applied to a plane it creates random hills and valleys as it should. Now here lies my question. How do I make the end points stop at 0 naturally. For example I would have a plane and in the center would be random hills and valleys but the edges would be flat. Here is my Perlin Noise Script;

     public float power = 3.0f;
     public float scale = 1.0f;
     private Vector2 v2SampleStart = new Vector2(0f, 0f);
     
     void Start () 
     {
         Noise ();
     }
     
     void Update () {
         if (Input.GetKeyDown (KeyCode.Space)) 
         {
             v2SampleStart = new Vector2(Random.Range (0.0f, 100.0f), Random.Range (0.0f, 100.0f));
             Noise();
         }
     }
     
     void Noise() {
         MeshFilter mf = GetComponent<MeshFilter>();
         Vector3[] vertices = mf.mesh.vertices;
         for (int i = 0; i < vertices.Length; i++) 
         {    
             float xCoord = v2SampleStart.x + vertices[i].x  * scale;
             float yCoord = v2SampleStart.y + vertices[i].z  * scale;
             vertices[i].y = (Mathf.PerlinNoise (xCoord, yCoord) - 0.5f) * power; 
         }
         mf.mesh.vertices = vertices;
         mf.mesh.RecalculateBounds();
         mf.mesh.RecalculateNormals();
     }


Thanks in advanced!

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
1
Best Answer

Answer by twobob · Nov 18, 2014 at 03:42 AM

erm.

off the top of my head.

determine the total mesh size.

and use an exp rolloff beyond a certain x , y threshold taken absolutely from the center.

something like 0.9 of the radius/width (circle might be nice) would be a decent start value and tend toward zero after that with a factor.

just use the x,y since it looks like you know that already. so piece of cake.

As an aside there should be some way of dealing with the numbers offset absolutely to negate needing to know the direction of falloff but either way it's calculable and the shortcut evades me.

But roughly. As a method:

 if ( NeedsRolloffApplying(vertices[i]))
 vertices[i].y = (Mathf.PerlinNoise (xCoord, yCoord) - 0.5f) * power * factor;

or just

 vertices[i].y = (Mathf.PerlinNoise (xCoord, yCoord) - 0.5f) * power * factor;

and make the factor unity (err 1) in the central cases and toward zero where the x or y is greater 40% distance away from the central value exponentially.

So. No Code. But that's what I would do.

Comment
Add comment · Show 1 · 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 Kiwasi · Nov 18, 2014 at 05:46 AM 1
Share

This is how I would do it too. You can experiment with different drop off functions for different appearances.

Note that this won't look overly natural up close. But then nature doesn't do this either.

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

28 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

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Raycast visual and moving text possition. 1 Answer

Aligning planes thin gap? c# 0 Answers

How to detect if number has a decimal point or not 2 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