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="wrap-texture">
  <!-- 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://images.unsplash.com/photo-1575144103487-b8da1f444b45?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ" crossorigin="anonymous" />
  </div>
</div>

<script id="vs"> 
    #ifdef GL_ES
    precision mediump float;
    #endif
    
    uniform float uTime; 
    
    // those are the mandatory attributes that the lib sets
    attribute vec3 aVertexPosition;
    attribute vec2 aTextureCoord;

    // those are mandatory uniforms that the lib sets and that contain our model view and projection matrix
    uniform mat4 uMVMatrix;
    uniform mat4 uPMatrix;

    uniform mat4 texture0Matrix;
    uniform mat4 texture1Matrix;

    // if you want to pass your vertex and texture coords to the fragment shader
    varying vec3 vVertexPosition;
    varying vec2 vTextureCoord0;
    varying vec2 vTextureCoord1;
    varying float vTime;

    void main() {
        vec3 vertexPosition = aVertexPosition;
        vTime = uTime;
      // set the varyings
        vTextureCoord0 = (texture0Matrix * vec4(aTextureCoord, 0., 1.)).xy;
        vTextureCoord1 = (texture1Matrix * vec4(aTextureCoord, 0., 1.)).xy;
        vVertexPosition = vertexPosition;
      
        vec2 center = vTextureCoord0 - .5;
      
        float dist = length(center);
      
        gl_Position = uPMatrix * uMVMatrix * vec4(vertexPosition, 1.0);
    }
</script>
<script id="fs">
    #ifdef GL_ES
    precision mediump float;
    #endif

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

    varying float vTime;
    uniform float uProgress;
    uniform vec2 uReso;
    uniform vec2 uMouse;
    
    // get our varyings
    varying vec3 vVertexPosition;
    varying vec2 vTextureCoord0;
    varying vec2 vTextureCoord1;

    // the uniform we declared inside our javascript

    // our texture sampler (default name, to use a different name please refer to the documentation)
    uniform sampler2D texture0;
    uniform sampler2D texture1;

    float N21(vec2 p) {
      return fract(sin(p.x*123.+p.y*3456.)*3524.);
    }

    vec2 N22(vec2 p) {
      return vec2(N21(p), N21(p+324.));
    }
    
    float DistLine(vec2 p, vec2 a, vec2 b){
      vec2 pa = p - a;
      vec2 ba = b - a;
      
      float t = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);
      
      return length(pa - ba * t);
    }
  
    vec2 GetPos(vec2 id, vec2 offs){
      vec2 n = N22(id + offs) * vTime * 2.0;
         
      return offs + sin(n) * 0.4;
    }
  
    float Line(vec2 p, vec2 a, vec2 b){
      float d = DistLine(p, a, b);
      float m = S(0.03, 0.01, d);
      float d2 = length(a - b);
      m *= S(1.2, .8, d2) * 0.5 + S(0.05, 0.03, abs(d2 - .75));
      return m;
    }
    
    float Layer(vec2 st){
        st *= 5.0;
      
        vec2 gv = fract(st) - 0.5;
        vec2 id = floor(st);

        vec2 p[9];
        int i = 0;
        
        for(float y = -1.0; y <= 1.0; y++){
          for(float x = -1.0; x <= 1.0; x++){
            if(0 == i) p[0] = GetPos(id, vec2(x,y));  
            if(1 == i) p[1] = GetPos(id, vec2(x,y)); 
            if(2 == i) p[2] = GetPos(id, vec2(x,y)); 
            if(3 == i) p[3] = GetPos(id, vec2(x,y)); 
            if(4 == i) p[4] = GetPos(id, vec2(x,y)); 
            if(5 == i) p[5] = GetPos(id, vec2(x,y)); 
            if(6 == i) p[6] = GetPos(id, vec2(x,y)); 
            if(7 == i) p[7] = GetPos(id, vec2(x,y)); 
            if(8 == i) p[8] = GetPos(id, vec2(x,y)); 
             
            i++;
          }
        }
      
        float m = 0.0;
        float t = vTime * 0.01;
        
        for(int i = 0; i < 9; i++){
          m += Line(gv, p[4], p[i]);
          
          vec2 j = (p[i] - gv) * 10.0;
          
          float sparkle = 1. / dot(j, j);
          
          m += sparkle * (sin(t + fract(p[i].x) * 10.) * 0.5 + 0.5);
        }
        
        m += Line(gv, p[1], p[3]);
        m += Line(gv, p[1], p[5]);
        m += Line(gv, p[7], p[3]);
        m += Line(gv, p[7], p[5]);
      
      return m;
    }
  
    void main(){
        vec2 st = (gl_FragCoord.xy - 0.5 * uReso) / min(uReso.y, uReso.y);
        vec2 mouse = (uMouse - 0.5 * uReso) / min(uReso.y, uReso.y);
              
        float m = 0.0;
        float t = vTime * 0.1;
      
        float s = sin(t);
        float c = cos(t);
        mat2 rot = mat2(c, -s, s, c);
      
        st *= rot;
        mouse *= rot;

         for(float i = 0.0; i <= 1.0; i += 1./4.){
           float z = fract(i + t);
           float size = mix(10., 0.5, z);
           float fade = S(0.0, 1.0, z) * S(1., .8, z);
           
           m += Layer(st * size + i * 20. - mouse) * fade;
         }
      
        vec3 base = sin(t * 20. * vec3(.345, .456, .657)) * .4 + .6;
        vec3 color = m * base;
      
        float gradient = st.y; 
      
        color -= gradient * base;
      
        gl_FragColor = vec4(color, 1.);
    }
</script>
              
            
!

CSS

              
                body {
  /* make the body fits our viewport */
  position: relative;
  width: 100%;
  height: 100vh;
  margin: 0;
  overflow: hidden;
  background-color: #1d1e22;
}

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

#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 => {
      TweenMax.to(this.plane.uniforms.mousepos.value, .7, {
        0: e.clientX,
        1: innerHeight - e.clientY
      });
    });

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

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

webgl.initPlane();

              
            
!
999px

Console