Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <div id="texture-container">
  <!-- div that will hold our WebGL canvas -->
  <div id="canvas"></div>

  <!-- div used to create our plane -->
  <div class="plane">

    <!-- images that will be used as textures by our plane -->
    <img data-sampler="texture0" id="texture0" src="https://i.ibb.co/q03J05s/background.jpg" crossorigin="anonymous" />
  </div>
</div>

<script id="vs" type="x-shader/x-vertex">
    #ifdef GL_ES
    precision mediump float;
    #endif
    
    uniform float uProgress;
    uniform vec2 uMouse;
    
    // those are the mandatory attributes that the lib sets
    attribute vec3 aVertexPosition;
    attribute vec2 aTextureCoord;

    uniform mat4 uMVMatrix;
    uniform mat4 uPMatrix;

    uniform mat4 texture0Matrix;

    varying vec3 vVertexPosition;
    varying vec2 vTextureCoord0;


    void main() {
        float strength = 50.0;
      
        vec3 vertexPosition = aVertexPosition;

        vTextureCoord0 = (texture0Matrix * vec4(aTextureCoord, 0., 1.)).xy;
      
        vVertexPosition = vertexPosition;
        
        float dist = clamp(1.0 - length( (vertexPosition.xy * 0.5) - uMouse ) / 1.0,0.0, 1.0);
        dist = dist * pow(dist, 2.0);
      
        vertexPosition.z -= dist * strength * uProgress;
      
        gl_Position = uPMatrix * uMVMatrix * vec4(vertexPosition, 1.0);
    }
</script>
<script id="fs" type="x-shader/x-fragment">
    #ifdef GL_ES
    precision mediump float;
    #endif

    #define TAU 6.28318530718
    #define PI 3.14159265359
    #define S(a,b,n) smoothstep(a,b,n)
    #define NUM_OCTAVES 5

    varying vec3 vVertexPosition;
    varying vec2 vTextureCoord0;

    uniform sampler2D texture0;

    void main(){
        vec2 uv0 = vTextureCoord0;
     
        vec4 color = texture2D(texture0, uv0);
      
        gl_FragColor = color;
    }
</script>
            
          
!

CSS

            
              body {
  /* make the body fits our viewport */
  position: relative;
  width: 100%;
  height: 100vh;
  margin: 0;
  overflow: hidden;
  background-color: rgb(0, 0, 0);
}

#texture-container {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

#canvas {
  /* make the canvas wrapper fits the document */
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

.plane {
  /* define the size of your plane */
  width: 100%;
  height: 100vh;
  z-index: 100;
}

.plane img {
  /* hide the img element */
  display: none;
}

            
          
!

JS

            
              class WEBGL {
  constructor(set) {
    this.canvas = set.canvas;
    this.webGLCurtain = new Curtains("canvas");
    this.planeElement = set.planeElement;
    this.mouse = {
      x: 0,
      y: 0
    };
    this.params = {
      vertexShader: document.getElementById("vs").textContent, // our vertex shader ID
      fragmentShader: document.getElementById("fs").textContent, // our framgent shader ID
      widthSegments: 40,
      heightSegments: 40, // we now have 40*40*6 = 9600 vertices !
      uniforms: {
        time: {
          name: "uTime", // uniform name that will be passed to our shaders
          type: "1f", // this means our uniform is a float
          value: 0
        },
        mousepos: {
          name: "uMouse",
          type: "2f",
          value: [0, 0]
        },
        resolution: {
          name: "uReso",
          type: "2f",
          value: [innerWidth, innerHeight]
        },
        progress: {
          name: "uProgress",
          type: "1f",
          value: 0
        }
      }
    };
  }

  initPlane() {
    // create our plane mesh
    this.plane = this.webGLCurtain.addPlane(this.planeElement, this.params);

    // use the onRender method of our plane fired at each requestAnimationFrame call

    if (this.plane) {
      this.plane.onReady(() => {
        this.update();
        this.initEvent();
      });
    }
  }

  update() {
    this.plane.onRender(() => {
      this.plane.uniforms.time.value += 0.01; // update our time uniform value

      this.plane.uniforms.resolution.value = [innerWidth, innerHeight];
    });
  }

  initEvent() {
    this.planeElement.addEventListener("mousemove", e => {
      
          const mouseCoords = this.plane.mouseToPlaneCoords(e.clientX, e.clientY);
      
    // update our mouse position uniform

      TweenMax.to(this.plane.uniforms.mousepos.value, 0.7, {
        0: mouseCoords.x,
        1: mouseCoords.y
      });
    });

    this.planeElement.addEventListener("mousedown", e => {
      TweenMax.to(this.plane.uniforms.progress, 0.5, {
        value: 1,
        ease: "power2.out"
      });
    });

    this.planeElement.addEventListener("mouseup", e => {
      TweenMax.to(this.plane.uniforms.progress, 0.5, {
        value: 0
      });
    });
  }
}

const webgl = new WEBGL({
  canvas: document.getElementById("canvas"),
  planeElement: document.getElementsByClassName("plane")[0]
});

webgl.initPlane();

            
          
!
999px

Console