float getValue2D(in vec2 pos, in float size, in vec2 offset) {
    pos /= 512;
    pos *= size;
    pos += offset;

    return texture(noisetex, pos.xy).x*2.0-1.0;
}
float getValue2D(in vec2 pos) {
    pos /= 512;

    return texture(noisetex, pos.xy).x*2.0-1.0;
}
float getValue2Dn(in vec2 pos, in float size, in vec2 offset) {
    pos /= 512;
    pos *= size;
    pos += offset;

    return texture(noisetex, pos.xy).x*2.0-1.0;
}

float getValue3D(in vec3 pos, in float size, in vec3 offset) {
    pos     *= size;
    pos     += offset*1024;

    vec3 p  = floor(pos); 
    vec3 b  = fract(pos);
        b   = b*b*(3.0-2.0*b);

    vec2 uv = (p.xy+vec2(37.0, 17.0)*p.z)+b.xy;
    vec2 rg = texture(noisetex, (uv+0.5)/512.0).xy;

    return mix(rg.x, rg.y, b.z);
}
float getValue3Dn(in vec3 pos, in float size, in vec3 offset) {
    pos     *= size;
    pos     += offset*1024;

    vec3 p  = floor(pos); 
    vec3 b  = fract(pos);
        b   = b*b*(3.0-2.0*b);

    vec2 uv = (p.xy+vec2(37.0, 17.0)*p.z)+b.xy;
    vec2 rg = texture(noisetex, (uv+0.5)/512.0).xy;

    return mix(rg.x, rg.y, b.z);
}

float getValue3D(in vec3 pos) {
    vec3 p  = floor(pos); 
    vec3 b  = fract(pos);
        b   = b*b*(3.0-2.0*b);

    vec2 uv = (p.xy+vec2(37.0, 17.0)*p.z)+b.xy;
    vec2 rg = texture(noisetex, (uv+0.5)/512.0).xy;

    return smoothCubic(mix(rg.x, rg.y, b.z));
}

float getValue3Db(in vec3 pos, in float size, in vec3 offset) {
    pos     *= size;
    pos     += offset*1024;

    vec3 p  = floor(pos); 
    vec3 b  = fract(pos);
        b   = b*b*(3.0-2.0*b);

    vec2 uv = (p.xy+vec2(37.0, 17.0)*p.z)+b.xy;
    vec2 rg = texture(noisetex, (uv+0.5)/512.0).xy;

    return mix(rg.x, rg.y, b.z)*2.0-1.0;
}