<commit_before><!DOCTYPE html>
<!--
  The MIT License (MIT)

  Copyright (c) 2017 <NAME>

  Permission is hereby granted, free of charge, to any person obtaining a copy of
  this software and associated documentation files (the "Software"), to deal in
  the Software without restriction, including without limitation the rights to
  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  the Software, and to permit persons to whom the Software is furnished to do so,
  subject to the following conditions:

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<!-- 
    Based on "Weighted Blended Order-Independent Transparency"
    By <NAME> and <NAME> 
    http://jcgt.org/published/0002/02/09/
-->
<html>
<head>
    <style>
        html {
            overflow: hidden;
        }

        body {
            margin: 0;
        }
    </style>
</head>
<body>
    <canvas id="gl-canvas"></canvas>
    <script type="x-shader/vs" id="vertex-accum">
        #version 300 es

        layout(std140, column_major) uniform;
        
        layout(location=0) in vec4 position;
        
        uniform SceneUniforms {
            mat4 uViewProj;
        };

        uniform ObjectUniforms {
            vec4 color;
            vec3 translation;
        };
        
        out vec3 vPosition;

        void main() {
            gl_Position = uViewProj * (position + vec4(translation, 0.0));
        }
    </script>
    <script type="x-shader/fs" id="fragment-accum">
        #version 300 es
        precision highp float;

        ////////////////////////
        // WEIGHT FUNCTIONS
        ////////////////////////

        // From: https://casual-effects.blogspot.com/2015/03/implemented-weighted-blended-order.html
        #define BLOG 1

        // From Morgan's message on Twitter
        #define TWITTER 2

        // Tweaks to Morgans's weight function
        #define MODIFIED_TWITTER 3

        //From: http://casual-effects.com/research/McGuire2017Transparency/index.html
        #define PERCEP_PAPER 3

        ////////////////////////
        // SET WEIGHT FUNCTION
        ////////////////////////

        #define WEIGHT_FUNC TWITTER

        layout(std140, column_major) uniform;

        uniform ObjectUniforms {
            vec4 color;
            vec3 translation;
        };


        layout(location=0) out vec4 accumColor;
        layout(location=1) out float accumAlpha;
        
        float weight(float a) {
            #if WEIGHT_FUNC == BLOG
                return clamp(pow(min(1.0, a * 10.0) + 0.01, 3.0) * 1e8 * pow(1.0 - gl_FragCoord.z * 0.9, 3.0), 1e-2, 3e3);
            #elif WEIGHT_FUNC == TWITTER   
                float tmp = 1.0 - gl_FragCoord.z * 0.99; 
                tmp *= tmp * tmp * 1e4;
                tmp = clamp(tmp, 1e-3, 1.0);
                return clamp(a * tmp, 1e-3, 1.5e2); 
            #elif WEIGHT_FUNC == MODIFIED_TWITTER
                float tmp = 1.0 - gl_FragCoord.z * 0.99;
                tmp *= tmp * tmp * 1e4; 
                return clamp(a * tmp, 1e-3, 3e4);
            #elif WEIGHT_FUNC == PERCEP_PAPER
                float tmp = 10.0 * (1.0 - 0.99 * gl_FragCoord.z) * a;
                float tmp *= tmp * tmp;
                return clamp(tmp, 0.01, 30.0);
            #endif
        }

        void main() {
            vec4 c = color;
            c.rgb *= c.a;
            float w = weight(c.a);
            accumColor = vec4(c.rgb * w, c.a);
            accumAlpha = c.a * w;
        }
    </script>
    <script type="x-shader/vs" id="vertex-quad">
        #version 300 es

        layout(location=0) in vec4 aPosition;
        
        void main() {
            gl_Position = aPosition;
        }
    </script>

    <script type="x-shader/fs" id="fragment-draw">
        #version 300 es
        precision highp float;

        uniform sampler2D uAccumulate;
        uniform sampler2D uAccumulateAlpha;
        out vec4 fragColor;
        void main() {
            ivec2 fragCoord = ivec2(gl_FragCoord.xy);
            vec4 accum = texelFetch(uAccumulate, fragCoord, 0);
            float a = 1.0 - accum.a;
            accum.a = texelFetch(uAccumulateAlpha, fragCoord, 0).r;
            fragColor = vec4(a * accum.rgb / clamp(accum.a, 0.001, 50000.0), a);
        }
    </script>
    <script>
        var canvas = document.getElementById("gl-canvas");
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;

        var gl = canvas.getContext("webgl2");

        if (!gl) {
            console.error("WebGL 2 not available");
            document.body.innerHTML = "This example requires WebGL 2 which is unavailable on this system."
        }

        if (!gl.getExtension("EXT_color_buffer_float")) {
            console.error("FLOAT color buffer not available");
            document.body.innerHTML = "This example requires EXT_color_buffer_float which is unavailable on this system."
        }

        /////////////////////////
        // OBJECT DESCRIPTIONS
        /////////////////////////

        var CAMERA_Z = 2;
        var NEAR = 2.9;
        var FAR = 3;
        var Z_DELTA = 0.01;

        var QUAD_COLORS = [
            [1, 0, 0],
            [0, 1, 0],
            [0, 0, 1],
            [1, 1, 0],
            [0, 1, 1],
            [1, 0, 1],
            [1, 1, 1]
        ];
        QUAD_ALPHA = 0.95;

        var NUM_QUADS = QUAD_COLORS.length;
        var quads = new Array(NUM_QUADS);

        var x = -1;
        var y = -1;
        var z = -1;

        for (var i = 0; i < NUM_QUADS; ++i) {
            var quadUniformData = new Float32Array(8);
            quadUniformData.set(QUAD_COLORS[i]);
            quadUniformData[3] = QUAD_ALPHA;
            quadUniformData[4] = x;
            quadUniformData[5] = y;
            quadUniformData[6] = z;

            var quadUniformBuffer = gl.createBuffer();
            gl.bindBufferBase(gl.UNIFORM_BUFFER, 1, quadUniformBuffer);
            gl.bufferData(gl.UNIFORM_BUFFER, quadUniformData, gl.STATIC_DRAW);

            quads[i] = {
                uniformBuffer: quadUniformBuffer,
                uniformData: quadUniformData
            };

            x += 0.2;
            y += 0.2;
            z += Z_DELTA;
        }

        /////////////////////////
        // ACCUMULATION PROGRAM
        /////////////////////////

        var accumVsSource =  document.getElementById("vertex-accum").text.trim();
        var accumFsSource =  document.getElementById("fragment-accum").text.trim();
        
        var accumVertexShader = gl.createShader(gl.VERTEX_SHADER);
        gl.shaderSource(accumVertexShader, accumVsSource);
        gl.compileShader(accumVertexShader);

        if (!gl.getShaderParameter(accumVertexShader, gl.COMPILE_STATUS)) {
            console.error(gl.getShaderInfoLog(accumVertexShader));
        }

        var accumFragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
        gl.shaderSource(accumFragmentShader, accumFsSource);
        gl.compileShader(accumFragmentShader);

        if (!gl.getShaderParameter(accumFragmentShader, gl.COMPILE_STATUS)) {
            console.error(gl.getShaderInfoLog(accumFragmentShader));
        }

        var accumProgram = gl.createProgram();
        gl.attachShader(accumProgram, accumVertexShader);
        gl.attachShader(accumProgram, accumFragmentShader);
        gl.linkProgram(accumProgram);

        if (!gl.getProgramParameter(accumProgram, gl.LINK_STATUS)) {
            console.error(gl.getProgramInfoLog(accumProgram));
        }

        /////////////////////
        // DRAW PROGRAM
        /////////////////////

        var quadVsSource =  document.getElementById("vertex-quad").text.trim();
        var drawFsSource = document.getElementById("fragment-draw").text.trim();

        var drawVertexShader = gl.createShader(gl.VERTEX_SHADER);
        gl.shaderSource(drawVertexShader, quadVsSource);
        gl.compileShader(drawVertexShader);

        if (!gl.getShaderParameter(drawVertexShader, gl.COMPILE_STATUS)) {
            console.error(gl.getShaderInfoLog(drawVertexShader));
        }

        var drawFragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
        gl.shaderSource(drawFragmentShader, drawFsSource);
        gl.compileShader(drawFragmentShader);

        if (!gl.getShaderParameter(drawFragmentShader, gl.COMPILE_STATUS)) {
            console.error(gl.getShaderInfoLog(drawFragmentShader));
        }

        var drawProgram = gl.createProgram();
        gl.attachShader(drawProgram, drawVertexShader);
        gl.attachShader(drawProgram, drawFragmentShader);
        gl.linkProgram(drawProgram);

        if (!gl.getProgramParameter(drawProgram, gl.LINK_STATUS)) {
            console.error(gl.getProgramInfoLog(drawProgram));
        }

        /////////////////////////
        // GET UNIFORM LOCATIONS
        /////////////////////////

        var sceneUniformsLocation = gl.getUniformBlockIndex(accumProgram, "SceneUniforms");
        gl.uniformBlockBinding(accumProgram, sceneUniformsLocation, 0);

        var objectUniformsLocation = gl.getUniformBlockIndex(accumProgram, "ObjectUniforms");
        gl.uniformBlockBinding(accumProgram, objectUniformsLocation, 1);

        var accumLocation = gl.getUniformLocation(drawProgram, "uAccumulate");
        var accumAlphaLocation = gl.getUniformLocation(drawProgram, "uAccumulateAlpha");

        ////////////////////////////////
        //  SET UP FRAMEBUFFERS
        ////////////////////////////////

        var accumBuffer = gl.createFramebuffer();

        gl.bindFramebuffer(gl.FRAMEBUFFER, accumBuffer);

        gl.activeTexture(gl.TEXTURE0);
        var accumTarget = gl.createTexture();
        gl.bindTexture(gl.TEXTURE_2D, accumTarget);
        gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
        gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGBA32F, gl.drawingBufferWidth, gl.drawingBufferHeight);
        gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, accumTarget, 0);

        gl.activeTexture(gl.TEXTURE1);
        var accumAlphaTarget = gl.createTexture();
        gl.bindTexture(gl.TEXTURE_2D, accumAlphaTarget);
        gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
        gl.texStorage2D(gl.TEXTURE_2D, 1, gl.R32F, gl.drawingBufferWidth, gl.drawingBufferHeight);
        gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT1, gl.TEXTURE_2D, accumAlphaTarget, 0);

        gl.activeTexture(gl.TEXTURE2);
        var depthTarget = gl.createTexture();
        gl.bindTexture(gl.TEXTURE_2D, depthTarget);
        gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
        gl.texStorage2D(gl.TEXTURE_2D, 1, gl.DEPTH_COMPONENT32F, gl.drawingBufferWidth, gl.drawingBufferHeight);
        gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, depthTarget, 0);

         gl.drawBuffers([
            gl.COLOR_ATTACHMENT0,
            gl.COLOR_ATTACHMENT1
        ]);

        gl.bindFramebuffer(gl.FRAMEBUFFER, null);


        gl.useProgram(drawProgram);
        gl.uniform1i(accumLocation, 0);
        gl.uniform1i(accumAlphaLocation, 1);

        /////////////////////
        // SET UP GEOMETRY
        /////////////////////

        // Quad for draw pass
        var quadArray = gl.createVertexArray();
        gl.bindVertexArray(quadArray);

        var quadPositionBuffer = gl.createBuffer();
        gl.bindBuffer(gl.ARRAY_BUFFER, quadPositionBuffer);<commit_msg>New weight func for OIT test<commit_after><!DOCTYPE html>
