Normalizing position values is a fast and intuitive way to spherify a box. By doing this, all points have the same distance towards the center which turns the entire mesh into a sphere. However, especially the corner regions will turn out quite dense.
// Normalize point positions, set to unit length.
// Divide by 2 to scale the sphere to unit size.
v@P = normalize(v@P) / 2.0;
A more regular quadrilateral sphere can be achieved with the code below.
Source: http://mathproofs.blogspot.com/2005/07/mapping-cube-to-sphere.html
function vector sphere(vector p){
vector psq = p * p;
return set(p.x * sqrt(1.0 - (psq.y + psq.z) / 2.0 + (psq.y * psq.z) / 3.0),
p.y * sqrt(1.0 - (psq.z + psq.x) / 2.0 + (psq.z * psq.x) / 3.0),
p.z * sqrt(1.0 - (psq.x + psq.y) / 2.0 + (psq.x * psq.y) / 3.0));
}
v@P = sphere(v@P);
This point wrangle maps a square sized from -1.0 to 1.0 to a unit circle.
Source: http://mathproofs.blogspot.com/2005/07/mapping-square-to-circle.html
float bias = chf('bias');
vector pos = v@P;
float x = pos.x * sqrt(1.0 - (pos.y * pos.y) / 2.0);
float y = pos.y * sqrt(1.0 - (pos.x * pos.x) / 2.0);
pos = set(x, y, 0.0);
v@P = lerp(v@P, pos, bias);