• 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
2
Question by Saitodepaula · Aug 08, 2012 at 11:16 PM · noiseperlin

Perlin noise continuous through different objects

I want to use a Perlin noise function that acts continuously through different objects (planes in this case), wich means, with no gaps between vertices of different meshes. I've attached the script that applies the Perlin noise in a parent game object (an empty game object). The script runs the Perlin noise function once and search for the childrens (the planes), applying the noise to each vertex of each plane.

It worked when the noise is applyied only in one direction, but it doesn't when two or more directions are used. This question seems to use the same idea I have here, but I've tried many things suggested by the answers and comments provided there and could not come to a solution (Actually, I didn't understand some of the code provided there, I'm not a experienced programmer).

Here are some screenshots of when it works and when it doesn't, and the code (JS). The script is a simplified version of the one found in the Unity's Procedural Examples, and the Perlin Noise function can be found there too.

EDIT: CODE UPDATED, NOW WORKING, SEE UPDATE BELOW

alt text

alt text

 var scale : float = 1.0;
 var recalculateNormals = true;

 private var perlin : Perlin = new Perlin();
 
 function Start ()
 {
 for(var childPlane : Transform in transform) 
  MakePerlin(childPlane);
 }
 
 function MakePerlin(childPlane : Transform){

 var baseVertices : Vector3[];
 
 var mesh : Mesh = childPlane.GetComponent(MeshFilter).mesh;
  
 if (baseVertices == null)
 baseVertices = mesh.vertices;
  
 var vertices = new Vector3[baseVertices.Length];
  
 for (var i = 0; i < vertices.Length; i++)
 {
 var vertex = baseVertices[i];

 var worldPosition : Vector3 = childPlane.transform.TransformPoint(baseVertices[i]);
  
 vertex.y += perlin.Noise(worldPosition.x + 0.1, worldPosition.z + 0.1) * scale;
  
 vertices[i] = vertex;
 }
  
 mesh.vertices = vertices;
  
 if (recalculateNormals) 
 mesh.RecalculateNormals();
  
 mesh.RecalculateBounds();

 childPlane.GetComponent(MeshCollider).sharedMesh = null;
 childPlane.GetComponent(MeshCollider).sharedMesh = mesh;
 }

I don't know if my logic is flawed, but it seems to be almost there. Thanks in advance.

EDIT: SOLVED.

Solved. It was very simple: it was just a matter of converting each vertex coordinate (by default, in local space) to world space. Once we know each vertex world coordinates, the Perlin noise function can be applied to world space coordinates, so every vertex that shares that world space coordinate will have the same noise. Below, an image showing it. And the code has been updated too.

alt text

Just posted it so that if anyone comes across this question, it may be useful.

perlin_example_3.jpg (153.7 kB)
perlin_example_2.jpg (124.8 kB)
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

2 Replies

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

Answer by Saitodepaula · Aug 10, 2012 at 05:30 PM

I don't know if I can answer my own question but I've come to a solution and just wanted to mark it as solved (look at the edits in the question itself).

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 DaveA · Feb 26, 2013 at 02:06 AM 1
Share

Sure. but usually, put the answer IN and answer. Glad you got it working.

avatar image
0

Answer by Fourthings · Feb 26, 2013 at 01:57 AM

That was quite useful, thank you!

Comment
Add comment · 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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

11 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

Related Questions

How to make perlin noise generate terrain in all directions? 2 Answers

3D Perlin Noise mesh even in all axes 1 Answer

How would I go about blending Noise? 1 Answer

creating a perlin noise generates all pixels the with the same shade of gray 2 Answers

Why Doesn't This Work? 3 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges