I don't know much about 3d stuff or shaders or this language, but I know golf, and I think I found a byte to save.
w = g-g*exp(-mix(h*3e2,d*2.5,a=h<.001?0.:1.))
w = g-g/exp(mix(h*3e2,d*2.5,a=h<.001?0.:1.))