//Spheremap Transform from https://aras-p.info/texts/CompactNormalStorage.html
vec2 EncodeNormal(vec3 n){
    float f=sqrt(n.z*8.+8.);
    return n.xy/f+.5;
}

vec3 DecodeNormal(vec2 enc){
    vec2 fenc=enc*4.-2.;
    float f=dot(fenc,fenc);
    float g=sqrt(1.-f/4.);
    vec3 n;
    n.xy=fenc*g;
    n.z=1.-f/2.;
    return n;
}