- Home /

# 2D noise function to generate voxel circles

This is a stretch but here we go:

I basically am making a game where I need to generate 2D planets (spheres out of square tiles). I have used Perlin noise to generate noise, however, I now need a noise algorithm to generate individual circles of all different shapes and sizes (I have looked everywhere and can't find anything). The algorithm must also allow for a seed to be used, any help will be appreciated :)

**Answer** by Dray
·
Jan 08, 2018 at 11:16 AM

Use any generic 2D noise function and divide the result for each point by the distance to your planets center:

```
// p is the current x, y coordinate, origin is the planets center
float value = Noise(p.x, p.y) / Vector2.Distance(p, origin);
if (value > 0) {
// add block at p ...
}
```

This should provide you with a sphere that is being deformed by your noise function.

from this, what defines the radius of the planet then?

Also, I would like the noise function to provide me with planet centers rather than me having to pre-define them somehow.

I'm sorry, I overlooked that you are trying to generate *multiple* planets. In fact though, this is not much more complex than just one.

I can imagine two ways to do this:

Apply the method described above to each of your planets. In other words, for each cell find the closest planet and then use the distance to this planets origin. Be aware that this approach could make your performance suffer a lot depending on the platform you are targeting and the count of planets you are going for.

Dig into noise generation in general. Understand how noise functions are actually based on primitive mathematical functions that are combined together. Find a Noise library for unity that lets you build your own noise and make a generator that produces almost spherical shapes. This will require some reading but might provide you with the more performant solution for your problem. You won't be able to actually

*place*planets where you want them like this though.

I found thebookofshaders.com to be a nice source to understand how certain shapes can be generated from noise. Have a look at the *algorithmic drawing* section if you are interested.

LibNoise could be the right library for you to play around with noises a little bit. There are some Unity ports of it out there, just google it

SimplexNoise is another nice approach to provide noise in a more performant way, the tutorial I linked looks quite promising even though I didn't have time to read it yet. If you don't like reading there are some finished Unity implementations of SimplexNoise too I'm pretty sure ;)

To answer the question what the radius would be; in the example above it would be simply 1 unit. To change the radius of your planet you could *divide the distance* by the actual radius you want before dividing the noise functions result by it. Like this:

```
float value = Noise(p.x, p.y) / (Vector2.Distance(p, origin) / radius);
```

### Your answer

### 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

### Related Questions

Firing Projectiles in the same direction as my character is looking. 1 Answer

How to check if an object hits the ground hard enough then add explosive force around it (2D) 1 Answer

Trying to make the camera follow the player but stop at the edge. 1 Answer

OnCollisionStay2D deactivates after a short amount of time 1 Answer