Hello.
I fight this problem already long time.
As we know naive z coordinate reconstruction from x and y coordinates doesn't work properly since there is a sign loss.
That is why i use cry engine approach:
The formulas are very simple:
Normal to GBufffer:
G=normalize(N.xy)*sqrt(N.z*0.5+0.5)
GBuffer to Normal:
N.z=length2(G.xy)*2-1
N.xy=normalize(G.xy)*sqrt(1-N.z*N.z)
I checked it in python and it gives very small error for normalized normal vector - 8.0e-07
But the image with this approach has …