<!--
  The MIT License (MIT)

  Copyright (c) 2017 <NAME>

  Permission is hereby granted, free of charge, to any person obtaining a copy of
  this software and associated documentation files (the "Software"), to deal in
  the Software without restriction, including without limitation the rights to
  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  the Software, and to permit persons to whom the Software is furnished to do so,
  subject to the following conditions:

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<!-- 
    Based on "Weighted Blended Order-Independent Transparency"
    By <NAME> and <NAME> 
    http://jcgt.org/published/0002/02/09/
-->
<html>
<head>
    <style>
        html {
            overflow: hidden;
        }

        body {
            margin: 0;
        }
    </style>
</head>
<body>
    <canvas id="gl-canvas"></canvas>
    <script type="x-shader/vs" id="vertex-accum">
        #version 300 es

        layout(std140, column_major) uniform;
        
        layout(location=0) in vec4 position;
        
        uniform SceneUniforms {
            mat4 uViewProj;
        };

        uniform ObjectUniforms {
            vec4 color;
            vec3 translation;
        };
        
        out vec3 vPosition;

        void main() {
            gl_Position = uViewProj * (position + vec4(translation, 0.0));
        }
    </script>
    <script type="x-shader/fs" id="fragment-accum">
        #version 300 es
        precision highp float;

        ////////////////////////
        // WEIGHT FUNCTIONS
        ////////////////////////

        // From: https://casual-effects.blogspot.com/2015/03/implemented-weighted-blended-order.html
        #define BLOG 1

        // From Morgan's message on Twitter
        #define TWITTER 2

        // Tweaks to Morgans's weight function
        #define MODIFIED_TWITTER 3

        //From: http://casual-effects.com/research/McGuire2017Transparency/index.html
        #define PERCEP_PAPER 3

        // My own. An 8th degree polynomial on depth.
        #define POLY_D 4

        ////////////////////////
        // SET WEIGHT FUNCTION
        ////////////////////////

        #define WEIGHT_FUNC TWITTER

        layout(std140, column_major) uniform;

        uniform ObjectUniforms {
            vec4 color;
            vec3 translation;
        };


        layout(location=0) out vec4 accumColor;
        layout(location=1) out float accumAlpha;
        
        float weight(float a) {            
            #if WEIGHT_FUNC == BLOG
                return clamp(pow(min(1.0, a * 10.0) + 0.01, 3.0) * 1e8 * pow(1.0 - gl_FragCoord.z * 0.9, 3.0), 1e-2, 3e3);
            #elif WEIGHT_FUNC == TWITTER   
                float tmp = 1.0 - gl_FragCoord.z * 0.99; 
                tmp *= tmp * tmp * 1e4;
                tmp = clamp(tmp, 1e-3, 1.0);
                return clamp(a * tmp, 1e-3, 1.5e2); 
            #elif WEIGHT_FUNC == MODIFIED_TWITTER
                float tmp = 1.0 - gl_FragCoord.z * 0.99;
                tmp *= tmp * tmp * 1e4; 
                return clamp(a * tmp, 1e-3, 3e4);
            #elif WEIGHT_FUNC == PERCEP_PAPER
                float tmp = 10.0 * (1.0 - 0.99 * gl_FragCoord.z) * a;
                float tmp *= tmp * tmp;
                return clamp(tmp, 0.01, 30.0);
            #elif WEIGHT_FUNC == POLY_D
                float d = 1.0 - gl_FragCoord.z * 0.99;
                float d2 = d * d;
                float d4 = d2 * d2;
                float d8 = d4 * d4;
                return clamp((d + 10.0 * d2 + 100.0 * d4 + 10000.0 * d8), 0.01, 2e4);
            #endif
        }

        void main() {
            vec4 c = color;
            c.rgb *= c.a;
            float w = weight(c.a);
            accumColor = vec4(c.rgb * w, c.a);
            accumAlpha = c.a * w;
        }
    </script>
    <script type="x-shader/vs" id="vertex-quad">
        #version 300 es

        layout(location=0) in vec4 aPosition;
        
        void main() {
            gl_Position = aPosition;
        }
    </script>

    <script type="x-shader/fs" id="fragment-draw">
        #version 300 es
        precision highp float;

        uniform sampler2D uAccumulate;
        uniform sampler2D uAccumulateAlpha;
        out vec4 fragColor;
        void main() {
            ivec2 fragCoord = ivec2(gl_FragCoord.xy);
            vec4 accum = texelFetch(uAccumulate, fragCoord, 0);
            float a = 1.0 - accum.a;
            accum.a = texelFetch(uAccumulateAlpha, fragCoord, 0).r;
            fragColor = vec4(a * accum.rgb / clamp(accum.a, 0.001, 50000.0), a);
        }
    </script>
    <script>
        var canvas = document.getElementById("gl-canvas");
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;

        var gl = canvas.getContext("webgl2");

        if (!gl) {
            console.error("WebGL 2 not available");
            document.body.innerHTML = "This example requires WebGL 2 which is unavailable on this system."
        }

        if (!gl.getExtension("EXT_color_buffer_float")) {
            console.error("FLOAT color buffer not available");
            document.body.innerHTML = "This example requires EXT_color_buffer_float which is unavailable on this system."
        }

        /////////////////////////
        // OBJECT DESCRIPTIONS
        /////////////////////////

        var CAMERA_Z = 2;
        var NEAR = 2.9;
        var FAR = 3;
        var Z_DELTA = 0.01;

        var QUAD_COLORS = [
            [1, 0, 0],
            [0, 1, 0],
            [0, 0, 1],
            [1, 1, 0],
            [0, 1, 1],
            [1, 0, 1],
            [1, 1, 1]
        ];
        QUAD_ALPHA = 0.95;

        var NUM_QUADS = QUAD_COLORS.length;
        var quads = new Array(NUM_QUADS);

        var x = -1;
        var y = -1;
        var z = -1;

        for (var i = 0; i < NUM_QUADS; ++i) {
            var quadUniformData = new Float32Array(8);
            quadUniformData.set(QUAD_COLORS[i]);
            quadUniformData[3] = QUAD_ALPHA;
            quadUniformData[4] = x;
            quadUniformData[5] = y;
            quadUniformData[6] = z;

            var quadUniformBuffer = gl.createBuffer();
            gl.bindBufferBase(gl.UNIFORM_BUFFER, 1, quadUniformBuffer);
            gl.bufferData(gl.UNIFORM_BUFFER, quadUniformData, gl.STATIC_DRAW);

            quads[i] = {
                uniformBuffer: quadUniformBuffer,
                uniformData: quadUniformData
            };

            x += 0.2;
            y += 0.2;
            z += Z_DELTA;
        }

        /////////////////////////
        // ACCUMULATION PROGRAM
        /////////////////////////

        var accumVsSource =  document.getElementById("vertex-accum").text.trim();
        var accumFsSource =  document.getElementById("fragment-accum").text.trim();
        
        var accumVertexShader = gl.createShader(gl.VERTEX_SHADER);
        gl.shaderSource(accumVertexShader, accumVsSource);
        gl.compileShader(accumVertexShader);

        if (!gl.getShaderParameter(accumVertexShader, gl.COMPILE_STATUS)) {
            console.error(gl.getShaderInfoLog(accumVertexShader));
        }

        var accumFragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
        gl.shaderSource(accumFragmentShader, accumFsSource);
        gl.compileShader(accumFragmentShader);

        if (!gl.getShaderParameter(accumFragmentShader, gl.COMPILE_STATUS)) {
            console.error(gl.getShaderInfoLog(accumFragmentShader));
        }

        var accumProgram = gl.createProgram();
        gl.attachShader(accumProgram, accumVertexShader);
        gl.attachShader(accumProgram, accumFragmentShader);
        gl.linkProgram(accumProgram);

        if (!gl.getProgramParameter(accumProgram, gl.LINK_STATUS)) {
            console.error(gl.getProgramInfoLog(accumProgram));
        }

        /////////////////////
        // DRAW PROGRAM
        /////////////////////

        var quadVsSource =  document.getElementById("vertex-quad").text.trim();
        var drawFsSource = document.getElementById("fragment-draw").text.trim();

        var drawVertexShader = gl.createShader(gl.VERTEX_SHADER);
        gl.shaderSource(drawVertexShader, quadVsSource);
        gl.compileShader(drawVertexShader);

        if (!gl.getShaderParameter(drawVertexShader, gl.COMPILE_STATUS)) {
            console.error(gl.getShaderInfoLog(drawVertexShader));
        }

        var drawFragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
        gl.shaderSource(drawFragmentShader, drawFsSource);
        gl.compileShader(drawFragmentShader);

        if (!gl.getShaderParameter(drawFragmentShader, gl.COMPILE_STATUS)) {
            console.error(gl.getShaderInfoLog(drawFragmentShader));
        }

        var drawProgram = gl.createProgram();
        gl.attachShader(drawProgram, drawVertexShader);
        gl.attachShader(drawProgram, drawFragmentShader);
        gl.linkProgram(drawProgram);

        if (!gl.getProgramParameter(drawProgram, gl.LINK_STATUS)) {
            console.error(gl.getProgramInfoLog(drawProgram));
        }

        /////////////////////////
        // GET UNIFORM LOCATIONS
        /////////////////////////

        var sceneUniformsLocation = gl.getUniformBlockIndex(accumProgram, "SceneUniforms");
        gl.uniformBlockBinding(accumProgram, sceneUniformsLocation, 0);

        var objectUniformsLocation = gl.getUniformBlockIndex(accumProgram, "ObjectUniforms");
        gl.uniformBlockBinding(accumProgram, objectUniformsLocation, 1);

        var accumLocation = gl.getUniformLocation(drawProgram, "uAccumulate");
        var accumAlphaLocation = gl.getUniformLocation(drawProgram, "uAccumulateAlpha");

        ////////////////////////////////
        //  SET UP FRAMEBUFFERS
        ////////////////////////////////

        var accumBuffer = gl.createFramebuffer();

        gl.bindFramebuffer(gl.FRAMEBUFFER, accumBuffer);

        gl.activeTexture(gl.TEXTURE0);
        var accumTarget = gl.createTexture();
        gl.bindTexture(gl.TEXTURE_2D, accumTarget);
        gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
        gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGBA32F, gl.drawingBufferWidth, gl.drawingBufferHeight);
        gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, accumTarget, 0);

        gl.activeTexture(gl.TEXTURE1);
        var accumAlphaTarget = gl.createTexture();
        gl.bindTexture(gl.TEXTURE_2D, accumAlphaTarget);
        gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
        gl.texStorage2D(gl.TEXTURE_2D, 1, gl.R32F, gl.drawingBufferWidth, gl.drawingBufferHeight);
        gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT1, gl.TEXTURE_2D, accumAlphaTarget, 0);

        gl.activeTexture(gl.TEXTURE2);
        var depthTarget = gl.createTexture();
        gl.bindTexture(gl.TEXTURE_2D, depthTarget);
        gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
        gl.texStorage2D(gl.TEXTURE_2D, 1, gl.DEPTH_COMPONENT32F, gl.drawingBufferWidth, gl.drawingBufferHeight);
        gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, depthTarget, 0);

        gl.drawBuffers([
            gl.COLOR_ATTACHMENT0,
            gl.COLOR_ATTACHMENT1
        ]);

        gl.bindFramebuffer(gl.FRAMEBUFFER, null);


        gl.useProgram(drawProgram);
        gl.uniform1i(accumLocation, 0);
        gl.uniform1i(accumAlphaLocation, 1);

        /////////////////////
        // SET UP GEOMETRY
        /////////////////////

        // Quad for draw pass
        var quadArray = gl.createVertexArray();
        gl.bindVertexArray(quadArray);

        var quadPositionBuffer = gl.createBuffer();
        gl.bindBuffer(gl.ARRAY_BUFFER, quadPositionBuffer);
{'fraction_non_alphanumeric': 0.12915918554456202, 'fraction_numerical': 0.02036138594949765, 'mean_word_length': 2.0048209366391183, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 49, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '6481709', 'n_tokens_mistral': 8350, 'n_tokens_neox': 7676, 'n_words': 1675}