• 9
• 16
• 15
• 12
• 9

# Having a bigger voxel density in a sphere

This topic is 796 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm writing a very simple Voxel Raytracer for fun. The voxels are stored in a 3d array and here is the code that stores them to create a sphere.

 if ((Math.Pow((cx - 200), 2) + (Math.Pow((cy - 140), 2)) + (Math.Pow((i - 10), 2)) == Math.Pow(50, 2)))
{

Map[cx+d, cy+d, i+d] = 2;

}


[attachment=30289:sphere.png]

However, the sphere seems to be composed of an extremely tin pixel density. I suppose this has something to do with the pixels being integers. It still gives a nice effect but i was wondering if anyone here had any idea to improve the pixel density on the surface of the sphere.

PS: also do you know any resources on how to fill the surface of certain prism via general equations ? I can't seem to find any.

Edited by FFA702

##### Share on other sites

Maybe try doing something like this?

This will produce a solid voxel-sphere.. I think your issues is because you do a == compare, and when dealing with integers the radius from (cx, cy, i..) won't hit the radius (50) at every point on the edge, and thus you get holes in it :)

BTW: doing a x * x instead of pow(x, 2) will probably be faster :)

for (int z = -radius; z <= radius; z++)
{
{
{
int dist = (x * x + y * y + z * z);
Map[cx + x, cy + y, cz + z] = 2;
}
}
}


##### Share on other sites

You could also check whether the individual voxels intersect the sphere surface, instead of whether their center is exactly on the surface.

For that youd need to calculate the furthest and closest point of the voxel from the sphere.

I dont know what the best way to do that is assuming a cube-shaped voxel, but for quick results you could just assume theyre spheres, which means just checking that the center is within radius +- some constant from the sphere center (where the constant is the voxel radius).

##### Share on other sites

also do you know any resources on how to fill the surface of certain prism via general equations ? I can't seem to find any.

Íñgo Quílez's assorted collection of signed distance field functions