The goal for a new shader was better performance, specially when using older gfx-cards. Using
sqrt instead of
atan2 gets rid of 13 ALU (or
atan(y_over_x) 7 ALU) and lots of instructions, but it has consequences (hexagons and distribution of stars). It's a 'either - or' choice, not a problem - hence the question about Oolites
OO_REDUCED_COMPLEXITY (which is gone it seems).
I don't know if it helps, but there's some code in the planet shader that approximately calculates atan:
/* Approximation of atan(y/z) with quadrant rectification, scaled to -0.5..0.5 instead of -pi..pi.
It is assumed that the values are in range. You are not expected to understand this.
float TexLongitude(float z, float y)
const float k2Pi = 6.283185307179586;
const float kMagic = 0.2732395447351; // (4 - pi) / pi
float ratio = z / y;
float r1 = 1.0 / ((ratio + kMagic / ratio) * k2Pi); // Result when abs(z) >= abs(x).
float r2 = 0.25 * sign(ratio) - ratio / ((1.0 + kMagic * ratio * ratio) * k2Pi); // Result when abs(z) <= abs(x).
float result = (abs(ratio) > 1.0) ? r1 : r2;
// Adjust for sector.
// Equivalent to (z < 0.0) ? ((y > 0.0) ? 0.75 : -0.25) : 0.25.
// Well, technically not equivalent for z < 0, y = 0, but you'll very rarely see that exact case.
return result + step(z, 0.0) * sign(y) * 0.5 + 0.25;
I don't know how it works, either!
Edit: Forgot to say - thanks kanthoney .-)