Trying to map a 2d array into a disk

im not really good at working on the same codebase as other people(youve seen my spagetti first hand and survived), but math might work.

Now what im most having issues with at the moment regarding the 3d planets, is the artifacts coming from the curvature of the donut planet. blocks on the inner ring are much smaller than the outer ring. basically, theres 2 solutions, 1: make the worlds thin and long, this reduces the local curvature since its total is a constant i believe. 2: dynamically change the length of the world based on where the player is. This might also work due to there always being a select height of the world with minamal artifacts. Option 1 is the simplest personally since its the most bang for the buck when it comes to time to implement, and option being limited some other way. But Option 2 will be needed to make a decent build height.

This is the algorythm ive basically ended up with. The inputs are directly from their voxel map position.

Now, im not much of a math person so i dont know if there is a mapping with less artifacts. But from what i understand, there shouldnt be? but then again i reworked the 2d algorythms version 10 times until it worked like i wanted.

//Inputs
vec3 vertexposition;
float WorldXlength, WorldZlength;
// Normalize inputs
float u = aPos.x / gridX; // major angle around torus
float w = aPos.z / gridZ; // minor circle angle

// Angles
float theta = 2.0 * 3.1415926535 * u; // major angle
float phi   = 2.0 * 3.1415926535 * w; // minor angle

// Radii
float majorRadius = gridX / (2.0 * 3.1415926535); // donut center distance
float minorRadius = gridZ / (2.0 * 3.1415926535); // donut tube radius

float effective_r = minorRadius + aPos.y;

vec3 pos;
pos.x = (majorRadius + effective_r * cos(phi)) * cos(theta);
pos.y = (majorRadius + effective_r * cos(phi)) * sin(theta);
pos.z = effective_r * sin(phi);
2 Likes