declare const _default: "\n\nvarying vec2 vUv0;\n\n// source\n#ifdef CUBEMAP_SOURCE\n    uniform samplerCube sourceCube;\n#else\n    uniform sampler2D sourceTex;\n#endif\n\n#ifdef USE_SAMPLES_TEX\n    // samples\n    uniform sampler2D samplesTex;\n    uniform vec2 samplesTexInverseSize;\n#endif\n\n// params:\n// x - target cubemap face 0..6\n// y - target image total pixels\n// z - source cubemap size\nuniform vec3 params;\n\nfloat targetFace() { return params.x; }\nfloat targetTotalPixels() { return params.y; }\nfloat sourceTotalPixels() { return params.z; }\n\nfloat PI = 3.141592653589793;\n\nfloat saturate(float x) {\n    return clamp(x, 0.0, 1.0);\n}\n\n#include \"decodePS\"\n#include \"encodePS\"\n\n//-- supported projections\n\nvec3 modifySeams(vec3 dir, float scale) {\n    vec3 adir = abs(dir);\n    float M = max(max(adir.x, adir.y), adir.z);\n    return dir / M * vec3(\n        adir.x == M ? 1.0 : scale,\n        adir.y == M ? 1.0 : scale,\n        adir.z == M ? 1.0 : scale\n    );\n}\n\nvec2 toSpherical(vec3 dir) {\n    return vec2(dir.xz == vec2(0.0) ? 0.0 : atan(dir.x, dir.z), asin(dir.y));\n}\n\nvec3 fromSpherical(vec2 uv) {\n    return vec3(cos(uv.y) * sin(uv.x),\n                sin(uv.y),\n                cos(uv.y) * cos(uv.x));\n}\n\nvec3 getDirectionEquirect() {\n    return fromSpherical((vec2(vUv0.x, 1.0 - vUv0.y) * 2.0 - 1.0) * vec2(PI, PI * 0.5));\n}\n\n// octahedral code, based on https://jcgt.org/published/0003/02/01/\n// \"Survey of Efficient Representations for Independent Unit Vectors\" by Cigolle, Donow, Evangelakos, Mara, McGuire, Meyer\n\nfloat signNotZero(float k){\n    return(k >= 0.0) ? 1.0 : -1.0;\n}\n\nvec2 signNotZero(vec2 v) {\n    return vec2(signNotZero(v.x), signNotZero(v.y));\n}\n\n// Returns a unit vector. Argument o is an octahedral vector packed via octEncode, on the [-1, +1] square\nvec3 octDecode(vec2 o) {\n    vec3 v = vec3(o.x, 1.0 - abs(o.x) - abs(o.y), o.y);\n    if (v.y < 0.0) {\n        v.xz = (1.0 - abs(v.zx)) * signNotZero(v.xz);\n    }\n    return normalize(v);\n}\n\nvec3 getDirectionOctahedral() {\n    return octDecode(vec2(vUv0.x, 1.0 - vUv0.y) * 2.0 - 1.0);\n}\n\n// Assumes that v is a unit vector. The result is an octahedral vector on the [-1, +1] square\nvec2 octEncode(in vec3 v) {\n    float l1norm = abs(v.x) + abs(v.y) + abs(v.z);\n    vec2 result = v.xz * (1.0 / l1norm);\n    if (v.y < 0.0) {\n        result = (1.0 - abs(result.yx)) * signNotZero(result.xy);\n    }\n    return result;\n}\n\n/////////////////////////////////////////////////////////////////////\n\n#ifdef CUBEMAP_SOURCE\n    vec4 sampleCubemap(vec3 dir) {\n        return textureCube(sourceCube, modifySeams(dir, 1.0));\n    }\n\n    vec4 sampleCubemap(vec2 sph) {\n        return sampleCubemap(fromSpherical(sph));\n    }\n\n    vec4 sampleCubemap(vec3 dir, float mipLevel) {\n        return textureCubeLod(sourceCube, modifySeams(dir, 1.0), mipLevel);\n    }\n\n    vec4 sampleCubemap(vec2 sph, float mipLevel) {\n        return sampleCubemap(fromSpherical(sph), mipLevel);\n    }\n#else\n\n    vec4 sampleEquirect(vec2 sph) {\n        vec2 uv = sph / vec2(PI * 2.0, PI) + 0.5;\n        return texture2D(sourceTex, vec2(uv.x, 1.0 - uv.y));\n    }\n\n    vec4 sampleEquirect(vec3 dir) {\n        return sampleEquirect(toSpherical(dir));\n    }\n\n    vec4 sampleEquirect(vec2 sph, float mipLevel) {\n        vec2 uv = sph / vec2(PI * 2.0, PI) + 0.5;\n        return texture2DLod(sourceTex, vec2(uv.x, 1.0 - uv.y), mipLevel);\n    }\n\n    vec4 sampleEquirect(vec3 dir, float mipLevel) {\n        return sampleEquirect(toSpherical(dir), mipLevel);\n    }\n\n    vec4 sampleOctahedral(vec3 dir) {\n        vec2 uv = octEncode(dir) * 0.5 + 0.5;\n        return texture2D(sourceTex, vec2(uv.x, 1.0 - uv.y));\n    }\n\n    vec4 sampleOctahedral(vec2 sph) {\n        return sampleOctahedral(fromSpherical(sph));\n    }\n\n    vec4 sampleOctahedral(vec3 dir, float mipLevel) {\n        vec2 uv = octEncode(dir) * 0.5 + 0.5;\n        return texture2DLod(sourceTex, vec2(uv.x, 1.0 - uv.y), mipLevel);\n    }\n\n    vec4 sampleOctahedral(vec2 sph, float mipLevel) {\n        return sampleOctahedral(fromSpherical(sph), mipLevel);\n    }\n\n#endif\n\nvec3 getDirectionCubemap() {\n    vec2 st = vUv0 * 2.0 - 1.0;\n    float face = targetFace();\n\n    vec3 vec;\n    if (face == 0.0) {\n        vec = vec3(1, -st.y, -st.x);\n    } else if (face == 1.0) {\n        vec = vec3(-1, -st.y, st.x);\n    } else if (face == 2.0) {\n        vec = vec3(st.x, 1, st.y);\n    } else if (face == 3.0) {\n        vec = vec3(st.x, -1, -st.y);\n    } else if (face == 4.0) {\n        vec = vec3(st.x, -st.y, 1);\n    } else {\n        vec = vec3(-st.x, -st.y, -1);\n    }\n\n    return normalize(modifySeams(vec, 1.0));\n}\n\nmat3 matrixFromVector(vec3 n) { // frisvad\n    float a = 1.0 / (1.0 + n.z);\n    float b = -n.x * n.y * a;\n    vec3 b1 = vec3(1.0 - n.x * n.x * a, b, -n.x);\n    vec3 b2 = vec3(b, 1.0 - n.y * n.y * a, -n.y);\n    return mat3(b1, b2, n);\n}\n\nmat3 matrixFromVectorSlow(vec3 n) {\n    vec3 up = (1.0 - abs(n.y) <= 0.0000001) ? vec3(0.0, 0.0, n.y > 0.0 ? 1.0 : -1.0) : vec3(0.0, 1.0, 0.0);\n    vec3 x = normalize(cross(up, n));\n    vec3 y = cross(n, x);\n    return mat3(x, y, n);\n}\n\nvec4 reproject() {\n    if ({NUM_SAMPLES} <= 1) {\n        // single sample\n        return {ENCODE_FUNC}({DECODE_FUNC}({SOURCE_FUNC}({TARGET_FUNC}())));\n    } else {\n        // multi sample\n        vec3 t = {TARGET_FUNC}();\n        vec3 tu = dFdx(t);\n        vec3 tv = dFdy(t);\n\n        vec3 result = vec3(0.0);\n        for (float u = 0.0; u < {NUM_SAMPLES_SQRT}; ++u) {\n            for (float v = 0.0; v < {NUM_SAMPLES_SQRT}; ++v) {\n                result += {DECODE_FUNC}({SOURCE_FUNC}(normalize(t +\n                                                            tu * (u / {NUM_SAMPLES_SQRT} - 0.5) +\n                                                            tv * (v / {NUM_SAMPLES_SQRT} - 0.5))));\n            }\n        }\n        return {ENCODE_FUNC}(result / ({NUM_SAMPLES_SQRT} * {NUM_SAMPLES_SQRT}));\n    }\n}\n\nvec4 unpackFloat = vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0);\n\n#ifdef USE_SAMPLES_TEX\n    void unpackSample(int i, out vec3 L, out float mipLevel) {\n        float u = (float(i * 4) + 0.5) * samplesTexInverseSize.x;\n        float v = (floor(u) + 0.5) * samplesTexInverseSize.y;\n\n        vec4 raw;\n        raw.x = dot(texture2D(samplesTex, vec2(u, v)), unpackFloat); u += samplesTexInverseSize.x;\n        raw.y = dot(texture2D(samplesTex, vec2(u, v)), unpackFloat); u += samplesTexInverseSize.x;\n        raw.z = dot(texture2D(samplesTex, vec2(u, v)), unpackFloat); u += samplesTexInverseSize.x;\n        raw.w = dot(texture2D(samplesTex, vec2(u, v)), unpackFloat);\n\n        L.xyz = raw.xyz * 2.0 - 1.0;\n        mipLevel = raw.w * 8.0;\n    }\n\n    // convolve an environment given pre-generated samples\n    vec4 prefilterSamples() {\n        // construct vector space given target direction\n        mat3 vecSpace = matrixFromVectorSlow({TARGET_FUNC}());\n\n        vec3 L;\n        float mipLevel;\n\n        vec3 result = vec3(0.0);\n        float totalWeight = 0.0;\n        for (int i = 0; i < {NUM_SAMPLES}; ++i) {\n            unpackSample(i, L, mipLevel);\n            result += {DECODE_FUNC}({SOURCE_FUNC}(vecSpace * L, mipLevel)) * L.z;\n            totalWeight += L.z;\n        }\n\n        return {ENCODE_FUNC}(result / totalWeight);\n    }\n\n    // unweighted version of prefilterSamples\n    vec4 prefilterSamplesUnweighted() {\n        // construct vector space given target direction\n        mat3 vecSpace = matrixFromVectorSlow({TARGET_FUNC}());\n\n        vec3 L;\n        float mipLevel;\n\n        vec3 result = vec3(0.0);\n        float totalWeight = 0.0;\n        for (int i = 0; i < {NUM_SAMPLES}; ++i) {\n            unpackSample(i, L, mipLevel);\n            result += {DECODE_FUNC}({SOURCE_FUNC}(vecSpace * L, mipLevel));\n        }\n\n        return {ENCODE_FUNC}(result / float({NUM_SAMPLES}));\n    }\n#endif\n\nvoid main(void) {\n    gl_FragColor = {PROCESS_FUNC}();\n}\n";
export default _default;
