 - 0.5*(bmax-bmin);
        return min(max(d.x,max(d.y,d.z)),0.0) + length(max(d,0.0));
    }

    float R10(float r) { float p = 2.0*r/R; return exp(-0.5*p) * 2.0;                                                        }
    float R20(float r) { float p = 2.0*r/R; return exp(-0.5*p) * 1.0/(2.0*sqrt(2.0))   * (2.0 - p);                          }
    float R21(float r) { float p = 2.0*r/R; return exp(-0.5*p) * 1.0/(2.0*sqrt(6.0))   * p;                                  }
    float R30(float r) { float p = 3