Last active
May 30, 2020 13:14
-
-
Save menduz/2c354969f9c28fed1bdde0d7b473abb6 to your computer and use it in GitHub Desktop.
Normal encoding/decoding in float2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Encoding: | |
float2 atanYX = atan2(normalIn.y,normalIn.x); | |
float2 normalOut = float2(atanYX/PI,normalIn.z); | |
normalOut = (normalOut+1.0)+0.5; | |
//Decoding: | |
float2 angles = normalOut*2.0- 1.0; | |
float2 theta = sincos(angles.x*PI,theta.x,theta.y); | |
float2 phi = float2(sqrt(1.0- angles.y*angles.y),angles.y); | |
float3 normal = float3(theta.y*phi.x,theta.x*phi.x,phi.y); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment