- Home /

# Voxel-Grid rounded Marching Cube values for a sphere

Hey Guys, I'm currently trying to create a planet using the marching cubes algorithm, but I don't really understand the density value! If I set the density value for every point in the sphere to 1, I get a blocky sphere. How can I calculate the right density values to get a round sphere?

Here's my current code to fill the voxel grid:

```
public void generatePlanet() {
for (int x=0; x<planetDiameter; x++) {
for (int y=0; y<planetDiameter; y++) {
for (int z=0; z<planetDiameter; z++) {
Vector3 pos = new Vector3(x,y,z);
float distance = Vector3.Distance(pos, center);
if (distance <= planetRadius) {
if (distance >= planetRadius -1) {
map[x,y,z] = ??
}else {
map[x,y,z] = 1;
}
}else {
map[x,y,z] = 0;
}
}
}
}
}
```

Thanks in advance!

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

Generating scalar field for a sphere 1 Answer

Rounding edges of cubes (Voxels and Marching Cubes) 1 Answer

Smooth Voxel Planets? 0 Answers

Editing voxels @ chunk borders 1 Answer

How can I smoothen my cubic mesh using marching cubes? 0 Answers