Skip to content

Instantly share code, notes, and snippets.

@reinsteam
Created November 29, 2017 17:39
Show Gist options
  • Save reinsteam/ab7c62dc49de29974bfcf37b89dd1d9d to your computer and use it in GitHub Desktop.
Save reinsteam/ab7c62dc49de29974bfcf37b89dd1d9d to your computer and use it in GitHub Desktop.
// construct SunDir from cosine of an angle between the vector and zenith (MuS)
SunDir.x = 0.0;
SunDir.y = MuS;
SunDir.z = sqrt(1.0 - MuS * MuS);
// construct EyeDir from cosine of an angle between the vector and zenith (Mu)
EyeDir.x = 0.0;
EyeDir.y = Mu;
EyeDir.z = sqrt(1.0 - Mu * Mu);
Theta => angular difference of projection SunDir and some vector EyeDirRot onto XZ-plane
[ CosTheta 0 SinTheta]
RotYMat = [ 0 1 0 ]
[-SinTheta 0 CosTheta]
// construct EyeDirRot from EyeDir and RotYMat
EyeDirRot.x = SinTheta * sqrt(1.0 - Mu * Mu);
EyeDirRot.y = Mu
EyeDirRot.z = CosTheta * sqrt(1.0 - Mu * Mu);
// compute dot-product SunDir and EyeDirRot
Nu = dot(SunDir, EyeDirRot) = Mu * MuS + CosTheta * SinFromMu * SinFromMuS;
// Express EyeDirRot.z in terms of original parameters
EyeDirRot.z = (Mu * MuS - Nu) / SunDir.z;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment