#ifndef worleyNoiseTex
    #define worleyNoiseTex colortex4
#endif

float worley2D(in vec2 coord, in float size, in vec2 offset) {
    coord      *= size;
    coord      += offset;
    coord      /= 1024;
    return texture(noisetex, coord).g;
}

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

    pos    /= 1024;

    float xy        = texture(noisetex, pos.xy).g;
    float xz        = texture(worleyNoiseTex, pos.xz).g;

    float noise     = xy*xz;
    return sqrt(noise);
}
float worleyVolume(in vec3 pos) {
    pos    /= 1024;

    float xy        = texture(noisetex, pos.xy).g;
    float xz        = texture(worleyNoiseTex, pos.xz).g;

    float noise     = xy*xz;
    return sqrt(noise);
}

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

    pos    /= 1024;

    float xy        = texture(noisetex, pos.xy).g;
    float xz        = texture(worleyNoiseTex, pos.xz).g;
    float yz        = texture(worleyNoiseTex, pos.yz).b;

    float noise     = sqrt(xy*xz)*yz;
    return sqrt(noise);
}
float worleyVolumeHQ(in vec3 pos) {
    pos    /= 1024;
    
    float xy        = texture(noisetex, pos.xy).g;
    float xz        = texture(worleyNoiseTex, pos.xz).g;
    float yz        = texture(worleyNoiseTex, pos.yz).b;

    float noise     = sqrt(xy*xz)*yz;
    return sqrt(noise);
}