Hello. I have to admit that my SUN math was all screwed up. Now here is finally the true scientific way.
Check out this page:
http://mathworld.wolfram.com/SphericalCoordinates.htmlWhat we have are UV coordinates on that sphere, turning it into a carthesian coordinate system.
First thing is to convert the UV into Theta and Phi.
Our SunU is their Theta. SunU goes 0...1, Theta goes 0...2PI.
A simple remapping will do. In LW I have to shift it halfway round, so I end up with
theta = (SunU + 0.5)*PI*2;
Same goes for Phi. SunV goes 0...1, Phi goes 0...PI
This is straight forward:
phi = SunV*PI;
And now, the page lists the formulas for carthesian coordinates. Make sure to check their axis orientation on the figure drawing, and swap out the according variables.
In LW, the Y axis goes up, and it's also reversed from the drawing, my adaption looks like this:
z = cos(theta) * sin(phi) * -1;
x = sin(theta) * sin(phi) * -1;
y = cos(phi);
That should get you running... Good luck!
Blochi