<commit_before><html lang="en">
    <head>
        <title>WebGL/GLSL - Mars Pixel Shader</title>
        <meta charset="utf-8">
        <link rel="stylesheet" type="text/css" href="../../css/styles.css">
    </head>

    <body>
        <div id="container"></div>
    </body>

    <script src="../../js/Three.min.js"></script>
    <script src="../../js/Detector.js"></script>

    <script type="x-shader/x-vertex" id="vertexShader">
        // Vertex Shader code

        void main() {
            gl_Position = vec4(position.xy, 1.0, 1.0);
        }
    </script>

    <script type="x-shader/x-fragment" id="fragmentShader">
        // Fragment Shader code

        // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
        // This shader has been an entry for the NVScene 2015 Shadertoy Hackaton.

        uniform vec2 uResolution;
        uniform float uGlobalTime;
        uniform vec4 uMouse;
        uniform sampler2D uTexture0;

        vec3 skyColor = vec3(0.65, 0.28, 0.1);
        vec3 sunColor = vec3(1.8, 1.0, 0.6);
        vec3 sunLightColor = vec3(1.7, 1.25, 0.9);
        vec3 skyLightColor = vec3(0.8, 0.35, 0.15);
        vec3 indLightColor = vec3(0.4, 0.3, 0.2);
        vec3 horizonColor = vec3(0.85, 0.35, 0.15);

        vec3 sunDirection = normalize(vec3(0.6, 0.4, 0.9));

        float noise(in vec2 p) {
            p += vec2(16.6, 17.0);
            return texture2D(uTexture0, p / 256.0, -100.0).x;
        }

        float noise3d(vec3 x) {
            // fast 3d noise fetched from 2d rgb texture by IQ.
            vec3 p = floor(x);
            vec3 f = fract(x);
            f = f * f * (3.0 - 2.0 * f);
            vec2 uv = (p.xy + vec2(37.0, 17.0) * p.z) + f.xy;
            vec2 rg = texture2D(uTexture0, (uv + 0.5) / 256.0, -100.0).yx;
            return mix(rg.x, rg.y, f.z);
        }

        float fBm(in vec2 p) {
            float sum = 0.0;
            float amp = 1.0;
            for(int i = 0; i < 4; i++) {
                sum += amp * noise(p);
                amp *= 0.5;
                p *= 2.5;
            }
            return sum * 0.5 + 0.15;
        }

        float fBm3d(in vec3 p) {
            float sum = 0.0;
            float amp = 1.0;
            for(int i = 0; i < 4; i++) {
                sum += amp * noise3d(p);
                amp *= 0.5;
                p *= 2.0;
            }
            return sum;
        }

        float warp(in vec3 p) {
            vec3 q, r;
            q.x = fBm3d(p);
            q.y = fBm3d(p + vec3(5.2,1.3,8.4));
            q.z = fBm3d(p + vec3(2.2,5.4,7.9));
            r.x = fBm3d(p + 2.0 * q + vec3(1.7,9.2,5.2));
            r.y = fBm3d(p + 2.0 * q + vec3(8.3,2.8,4.8));
            r.z = fBm3d(p + 2.0 * q + vec3(5.7,4.3,2.4));
            return fBm3d(p + 4.0 * r);
        }

        float length2(in vec2 p) {
            return sqrt(p.x*p.x + p.y*p.y);
        }

        float length8(in vec2 p) {
            p = p*p; p = p*p; p = p*p;
            return pow(p.x + p.y, 1.0 / 8.0);
        }

        float sdTorus82(in vec3 p, in vec2 t) {
            // signed torus distance function, check out IQ's page
            // for a list of useful distance functions:
            // http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
            vec2 q = vec2(length2(p.xz) - t.x, p.y);
            return length8(q) - t.y;
        }

        float sdBox(in vec3 p, in vec3 box) {
            // signed box distance function, check out IQ's page
            // for a list of useful distance functions:
            // http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
            vec3 d = abs(p) - box;
            return min(max(d.x, max(d.y, d.z)), 0.0) + length(max(d, 0.0));
        }

        float sdSphere(in vec3 p, float s) {
            // signed sphere distance function, check out IQ's page
            // for a list of useful distance functions:
            // http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
            return length(p) - s;
        }

        float sdTriPrism(in vec3 p, vec2 h) {
            // signed triangular prism distance function, check out IQ's page
            // for a list of useful distance functions:
            // http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
            vec3 q = abs(p);
            return max(q.z - h.y, max(q.x * 0.866025 + p.y * 0.5, -p.y) - h.x * 0.5);
        }

        float smin(float a, float b, float k) {
            // smooth minimum, used to blend shapes:
            // http://www.iquilezles.org/www/articles/smin/smin.htm
            float res = exp(-k * a) + exp(-k * b);
            return -log(res) / k;
        }

        vec3 rotateX(in vec3 p, float an) {
            float c = cos(an);
            float s = sin(an);
            return vec3(p.x, c * p.y - s * p.z, s * p.y + c * p.z);
        }

        vec3 rotateY(in vec3 p, float an) {
            float c = cos(an);
            float s = sin(an);
            return vec3(c * p.x + s * p.z, p.y, -s * p.x + c * p.z);
        }

        vec3 rotateZ(in vec3 p, float an) {
            float c = cos(an);
            float s = sin(an);
            return vec3(c * p.x - s * p.y, s * p.x + c * p.y, p.z);
        }

        vec2 map(in vec3 p, bool frame) {
            vec2 res = vec2(0.0, p.y - fBm(p.xz));
            if (frame) {
                float d1 = sdBox(rotateX(rotateY(p - vec3(0.0, 1.0, 0.0), -1.25), 1.58), vec3(0.5, 0.0, 0.5));
                vec2 obj = vec2(1.0, max(d1, sdSphere(p - vec3(0.0, 1.0, 0.0), 0.5)));
                if (obj.y < res.y) res = obj;
            }
            float d2 = sdTriPrism(rotateX(rotateY(p - vec3(0.0, 1.51, 0.0), -1.25), 3.14159), vec2(0.025, 0.055));
            vec2 obj = vec2(2.0, smin(sdTorus82(rotateX(rotateY(p - vec3(0.0, 1.0, 0.0), -1.25), 1.58), vec2(0.5, 0.05)), d2, 16.0));
            if (obj.y < res.y) res = obj;
            obj = vec2(3.0, sdTriPrism(rotateX(rotateY(p - vec3(0.0, 1.51, 0.0), -1.25), 3.14159), vec2(0.025, 0.1)));
            if (obj.y < res.y) res = obj;
            obj = vec2(3.1, sdTriPrism(rotateZ(rotateX(rotateY(p - vec3(-0.1, 1.41, 0.3), -1.25), 3.14159), 0.68), vec2(0.025, 0.055)));
            if (obj.y < res.y) res = obj;
            obj = vec2(3.2, sdTriPrism(rotateZ(rotateX(rotateY(p - vec3(0.1, 1.41, -0.3), -1.25), 3.14159), -0.68), vec2(0.025, 0.055)));
            if (obj.y < res.y) res = obj;
            obj = vec2(3.3, sdTriPrism(rotateZ(rotateX(rotateY(p - vec3(-0.155, 1.15, 0.47), -1.25), 3.14159), 1.26), vec2(0.025, 0.055)));
            if (obj.y < res.y) res = obj;
            obj = vec2(3.4, sdTriPrism(rotateZ(rotateX(rotateY(p - vec3(0.155, 1.15, -0.47), -1.25), 3.14159), -1.26), vec2(0.025, 0.055)));
            if (obj.y < res.y) res = obj;
            obj = vec2(3.5, sdTriPrism(rotateZ(rotateX(rotateY(p - vec3(-0.152, 0.825, 0.467), -1.25), 3.14159), 1.94), vec2(0.025, 0.055)));
            if (obj.y < res.y) res = obj;
            obj = vec2(3.6, sdTriPrism(rotateZ(rotateX(rotateY(p - vec3(0.157, 0.825, -0.467), -1.25), 3.14159), -1.94), vec2(0.025, 0.055)));
            if (obj.y < res.y) res = obj;

            return res;
        }

        vec2 map(in vec3 p) {
            return map(p, true);
        }

        vec3 raymarchTerrain(in vec3 ro, in vec3 rd, in float tmin, in float tmax) {
            // terrain marching as explained by <NAME> in his articles:
            // http://www.iquilezles.org/www/articles/terrainmarching/terrainmarching.htm
            float t = tmin;
            vec3 res = vec3(-1.0);
            for (int i = 0; i < 110; i++) {
                vec3 p = ro + rd * t;
                res = vec3(map(p), t);
                float d = res.y;
                if (d < (0.001 * t) || t > tmax)
                    break;
                t += 0.5 * d;
            }
            return res;
        }

        vec3 getTerrainNormal(in vec3 p) {
            // computes terrain normal with central differences: http://en.wikipedia.org/wiki/Finite_difference<commit_msg>Improve TheBarsoomGate demo<commit_after><html lang="en">
    <head>
        <title>WebGL/GLSL - Mars Pixel Shader</title>
        <meta charset="utf-8">
        <link rel="stylesheet" type="text/css" href="../../css/styles.css">
    </head>

    <body>
        <div id="container"></div>
    </body>

    <script src="../../js/Three.min.js"></script>
    <script src="../../js/Detector.js"></script>

    <script type="x-shader/x-vertex" id="vertexShader">
        // Vertex Shader code

        void main() {
            gl_Position = vec4(position.xy, 1.0, 1.0);
        }
    </script>

    <script type="x-shader/x-fragment" id="fragmentShader">
        // Fragment Shader code

        // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
        // This shader has been an entry for the NVScene 2015 Shadertoy Hackaton.

        uniform vec2 uResolution;
        uniform float uGlobalTime;
        uniform vec4 uMouse;
        uniform sampler2D uTexture0;

        vec3 skyColor = vec3(0.65, 0.28, 0.1);
        vec3 sunColor = vec3(1.8, 1.0, 0.6);
        vec3 sunLightColor = vec3(1.7, 1.25, 0.9);
        vec3 skyLightColor = vec3(0.8, 0.35, 0.15);
        vec3 indLightColor = vec3(0.4, 0.3, 0.2);
        vec3 horizonColor = vec3(0.85, 0.35, 0.15);

        vec3 sunDirection = normalize(vec3(0.6, 0.4, 0.9));

        float noise(in vec2 p) {
            p += vec2(16.6, 17.0);
            return texture2D(uTexture0, p / 256.0, -100.0).x;
        }

        float noise3d(vec3 x) {
            // fast 3d noise fetched from 2d rgb texture by IQ.
            vec3 p = floor(x);
            vec3 f = fract(x);
            f = f * f * (3.0 - 2.0 * f);
            vec2 uv = (p.xy + vec2(37.0, 17.0) * p.z) + f.xy;
            vec2 rg = texture2D(uTexture0, (uv + 0.5) / 256.0, -100.0).yx;
            return mix(rg.x, rg.y, f.z);
        }

        float fBm(in vec2 p) {
            float sum = 0.0;
            float amp = 1.0;
            for(int i = 0; i < 4; i++) {
                sum += amp * noise(p);
                amp *= 0.5;
                p *= 2.5;
            }
            return sum * 0.5 + 0.15;
        }

        float fBm3d(in vec3 p) {
            float sum = 0.0;
            float amp = 1.0;
            for(int i = 0; i < 4; i++) {
                sum += amp * noise3d(p);
                amp *= 0.5;
                p *= 2.0;
            }
            return sum;
        }

        float warp(in vec3 p) {
            vec3 q, r;
            q.x = fBm3d(p);
            q.y = fBm3d(p + vec3(5.2,1.3,8.4));
            q.z = fBm3d(p + vec3(2.2,5.4,7.9));
            r.x = fBm3d(p + 2.0 * q + vec3(1.7,9.2,5.2));
            r.y = fBm3d(p + 2.0 * q + vec3(8.3,2.8,4.8));
            r.z = fBm3d(p + 2.0 * q + vec3(5.7,4.3,2.4));
            return fBm3d(p + 4.0 * r);
        }

        float length2(in vec2 p) {
            return sqrt(p.x*p.x + p.y*p.y);
        }

        float length8(in vec2 p) {
            p = p*p; p = p*p; p = p*p;
            return pow(p.x + p.y, 1.0 / 8.0);
        }

        float sdTorus82(in vec3 p, in vec2 t) {
            // signed torus distance function, check out IQ's page
            // for a list of useful distance functions:
            // http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
            vec2 q = vec2(length2(p.xz) - t.x, p.y);
            return length8(q) - t.y;
        }

        float sdBox(in vec3 p, in vec3 box) {
            // signed box distance function, check out IQ's page
            // for a list of useful distance functions:
            // http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
            vec3 d = abs(p) - box;
            return min(max(d.x, max(d.y, d.z)), 0.0) + length(max(d, 0.0));
        }

        float sdSphere(in vec3 p, float s) {
            // signed sphere distance function, check out IQ's page
            // for a list of useful distance functions:
            // http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
            return length(p) - s;
        }

        float sdTriPrism(in vec3 p, vec2 h) {
            // signed triangular prism distance function, check out IQ's page
            // for a list of useful distance functions:
            // http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
            vec3 q = abs(p);
            return max(q.z - h.y, max(q.x * 0.866025 + p.y * 0.5, -p.y) - h.x * 0.5);
        }

        float smin(float a, float b, float k) {
            // smooth minimum, used to blend shapes:
            // http://www.iquilezles.org/www/articles/smin/smin.htm
            float res = exp(-k * a) + exp(-k * b);
            return -log(res) / k;
        }

        vec3 rotateX(in vec3 p, float an) {
            float c = cos(an);
            float s = sin(an);
            return vec3(p.x, c * p.y - s * p.z, s * p.y + c * p.z);
        }

        vec3 rotateY(in vec3 p, float an) {
            float c = cos(an);
            float s = sin(an);
            return vec3(c * p.x + s * p.z, p.y, -s * p.x + c * p.z);
        }

        vec3 rotateZ(in vec3 p, float an) {
            float c = cos(an);
            float s = sin(an);
            return vec3(c * p.x - s * p.y, s * p.x + c * p.y, p.z);
        }

        vec2 map(in vec3 p, bool frame) {
            vec2 res = vec2(0.0, p.y - fBm(p.xz));
            if (frame) {
                float d1 = sdBox(rotateX(rotateY(p - vec3(0.0, 1.0, 0.0), -1.25), 1.58), vec3(0.5, 0.0, 0.5));
                vec2 obj = vec2(1.0, max(d1, sdSphere(p - vec3(0.0, 1.0, 0.0), 0.5)));
                if (obj.y < res.y) res = obj;
            }
            float d2 = sdTriPrism(rotateX(rotateY(p - vec3(0.0, 1.51, 0.0), -1.25), 3.14159), vec2(0.025, 0.055));
            float d3 = sdTriPrism(rotateZ(rotateX(rotateY(p - vec3(-0.112, 0.635, 0.35), -1.25), 3.14159), 2.35), vec2(0.025, 0.055));
            float d4 = sdTriPrism(rotateZ(rotateX(rotateY(p - vec3(0.112, 0.635, -0.35), -1.25), 3.14159), -2.35), vec2(0.025, 0.055));
            vec2 obj = vec2(2.0, smin(smin(smin(sdTorus82(rotateX(rotateY(p - vec3(0.0, 1.0, 0.0), -1.25), 1.58), vec2(0.5, 0.05)), d2, 16.0), d3, 16.0), d4, 16.0));
            if (obj.y < res.y) res = obj;
            obj = vec2(3.0, sdTriPrism(rotateX(rotateY(p - vec3(0.0, 1.51, 0.0), -1.25), 3.14159), vec2(0.025, 0.1)));
            if (obj.y < res.y) res = obj;
            obj = vec2(3.1, sdTriPrism(rotateZ(rotateX(rotateY(p - vec3(-0.122, 1.36, 0.35), -1.25), 3.14159), 0.84), vec2(0.025, 0.055)));
            if (obj.y < res.y) res = obj;
            obj = vec2(3.2, sdTriPrism(rotateZ(rotateX(rotateY(p - vec3(0.117, 1.36, -0.35), -1.25), 3.14159), -0.84), vec2(0.025, 0.055)));
            if (obj.y < res.y) res = obj;
            obj = vec2(3.3, sdTriPrism(rotateZ(rotateX(rotateY(p - vec3(-0.162, 1.0, 0.49), -1.25), 3.14159), 1.6), vec2(0.025, 0.055)));
            if (obj.y < res.y) res = obj;
            obj = vec2(3.4, sdTriPrism(rotateZ(rotateX(rotateY(p - vec3(0.162, 1.0, -0.49), -1.25), 3.14159), -1.6), vec2(0.025, 0.055)));
            if (obj.y < res.y) res = obj;
            obj = vec2(3.5, sdTriPrism(rotateZ(rotateX(rotateY(p - vec3(-0.112, 0.635, 0.35), -1.25), 3.14159), 2.35), vec2(0.025, 0.1)));
            if (obj.y < res.y) res = obj;
            obj = vec2(3.6, sdTriPrism(rotateZ(rotateX(rotateY(p - vec3(0.115, 0.635, -0.35), -1.25), 3.14159), -2.35), vec2(0.025, 0.1)));
            if (obj.y < res.y) res = obj;

            return res;
        }

        vec2 map(in vec3 p) {
            return map(p, true);
        }

        vec3 raymarchTerrain(in vec3 ro, in vec3 rd, in float tmin, in float tmax) {
            // terrain marching as explained by <NAME> in his articles:
            // http://www.iquilezles.org/www/articles/terrainmarching/terrainmarching.htm
            float t = tmin;
            vec3 res = vec3(-1.0);
            for (int i = 0; i < 110; i++) {
                vec3 p = ro + rd * t;
                res = vec3(map(p), t);
                float d = res.y;
                if (d < (0.001 * t) || t > tmax)
                    break;
                t += 0.5 * d;
            }
            return res;
        }

        vec3 getTerrainNormal(in vec3 p) {
            // computes terrain normal with central differences: http://en.wikipedia.org/wiki/Finite_difference
{'fraction_non_alphanumeric': 0.1660918497004901, 'fraction_numerical': 0.07841713559629697, 'mean_word_length': 1.4698147041243275, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 24, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4427688', 'n_tokens_mistral': 6909, 'n_tokens_neox': 6205, 'n_words': 1509}