There is difference. Rotate around Z axis, or rotate around tilted Z axis.
I have both rotation, and combined rotation is wrong. I ether need to make custom HLSS that uses quaternions (which refuses to work atm). Or make combined rotation out of quaternion nodes in material (and i think there are no quaternion nodes in non custom materials).
Best would be getting Up vector at long,lat, matching skybox to it then rotating around that new Z (aka new up vector at long lat).
Update, after refreshing my HLSL skills i got it working:
This material uses CUSTOM node to calculate rotations.
This is setup for custom node
struct ComputeVector {
float3 RotateVector(float3 R, float Longitude, float Latitude)
{
// Convert degrees to radians
float lambda = Longitude; // * (3.14159265359 / 180.0);
float phi = Latitude; // * (3.14159265359 / 180.0);
// Compute observer's local basis vectors
float3 U = float3(cos(lambda) * cos(phi), sin(lambda) * cos(phi), sin(phi));
float3 E = float3(-sin(lambda), cos(lambda), 0);
float3 N = float3(-cos(lambda) * sin(phi), -sin(lambda) * sin(phi), cos(phi));
// Construct rotation matrix (column-major)
float3x3 M = float3x3(E, N, U);
// Transform reflection vector to skybox space
return mul(M, R);
}
};
ComputeVector f;
return f.RotateVector(CameraVector,Long,Lat);
And this is shader code (just copy paste it in code part of custom node).
Looks like it works, however:
- i did not checked if positive lat and long are positive (multiply camera vector by -1 may be in wrong place)
- i did not checked if it correctly rotates to long,lat location (again they may be flipped, because you moving Z axis (north pole) in opposite direction, matter of visualizing where Up goes when you move on surface of earth.
- long/lat are in degrees, but i am not absolutely certain.
ps.
there is no way (that i could find) to calculate that all with quats or matrixes in non custom nodes, that stuff is not exposed.
pps.
long and lat are not in degrees, i butchered that calculations somewhere.
Oh and probably vectors are swapped, so it rotates around 0-x instead of Z axis