Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.




        margin: 0;
        overflow: hidden;
        background-color: black;
        display: flex;
        justify-content: center;
        align-items: center;
        box-sizing: border-box;


async function init() {
    var img = new Image();
    img.crossOrigin = "Anonymous";
    img.src = "";
    await new Promise( r=> img.onload = r);

    var depth = new Image();
    depth.crossOrigin = "Anonymous";
    depth.src = "";
    await new Promise( r=> depth.onload = r);

    var canvas = document.createElement("canvas");
    canvas.height = img.height;
    canvas.width = img.width;

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

    Object.assign(, {
        maxWidth: "100vw",
        maxHeight: "100vh",
        objectFit: "contain",


    var buffer = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
        -1, -1, -1, 1,
        1, -1, 1, 1,
    ]), gl.STATIC_DRAW);

    gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);

    var vshader = `
    attribute vec2 pos;
    varying vec2 vpos;
    void main(){
        vpos = pos*-0.5 + vec2(0.5);
        gl_Position = vec4(pos, 0.0, 1.0);
    var vs = gl.createShader(gl.VERTEX_SHADER);
    gl.shaderSource(vs, vshader);

    var fshader = `
    precision highp float;
    uniform sampler2D img;
    uniform sampler2D depth;
    uniform vec2 mouse;
    varying vec2 vpos;
    void main(){
        float dp = -0.5 + texture2D(depth, vpos).x;
        gl_FragColor = texture2D(img, vpos + mouse * 0.2 * dp);
    var fs = gl.createShader(gl.FRAGMENT_SHADER);
    gl.shaderSource(fs, fshader);

    var program = gl.createProgram();
    gl.attachShader(program, fs);
    gl.attachShader(program, vs);

    function setTexture(im,name, num) {
        var texture = gl.createTexture();
        gl.activeTexture(gl.TEXTURE0 + num);
        gl.bindTexture(gl.TEXTURE_2D, texture);

        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
        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.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, im);
        gl.uniform1i(gl.getUniformLocation(program, name), num);

    setTexture(img, "img", 0);
    setTexture(depth, "depth", 1);


    function loop() {
        gl.clearColor(0.25, 0.65, 1, 1);
        gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);

    var mouseLoc = gl.getUniformLocation(program, "mouse");
    canvas.onmousemove = function (d) {
        var mpos = [-0.5 + d.layerX / canvas.width, 0.5 - d.layerY / canvas.width]
        gl.uniform2fv(mouseLoc, new Float32Array(mpos));