Jump to content
• Advertisement

Having a bigger voxel density in a sphere

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

If you intended to correct an error in the post then please contact us.

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 this post

Share on other sites
Advertisement

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++)
{
for (int y = -radius; y <= radius; y++)
{
for (int x = -radius; x <= radius; x++)
{
int dist = (x * x + y * y + z * z);
if (dist <= radius_squared)    // radius_squared = radius * radius
Map[cx + x, cy + y, cz + z] = 2;
}
}
}


Share this post

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 this post

Share on other sites

• Advertisement
• Advertisement

• Popular Contributors

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5
• Advertisement

• 12
• 16
• 26
• 10
• 11
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!